mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-15 16:47:42 +00:00
🐛 fix sub plugin relative import
This commit is contained in:
parent
247456df56
commit
9bbadddfa9
@ -35,9 +35,8 @@ class _NamespaceModule(ModuleType):
|
|||||||
class _InternalModule(ModuleType):
|
class _InternalModule(ModuleType):
|
||||||
"""Internal module for each plugin manager."""
|
"""Internal module for each plugin manager."""
|
||||||
|
|
||||||
def __init__(self, plugin_manager: "PluginManager"):
|
def __init__(self, prefix: str, plugin_manager: "PluginManager"):
|
||||||
super().__init__(
|
super().__init__(f"{prefix}.{plugin_manager.internal_id}")
|
||||||
f"{_internal_space.__name__}.{plugin_manager.internal_id}")
|
|
||||||
self.__plugin_manager__ = plugin_manager
|
self.__plugin_manager__ = plugin_manager
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -88,7 +87,12 @@ class PluginManager:
|
|||||||
def _setup_internal_module(self, internal_id: str) -> ModuleType:
|
def _setup_internal_module(self, internal_id: str) -> ModuleType:
|
||||||
if hasattr(_internal_space, internal_id):
|
if hasattr(_internal_space, internal_id):
|
||||||
raise RuntimeError("Plugin manager already exists!")
|
raise RuntimeError("Plugin manager already exists!")
|
||||||
module = _InternalModule(self)
|
|
||||||
|
prefix = sys._getframe(2).f_globals.get(
|
||||||
|
"__name__") or _internal_space.__name__
|
||||||
|
if not prefix.startswith(_internal_space.__name__):
|
||||||
|
prefix = _internal_space.__name__
|
||||||
|
module = _InternalModule(prefix, self)
|
||||||
sys.modules[module.__name__] = module
|
sys.modules[module.__name__] = module
|
||||||
setattr(_internal_space, internal_id, module)
|
setattr(_internal_space, internal_id, module)
|
||||||
return module
|
return module
|
||||||
|
Loading…
x
Reference in New Issue
Block a user