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: minor change on verdi plugin list logic to show description #6411

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 (
False if not hasattr(plugin, 'is_process_function') else plugin.is_process_function
):
Copy link
Contributor

Choose a reason for hiding this comment

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

This phrasing with a nested if feels a bit awkward. I think a more typical formulation would be

Suggested change
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
False if not hasattr(plugin, 'is_process_function') else 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
18 changes: 18 additions & 0 deletions tests/cmdline/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

Expand Down Expand Up @@ -56,3 +57,20 @@ 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 if `verdi plugin list` would show description of an external plugin."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Test if `verdi plugin list` would show description of an external plugin."""
"""Test that ``verdi plugin list`` uses ``get_description`` if defined."""

from aiida.plugins import ParserFactory

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.stdout_bytes.decode('utf-8').strip() == 'str69'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert result.stdout_bytes.decode('utf-8').strip() == 'str69'
assert result.output.strip() == 'str69'

Loading