-
Notifications
You must be signed in to change notification settings - Fork 191
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
Conversation
I don't understand the problem from your description to be honest. Could you please provide an example where this failed? It would anyway be good to add that as a regression test. |
Alright, I try to improve the description: Suppose you write a plugin named X. Class X(Transport):
..
@classmethod
def get_description(cls) -> str:
return "I'm X"
.. Once the plugin is installed, try What you get is: Which means this AttributeError was handled only because I agree, it would be great to write a test for this, but one has to know how to mock a plugin, which I don't. |
Thanks, I understand now. I missed this because I thought the conditional had and instead of or and so I mistakenly thought that if the plugin was not a process, it would have been caught by the first part of the conditional and woulnd't even get to the Now that we understand that though, a better solution is not to just broadly catch this if (inspect.isclass(plugin) and issubclass(plugin, Process)) or hasattr(plugin, 'is_process_function'):
|
I would still check the value of Unfortunately, that example doesn't seem to work.
And then if I do: def test_parser(entry_points):
from aiida.parsers import Parser
from aiida.plugins import ParserFactory
class CustomParser(Parser):
return ''
entry_points.add(CustomParser, 'aiida.parsers:test')
> assert ParserFactory('test', CustomParser) still, returns I'm sorry to log the error here, but it's kind of time consuming to dig into this without further information. |
There are more problems with the example. The assert statement also doesn't make sense. It should be assert ParserFactory('test') is CustomParser and then the final problem is that the from aiida.parsers import Parser
class CustomParser(Parser):
"""Parser implementation."""
def test_parser(entry_points):
"""Test a custom ``Parser`` implementation."""
from aiida.plugins import ParserFactory
entry_points.add(CustomParser, 'aiida.parsers:custom.parser')
assert ParserFactory('custom.parser') is CustomParser I will submit a PR to fix the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @khsrali just a few minor corrections
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert result.stdout_bytes.decode('utf-8').strip() == 'str69' | |
assert result.output.strip() == 'str69' |
|
||
|
||
def test_plugin_description(run_cli_command, entry_points): | ||
"""Test if `verdi plugin list` would show description of an external plugin.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Test if `verdi plugin list` would show description of an external plugin.""" | |
"""Test that ``verdi plugin list`` uses ``get_description`` if defined.""" |
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or ( | ||
False if not hasattr(plugin, 'is_process_function') else plugin.is_process_function | ||
): |
There was a problem hiding this comment.
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
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 | |
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @khsrali
Hmm, not sure if related to this PR, but I now get the following on
Happens with a few (if not all) data entry points. v2.6.2 |
It is in fact related to this PR. The PR fixed a bug where the conditional would always raise an |
…iidateam#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.
If a plugin that is not a
Process
but hasn't setplugin.is_process_function=False
supportsget_description()
aiida-core
should understand in this scenario,plugin.is_process_function
is obviouslyFalse
.Currently,
AttributeError
could get caught by not havingis_process_function
instead ofget_description()