跳转到主要内容

轻量级Python插件系统,支持配置继承

项目描述

pluginmgr

PyPI PyPI Tests Codecov Language grade: Python

轻量级Python插件系统,支持配置继承

使用方法

有关完整示例,请参阅 https://github.com/20c/pluginmgr/tree/master/tests/pluginmgr_test

创建管理器,例如在模块 __init__.py 文件中

import pluginmgr

# this is the namespace string that import uses
namespace = 'pluginmgr_test.plugins'

# directories to look in, string or list of strings
searchpath = 'path/to/search/in'

# determines if this should create a blank loader to import through. This
# should be enabled if there isn't a real module path for the namespace and
# disabled for sharing the namespace with static modules
# default is False
create_loader = False

plugin = pluginmgr.PluginManager(namespace, searchpath, create_loader)

创建并注册插件,请注意文件名需要与注册名称相同

from pluginmgr_test import plugin


# register a plugin named mod0
@plugin.register('mod0')
class Mod0(pluginmgr.PluginBase):
    pass

查看包含所有注册插件的字典

from pluginmgr_test import plugin

# dict of all registered plugins
print(plugin.registry)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码发行版

pluginmgr-1.2.0.tar.gz (8.9 kB 查看哈希值)

上传时间:

构建发行版

pluginmgr-1.2.0-py3-none-any.whl (9.5 kB 查看哈希值)

上传时间: Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面