Skip to content

Commit c3b10b7

Browse files
authored
CLI: Fix exception for verdi plugin list (aiidateam#6560)
In e952d77 a bug in `verdi plugin list` was fixed where the conditional to check whether the plugin was a process class would always raise an `AttributeError` if the plugin was not a `Process` or a proces function. As a result, the code would never get to the else-clause. The else-clause contained itself another bug, which was now revealed by the fixing of the bug in the conditional. The else-clause would call the `get_description` classmethod of the plugin, but no classes in AiiDA that are pluginnable even define such a class method. Probably, the original author confused it with the instance method `get_description` but the `verdi plugin list` command just deals with the class. The `get_description` call is replaced with just getting `__doc__` which returns the docstring of the class/function, or `None` if it is not defined. In the latter case, a default message is displayed saying that no description is available. Since the else-clause code was never reached before the recent fix and the `get_description` method was never supported officially by AiiDA's pluginnable interfaces, it is fine to just change this behavior.
1 parent fb36862 commit c3b10b7

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/aiida/cmdline/commands/cmd_plugin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ def plugin_list(entry_point_group, entry_point):
4747
except EntryPointError as exception:
4848
echo.echo_critical(str(exception))
4949
else:
50-
try:
51-
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
52-
hasattr(plugin, 'is_process_function') and plugin.is_process_function
53-
):
54-
print_process_info(plugin)
55-
else:
56-
echo.echo(str(plugin.get_description()))
57-
except AttributeError:
50+
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
51+
hasattr(plugin, 'is_process_function') and plugin.is_process_function
52+
):
53+
print_process_info(plugin)
54+
elif plugin.__doc__:
55+
echo.echo(plugin.__doc__)
56+
else:
5857
echo.echo_error(f'No description available for {entry_point}')
5958
else:
6059
entry_points = get_entry_point_names(entry_point_group)

tests/cmdline/commands/test_plugin.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212
from aiida.cmdline.commands import cmd_plugin
1313
from aiida.parsers import Parser
14-
from aiida.plugins import CalculationFactory, ParserFactory, WorkflowFactory
14+
from aiida.plugins import BaseFactory
1515
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP
1616

1717

@@ -43,6 +43,7 @@ def test_plugin_list_non_existing(run_cli_command):
4343
'entry_point_string',
4444
(
4545
'aiida.calculations:core.arithmetic.add',
46+
'aiida.data:core.array',
4647
'aiida.workflows:core.arithmetic.multiply_add',
4748
'aiida.workflows:core.arithmetic.add_multiply',
4849
),
@@ -52,24 +53,20 @@ def test_plugin_list_detail(run_cli_command, entry_point_string):
5253
from aiida.plugins.entry_point import parse_entry_point_string
5354

5455
entry_point_group, entry_point_name = parse_entry_point_string(entry_point_string)
55-
factory = CalculationFactory if entry_point_group == 'aiida.calculations' else WorkflowFactory
56-
entry_point = factory(entry_point_name)
56+
entry_point = BaseFactory(entry_point_group, entry_point_name)
5757

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

6161

62-
class CustomParser(Parser):
63-
@classmethod
64-
def get_description(cls) -> str:
65-
return 'str69'
62+
class NoDocStringPluginParser(Parser):
63+
pass
6664

6765

68-
def test_plugin_description(run_cli_command, entry_points):
69-
"""Test that ``verdi plugin list`` uses ``get_description`` if defined."""
70-
71-
entry_points.add(CustomParser, 'aiida.parsers:custom.parser')
72-
assert ParserFactory('custom.parser') is CustomParser
66+
def test_plugin_list_no_docstring(run_cli_command, entry_points):
67+
"""Test ``verdi plugin list`` does not fail if the plugin does not define a docstring."""
68+
entry_points.add(NoDocStringPluginParser, 'aiida.parsers:custom.parser')
69+
assert BaseFactory('aiida.parsers', 'custom.parser') is NoDocStringPluginParser
7370

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

0 commit comments

Comments
 (0)