mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 04:36:44 +08:00
🐛 improve sub plugin detect
This commit is contained in:
parent
571cdef826
commit
f48c61c2e0
@ -7,7 +7,6 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from functools import reduce
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from contextvars import Context, copy_context
|
from contextvars import Context, copy_context
|
||||||
|
@ -89,8 +89,20 @@ class PluginManager:
|
|||||||
if hasattr(_internal_space, internal_id):
|
if hasattr(_internal_space, internal_id):
|
||||||
raise RuntimeError("Plugin manager already exists!")
|
raise RuntimeError("Plugin manager already exists!")
|
||||||
|
|
||||||
prefix = sys._getframe(3).f_globals.get(
|
index = 2
|
||||||
"__name__") or _internal_space.__name__
|
prefix: str = _internal_space.__name__
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
frame = sys._getframe(index)
|
||||||
|
except ValueError:
|
||||||
|
break
|
||||||
|
# check if is called in plugin
|
||||||
|
if "__plugin_name__" not in frame.f_globals:
|
||||||
|
index += 1
|
||||||
|
continue
|
||||||
|
prefix = frame.f_globals.get("__name__", _internal_space.__name__)
|
||||||
|
break
|
||||||
|
|
||||||
if not prefix.startswith(_internal_space.__name__):
|
if not prefix.startswith(_internal_space.__name__):
|
||||||
prefix = _internal_space.__name__
|
prefix = _internal_space.__name__
|
||||||
module = _InternalModule(prefix, self)
|
module = _InternalModule(prefix, self)
|
||||||
|
Loading…
Reference in New Issue
Block a user