Skip to content

Commit

Permalink
🐛 version 0.10.3
Browse files Browse the repository at this point in the history
fix submod import again
  • Loading branch information
RF-Tar-Railt committed Dec 17, 2024
1 parent 10f0439 commit a93df05
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 99 deletions.
2 changes: 1 addition & 1 deletion arclet/entari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
WH = WebhookInfo
filter_ = Filter

__version__ = "0.10.2"
__version__ = "0.10.3"
20 changes: 6 additions & 14 deletions arclet/entari/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@
"prefix": ["/"]
},
"plugins": {
"$prelude": ["::auto_reload"],
"~record_message": true,
"::auto_reload": {
"watch_dirs": ["."]
},
"::echo": true,
"::inspect": true
"~record_message": {},
"::echo": {},
"::inspect": {}
}
}
"""
Expand All @@ -57,13 +53,9 @@
log_level: "info"
prefix: ["/"]
plugins:
$prelude:
- ::auto_reload
.record_message: true
::auto_reload:
watch_dirs: ["."]
::echo: true
::inspect: true
.record_message: {}
::echo: {}
::inspect: {}
"""


Expand Down
15 changes: 15 additions & 0 deletions arclet/entari/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from pathlib import Path
from typing import Any, Callable, ClassVar, TypedDict
import warnings


class BasicConfig(TypedDict, total=False):
Expand Down Expand Up @@ -32,6 +33,20 @@ def reload(self):
self.updater(self)
self.plugin.setdefault(".commands", {})
self.prelude_plugin = self.plugin.pop("$prelude", []) # type: ignore
disabled = []
for k, v in self.plugin.items():
if v is True:
self.plugin[k] = {}
warnings.warn(
f"`True` usage in plugin '{k}' config is deprecated, use empty dict instead", DeprecationWarning
)
elif v is False:
disabled.append(k)
for k in disabled:
self.plugin[f"~{k}"] = self.plugin.pop(k)
warnings.warn(
f"`False` usage in plugin '{k}' config is deprecated, use `~` prefix instead", DeprecationWarning
)

@classmethod
def load(cls, path: str | os.PathLike[str] | None = None) -> EntariConfig:
Expand Down
2 changes: 1 addition & 1 deletion arclet/entari/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_plugin(
recursive_guard.add(referent)
plugin_service._unloaded.discard(mod.__name__)
return mod.__plugin__
except (RegisterNotInPluginError, StaticPluginDispatchError) as e:
except (ImportError, RegisterNotInPluginError, StaticPluginDispatchError) as e:
log.plugin.opt(colors=True).error(f"failed to load plugin <blue>{path!r}</blue>: {e.args[0]}")
except Exception as e:
log.plugin.opt(colors=True).exception(
Expand Down
6 changes: 3 additions & 3 deletions arclet/entari/plugin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ def validate(self, func):
if "__plugin__" in func.__globals__ and func.__globals__["__plugin__"] is self:
return
raise RegisterNotInPluginError(
f"Handler {func.__qualname__} should define "
f"Handler `{func.__qualname__}` should define "
f"in the same module as the plugin: {self.module.__name__}. "
f"Please use the `load_plugin({func.__module__!r})` or "
f"`package({func.__module__!r})` before import it."
f"Please use the `load_plugin({func.__module__!r})` or `requires({func.__module__!r})`"
f"or `package({func.__module__!r})` before import it."
)

def proxy(self):
Expand Down
4 changes: 0 additions & 4 deletions arclet/entari/plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from importlib.abc import MetaPathFinder
from importlib.machinery import ExtensionFileLoader, PathFinder, SourceFileLoader
from importlib.util import module_from_spec, resolve_name
from pathlib import Path
import sys
from types import ModuleType
from typing import Optional
Expand Down Expand Up @@ -115,10 +114,7 @@ def source_to_code(self, data, path, *, _optimize=-1): # type: ignore
The 'data' argument can be any object type that compile() supports.
"""
is_init = Path(path).name == "__init__.py"
name = self.name
if is_init and self.name.count("."):
name = self.name.rpartition(".")[0]
try:
nodes = ast.parse(data, type_comments=True)
except SyntaxError:
Expand Down
7 changes: 6 additions & 1 deletion arclet/entari/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from launart import Launart, Service, any_completed
from launart.status import Phase

from .plugin import _current_plugin
from .plugin import RootlessPlugin, _current_plugin


class _ScheduleEvent:
Expand Down Expand Up @@ -99,6 +99,11 @@ async def launch(self, manager: Launart):
scheduler = service = Scheduler()


@RootlessPlugin.apply("scheduler")
def _(plg: RootlessPlugin):
plg.service(service)


def every_second():
"""每秒执行一次"""
return lambda: timedelta(seconds=1)
Expand Down
148 changes: 74 additions & 74 deletions pdm.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "arclet-entari"
version = "0.10.2"
version = "0.10.3"
description = "Simple IM Framework based on satori-python"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down Expand Up @@ -28,6 +28,9 @@ yaml = ["pyyaml>=6.0.2"]
cron = [
"croniter>=5.0.1",
]
reload = [
"watchfiles>=1.0.3",
]

[project.scripts]
entari = "arclet.entari.__main__:main"
Expand Down

0 comments on commit a93df05

Please sign in to comment.