Skip to content

Commit

Permalink
🔖 version 0.11.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Jan 25, 2025
1 parent 8e2588b commit eda7a55
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion arclet/entari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
WS = WebsocketsInfo
WH = WebhookInfo

__version__ = "0.11.1"
__version__ = "0.11.2"
38 changes: 19 additions & 19 deletions arclet/entari/builtins/auto_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Config(BasicConfModel):
)


logger = log.wrapper("[AutoReload]")
logger = log.wrapper("[AutoReload]").opt(colors=True)


def detect_filter_change(old: dict, new: dict):
Expand Down Expand Up @@ -73,28 +73,28 @@ async def watch(self):
for change in event:
if plugin := find_plugin_by_file(change[1]):
if plugin.is_static:
logger.opt(colors=True).info(f"Plugin <y>{plugin.id!r}</y> is static, ignored.")
logger.info(f"Plugin <y>{plugin.id!r}</y> is static, ignored.")
continue
logger.opt(colors=True).info(f"Detected change in <blue>{plugin.id!r}</blue>, reloading...")
logger.info(f"Detected change in <blue>{plugin.id!r}</blue>, reloading...")
pid = plugin.id
del plugin
unload_plugin(pid)
if plugin := load_plugin(pid):
logger.opt(colors=True).info(f"Reloaded <blue>{plugin.id!r}</blue>")
logger.info(f"Reloaded <blue>{plugin.id!r}</blue>")
del plugin
else:
logger.opt(colors=True).error(f"Failed to reload <blue>{pid!r}</blue>")
logger.error(f"Failed to reload <blue>{pid!r}</blue>")
self.fail[change[1]] = pid
elif change[1] in self.fail:
logger.opt(colors=True).info(
logger.info(
f"Detected change in {change[1]!r} which failed to reload, retrying..."
)
if plugin := load_plugin(self.fail[change[1]]):
logger.opt(colors=True).info(f"Reloaded <blue>{plugin.id!r}</blue>")
logger.info(f"Reloaded <blue>{plugin.id!r}</blue>")
del plugin
del self.fail[change[1]]
else:
logger.opt(colors=True).error(f"Failed to reload <blue>{self.fail[change[1]]!r}</blue>")
logger.error(f"Failed to reload <blue>{self.fail[change[1]]!r}</blue>")

async def watch_config(self):
file = EntariConfig.instance.path.resolve()
Expand All @@ -110,20 +110,20 @@ async def watch_config(self):
):
print(change)
continue
logger.opt(colors=True).info(f"Detected change in {change[1]!r}, reloading config...")
logger.info(f"Detected change in {change[1]!r}, reloading config...")

old_basic = EntariConfig.instance.basic.copy()
old_plugin = EntariConfig.instance.plugin.copy()
EntariConfig.instance.reload()
for key in old_basic:
if key in EntariConfig.instance.basic and old_basic[key] != EntariConfig.instance.basic[key]:
logger.opt(colors=True).debug(
logger.debug(
f"Basic config <y>{key!r}</y> changed from <r>{old_basic[key]!r}</r> "
f"to <g>{EntariConfig.instance.basic[key]!r}</g>",
)
await es.publish(ConfigReload("basic", key, EntariConfig.instance.basic[key], old_basic[key]))
for key in set(EntariConfig.instance.basic) - set(old_basic):
logger.opt(colors=True).debug(f"Basic config <y>{key!r}</y> appended")
logger.debug(f"Basic config <y>{key!r}</y> appended")
await es.publish(ConfigReload("basic", key, EntariConfig.instance.basic[key]))
for plugin_name in old_plugin:
if plugin_name.startswith("$") or plugin_name.startswith("~"):
Expand All @@ -133,10 +133,10 @@ async def watch_config(self):
if plugin := find_plugin(pid):
del plugin
unload_plugin(pid)
logger.opt(colors=True).info(f"Disposed plugin <blue>{pid!r}</blue>")
logger.info(f"Disposed plugin <blue>{pid!r}</blue>")
continue
if old_plugin[plugin_name] != EntariConfig.instance.plugin[plugin_name]:
logger.opt(colors=True).debug(
logger.debug(
f"Plugin <y>{plugin_name!r}</y> config changed from <r>{old_plugin[plugin_name]!r}</r> "
f"to <g>{EntariConfig.instance.plugin[plugin_name]!r}</g>",
)
Expand All @@ -146,27 +146,27 @@ async def watch_config(self):
allow, deny, only_filter = detect_filter_change(old_conf, new_conf)
plugin.update_filter(allow, deny)
if only_filter:
logger.opt(colors=True).debug(f"Plugin <y>{pid!r}</y> config only changed filter.")
logger.debug(f"Plugin <y>{pid!r}</y> config only changed filter.")
continue
res = await es.post(
ConfigReload("plugin", plugin_name, new_conf, old_conf),
)
if res and res.value:
logger.opt(colors=True).debug(f"Plugin <y>{pid!r}</y> config change handled by itself.")
logger.debug(f"Plugin <y>{pid!r}</y> config change handled by itself.")
continue
logger.opt(colors=True).info(
logger.info(
f"Detected config of <blue>{pid!r}</blue> changed, reloading..."
)
plugin_file = str(plugin.module.__file__)
unload_plugin(plugin_name)
if plugin := load_plugin(plugin_name, new_conf):
logger.opt(colors=True).info(f"Reloaded <blue>{plugin.id!r}</blue>")
logger.info(f"Reloaded <blue>{plugin.id!r}</blue>")
del plugin
else:
logger.opt(colors=True).error(f"Failed to reload <blue>{plugin_name!r}</blue>")
logger.error(f"Failed to reload <blue>{plugin_name!r}</blue>")
self.fail[plugin_file] = pid
else:
logger.opt(colors=True).info(f"Detected <blue>{pid!r}</blue> appended, loading...")
logger.info(f"Detected <blue>{pid!r}</blue> appended, loading...")
load_plugin(plugin_name, new_conf)
if new := (set(EntariConfig.instance.plugin) - set(old_plugin)):
for plugin_name in new:
Expand Down
6 changes: 3 additions & 3 deletions arclet/entari/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def __init__(
):
from . import __version__

log.core.opt(colors=True).info(f"Entari <b><c>version {__version__}</c></b>")
log.core.info(f"Entari <b><c>version {__version__}</c></b>")
super().__init__(*configs, default_api_cls=EntariProtocol)
if not hasattr(EntariConfig, "instance"):
EntariConfig.load()
alconna_config.command_max_count = EntariConfig.instance.basic.get("cmd_count", 4096)
log.set_level(log_level)
log.core.opt(colors=True).debug(f"Log level set to <y><c>{log_level}</c></y>")
log.core.debug(f"Log level set to <y><c>{log_level}</c></y>")
requires(*EntariConfig.instance.prelude_plugin)
for plug in EntariConfig.instance.prelude_plugin:
load_plugin(plug, prelude=True)
Expand All @@ -155,7 +155,7 @@ def reset_self(self, scope, key, value):
return
if key == "log_level":
log.set_level(value)
log.core.opt(colors=True).debug(f"Log level set to <y><c>{value}</c></y>")
log.core.debug(f"Log level set to <y><c>{value}</c></y>")
elif key == "ignore_self_message":
self.ignore_self_message = value
elif key == "network":
Expand Down
2 changes: 1 addition & 1 deletion arclet/entari/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):

def fork(self, child_name: str):
patched = logger.patch(lambda r: r.update(name=child_name))
patched = patched.bind(name=child_name)
patched = patched.bind(name=child_name).opt(colors=True)
self.loggers[child_name] = patched
return patched

Expand Down
10 changes: 5 additions & 5 deletions arclet/entari/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def load_plugin(
path1 = f"entari_plugin_{path}"
mod = import_plugin(path1, config=conf)
if not mod:
log.plugin.opt(colors=True).error(f"cannot found plugin <blue>{path!r}</blue>")
log.plugin.error(f"cannot found plugin <blue>{path!r}</blue>")
es.publish(PluginLoadedFailed(path))
return
log.plugin.opt(colors=True).success(f"loaded plugin <blue>{mod.__name__!r}</blue>")
log.plugin.success(f"loaded plugin <blue>{mod.__name__!r}</blue>")
if mod.__name__ in plugin_service._unloaded:
if mod.__name__ in plugin_service._referents and plugin_service._referents[mod.__name__]:
referents = plugin_service._referents[mod.__name__].copy()
Expand All @@ -94,7 +94,7 @@ def load_plugin(
if referent in recursive_guard:
continue
if referent in plugin_service.plugins:
log.plugin.opt(colors=True).debug(
log.plugin.debug(
f"reloading <y>{mod.__name__}</y>'s referent <y>{referent!r}</y>"
)
unload_plugin(referent)
Expand All @@ -106,10 +106,10 @@ def load_plugin(
es.publish(PluginLoadedSuccess(mod.__name__))
return mod.__plugin__
except (ImportError, RegisterNotInPluginError, StaticPluginDispatchError) as e:
log.plugin.opt(colors=True).error(f"failed to load plugin <blue>{path!r}</blue>: {e.args[0]}")
log.plugin.error(f"failed to load plugin <blue>{path!r}</blue>: {e.args[0]}")
es.publish(PluginLoadedFailed(path, e))
except Exception as e:
log.plugin.opt(colors=True).exception(
log.plugin.exception(
f"failed to load plugin <blue>{path!r}</blue> caused by {e!r}", exc_info=e
)
es.publish(PluginLoadedFailed(path, e))
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/plugin/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ def dispose(self):
if self.subplugins:
subplugs = [i.removeprefix(self.id)[1:] for i in self.subplugins]
subplugs = (subplugs[:3] + ["..."]) if len(subplugs) > 3 else subplugs
log.plugin.opt(colors=True).debug(f"disposing sub-plugin <r>{', '.join(subplugs)}</r> of <y>{self.id}</y>")
log.plugin.debug(f"disposing sub-plugin <r>{', '.join(subplugs)}</r> of <y>{self.id}</y>")
for subplug in self.subplugins:
if subplug not in plugin_service.plugins:
continue
try:
plugin_service.plugins[subplug].dispose()
except Exception as e:
log.plugin.opt(colors=True).error(f"failed to dispose sub-plugin <r>{subplug}</r> caused by {e!r}")
log.plugin.error(f"failed to dispose sub-plugin <r>{subplug}</r> caused by {e!r}")
plugin_service.plugins.pop(subplug, None)
self.subplugins.clear()
self._scope.dispose()
Expand Down
6 changes: 3 additions & 3 deletions arclet/entari/plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __entari_import__(name: str, plugin_name: str, ensure_plugin: bool = False):
if name in _ENSURE_IS_PLUGIN:
mod = import_plugin(name)
if mod:
log.plugin.opt(colors=True).success(f"loaded plugin <blue>{name!r}</blue>")
log.plugin.success(f"loaded plugin <blue>{name!r}</blue>")
if plugin_name != mod.__plugin__.id:
plugin_service._referents[mod.__plugin__.id].add(plugin_name)
return mod.__plugin__.proxy()
Expand All @@ -58,7 +58,7 @@ def __entari_import__(name: str, plugin_name: str, ensure_plugin: bool = False):
del config["$static"]
mod = import_plugin(name, config=config)
if mod:
log.plugin.opt(colors=True).success(f"loaded plugin <blue>{name!r}</blue>")
log.plugin.success(f"loaded plugin <blue>{name!r}</blue>")
if plugin_name != mod.__plugin__.id:
plugin_service._referents[mod.__plugin__.id].add(plugin_name)
return mod.__plugin__.proxy()
Expand All @@ -68,7 +68,7 @@ def __entari_import__(name: str, plugin_name: str, ensure_plugin: bool = False):
if plugin_name != module.__plugin__.id:
plugin_service._referents[module.__plugin__.id].add(plugin_name)
return module.__plugin__.subproxy(f"{plugin_name}{name}")
log.plugin.opt(colors=True).success(f"loaded plugin <blue>{name!r}</blue>")
log.plugin.success(f"loaded plugin <blue>{name!r}</blue>")
return module
# if name not in sys.modules and name not in sys.builtin_module_names:
# mod = import_plugin(name, plugin_name)
Expand Down
4 changes: 2 additions & 2 deletions arclet/entari/plugin/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ async def launch(self, manager: Launart):
for plug_id in reversed(ids):
plug = self.plugins[plug_id]
if not plug.id.startswith("."):
log.plugin.opt(colors=True).debug(f"disposing plugin <y>{plug.id}</y>")
log.plugin.debug(f"disposing plugin <y>{plug.id}</y>")
try:
await es.publish(PluginUnloaded(plug.id))
plug.dispose()
except Exception as e:
log.plugin.opt(colors=True).error(f"failed to dispose plugin <y>{plug.id}</y> caused by {e!r}")
log.plugin.error(f"failed to dispose plugin <y>{plug.id}</y> caused by {e!r}")
self.plugins.pop(plug_id, None)
for values in self._keep_values.values():
for value in values.values():
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "arclet-entari"
version = "0.11.1"
version = "0.11.2"
description = "Simple IM Framework based on satori-python"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
]
dependencies = [
"arclet-letoderea>=0.14.9",
"arclet-letoderea<0.15.0,>=0.14.9",
"arclet-alconna<2.0,>=1.8.34",
"satori-python-core>=0.15.2",
"satori-python-client>=0.15.2",
Expand Down

0 comments on commit eda7a55

Please sign in to comment.