forked from deepmodeling/dpdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
41 lines (30 loc) · 799 Bytes
/
plugin.py
File metadata and controls
41 lines (30 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Base of plugin systems."""
from __future__ import annotations
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 = {}
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
def get_plugin(self, key):
return self.plugins[key]
def __add__(self, other):
self.plugins.update(other.plugins)
return self