plugins.manager module

Provides plugin loading/unloading functionality.

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

Bases: collections.OrderedDict

Stores plugins and their instances.

__init__(base_import='')[source]

Called when the class instance is initialized.

_create_plugin_info(plugin_name)[source]

Create a new plugins.info.PluginInfo instance.

Parameters:plugin_name (str) – Name of the plugin whose plugin info should be created.
Raises:PluginFileNotFoundError – Raised if the plugin’s main file wasn’t found.
Return type:PluginInfo
_create_plugin_instance(plugin_name)[source]

Create a new plugin instance.

Overwrite this method if you wish to use your own Plugin subclass.

Return type:Plugin
static _get_display_in_listing_from_info_file(info)[source]
static _get_public_convar_from_info_file(info)[source]

Check if a plugin’s base name is related to a module name.

Return type:bool
_remove_modules(plugin_name)[source]

Remove all modules from the plugin.

static _unload_auto_unload_instances(instances)[source]

Unload all given AutoUnload instances.

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])$')
base_import

Return the base import path for the manager.

Return type:str
loaded_plugins

Return a tuple containing all loaded plugins.

Returns:The tuple contains plugins.instance.Plugin instances.
Return type:tuple
plugins

Return a generator to iterate over all existing plugins.

Returns:The generator yields the plugin names.
Return type:generator
plugins_directory

Return the directory where the plugins are stored.

Return type:path.Path
class plugins.manager.ServerPluginManager

Bases: Boost.Python.instance

__init__()

Raises an exception This class cannot be instantiated from Python

loaded_plugins

Return a generator to iterate over all loaded server plugins.