Giter VIP home page Giter VIP logo

presets's People

Contributors

bmcfee avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

beasteers

presets's Issues

Fix decorator call signatures

Currently, the function decorator fails to preserve the docstring and call signature of the wrapped function.

While full call signature preservation is impossible with dynamically adapting default parameters, we could at least trap and modify the docstring so as to not be completely opaque.

The decorator package should be useful here.

Feature Proposal: built-in way to inject Preset into sys.modules?

Nice package! I've been using something similar with Sacred and was wondering if I could use something similar to change a package's defaults. And then I stumbled across this!

So I'm thinking about changing the defaults of librosa program-wide, but seeing as I need to wrap it, I need to import everything through wherever I define the Preset.

This is only a minor inconvenience so it's not a big deal, but I was wondering if there would be a way to tap into python's import system to override it everywhere.

import librosa
from presets import patch_preset

def patch_preset(module):
    import sys
    sys.modules[module.__name__] = Preset(module)

patch_preset(librosa)

# testing
del librosa
import librosa
print(librosa) # it's a Patch
import librosa.display # ModuleNotFoundError: No module named 'librosa.display'; 'librosa' is not a package

It doesn't quite work because it breaks subsequent imports of submodules, which makes sense, so I think we'd have to extend Python's Module class (I believe I've seen it under ast? but the docs are lousy) so that it can still read a Patch as a module.

Anyways, I'm not saying that we have to do anything about this, but I thought it could be a cool/convenient feature.

Bonus: I wonder if we could use Python's Import Hooks to do something like this:

# __init__.py
from presets import librosa # overrides sys.modules
librosa.update(...)

# some_scripy.py
import librosa # Preset

not even sure if that's a good idea. but it's an idea ๐Ÿคทโ€โ™€๏ธ

I think awkward thing is that, if the Preset replacement is called after anywhere else imports the package, then they'd be using the original module reference. So maybe explicit is better.

propagate anonymous kwargs

Presets currently inspects the wrapped function to check for keyword arguments to be propagated. This fails when the wrapped function has a **kwargs, which causes presets to drop any anonymous keyword arguments.

This should be an easy fix.

Python 3.5 built-in module exception

In [7]: librosa = Preset(_librosa)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-f50f34fc9f9e> in <module>()
----> 1 librosa = Preset(_librosa)

/home/bmcfee/git/presets/presets/__init__.py in __init__(self, module, dispatch, defaults)
    132                         self._dispatch[value] = Preset(value,
    133                                                        dispatch=self._dispatch,
--> 134                                                        defaults=self._defaults)
    135 
    136                     setattr(self, attr, self._dispatch[value])

/home/bmcfee/git/presets/presets/__init__.py in __init__(self, module, dispatch, defaults)
    122             elif isinstance(value, types.ModuleType):
    123                 # test if this is a submodule of the current module
--> 124                 submodpath = inspect.getfile(value)
    125 
    126                 if os.path.commonprefix([modpath, submodpath]) == modpath:

/home/bmcfee/miniconda/envs/py35/lib/python3.5/inspect.py in getfile(object)
    604         if hasattr(object, '__file__'):
    605             return object.__file__
--> 606         raise TypeError('{!r} is a built-in module'.format(object))
    607     if isclass(object):
    608         if hasattr(object, '__module__'):

TypeError: <module 'sys' (built-in)> is a built-in module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.