Plugin
Represents a plugin.
Attributes
list of
strA list of the added variables' names to the module.
Child plugins.
None
, HybridValueDictionary
of (str
, object
) itemsAn optionally weak value dictionary to store objects for assigning them to modules before loading them. If it would be set as empty, then it is set as None
instead.
None
, str
, callable
Internal slot used by the .entry_point
property.
None
, str
, callable
Internal slot used by the .exit_point
property.
bool
Internal slot used by the .extend_default_variables
property.
bool
The internal slot used for the .locked
property.
Parent plugins.
Snapshot difference if applicable. Defaults to None
.
Additional snapshots to extract from own.
The module specification for the plugin's module's import system related state.
int
The state of the plugin. Can be:
Respective name | Value |
---|---|
PLUGIN_STATE_UNDEFINED | 0 |
PLUGIN_STATE_LOADED | 1 |
PLUGIN_STATE_UNLOADED | 2 |
PLUGIN_STATE_UNSATISFIED | 3 |
Sub module plugins.
bool
Whether snapshot difference should be taken.
Properties
entry_point
Get-set-del descriptor for modifying the plugin's entry point.
Accepts and returns None
, str
or a callable
. If invalid type is given, raises TypeError
.
exit_point
Get-set-del descriptor for modifying the plugin's exit point.
Accepts and returns None
, str
or a callable
. If invalid type is given, raises TypeError
.
extend_default_variables
Get-set descriptor to define whether the plugin uses the loader's default variables or just it's own.
Accepts and returns bool
.
file_name
Returns the plugin's file's name.
Returns
file_name : str
locked
Get-set property to define whether the plugin should be picked up by the {}_all
methods of the plugin loader.
Accepts and returns bool
.
name
Returns the plugin's name.
Returns
name : str
path
Returns the plugin's name.
Returns
name : str
short_name
Returns the plugin's name's shortened version.
Returns
name : str
sort_key
Returns the plugin's sort key.
Returns
sort_key : tuple
of str
_module
Deprecated attribute of Plugin
.
Methods
(name, path, entry_point, exit_point, extend_default_variables, locked, take_snapshot_difference, default_variables)
__new__Creates a plugin with the given parameters. If a plugin already exists with the given name, returns that.
Parameter | Type | Description |
---|---|---|
name |
| The plugin's name (or import path). |
path |
| Path to the plugin file. |
entry_point |
| The entry point of the plugin. |
exit_point |
| The exit point of the plugin. |
extend_default_variables |
| Whether the plugin should use the loader's default variables or just it's own. |
locked |
| Whether the plugin should be picked up by the |
take_snapshot_difference |
| Whether snapshots should be taken before and after loading a plugin, and when the plugin is unloaded, the snapshot difference should be reverted. |
default_variables |
| An optionally weak value dictionary to store objects for assigning them to modules before loading them. If would be empty, is set as |
Returns
self : Plugin
Raises
ModuleNotFoundError
If the plugin was not found.
(plugin)
add_child_pluginRegisters a child plugin.
Parameter | Type | Description |
---|---|---|
plugin | The plugin to register. |
(...)
add_default_variablesAdds default variables to the plugin.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
**variables | Keyword Parameters | Variables to assigned to the plugin's module before it is loaded. |
Raises
ValueError
If a variable name is would be used, what is module
attribute.
(plugin)
add_parent_pluginRegisters a parent plugin.
Parameter | Type | Description |
---|---|---|
plugin | The plugin to register. |
(snapshots)
add_snapshot_extractionAdds snapshot extraction to the plugin.
Parameter | Type |
---|---|
snapshots |
|
(plugin)
add_sub_module_pluginRegisters a sub module plugin.
Parameter | Type | Description |
---|---|---|
plugin | The plugin to register. |
(plugins)
are_child_plugins_present_inReturns whether all the child plugins are present in the given plugins
.
Parameter | Type | Description |
---|---|---|
plugins |
| Already present plugins to check satisfaction form. |
Returns
are_child_plugins_present_in : bool
(plugins)
are_parent_plugins_present_inReturns whether all the parent plugins are present in the given plugins
.
Parameter | Type | Description |
---|---|---|
plugins |
| Already present plugins to check satisfaction form. |
Returns
are_parent_plugins_present_in : bool
(plugins)
are_sub_module_plugins_present_inReturns whether all the sub module plugins are present in the given plugins
.
Parameter | Type | Description |
---|---|---|
plugins |
| Already present plugins to check satisfaction form. |
Returns
are_sub_module_plugins_present_in : bool
()
clear_child_pluginsClears the child plugins of the plugin.
()
clear_default_variablesRemoves all the default variables of the plugin.
()
clear_parent_pluginsClears the parent plugins of the plugin.
()
clear_snapshot_extractionsClears the snapshot extractions of the plugin.
()
clear_sub_module_pluginsClears the sub module plugins of the plugin.
()
get_moduleReturns the module of the plugin.
Returns
module : None
, ModuleType
()
get_module_proxy()
is_directoryReturns whether the plugin is a directory.
Returns
is_directory : bool
()
is_loadedReturns whether the plugin is loaded.
Returns
is_loaded : bool
()
is_unsatisfiedReturns whether the plugin is unsatisfied.
Returns
is_unsatisfied : bool
()
iter_child_pluginsIterates over the child plugins.
This method is an iterable generator.
Yields
child_plugin : None
()
iter_loaded_plugins_in_directoryIterates over the loaded plugins directly under this one. This one must be a directory (so an __init__
file).
This method is an iterable generator.
Yields
plugin : Plugin
()
iter_parent_pluginsIterates over the parent plugins.
This method is an iterable generator.
Yields
parent_plugin : None
()
iter_snapshot_extractionsIterates over the snapshot extractions of the plugin.
This method is an iterable generator.
Yields
snapshots : list
of BaseSnapshotType
()
iter_sub_module_pluginsIterates over the sub module plugins.
This method is an iterable generator.
Yields
sub_module_plugin : None
(child_plugin)
remove_child_pluginRemoves the given plugin from the plugin's children.
Parameter | Type | Description |
---|---|---|
child_plugin | The plugin to remove. |
(...)
remove_default_variablesRemoves the mentioned default variables of the plugin.
If a variable with a specified name is not found, no error is raised.
Parameter | Type | Optional | Description |
---|---|---|---|
*names |
| Default variable names. |
(parent_plugin)
remove_parent_pluginRemoves the given plugin from the plugin's parents.
Parameter | Type | Description |
---|---|---|
parent_plugin | The plugin to remove. |
(sub_module_plugin)
remove_sub_module_pluginRemoves the given plugin from the plugin's sub modules.
Parameter | Type | Description |
---|---|---|
sub_module_plugin | The plugin to remove. |
()
_check_for_syntaxChecks the file's new syntax.
Used when reloading, to avoid unloading un-loadable files.
This method is blocking. Run it inside of an executor.
Returns
exception : PluginError
PluginError wrapping invalid syntax.
()
_loadLoads the module and returns it. If it is already loaded returns None
.
Returns
module : None
, ModuleType
Raises
ImportError
Circular imports.
RuntimeError
Module already imported.
BaseException
Any exception raised from the plugin file.
()
_load_moduleLoads the module and returns whether it was successfully loaded.
Returns
loaded : bool
Raises
BaseException
Any exception raised from the plugin file.
()
_unassign_variablesUnassigns the assigned variables to the respective module and clears ._added_variable_names
.
()
_unlinkRemoves the plugin's module from the loaded ones.
Should not be called on loaded plugins.
()
_unloadUnloads the module and returns it. If it is already unloaded returns None
.
Returns
module : None
, ModuleType
Raises
SyntaxError
If check_for_syntax
and the file's syntax is incorrect.
()
__getattr__Drops a rich attribute error.
()
__gt__Returns whether self is greater than other.
()
__hash__Returns the plugin's ._spec
's .origin
's hash.
()
__lt__Returns whether self is less than other.
()
__repr__Returns the plugin's representation.