From a2ddda812ad74cfacfdd92f467d6e24407b162b2 Mon Sep 17 00:00:00 2001 From: CyclingNinja Date: Thu, 9 May 2024 11:54:27 +0100 Subject: [PATCH] Prevents duplicate loading of plugins In cases of multiple load_plugins calls Adds test for future proofing --- glue/main.py | 5 +++-- glue/tests/test_main.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 glue/tests/test_main.py diff --git a/glue/main.py b/glue/main.py index 37b1013c3..0637c6d5e 100644 --- a/glue/main.py +++ b/glue/main.py @@ -49,7 +49,7 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): config = PluginConfig.load() if plugins_to_load is None: - plugins_to_load = [i.value for i in list(iter_plugin_entry_points())] + plugins_to_load = [i.module for i in list(iter_plugin_entry_points())] if require_qt_plugins: plugins_to_require = [*REQUIRED_PLUGINS, *REQUIRED_PLUGINS_QT] else: @@ -59,7 +59,8 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): n_plugins = len(plugins_to_require) for i_plugin, item in enumerate(list(iter_plugin_entry_points())): - if item.value.replace(':setup', '') in plugins_to_load: + + if item.module in plugins_to_load: if item.module not in _installed_plugins: _installed_plugins.add(item.name) diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py new file mode 100644 index 000000000..10b35bd86 --- /dev/null +++ b/glue/tests/test_main.py @@ -0,0 +1,20 @@ +from unittest.mock import patch + +from glue.main import load_plugins + + +def test_no_duplicate_loading(capsys): + """ + Regression test for duplicated loading of plugins + on subsequent calls of `load_plugins()` after initial + glue-qt startup. + + """ + from glue.logger import logger + + with patch.object(logger, 'info') as info: + load_plugins() + + for acall in info.call_args_list: + if 'Loading plugin' in acall[0][0]: + assert 'failed' in acall[0][0]