Skip to content

Commit

Permalink
refactor: simplify boot.py
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Mar 8, 2022
1 parent 153cff0 commit e850980
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
17 changes: 4 additions & 13 deletions boot.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 16 additions & 2 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions plugin/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
from .fanhuaji_convert import FanhuajiConvertCommand
from .fanhuaji_convert_panel import FanhuajiConvertPanelCommand

__all__ = (
"FanhuajiConvertCommand",
"FanhuajiConvertPanelCommand",
)

0 comments on commit e850980

Please sign in to comment.