Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list plugins method and tests #2496

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion glue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ 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.module in plugins_to_load:
if item.module not in _installed_plugins:
_installed_plugins.add(item.name)
Expand Down Expand Up @@ -115,3 +114,20 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None):
# that were previously read.
from glue._settings_helpers import load_settings
load_settings()


def list_loaded_plugins():
"""
Function to list all plugins that are currently loaded
"""
return sorted(_loaded_plugins)


def list_available_plugins():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you import these two functions into the top-level of the package? See:

from .main import load_plugins # noqa

"""
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
50 changes: 49 additions & 1 deletion glue/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
from unittest.mock import patch

from glue.main import load_plugins
from glue.main import load_plugins, list_loaded_plugins, list_available_plugins
from glue._plugin_helpers import REQUIRED_PLUGINS


def test_load_plugins(capsys):
"""
Test customisable list of plugins load
"""
from glue.logger import logger

with patch.object(logger, 'info') as info:
load_plugins()

# plugins = [call[0][0] for call in info.call_args_list if ('succeeded' or 'loaded') in call[0][0]]
plugins = []
for acall in info.call_args_list:
if ('loaded' or 'succeeded') in acall[0][0]:
plugins.append(acall[0][0].split(' ')[1])

assert 'coordinate_helpers' in plugins


def test_no_duplicate_loading(capsys):
Expand All @@ -15,6 +34,35 @@ def test_no_duplicate_loading(capsys):
with patch.object(logger, 'info') as info:
load_plugins()

plugins = []
for acall in info.call_args_list:
plugins.append(acall[0][0])
if 'Loading plugin' in acall[0][0]:
assert 'failed' in acall[0][0]

loaded_plugins = list_loaded_plugins()
assert 'glue.plugins.wcs_autolinking' in loaded_plugins
assert 'glue.core.data_exporters' in loaded_plugins
assert 'glue.plugins.coordinate_helpers' in loaded_plugins


def test_list_loaded_plugins():
"""
Unit test for retrieving the list of currently loaded plugins
"""
load_plugins(require_qt_plugins=False)
plugins = list_loaded_plugins()
assert isinstance(plugins, list)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can check that certain plugins are in the list

for test_plugin in REQUIRED_PLUGINS:
assert test_plugin in plugins


def test_list_available_plugins():
"""
Unit test for retrieving the list of currently available plugins
"""
available_plugins = list_available_plugins()
assert isinstance(available_plugins, list)
assert 'glue.plugins.wcs_autolinking' in available_plugins
assert 'glue.core.data_exporters' in available_plugins
assert 'glue.plugins.coordinate_helpers' in available_plugins