Skip to content

Commit 909701f

Browse files
committed
🐛 version 0.17.1
fix several bugs
1 parent e3007a6 commit 909701f

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

arclet/entari/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
WS = WebsocketsInfo
9191
WH = WebhookInfo
9292

93-
__version__ = "0.17.0"
93+
__version__ = "0.17.1"

arclet/entari/exceptions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from .utils import escape_tag
2+
3+
14
class RegisterNotInPluginError(Exception):
25
def __init__(self, func, mod, pid):
36
self.msg = f"""\
4-
Handler `{func.__qualname__}` from {func.__module__!r} should define in the same module as the plugin: {mod.__name__!r}.
7+
Handler `{escape_tag(func.__qualname__)}` from {func.__module__!r}\
8+
should define in the same module as the plugin: {mod.__name__!r}.
59
610
Please choose one of the following solutions before import it:
711
* add {func.__module__!r} to your config file.
@@ -18,7 +22,7 @@ def __init__(self, func, mod, pid):
1822

1923
panel = Panel(
2024
f"""\
21-
[cyan]Handler [bright_yellow]`{func.__qualname__}`[/] from [blue]{func.__module__!r}\
25+
[cyan]Handler [bright_yellow]`{escape_tag(func.__qualname__)}`[/] from [blue]{func.__module__!r}\
2226
[/] should define [u bright_white]in the same module[/] as the plugin: [blue]{mod.__name__!r}[/].
2327
2428
Please choose one of the following solutions:

arclet/entari/logger.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import inspect
55
import logging
66
from pathlib import Path
7-
import re
87
import sys
98
import traceback
109
from types import TracebackType
@@ -14,6 +13,8 @@
1413
from loguru import logger
1514
from satori.parser import snake_case
1615

16+
from .utils import escape_tag
17+
1718
if TYPE_CHECKING:
1819
from loguru import Logger, Record
1920

@@ -22,17 +23,6 @@
2223
DEBUG_NO = logger.level("DEBUG").no
2324

2425

25-
def escape_tag(s: str) -> str:
26-
"""用于记录带颜色日志时转义 `<tag>` 类型特殊标签
27-
28-
参考: [loguru color 标签](https://loguru.readthedocs.io/en/stable/api/logger.html#color)
29-
30-
参数:
31-
s: 需要转义的字符串
32-
"""
33-
return re.sub(r"</?((?:[fb]g\s)?[^<>\s]*)>", r"\\\g<0>", s)
34-
35-
3626
class LoggerManager:
3727
def __init__(self):
3828
self.loggers: dict[str, Logger] = {}

arclet/entari/plugin/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from ..event.lifespan import Ready
1818
from ..event.plugin import PluginLoadedFailed
1919
from ..exceptions import RegisterNotInPluginError, ReusablePluginError, StaticPluginDispatchError
20-
from ..logger import escape_tag, log
20+
from ..logger import log
21+
from ..utils import escape_tag
2122
from .model import PluginMetadata as PluginMetadata
2223
from .model import RootlessPlugin as RootlessPlugin
2324
from .model import TS, Plugin, PluginDispatcher

arclet/entari/plugin/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ def validate(self, func):
526526
if isinstance(func, Subscriber):
527527
func = func.callable_target
528528
if func.__module__ != self.module.__name__:
529+
if func.__module__.startswith("arclet.entari"):
530+
return
529531
if "__plugin__" in func.__globals__ and func.__globals__["__plugin__"] is self:
530532
return
531533
raise RegisterNotInPluginError(func, self.module, self.id)

arclet/entari/plugin/module.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,17 @@ def exec_module(self, module: ModuleType, config: dict[str, Any] | None = None)
250250
is_sub = True
251251
if config is None or not {k: v for k, v in config.items() if k not in ("$path", "$static")}:
252252
config = plugin.config.copy()
253+
config["$path"] = plugin._config_key
253254
for key in config:
254255
if key.startswith(".") and self.plugin_id.endswith(key):
255256
config = config[key]
257+
config["$path"] = plugin._config_key # type: ignore
256258
break
257259

258260
if self.loaded:
259261
return
260262

261-
if config is None or not {k: v for k, v in config.items() if k not in ("$path", "$static")}:
263+
if config is None or (not is_sub and not {k: v for k, v in config.items() if k not in ("$path", "$static")}):
262264
key = module.__name__
263265
if key.startswith("arclet.entari.builtins.") and f"::{key[23:]}" in EntariConfig.instance.plugin:
264266
key = f"::{key[23:]}"
@@ -378,6 +380,9 @@ def find_spec(
378380
if module_spec.parent and module_spec.parent == plug.module.__name__:
379381
module_spec.loader = PluginLoader(fullname, module_origin, origin_id_ or fullname, plug.id)
380382
return module_spec
383+
elif module_spec.parent == module_spec.name and module_spec.name.rpartition(".")[0] == plug.module.__name__:
384+
module_spec.loader = PluginLoader(fullname, module_origin, origin_id_ or fullname, plug.id)
385+
return module_spec
381386
elif module_spec.name in _SUBMODULE_WAITLIST.get(plug.module.__name__, ()):
382387
module_spec.loader = PluginLoader(fullname, module_origin, origin_id_ or fullname, plug.id)
383388
# plugin_service.referents.setdefault(module_spec.name, set()).add(plug.id)

arclet/entari/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
3+
4+
def escape_tag(s: str) -> str:
5+
"""用于记录带颜色日志时转义 `<tag>` 类型特殊标签
6+
7+
参考: [loguru color 标签](https://loguru.readthedocs.io/en/stable/api/logger.html#color)
8+
9+
参数:
10+
s: 需要转义的字符串
11+
"""
12+
return re.sub(r"</?((?:[fb]g\s)?[^<>\s]*)>", r"\\\g<0>", s)

0 commit comments

Comments
 (0)