pluginmanager.PluginManager

class pluginmanager.PluginManager(unique_instances=True, instantiate_classes=True, plugins=None, blacklisted_plugins=None)[source]

PluginManager manages the plugin state. It can automatically instantiate classes and enforce uniqueness, which it does by default.

__init__(unique_instances=True, instantiate_classes=True, plugins=None, blacklisted_plugins=None)[source]

unique_instances determines if all plugins have to be unique. This will also ensure that no two instances of the same class are tracked internally.

instantiate_classes tracks to see if the class should automatically instantiate class objects that are passed in. plugins can be a single obj or iterable blacklisted plugins can be a single obj or iterable

Methods

__init__([unique_instances, ...]) unique_instances determines if all plugins have to be unique.
activate_plugins() helper method that attempts to activate plugins
add_blacklisted_plugins(plugins) add blacklisted plugins.
add_plugins(plugins) Adds plugins to the internal state.
deactivate_plugins() helper method that attempts to deactivate plugins.
get_blacklisted_plugins() gets blacklisted plugins tracked in the internal state
get_instances([filter_function]) Gets instances out of the internal state using the default filter supplied in filter_function.
get_plugins([filter_function]) Gets out the plugins from the internal state.
register_classes(classes) Register classes as plugins that are not subclassed from IPlugin.
remove_blacklisted_plugins(plugins) removes plugins from the blacklisted plugins.
remove_instance(instances) removes instances from the internal state.
remove_plugins(plugins) removes plugins from the internal state
set_blacklisted_plugins(plugins) sets blacklisted plugins.
set_plugins(plugins) sets plugins to the internal state. plugins may be a single object
activate_plugins()[source]

helper method that attempts to activate plugins checks to see if plugin has method call before calling it.

add_blacklisted_plugins(plugins)[source]

add blacklisted plugins. plugins may be a single object or iterable.

add_plugins(plugins)[source]

Adds plugins to the internal state. plugins may be a single object or an iterable.

If instantiate_classes is True and the plugins have class instances in them, attempts to instatiate the classes.

If unique_instances is True and duplicate instances are passed in, this method will not track the new instances internally.

deactivate_plugins()[source]

helper method that attempts to deactivate plugins. checks to see if plugin has method call before calling it.

get_blacklisted_plugins()[source]

gets blacklisted plugins tracked in the internal state Returns a list object.

get_instances(filter_function=<class 'pluginmanager.iplugin.IPlugin'>)[source]

Gets instances out of the internal state using the default filter supplied in filter_function. By default, it is the class IPlugin.

Can optionally pass in a list or tuple of classes in for filter_function which will accomplish the same goal.

lastly, a callable can be passed in, however it is up to the user to determine if the objects are instances or not.

get_plugins(filter_function=None)[source]

Gets out the plugins from the internal state. Returns a list object. If the optional filter_function is supplied, applies the filter function to the arguments before returning them. Filters should be callable and take a list argument of plugins.

register_classes(classes)[source]

Register classes as plugins that are not subclassed from IPlugin. classes may be a single object or an iterable.

remove_blacklisted_plugins(plugins)[source]

removes plugins from the blacklisted plugins. plugins may be a single object or iterable.

remove_instance(instances)[source]

removes instances from the internal state.

Note that this method is syntatic sugar for the remove_plugins acts as a passthrough for that function. instances may be a single object or an iterable

remove_plugins(plugins)[source]

removes plugins from the internal state

plugins may be a single object or an iterable.

set_blacklisted_plugins(plugins)[source]

sets blacklisted plugins. plugins may be a single object or iterable.

set_plugins(plugins)[source]

sets plugins to the internal state. plugins may be a single object or an iterable.

If instatntiate_classes is True and the plugins have class instances in them, attempts to instatiate the classes.

If unique_instances is True and duplicate instances are passed in, this method will not track the new instances internally.