diff --git a/glue/main.py b/glue/main.py index d32aca234..353cd7342 100644 --- a/glue/main.py +++ b/glue/main.py @@ -3,7 +3,7 @@ from importlib import import_module from glue.logger import logger -from glue._plugin_helpers import REQUIRED_PLUGINS, REQUIRED_PLUGINS_QT +from glue._plugin_helpers import REQUIRED_PLUGINS _loaded_plugins = set() @@ -50,8 +50,8 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): if plugins_to_load is None: 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] + if plugins_to_load: + plugins_to_require = [*REQUIRED_PLUGINS] else: plugins_to_require = REQUIRED_PLUGINS else: @@ -116,8 +116,18 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None): load_settings() -def list_plugins(): +def list_loaded_plugins(): """ Function to list all plugins that are currently loaded """ return sorted(_loaded_plugins) + + +def list_available_plugins(): + """ + Function to list all available plugins + """ + from glue._plugin_helpers import iter_plugin_entry_points + + plugins_load_list = [i.module for i in list(iter_plugin_entry_points())] + return plugins_load_list diff --git a/glue/tests/test_main.py b/glue/tests/test_main.py index 7d4c83744..da995d8af 100644 --- a/glue/tests/test_main.py +++ b/glue/tests/test_main.py @@ -1,7 +1,6 @@ from unittest.mock import patch -from glue.main import load_plugins -from glue.main import list_plugins +from glue.main import load_plugins, list_loaded_plugins, list_available_plugins def test_load_plugins(capsys): @@ -17,9 +16,10 @@ def test_load_plugins(capsys): plugins = [] for acall in info.call_args_list: if ('loaded' or 'succeeded') in acall[0][0]: - plugins.append(acall[0][0]) + plugins.append(acall[0][0].split(' ')[1]) assert len(plugins) == 5 + assert 'coordinate_helpers' in plugins def test_no_duplicate_loading(capsys): @@ -39,11 +39,22 @@ def test_no_duplicate_loading(capsys): assert 'failed' in acall[0][0] -def test_list_plugins(): +def test_list_loaded_plugins(): """ Regression test for retrieving the list of currently loaded plugins """ load_plugins(require_qt_plugins=False) - plugins = list_plugins() + plugins = list_loaded_plugins() assert isinstance(plugins, list) assert len(plugins) == 5 + + +def test_list_available_plugins(): + """ + Regression test for retrieving the list of currently available plugins + """ + available_plugins = list_available_plugins() + assert isinstance(available_plugins, list) + assert len(available_plugins) == 7 + assert 'casa_formats_io.glue_factory' in available_plugins + assert 'glue.plugins.wcs_autolinking' in available_plugins