From e8509804261d8427046bc1a63c60cc65d6605396 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Tue, 8 Mar 2022 17:49:50 +0800 Subject: [PATCH] refactor: simplify boot.py Signed-off-by: Jack Cherng --- boot.py | 17 ++++------------- plugin/__init__.py | 18 ++++++++++++++++-- plugin/commands/__init__.py | 7 ------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/boot.py b/boot.py index 9aa73b6..1b1d110 100644 --- a/boot.py +++ b/boot.py @@ -1,21 +1,12 @@ -def plugin_reload() -> None: +def reload_plugin() -> None: import sys + # Remove all previously loaded plugin modules. prefix = f"{__package__}." for module_name in tuple(filter(lambda m: m.startswith(prefix) and m != __name__, sys.modules)): del sys.modules[module_name] -plugin_reload() +reload_plugin() -from .plugin import set_up -from .plugin import tear_down -from .plugin.commands import * # noqa: F401, F403 - - -def plugin_loaded() -> None: - set_up() - - -def plugin_unloaded() -> None: - tear_down() +from .plugin import * # noqa: F401, F403 diff --git a/plugin/__init__.py b/plugin/__init__.py index 70b429e..0158450 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1,6 +1,20 @@ -def set_up() -> None: +# import all listeners and commands +from .commands.fanhuaji_convert import FanhuajiConvertCommand +from .commands.fanhuaji_convert_panel import FanhuajiConvertPanelCommand + +__all__ = ( + # ST: core + "plugin_loaded", + "plugin_unloaded", + # ST: commands + "FanhuajiConvertCommand", + "FanhuajiConvertPanelCommand", +) + + +def plugin_loaded() -> None: pass -def tear_down() -> None: +def plugin_unloaded() -> None: pass diff --git a/plugin/commands/__init__.py b/plugin/commands/__init__.py index 599b8ae..e69de29 100644 --- a/plugin/commands/__init__.py +++ b/plugin/commands/__init__.py @@ -1,7 +0,0 @@ -from .fanhuaji_convert import FanhuajiConvertCommand -from .fanhuaji_convert_panel import FanhuajiConvertPanelCommand - -__all__ = ( - "FanhuajiConvertCommand", - "FanhuajiConvertPanelCommand", -)