Skip to content

Commit

Permalink
PICARD-2751: Avoid plugins with relative imports executing plugin bod…
Browse files Browse the repository at this point in the history
…y twice
  • Loading branch information
phw committed Sep 10, 2023
1 parent 70904c1 commit 4db506c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions picard/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ def _load_plugin_from_directory(self, name, plugindir):
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,
Expand Down

0 comments on commit 4db506c

Please sign in to comment.