From 8c142c01bda31a164cf5bacf5a7ae85366334a61 Mon Sep 17 00:00:00 2001 From: tza Date: Mon, 4 Apr 2022 18:10:02 +0300 Subject: hot reloading, plugin instantiation, plugin main method - The Loader now watches for file changes in the plugin directory, and will (re)import when a new plugin is created, or an existing one is modified. This is implemented by means of the watchdog library - Plugin classes are now instantiated (and therefore require a self arg in every method). This way they can maintain a state during the runtime of the loader (or until they are reloaded), and share data between methods. - Plugins can now have a __main() method, which can include long-running code. Every plugin's main method is ran in a separate asyncio task. - Plugin methods that start from __ are now uncallable from javascript. This can be helpful when implementing unfinished/development versions of methods. --- plugin_loader/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'plugin_loader/main.py') diff --git a/plugin_loader/main.py b/plugin_loader/main.py index 4ecb5158..da371310 100644 --- a/plugin_loader/main.py +++ b/plugin_loader/main.py @@ -12,14 +12,15 @@ from utilities import util_methods CONFIG = { "plugin_path": getenv("PLUGIN_PATH", "/home/deck/homebrew/plugins"), "server_host": getenv("SERVER_HOST", "127.0.0.1"), - "server_port": int(getenv("SERVER_PORT", "1337")) + "server_port": int(getenv("SERVER_PORT", "1337")), + "live_reload": getenv("LIVE_RELOAD", "1") == "1" } class PluginManager: def __init__(self) -> None: self.loop = get_event_loop() self.web_app = Application() - self.plugin_loader = Loader(self.web_app, CONFIG["plugin_path"]) + self.plugin_loader = Loader(self.web_app, CONFIG["plugin_path"], self.loop, CONFIG["live_reload"]) jinja_setup(self.web_app, loader=FileSystemLoader(path.join(path.dirname(__file__), 'templates'))) self.web_app.on_startup.append(self.inject_javascript) -- cgit v1.2.3