🐛 improve sub plugin detect

This commit is contained in:
yanyongyu 2021-07-29 17:31:28 +08:00
parent 571cdef826
commit f48c61c2e0
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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)