用于高度可重用应用程序及其组件的基于插件的微框架
groundwork的Python项目详细描述
groundwork是一个基于python的微框架,用于高度可重用的应用程序及其组件。
它的功能是基于可交换的、文档化的和经过测试的插件和模式。
它被设计为支持任何类型的python应用程序:命令行脚本、桌面程序或web应用程序。
groundwork允许应用程序在运行时激活和停用插件,并控制动态插件 插件状态、使用的信号、注册的命令等行为。
插件的功能可以很容易地通过使用可继承的模式来扩展。 因此,groundwork为开发人员提供了节省时间的解决方案:
- Command line interfaces
- Loose inter-plugin communication via signals and receivers
- Shared objects to provide and request content to and from other plugins
- Static and dynamic documents for an overall documentation
示例
下面的代码定义了一个支持命令行的插件,并创建了一个激活 插件:
from groundwork import App from groundwork.patterns import GwCommandsPattern class MyPlugin(GwCommandsPattern): def _init_(self, *args, **kwargs): self.name = "My Plugin" super().__init__(*args, **kwargs) def activate(self): self.commands.register(command='hello', description='prints "hello world"', function=self.greetings) def greetings(self): print("Hello world") if __name__ == "__main__": my_app = App(plugins=[MyPlugin]) # Creates app and registers MyPlugin my_app.plugins.activate(["My Plugin"]) # Initialise and activates 'My Plugin' my_app.commands.start_cli() # Starts the command line interface
现在可以在命令行上使用以下命令:
python my_app.py hello # Prints 'Hello world' python my_app.py # Prints a list of available commands python my_app.yp hello -h # Prints syntax help for the hello command