:
.
, , , :
plugins = some_package.plugin_for_your_app
another_plugin_module
:
plugins = [importlib.import_module(name) for name in config.get("plugins")]
: command name -> function:
commands = {name: func
for plugin in plugins
for name, func in plugin.get_commands().items()}
get_commands() , - , get_commands() .
, some_plugin.py ( ):
def f(a, b):
return a + b
def get_commands():
return {"add": f, "multiply": lambda x,y: x*y}
It defines two teams add, multiply.
source
share