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()
评论列表
文章目录