grim/pyscovery

Cleaned the crap out of the docstrings
v1.1
2013-04-14, Gary Kramlich
987b20d04d43
Parents 6b554c649f4e
Children a9cf55d8b275
Cleaned the crap out of the docstrings
  • +28 -45
    pyscovery.py
  • --- a/pyscovery.py Sun Apr 14 02:59:18 2013 -0500
    +++ b/pyscovery.py Sun Apr 14 02:59:31 2013 -0500
    @@ -23,35 +23,8 @@
    I wrote this because none of the existing solutions fit my need of being able
    to logically group similar plugins in the filesystem.
    -
    -Say you have the following structure in your project:
    -
    - module/
    - __init__.py
    - plugin.py
    - plugins/
    - __init__.py
    - plugin1/
    - __init__.py
    - plugin2/
    - __init__.py
    - plugin3.py
    -
    -With pyscovery, the following code will find plugins 1, 2, and 3 for you:
    -
    - import pyscovery
    -
    - from plugin import Plugin
    -
    - pyscovery.add_module('plugins')
    - for plugin in pyscovery.find(Plugin, recurse=True):
    - print plugin
    -
    -Recursion in the filesystem is off by default, since that's the way people are
    -used to. If there is enough demand, I will make it the default.
    """
    -
    import fnmatch
    import importlib
    import inspect
    @@ -62,11 +35,13 @@
    MODULES = []
    -__version__ = '1.0'
    +__version__ = '1.1'
    def add_module(module):
    - """
    - Adds a module to search for plugins under
    + """Adds a module to search for plugins under
    +
    + :param module: The module to add to the search paths
    + :type module: string
    """
    global MODULES # pylint:disable-msg=W0602
    @@ -76,8 +51,10 @@
    def remove_module(module):
    - """
    - Removes a module to search for plugins under
    + """Removes a module to search for plugins under
    +
    + :param module: The module to remove
    + :type module: string
    """
    global MODULES # pylint:disable-msg=W0602
    @@ -87,31 +64,37 @@
    def get_modules():
    - """
    - Returns the list of all module to search under
    + """Returns the list of all module to search under
    +
    + :returns: A list of the current modules used for searching
    """
    return MODULES
    def clear_modules():
    - """
    - Clears all search modules
    + """Clears all search modules
    """
    MODULES[:] = []
    def find(cls, recurse, create, *args, **kwargs):
    - """
    - Find all plugins that are subclasses of cls in the current search paths
    + """Find all plugins that are subclasses of cls in the current search paths
    - If recurse is set to true, all files under a package will be inspected as
    - well.
    -
    - If create is set to true, instances of the classes will be returned instead
    - of the class itself. Note that *args and **kwargs will passed directly to
    - the classes __init__ method.
    + :param cls: The class whose subclasses to find.
    + :type cls: class
    + :param recurse: Whether or not to recurse into packages.
    + :type recurse: bool
    + :param create: return instances rather than just return their class.
    + :type create: bool
    + :param args: Additional arguments to pass to each constructor. Ignored if
    + create is False.
    + :type args: arguments
    + :param kwargs: Additional keyword arguements to pass to each constructor.
    + Ignored if create is False.
    + :type kwargs: kwargs
    + :returns: Generator of subclasses of cls
    """
    if not inspect.isclass(cls):
    @@ -182,5 +165,5 @@
    add_module(make_module(base))
    -__all__ = [add_module, remove_module, get_modules, clear_modules, find]
    +#__all__ = [add_module, remove_module, get_modules, clear_modules, find]