diff --git a/src/aiida/cmdline/commands/cmd_plugin.py b/src/aiida/cmdline/commands/cmd_plugin.py index 9f43dd8b56..6cbbd958ce 100644 --- a/src/aiida/cmdline/commands/cmd_plugin.py +++ b/src/aiida/cmdline/commands/cmd_plugin.py @@ -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) diff --git a/tests/cmdline/commands/test_plugin.py b/tests/cmdline/commands/test_plugin.py index ec545ddea0..9960db7acd 100644 --- a/tests/cmdline/commands/test_plugin.py +++ b/tests/cmdline/commands/test_plugin.py @@ -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 @@ -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', ), @@ -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'