mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
🐛 fix parent plugin detect error
This commit is contained in:
parent
c2c3d5ef4b
commit
44e5182322
@ -150,9 +150,11 @@ class PluginLoader(SourceFileLoader):
|
|||||||
if self.loaded:
|
if self.loaded:
|
||||||
return
|
return
|
||||||
|
|
||||||
plugin = _new_plugin(self.name, module)
|
plugin = _new_plugin(self.name, module, self.manager)
|
||||||
parent_plugin = _current_plugin.get()
|
parent_plugin = _current_plugin.get()
|
||||||
if parent_plugin:
|
if parent_plugin and _managers.index(parent_plugin.manager) < _managers.index(
|
||||||
|
self.manager
|
||||||
|
):
|
||||||
plugin.parent_plugin = parent_plugin
|
plugin.parent_plugin = parent_plugin
|
||||||
parent_plugin.sub_plugins.add(plugin)
|
parent_plugin.sub_plugins.add(plugin)
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from dataclasses import field, dataclass
|
from dataclasses import field, dataclass
|
||||||
from typing import Set, Dict, Type, Optional
|
from typing import TYPE_CHECKING, Set, Dict, Type, Optional
|
||||||
|
|
||||||
from .export import Export
|
from .export import Export
|
||||||
from nonebot.matcher import Matcher
|
from nonebot.matcher import Matcher
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .manager import PluginManager
|
||||||
|
|
||||||
plugins: Dict[str, "Plugin"] = {}
|
plugins: Dict[str, "Plugin"] = {}
|
||||||
"""
|
"""
|
||||||
:类型: ``Dict[str, Plugin]``
|
:类型: ``Dict[str, Plugin]``
|
||||||
@ -31,6 +34,11 @@ class Plugin(object):
|
|||||||
- **类型**: ``str``
|
- **类型**: ``str``
|
||||||
- **说明**: 点分割模块路径
|
- **说明**: 点分割模块路径
|
||||||
"""
|
"""
|
||||||
|
manager: "PluginManager"
|
||||||
|
"""
|
||||||
|
- **类型**: ``PluginManager``
|
||||||
|
- **说明**: 导入该插件的插件管理器
|
||||||
|
"""
|
||||||
export: Export = field(default_factory=Export)
|
export: Export = field(default_factory=Export)
|
||||||
"""
|
"""
|
||||||
- **类型**: ``Export``
|
- **类型**: ``Export``
|
||||||
@ -83,10 +91,10 @@ def get_loaded_plugins() -> Set[Plugin]:
|
|||||||
return set(plugins.values())
|
return set(plugins.values())
|
||||||
|
|
||||||
|
|
||||||
def _new_plugin(fullname: str, module: ModuleType) -> Plugin:
|
def _new_plugin(fullname: str, module: ModuleType, manager: "PluginManager") -> Plugin:
|
||||||
name = fullname.rsplit(".", 1)[-1] if "." in fullname else fullname
|
name = fullname.rsplit(".", 1)[-1] if "." in fullname else fullname
|
||||||
if name in plugins:
|
if name in plugins:
|
||||||
raise RuntimeError("Plugin already exists! Check your plugin name.")
|
raise RuntimeError("Plugin already exists! Check your plugin name.")
|
||||||
plugin = Plugin(name, module, fullname)
|
plugin = Plugin(name, module, fullname, manager)
|
||||||
plugins[name] = plugin
|
plugins[name] = plugin
|
||||||
return plugin
|
return plugin
|
||||||
|
Loading…
Reference in New Issue
Block a user