Skip to content

Commit

Permalink
[melobot] Fix errors when loaded module try to read sys.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aicorein committed Oct 24, 2024
1 parent 037c4c1 commit ef795cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/melobot/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .typ import T

__version__ = "3.0.0rc9"
__version__ = "3.0.0rc10"


def _version_str_to_info(s: str) -> VersionInfo:
Expand Down
12 changes: 4 additions & 8 deletions src/melobot/plugin/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def _get_init_pyi_str(
imp_parts = list(parts1[len(parts2) :])
imp_parts[-1] = imp_parts[-1].rstrip(".py")

mod = Importer.import_mod(
share.__obj_module__, share_located.parent, sys_cache=False
)
mod = Importer.import_mod(share.__obj_module__, share_located.parent)
for k in dir(mod):
v = getattr(mod, k)
if v is share:
Expand Down Expand Up @@ -88,9 +86,7 @@ def _get_init_pyi_str(
if func.__name__.startswith("_"):
raise PluginError(f"导出函数 {func} 的名称不能以 _ 开头")

mod = Importer.import_mod(
func.__module__, func_located.parent, sys_cache=False
)
mod = Importer.import_mod(func.__module__, func_located.parent)
for k in dir(mod):
v = getattr(mod, k)
if v is func:
Expand Down Expand Up @@ -151,7 +147,7 @@ def run_init(*plugin_dirs: str | PathLike[str], load_depth: int = 1) -> None:

prefix = ".".join(p_dir.parts[-load_depth:])
p_load_mod_name = f"{prefix}.__plugin__"
p_load_mod = Importer.import_mod(p_load_mod_name, p_dir, sys_cache=False)
p_load_mod = Importer.import_mod(p_load_mod_name, p_dir)
for k in dir(p_load_mod):
v = getattr(p_load_mod, k)
if isinstance(v, type) and v is not Plugin and issubclass(v, Plugin):
Expand Down Expand Up @@ -244,6 +240,6 @@ def load(
prefix = ".".join(p_dir.parts[-load_depth:])
p_load_mod_name = f"{prefix}.__plugin__"

p_load_mod = Importer.import_mod(p_load_mod_name, p_dir, sys_cache=False)
p_load_mod = Importer.import_mod(p_load_mod_name, p_dir)
_plugin = self._build_plugin(p_name, p_load_mod)
return _plugin

0 comments on commit ef795cb

Please sign in to comment.