pymap.plugin
¶
- class pymap.plugin.PluginT¶
The plugin type variable.
alias of TypeVar(‘PluginT’)
- class pymap.plugin.Plugin(group, *, default=None)[source]¶
Plugin system, typically loaded from
importlib.metadata
entry points.>>> example: Plugin[Example] = Plugin('plugins.example') >>> example.add('two', ExampleTwo) >>> example.registered {'one': <class 'examples.ExampleOne'>, 'two': <class 'examples.ExampleTwo'>}
Note
Plugins registered from group entry points are lazy-loaded. This is to avoid cyclic imports.
- Parameters:
- property registered: Mapping[str, type[PluginT]]¶
A mapping of the registered plugins, keyed by name.
- property default: type[PluginT]¶
The default plugin implementation.
This property may also be assigned a new string value to change the name of the default plugin.
>>> example: Plugin[Example] = Plugin('plugins.example', default='one') >>> example.default <class 'examples.ExampleOne'> >>> example.default = 'two' >>> example.default <class 'examples.ExampleTwo'>
- Raises:
KeyError – The default plugin name was not registered.