PluginManager class.
This class manages the loading and registration of plugins.
| Method | __delattr__ |
Delete the plugin by name. |
| Method | __getattr__ |
Get the instance or plugin by name. |
| Method | call |
Call a service plugin endpoint. |
| Method | configure |
Configure the specified plugins. |
| Method | dependency |
Get the dependency graph of the plugins and other classes. |
| Method | dependency |
Get the provided instances that are not plugins, and who is using them. |
| Method | get |
Get the names of the plugins that have the given tag. |
| Method | has |
Check if a plugin instance with the given name exists. |
| Method | is |
Check if a provided instance with the given name is a function provided by the @provide decorator. |
| Method | load |
Load plugins from the specified directory. |
| Method | pause |
Pause the specified plugins. |
| Method | provide |
Provide a instance of any non-plugin class to be injected as a dependency. This can be used to provide instances of classes that are not plugins, but are required as dependencies by plugins or other classes. |
| Method | resolve |
Resolve the dependencies of all plugins and other classes. This is called before starting the plugins to ensure that all dependencies are resolved and the plugin instances have all the required attributes injected. |
| Method | restart |
Restart the specified plugins. |
| Method | setup |
Check if all required dependencies are resolved. This can be called after the resolvePlugins method to check if there are any unresolved dependencies that are required and not provided. This is a separate step because sometimes, we might want to resolve the plugins first and then check for missing dependencies, so that we can provide the missing dependencies before starting the plugins... |
| Method | start |
Start the specified plugins. |
| Method | stop |
Shutdown the specified plugins. Plugins are stopped in reverse order of their priority. |
| Method | unload |
Unload a plugin by name. If running, stop it first. |
| Method | unpause |
Unpause the specified plugins. Plugins are unpaused in reverse order of their priority. |
| Method | unresolve |
Unresolve the plugins. This is called when plugins are unloaded to clean up the injected dependencies and set the plugin instances to None. |
| Method | validate |
Validate the specified plugins. |
| Class Variable | plugins |
Dictionary to hold the loaded plugins. The keys are the plugin names, the values are PluginInfo objects. |
| Class Variable | unloaded |
List to hold the names of the plugins that were not loaded due to filtering. |
| Method | _check |
Check if a plugin matches the specified tags and excluded tags. |
| Method | _transition |
Transition the state of a plugin. This will happen in the order of the plugin priority, but can be reversed if necessary (e.g. for stopping plugins, which should happen in reverse order of starting). |
| Class Variable | _plugin |
Dictionary for the mapping between instance attribute names and the instances itself. |
| Class Variable | _provided |
Dictionary to hold instances that are extra provided class instances. The keys are the names of the instances, ie. the module name, the values are the instances themselves. |
| Class Variable | _tags |
Dictionary to map tags to plugin names and instances for easier lookup by tag. |
Get the instance or plugin by name.
| Parameters | |
name:str | The name of the instance orplugin. |
| Returns | |
Any | The instance or plugin module, or None if not found. |
Call a service plugin endpoint.
| Parameters | |
endpoint:str | The endpoint of the plugin to call. This is used to identify the method to call on the plugin instance. The endpoint must be defined in the plugin class using the endpoint decorator. |
tag:str | The tag of the plugin to call. This is used to identify the plugin to call. If multiple plugins with the same tag are found, the one with the highest priority is called. |
*args:Any | Positional arguments to pass to the endpoint method. |
**kwargs:Any | Keyword arguments to pass to the endpoint method. |
| Returns | |
Any | The result of the endpoint method call. |
| Raises | |
ValueError | If no plugin with the given tag and endpoint is found, or if multiple plugins with the same tag and endpoint are found. |
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None, *args: Any, **kwargs: Any):
¶
Configure the specified plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to configure. Configure all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
*args:Any | Positional arguments to pass to the configure method. |
**kwargs:Any | Keyword arguments to pass to the configure method. |
| Raises | |
KeyError | If a specified plugin is not found. |
Get the dependency graph of the plugins and other classes.
| Parameters | |
name:str | None | Optional name of the plugin to get the dependency graph for. If None, returns the entire graph. |
| Returns | |
dict[ | The dependency graph as a dictionary where the keys are the class names and the values are lists of dependencies (module name, optional instance name). |
Get the provided instances that are not plugins, and who is using them.
| Returns | |
dict[ |
|
str | list[ str], byPriority: bool = False) -> list[ tuple[ str, Any]]:
¶
Get the names of the plugins that have the given tag.
| Parameters | |
tags:str | list[ | The tag or tags to search for. |
bybool | Whether to sort the plugins by their priority. If True, the plugins are returned sorted by their priority, with the highest priority first (0 = highest priority). |
| Returns | |
list[ | A list of plugin names that have the given tag. |
Check if a plugin instance with the given name exists.
| Parameters | |
instancestr | The name of the plugin instance to check. |
| Returns | |
bool | True if a plugin instance with the given name exists, False otherwise. |
Check if a provided instance with the given name is a function provided by the @provide decorator.
| Parameters | |
name:str | The name of the provided instance to check. |
| Returns | |
bool | True if a provided instance with the given name is a function provided by the @provide decorator, False otherwise. |
str, packagePath: str, pluginFilter: Callable[ [ str], bool] | None = None, replace: bool = False, *args: Any, **kwargs: Any):
¶
Load plugins from the specified directory.
Plugins are initialized after loading according to their priority.
| Parameters | |
directory:str | The directory from which to load plugins. |
packagestr | The package path to use for the plugins. |
pluginCallable[ | A callback function to filter plugins. The function should take a plugin name as input and return True if the plugin should be loaded, False otherwise. |
replace:bool | Whether to replace already loaded plugins. |
*args:Any | Positional arguments to pass to the plugin init methods. |
**kwargs:Any | Keyword arguments to pass to the plugin init methods. |
| Raises | |
NotADirectoryError | If the directory does not exist. |
KeyError | If a plugin is already loaded. |
PluginConfigurationError | If the plugin is not valid. |
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Pause the specified plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to pause. Pause all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
| Raises | |
KeyError | If a specified plugin is not found. |
Provide a instance of any non-plugin class to be injected as a dependency. This can be used to provide instances of classes that are not plugins, but are required as dependencies by plugins or other classes.
The provided instances are injected into the dependent classes during the dependency resolution phase, just like plugin instances.
The provided instances are not managed by the plugin manager, so they are not started, stopped, etc. They are simply injected as attributes into the dependent classes.
| Parameters | |
modulestr | The name of the module that provides the instance. This is used to identify the instance in the dependency graph and to inject it into the dependent classes. |
instance:Any | The instance to provide. This can be any instance of any class, as long as it is not a plugin class (i.e. it does not have the @pluginClass decorator). |
str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Resolve the dependencies of all plugins and other classes. This is called before starting the plugins to ensure that all dependencies are resolved and the plugin instances have all the required attributes injected.
| Parameters | |
tags:str | list[ | The tags of the plugins to match for dependency resolution. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude from dependency resolution. Exclude none |
| Raises | |
DependencyError | If a required dependency cannot be resolved. |
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Restart the specified plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to restart. Restart all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
| Raises | |
KeyError | If a specified plugin is not found. |
Check if all required dependencies are resolved. This can be called after the resolvePlugins method to check if there are any unresolved dependencies that are required and not provided. This is a separate step because sometimes, we might want to resolve the plugins first and then check for missing dependencies, so that we can provide the missing dependencies before starting the plugins. For example, we might want to provide some extra instances that are not plugins, but are required by some plugins or other classes. In this case, we can call resolvePlugins first, then setupFinished to see if there are any missing dependencies, then provide the missing instances, and then start the plugins.
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Start the specified plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to start. Start all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
| Raises | |
KeyError | If a specified plugin is not found. |
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Shutdown the specified plugins. Plugins are stopped in reverse order of their priority.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to shutdown. Shutdown all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
| Raises | |
KeyError | If a specified plugin is not found. |
Unload a plugin by name. If running, stop it first.
| Parameters | |
pluginlist[ | The name(s) of the plugin(s) to remove. |
| Raises | |
KeyError | If the plugin is not found. |
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None):
¶
Unpause the specified plugins. Plugins are unpaused in reverse order of their priority.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to unpause. Unpause all if None. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
| Raises | |
KeyError | If a specified plugin is not found. |
Unresolve the plugins. This is called when plugins are unloaded to clean up the injected dependencies and set the plugin instances to None.
str | list[ str] | None = None, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None, *args: Any, **kwargs: Any):
¶
Validate the specified plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to validate. |
tags:str | list[ | The tags of the plugins to match. Match all if None. |
excludedstr | list[ | The tags of the plugins to exclude. Exclude none if None. |
*args:Any | Positional arguments to pass to the validate method. |
**kwargs:Any | Keyword arguments to pass to the validate method. |
| Raises | |
KeyError | If a specified plugin is not found. |
Dictionary to hold the loaded plugins. The keys are the plugin names, the values are PluginInfo objects.
str, tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None) -> bool:
¶
Check if a plugin matches the specified tags and excluded tags.
| Parameters | |
pluginstr | The name of the plugin to check. |
tags:str | list[ | The tags to match. Match all if None. |
excludedstr | list[ | The tags to exclude. Exclude none if None. |
| Returns | |
bool | True if the plugin matches the tags and excluded tags, False otherwise. |
str | list[ str] | None, action: Callable[ [ PluginInfo], None], tags: str | list[ str] | None = None, excludedTags: str | list[ str] | None = None, reverse: bool = False):
¶
Transition the state of a plugin. This will happen in the order of the plugin priority, but can be reversed if necessary (e.g. for stopping plugins, which should happen in reverse order of starting).
Plugins can be filtered by name, pattern and/or tags. If no filters are provided, the action will be applied to all plugins.
| Parameters | |
pluginstr | list[ | The name(s) of the plugin(s) to transition. If None, all plugins are transitioned. If a string is provided, it is treated as a pattern to match plugin names. |
action:Callable[ | The action to perform during the state transition. |
tags:str | list[ | The tags to match for the plugins to transition. If None, all plugins are transitioned. |
excludedstr | list[ | The tags to exclude from the plugins to transition. If None, no plugins are excluded. |
reverse:bool | Whether to process the plugins in reverse order. |
Dictionary to hold instances that are extra provided class instances. The keys are the names of the instances, ie. the module name, the values are the instances themselves.