plugins.manager module

Provides plugin loading/unloading functionality.

class plugins.manager.PluginManager(base_import='')[source]

Bases: OrderedDict

Stores plugins and their instances.

__init__(base_import='')[source]

Called when the class instance is initialized.

get_plugin_directory(plugin_name)[source]

Return the directory of the given plugin.

Return type:

path.Path

get_plugin_file_path(plugin_name)[source]

Return the path to the plugin’s main file.

Parameters:

plugin_name (str) – Name of the plugin.

Return type:

path.Path

get_plugin_info(plugin_name)[source]

Return information about the given plugin.

Parameters:

plugin_name (str) – The plugin to check. You can pass __name__ from one of your plugin files to retrieve its own plugin instance.

Return type:

PluginInfo

get_plugin_instance(plugin_name)[source]

Return a plugin’s instance, if it is loaded.

Parameters:

plugin_name (str) – The plugin to check. You can pass __name__ from one of your plugin files to retrieve its own plugin instance.

Return type:

Plugin

get_plugin_name(plugin_name)[source]

Return the plugin’s name.

Parameters:

plugin_name (str) – The plugin’s real name (will be passed through) or the __name__ variable of one of the plugin’s files.

Return type:

str

is_loaded(plugin_name)[source]

Return whether or not a plugin is loaded.

Parameters:

plugin_name (str) – The plugin to check.

Return type:

bool

is_valid_plugin_name(plugin_name)[source]

Return whether or not the given plugin name is valid.

Parameters:

plugin_name (str) – Name to check.

Return type:

bool

load(plugin_name)[source]

Load a plugin by name.

Parameters:

plugin_name (str) – Name of the plugin to load.

Raises:
  • InvalidPluginName – Raised if the given plugin name is invalid.

  • PluginAlreadyLoaded – Raised if the plugin was already loaded.

  • PluginFileNotFoundError – Raised if the plugin’s main file wasn’t found.

  • PluginHasBuiltInName – Raised if the plugin has the name of a built-in module.

  • Exception – Any other exceptions raised by the plugin during the load process.

Return type:

Plugin

plugin_exists(plugin_name)[source]

Return whether of not a plugin exists.

Parameters:

plugin_name (str) – The plugin to check.

Return type:

bool

reload(plugin_name)[source]

Reload a plugin by name.

Parameters:

plugin_name (str) – Name of the plugin to reload.

Raises:
  • PluginNotLoaded – Raised if the plugin is not loaded.

  • InvalidPluginName – Raised if the given plugin name is invalid.

  • PluginFileNotFoundError – Raised if the plugin’s main file wasn’t found.

  • PluginHasBuiltInName – Raised if the plugin has the name of a built-in module.

  • Exception – Any other exceptions raised by the plugin during the load process.

Return type:

Plugin

unload(plugin_name)[source]

Unload a plugin by name.

Parameters:

plugin_name (str) – Name of the plugin to unload.

Raises:

PluginNotLoaded – Raised if the plugin is not loaded.

RE_VALID_PLUGIN = re.compile('^([A-Za-z][A-Za-z0-9_]*[A-Za-z0-9])$')
property base_import

Return the base import path for the manager.

Return type:

str

property loaded_plugins

Return a tuple containing all loaded plugins.

Returns:

The tuple contains plugins.instance.Plugin instances.

Return type:

tuple

property plugins

Return a generator to iterate over all existing plugins.

Returns:

The generator yields the plugin names.

Return type:

generator

property plugins_directory

Return the directory where the plugins are stored.

Return type:

path.Path

class plugins.manager.ServerPluginManager

Bases: instance

__init__()

Raises an exception This class cannot be instantiated from Python

property loaded_plugins

Return a generator to iterate over all loaded server plugins.