Plugin importer might be missing a line to add plugin module to modules dictionary
We encountered difficulties when importing sub-modules relatively in the plugin package into file <code>__init__.py</code> due to a missing line sys.modules[self.name] = mod
to add the plugin module to the modules dictionary which results in imported sub-modules not being found:
def import_module(self: "Plugin", plugins_path: str, configs_path: str):
spec = importlib.util.spec_from_file_location(
self.name, plugins_path + "/" + self.name + "/__init__.py"
)
mod = importlib.util.module_from_spec(spec)
sys.modules[self.name] = mod
spec.loader.exec_module(mod)
plugin_class_type = getattr(mod, self.name)
plugin_config = load_plugin_config(configs_path, self.name, plugin_class_type)
self.plugin_class = plugin_class_type(plugin_config, self.logger)
This is in line with the suggested example implementation here: https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
Do you think this would be a valid solution to that?