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

CLI: Fix exception for verdi plugin list #6560

Merged
merged 1 commit into from
Aug 19, 2024
Merged
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
15 changes: 7 additions & 8 deletions src/aiida/cmdline/commands/cmd_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ def plugin_list(entry_point_group, entry_point):
except EntryPointError as exception:
echo.echo_critical(str(exception))
else:
try:
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
hasattr(plugin, 'is_process_function') and plugin.is_process_function
):
print_process_info(plugin)
else:
echo.echo(str(plugin.get_description()))
except AttributeError:
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
hasattr(plugin, 'is_process_function') and plugin.is_process_function
):
print_process_info(plugin)
elif plugin.__doc__:
echo.echo(plugin.__doc__)
else:
echo.echo_error(f'No description available for {entry_point}')
else:
entry_points = get_entry_point_names(entry_point_group)
Expand Down
23 changes: 10 additions & 13 deletions tests/cmdline/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest
from aiida.cmdline.commands import cmd_plugin
from aiida.parsers import Parser
from aiida.plugins import CalculationFactory, ParserFactory, WorkflowFactory
from aiida.plugins import BaseFactory
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP


Expand Down Expand Up @@ -43,6 +43,7 @@ def test_plugin_list_non_existing(run_cli_command):
'entry_point_string',
(
'aiida.calculations:core.arithmetic.add',
'aiida.data:core.array',
'aiida.workflows:core.arithmetic.multiply_add',
'aiida.workflows:core.arithmetic.add_multiply',
),
Expand All @@ -52,24 +53,20 @@ def test_plugin_list_detail(run_cli_command, entry_point_string):
from aiida.plugins.entry_point import parse_entry_point_string

entry_point_group, entry_point_name = parse_entry_point_string(entry_point_string)
factory = CalculationFactory if entry_point_group == 'aiida.calculations' else WorkflowFactory
entry_point = factory(entry_point_name)
entry_point = BaseFactory(entry_point_group, entry_point_name)

result = run_cli_command(cmd_plugin.plugin_list, [entry_point_group, entry_point_name])
assert entry_point.__doc__ in result.output


class CustomParser(Parser):
@classmethod
def get_description(cls) -> str:
return 'str69'
class NoDocStringPluginParser(Parser):
pass


def test_plugin_description(run_cli_command, entry_points):
"""Test that ``verdi plugin list`` uses ``get_description`` if defined."""

entry_points.add(CustomParser, 'aiida.parsers:custom.parser')
assert ParserFactory('custom.parser') is CustomParser
def test_plugin_list_no_docstring(run_cli_command, entry_points):
"""Test ``verdi plugin list`` does not fail if the plugin does not define a docstring."""
entry_points.add(NoDocStringPluginParser, 'aiida.parsers:custom.parser')
assert BaseFactory('aiida.parsers', 'custom.parser') is NoDocStringPluginParser

result = run_cli_command(cmd_plugin.plugin_list, ['aiida.parsers', 'custom.parser'])
assert result.output.strip() == 'str69'
assert result.output.strip() == 'Error: No description available for custom.parser'
Loading