Package: pluginmanager
.. pluginmanager documentation master file, created bysphinx-quickstart on Wed Dec  9 22:32:56 2015.You can adapt this file completely to your liking, but it should at leastcontain the root `toctree` directive... testsetup:: quickstartimport osfrom pluginmanager.tests.compat import tempfiletempdirectory = tempfile.TemporaryDirectory()plugin_directory_path = tempdirectory.namepath = os.path.join(tempdirectory.name, 'test.py')with open(path, 'w+') as f:f.write('from pluginmanager import IPlugin\nclass Test(IPlugin):\n    pass')pluginmanager=============|Build Status| |Coverage Status| |Code Climate|python plugin management, simplified.`Documentation <http://pluginmanager.readthedocs.org/en/latest/>`_`Source Code <https://github.com/benhoff/pluginmanager>`_Library under development. Contains rough edges/unfinished functionality. API subject to changes.Installation------------::pip install pluginmanager-or- ::pip install git+https://github.com/benhoff/pluginmanager.gitQuickstart----------::from pluginmanager import PluginInterfaceplugin_interface = PluginInterface()plugin_interface.set_plugin_directories(plugin_directory_path)plugin_interface.collect_plugins()plugins = plugin_interface.get_instances()Custom Plugins--------------The quickstart will only work if you subclass `IPlugin` for your custom plugins.::import pluginmanagerclass MyCustomPlugin(pluginmanager.IPlugin):def __init__(self):self.name = 'custom_name'super().__init__()Or register your class as subclass of IPlugin.::import pluginmanagerpluginmanager.IPlugin.register(YourClassHere)Add Plugins Manually--------------------Add classes.::import pluginmanagerclass CustomClass(pluginmanager.IPlugin):passplugin_interface = pluginmanager.PluginInterface()plugin_interface.add_plugins(CustomClass)plugins = plugin_interface.get_instances()Alternatively, add instances.::import pluginmanagerclass CustomClass(pluginmanager.IPlugin):passcustom_class_instance = CustomClass()plugin_interface = pluginmanager.PluginInterface()plugin_interface.add_plugins(custom_class_instance)plugins = plugin_interface.get_instances()pluginmanager is defaulted to automatically instantiate unique instances. Disable automatic instantiation.::import pluginmanagerplugin_interface = pluginmanager.PluginInterface()plugin_manager = plugin_interface.plugin_managerplugin_manager.instantiate_classes = FalseDisable uniqueness (Only one instance of class per pluginmanager)::import pluginmanagerplugin_interface = pluginmanager.PluginInterface()plugin_manager = plugin_interface.plugin_managerplugin_manager.unique_instances = FalseFilter Instances----------------Pass in a class to get back just the instances of a class::import pluginmanagerclass MyPluginClass(pluginmanager.IPlugin):passplugin_interface = pluginmanager.PluginInterface()plugin_interface.add_plugins(MyPluginClass)all_instances_of_class = plugin_interface.get_instances(MyPluginClass)Alternatively, create and pass in your own custom filters. Either make a class based filter::# create a custom plugin classclass Plugin(pluginmanager.IPlugin):def __init__(self, name):self.name = name# create a custom filterclass NameFilter(object):def __init__(self, name):self.stored_name = namedef __call__(self, plugins):result = []for plugin in plugins:if plugin.name == self.stored_name:result.append(plugin)return result# create an instance of our custom filtermypluginclass_name_filter = NameFilter('good plugin')plugin_interface = pluginmanager.PluginInterface()plugin_interface.add_plugins([Plugin('good plugin'),Plugin('bad plugin')])filtered_plugins = plugin_interface.get_instances(mypluginclass_name_filter)Or make a function based filter::# create a custom plugin classclass Plugin(pluginmanager.IPlugin):def __init__(self, name):self.name = name# create a function based filterdef custom_filter(plugins):result = []for plugin in plugins:if plugin.name == 'good plugin':result.append(plugin)return resultplugin_interface = pluginmanager.PluginInterface()plugin_interface.add_plugins([Plugin('good plugin'),Plugin('bad plugin')])filtered_plugins = plugin_interface.get_instances(mypluginclass_name_filter)Class Overview--------------.. currentmodule:: pluginmanager.. autosummary:::toctree: stubsDirectoryManagerFileManagerModuleManagerPluginManagerPluginInterfaceIndices and tables==================* :ref:`genindex`* :ref:`modindex`* :ref:`search`.. |Build Status| image:: https://travis-ci.org/benhoff/pluginmanager.svg?branch=master:target: https://travis-ci.org/benhoff/pluginmanager.. |Coverage Status| image:: https://coveralls.io/repos/benhoff/pluginmanager/badge.svg?branch=master&service=github:target: https://coveralls.io/github/benhoff/pluginmanager?branch=master.. |Code Climate| image:: https://codeclimate.com/github/benhoff/pluginmanager/badges/gpa.svg:target: https://codeclimate.com/github/benhoff/pluginmanager.. testcleanup::tempdirectory.cleanup()