Skip to content

Commit

Permalink
CLI: Fix verdi plugin list incorrectly not displaying description (#…
Browse files Browse the repository at this point in the history
…6411)

The implementation would call `get_description` on the plugin to retrieve
a verbose description and would catch the `AttributeError` in case the
method was not defined. However, the conditional determining whether the
plugin is a process or process function was flawed and it would always
call `plugin.is_process_function` for plugins that were not processes.
This would therefore raise an `AttributeError` for any other plugins
besides process functions and so the command would always print that no
additional information was available.
  • Loading branch information
khsrali authored May 23, 2024
1 parent 081fc55 commit e952d77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/aiida/cmdline/commands/cmd_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def plugin_list(entry_point_group, entry_point):
echo.echo_critical(str(exception))
else:
try:
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or plugin.is_process_function:
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()))
Expand Down
19 changes: 18 additions & 1 deletion tests/cmdline/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import pytest
from aiida.cmdline.commands import cmd_plugin
from aiida.plugins import CalculationFactory, WorkflowFactory
from aiida.parsers import Parser
from aiida.plugins import CalculationFactory, ParserFactory, WorkflowFactory
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP


Expand Down Expand Up @@ -56,3 +57,19 @@ def test_plugin_list_detail(run_cli_command, entry_point_string):

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'


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

result = run_cli_command(cmd_plugin.plugin_list, ['aiida.parsers', 'custom.parser'])
assert result.output.strip() == 'str69'

0 comments on commit e952d77

Please sign in to comment.