plugin_system.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:shanghai 作者: chireiden 项目源码 文件源码
def __init__(self, namespace: str, is_core: bool = False) -> None:
        # TODO add search base paths parameter
        if not namespace.isidentifier():
            raise ValueError("Invalid plugin namespace."
                             f" {namespace!r} contains invalid symbol(s).")
        if keyword.iskeyword(namespace):
            raise ValueError("Invalid plugin namespace."
                             f" {namespace!r} is a built-in keyword.")

        self.namespace = namespace
        if f'{__package__}.{namespace}' in sys.modules:
            raise RuntimeError(f"Expected '{__package__}.{namespace}' in `sys.modules` to be unset"
                               " but it was not")
        setattr(sys.modules[__package__], namespace, self)
        sys.modules[f'{__package__}.{namespace}'] = self

        if is_core:
            # just search in one single path
            self.plugin_search_paths = [pathlib.Path(self._shanghai_base_path, namespace)]
        else:
            self.plugin_search_paths = [pathlib.Path(base_path, namespace)
                                        for base_path in self.PLUGIN_SEARCH_BASE_PATHS]

        self.plugin_registry = {}
        self.logger = get_default_logger()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号