From 56f252f5884ac33ee29eb8738229d91519a4ef0a Mon Sep 17 00:00:00 2001 From: keyboard-slayer Date: Sat, 25 Nov 2023 12:28:37 +0100 Subject: [PATCH] feat: Plugins system allows __init__.py for relative imports --- cutekit/plugins.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cutekit/plugins.py b/cutekit/plugins.py index 7a3d3d9..d1c82e1 100644 --- a/cutekit/plugins.py +++ b/cutekit/plugins.py @@ -1,5 +1,6 @@ -import os import logging +import os +import sys from . import shell, model, const @@ -17,6 +18,7 @@ def load(path: str): return None module = importlib.module_from_spec(spec) + sys.modules["plugin"] = module spec.loader.exec_module(module) @@ -33,7 +35,11 @@ def loadAll(): for dirname in paths: pluginDir = os.path.join(project.dirname(), dirname, const.META_DIR, "plugins") + initFile = os.path.join(pluginDir, "__init__.py") - for files in shell.readdir(pluginDir): - if files.endswith(".py"): - load(os.path.join(pluginDir, files)) + if os.path.isfile(initFile): + load(initFile) + else: + for files in shell.readdir(pluginDir): + if files.endswith(".py"): + load(os.path.join(pluginDir, files))