diff options
| author | Jonas Dellinger <jonas@dellinger.dev> | 2022-05-11 01:11:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-11 02:11:14 +0300 |
| commit | 414e0da2f3a249423404057baa2503ee019f11d6 (patch) | |
| tree | fc11b6e3d6ecb4c49a59ee74f1fe75c3752a771d | |
| parent | cb9b888dc651a03e4a69ccbece932eb791fcc373 (diff) | |
| download | decky-loader-1.3.tar.gz decky-loader-1.3.zip | |
Fix hot-reload when there are subdirs (#56)v1.3
| -rw-r--r-- | plugin_loader/loader.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/plugin_loader/loader.py b/plugin_loader/loader.py index 681c8251..12483db8 100644 --- a/plugin_loader/loader.py +++ b/plugin_loader/loader.py @@ -6,6 +6,8 @@ from asyncio import Queue from os import path, listdir from logging import getLogger from time import time +from genericpath import exists +from pathlib import Path from injector import get_tabs, get_tab from plugin import PluginWrapper @@ -18,6 +20,12 @@ class FileChangeHandler(FileSystemEventHandler): self.plugin_path = plugin_path self.queue = queue + def maybe_reload(self, src_path): + plugin_dir = Path(path.relpath(src_path, self.plugin_path)).parts[0] + self.logger.info(path.join(self.plugin_path, plugin_dir, "plugin.json")) + if exists(path.join(self.plugin_path, plugin_dir, "plugin.json")): + self.queue.put_nowait((path.join(self.plugin_path, plugin_dir, "main.py"), plugin_dir, True)) + def on_created(self, event): src_path = event.src_path if "__pycache__" in src_path: @@ -27,13 +35,8 @@ class FileChangeHandler(FileSystemEventHandler): if path.isdir(src_path): return - # get the directory name of the plugin so that we can find its "main.py" and reload it; the - # file that changed is not necessarily the one that needs to be reloaded self.logger.debug(f"file created: {src_path}") - rel_path = path.relpath(src_path, path.commonprefix([self.plugin_path, src_path])) - plugin_dir = path.split(rel_path)[0] - main_file_path = path.join(self.plugin_path, plugin_dir, "main.py") - self.queue.put_nowait((main_file_path, plugin_dir, True)) + self.maybe_reload(src_path) def on_modified(self, event): src_path = event.src_path @@ -44,11 +47,8 @@ class FileChangeHandler(FileSystemEventHandler): if path.isdir(src_path): return - # get the directory name of the plugin so that we can find its "main.py" and reload it; the - # file that changed is not necessarily the one that needs to be reloaded self.logger.debug(f"file modified: {src_path}") - plugin_dir = path.split(path.relpath(src_path, path.commonprefix([self.plugin_path, src_path])))[0] - self.queue.put_nowait((path.join(self.plugin_path, plugin_dir, "main.py"), plugin_dir, True)) + self.maybe_reload(src_path) class Loader: def __init__(self, server_instance, plugin_path, loop, live_reload=False) -> None: |
