From d41235882a8d36a6ba669af4b5876a36758840ef Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 5 Sep 2022 20:15:32 -0500 Subject: [PATCH] Improving plugin imports --- src/plugins/plugins.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/plugins.py b/src/plugins/plugins.py index d54236f..86d08ea 100644 --- a/src/plugins/plugins.py +++ b/src/plugins/plugins.py @@ -21,6 +21,9 @@ class Plugins: """Plugins controller""" def __init__(self, settings: type): + path = os.path.dirname(os.path.realpath(__file__)) + sys.path.insert(0, path) # NOTE: I think I'm not using this correctly... + self._settings = settings self._builder = self._settings.get_builder() self._plugins_path = self._settings.get_plugins_path() @@ -69,11 +72,9 @@ class Plugins: def load_plugin_module(self, path, folder, target): os.chdir(path) - sys.path.insert(0, path) # NOTE: I think I'm not using this correctly... - # The folder and target aren't working to create parent package references, so using as stopgap. - # The above is probably polutling import logic and will cause unforseen import issues. - spec = importlib.util.spec_from_file_location(folder, target) + spec = importlib.util.spec_from_file_location(folder, target, submodule_search_locations=path) module = importlib.util.module_from_spec(spec) + sys.modules[folder] = module spec.loader.exec_module(module) return module