Skip to content

Commit

Permalink
🐛 fix plugin's submod import
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Dec 13, 2024
1 parent 529d26f commit c0aaa65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion arclet/entari/plugin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
from types import ModuleType
from typing import TYPE_CHECKING, Any, Callable, TypeVar, overload
from weakref import finalize, proxy
from weakref import ProxyType, finalize, proxy

from arclet.letoderea import BaseAuxiliary, Provider, ProviderFactory, Publisher, StepOut, Subscriber, es
from arclet.letoderea.publisher import Publishable
Expand Down Expand Up @@ -202,6 +202,8 @@ def dispose(self):
sys.modules.pop(self.module.__name__, None)
delattr(self.module, "__plugin__")
for member in self.module.__dict__.values():
if isinstance(member, ProxyType):
continue
if isinstance(member, Subscriber) and not hasattr(member, "__keeping__"):
member.dispose()
if self.subplugins:
Expand Down
6 changes: 5 additions & 1 deletion arclet/entari/plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def source_to_code(self, data, path, *, _optimize=-1): # type: ignore
new = ast.parse(
f"__mod = __entari_import__({body.module!r}, {name!r});"
+ ";".join(
f"{alias.asname or alias.name} = __getattr_or_import__(__mod, {alias.name!r})"
f"{alias.asname or alias.name} = "
f"__getattr_or_import__(__mod, {alias.name!r}, "
f"__mod.__name__ in __plugin_service__.plugins)"
for alias in body.names
)
+ ";del __mod"
Expand Down Expand Up @@ -231,6 +233,7 @@ def exec_module(self, module: ModuleType, config: Optional[dict[str, str]] = Non
setattr(module, "__plugin__", plugin)
setattr(module, "__entari_import__", __entari_import__)
setattr(module, "__getattr_or_import__", getattr_or_import)
setattr(module, "__plugin_service__", plugin_service)

# enter plugin context
with _current_plugin.use(plugin):
Expand All @@ -242,6 +245,7 @@ def exec_module(self, module: ModuleType, config: Optional[dict[str, str]] = Non
finally:
# leave plugin context
delattr(module, "__cached__")
delattr(module, "__plugin_service__")
sys.modules.pop(module.__name__, None)

# get plugin metadata
Expand Down

0 comments on commit c0aaa65

Please sign in to comment.