pluginmanager.ModuleManager

class pluginmanager.ModuleManager(module_plugin_filters=None)[source]

ModuleManager manages the module plugin filter state and is responsible for both loading the modules from source code and collecting the plugins from each of the modules.

ModuleManager can also optionally manage modules explicitly through the use of the add/get/set loaded modules methods. The default implementation is hardwired to use the tracked loaded modules if no modules are passed into the collect_plugins method.

__init__(module_plugin_filters=None)[source]

module_plugin_filters are callable filters. Each filter must take in a list of plugins and a list of plugin names in the form of:

def my_module_plugin_filter(plugins: list, plugin_names: list):
    pass

module_plugin_filters should return a list of the plugins and may be either a single object or an iterable.

Methods

__init__([module_plugin_filters]) module_plugin_filters are callable filters. Each filter must take
add_module_plugin_filters(module_plugin_filters) Adds module_plugin_filters to the internal module filters.
add_to_loaded_modules(modules) Manually add in modules to be tracked by the module manager.
collect_plugins([modules]) Collects all the plugins from modules.
get_loaded_modules() Returns all modules loaded by this instance.
get_module_plugin_filters([filter_function]) Gets the internal module filters.
load_modules(filepaths) Loads the modules from their filepaths.
remove_module_plugin_filters(...) Removes module_plugin_filters from the internal module filters.
set_module_plugin_filters(module_plugin_filters) Sets the internal module filters to module_plugin_filters module_plugin_filters may be a single object or an iterable.
add_module_plugin_filters(module_plugin_filters)[source]

Adds module_plugin_filters to the internal module filters. May be a single object or an iterable.

Every module filters must be a callable and take in a list of plugins and their associated names.

add_to_loaded_modules(modules)[source]

Manually add in modules to be tracked by the module manager.

modules may be a single object or an iterable.

collect_plugins(modules=None)[source]

Collects all the plugins from modules. If modules is None, collects the plugins from the loaded modules.

All plugins are passed through the module filters, if any are any, and returned as a list.

get_loaded_modules()[source]

Returns all modules loaded by this instance.

get_module_plugin_filters(filter_function=None)[source]

Gets the internal module filters. Returns a list object.

If supplied, the filter_function should take in a single list argument and return back a list. filter_function is designed to given the option for a custom filter on the module filters.

load_modules(filepaths)[source]

Loads the modules from their filepaths. A filepath may be a directory filepath if there is an __init__.py file in the directory.

If a filepath errors, the exception will be caught and logged in the logger.

Returns a list of modules.

remove_module_plugin_filters(module_plugin_filters)[source]

Removes module_plugin_filters from the internal module filters. If the filters are not found in the internal representation, the function passes on silently.

module_plugin_filters may be a single object or an iterable.

set_module_plugin_filters(module_plugin_filters)[source]

Sets the internal module filters to module_plugin_filters module_plugin_filters may be a single object or an iterable.

Every module filters must be a callable and take in a list of plugins and their associated names.