Skip to content

Commit

Permalink
🐛 fix plugin config read
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 4, 2024
1 parent f9dd3fa commit a8d40ff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ basic:
::echo: true
::auto_reload: true
plugin:
auto_reload:
::auto_reload:
watch_dirs: ["plugins"]
```
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _updater(self: Config):
with self.path.open("r", encoding="utf-8") as f:
data = json.load(f)
self.basic = data.get("basic", {})
self.plugin = data.get("plugin", {})
self.plugin = data.get("plugins", {})

obj = cls(_path, _updater)
cls.instance = obj
Expand All @@ -53,7 +53,7 @@ def _updater(self: Config):
with self.path.open("r", encoding="utf-8") as f:
data = yaml.safe_load(f)
self.basic = data.get("basic", {})
self.plugin = data.get("plugin", {})
self.plugin = data.get("plugins", {})

obj = cls(_path, _updater)
cls.instance = obj
Expand Down
2 changes: 2 additions & 0 deletions arclet/entari/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from loguru import logger
from tarina import init_spec

from ..config import Config
from .model import Plugin
from .model import PluginMetadata as PluginMetadata
from .model import RegisterNotInPluginError, _current_plugin
Expand Down Expand Up @@ -35,6 +36,7 @@ def load_plugin(path: str, config: dict | None = None, recursive_guard: set[str]
config (dict): 模块配置
recursive_guard (set[str]): 递归保护
"""
config = config or Config.instance.plugin.get(path)
if recursive_guard is None:
recursive_guard = set()
path = path.replace("::", "arclet.entari.builtins.")
Expand Down
3 changes: 1 addition & 2 deletions arclet/entari/plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from types import ModuleType
from typing import Optional

from ..config import Config
from .model import Plugin, PluginMetadata, _current_plugin
from .service import plugin_service

Expand Down Expand Up @@ -210,7 +209,7 @@ def exec_module(self, module: ModuleType, config: Optional[dict[str, str]] = Non
return

# create plugin before executing
plugin = Plugin(module.__name__, module, config=config or Config.instance.plugin.get(module.__name__, {}))
plugin = Plugin(module.__name__, module, config=config or {})
# for `dataclasses` module
sys.modules[module.__name__] = plugin.proxy() # type: ignore
setattr(module, "__plugin__", plugin)
Expand Down

0 comments on commit a8d40ff

Please sign in to comment.