"""Base of plugin systems."""
[docs]
class Plugin:
"""A class to register plugins.
Examples
--------
>>> example_plugin = Plugin()
>>> @example_plugin.register("xx")
def xxx():
pass
>>> print(example_plugin.plugins['xx'])
"""
def __init__(self):
self.plugins = {}
[docs]
def register(self, key):
"""Register a plugin.
Parameters
----------
key : str
Key of the plugin.
"""
def decorator(object):
self.plugins[key] = object
return object
return decorator
[docs]
def get_plugin(self, key):
return self.plugins[key]
def __add__(self, other):
self.plugins.update(other.plugins)
return self