Improving plugin imports
This commit is contained in:
parent
f5567d2631
commit
d41235882a
|
@ -21,6 +21,9 @@ class Plugins:
|
||||||
"""Plugins controller"""
|
"""Plugins controller"""
|
||||||
|
|
||||||
def __init__(self, settings: type):
|
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._settings = settings
|
||||||
self._builder = self._settings.get_builder()
|
self._builder = self._settings.get_builder()
|
||||||
self._plugins_path = self._settings.get_plugins_path()
|
self._plugins_path = self._settings.get_plugins_path()
|
||||||
|
@ -69,11 +72,9 @@ class Plugins:
|
||||||
|
|
||||||
def load_plugin_module(self, path, folder, target):
|
def load_plugin_module(self, path, folder, target):
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
sys.path.insert(0, path) # NOTE: I think I'm not using this correctly...
|
spec = importlib.util.spec_from_file_location(folder, target, submodule_search_locations=path)
|
||||||
# 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)
|
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
sys.modules[folder] = module
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
|
Loading…
Reference in New Issue