PICARD-2751: Avoid plugins with relative imports executing plugin body twice

This commit is contained in:
Philipp Wolfer
2023-09-10 12:28:48 +02:00
parent 70904c11e0
commit 4db506c49f

View File

@@ -353,6 +353,12 @@ class PluginManager(QtCore.QObject):
plugin_module = zip_importer.load_module(full_module_name)
else:
plugin_module = importlib.util.module_from_spec(spec)
# This is kind of a hack. The module will be in sys.modules
# after exec_module has run. But if inside of the loaded plugin
# there are relative imports it would load the same plugin
# module twice. This executes the plugins code twice and leads
# to potential side effects.
sys.modules[full_module_name] = plugin_module
spec.loader.exec_module(plugin_module)
plugin = PluginWrapper(plugin_module, plugindir,