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

Add support for process functions in verdi plugin list #4117

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented May 26, 2020

Fixes #4115

So far, only actual Process subclasses were supported, however,
process functions can be turned into a Process subclass just as well.
The wrapped function gets a new attribute spec, which when called
returns the ProcessSpec that is dynamically built based on the
function signature of the decorated function.

P.S.: this does not yet actually include a test through verdi plugin list for a registered process function since we don't have one yet. However, @mbercx should be working on a PR that would add one. If that get's merged before, I can use that to add an additional test.

@sphuber sphuber force-pushed the fix/4115/verdi-plugin-list-process-functions branch from ec6c428 to 22ed5f6 Compare June 2, 2020 14:26
@sphuber sphuber requested a review from unkcpz June 2, 2020 18:01
@sphuber
Copy link
Contributor Author

sphuber commented Jun 2, 2020

@unkcpz here is another PR that could be suitable for you. There is no rush on this one. So if you are too busy now that is fine too.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

Thanks! it is a useful feature and an elegant implementation. @sphuber,
Besides some minor request. Before I start looking into the detail of the test cases, I just wondering is there any particular reason you create a new fixture for cli testing? If so, is that all cmdline cli run test should be transformed to this strategy?

aiida/cmdline/commands/cmd_plugin.py Outdated Show resolved Hide resolved
aiida/engine/processes/functions.py Outdated Show resolved Hide resolved
@unkcpz
Copy link
Member

unkcpz commented Jun 3, 2020

Why a CI test is failed here? I guess it has nothing to do with the current PR right?

@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

Why a CI test is failed here? I guess it has nothing to do with the current PR right?

Looks like a random transient problem and should be fixed when we rerun

@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

I just wondering is there any particular reason you create a new fixture for cli testing? If so, is that all cmdline cli run test should be transformed to this strategy?

The reason I added this is because I think it makes the typical CLI tests written in pytest really concise and clear. It does all the logic that the current tests typically do, such as check for exception, and get output in lines with whitespace stripped. Currently, all tests are doing all these things a bit ad-hoc and makes the code a bit inconsistent. Ideally we would convert all tests like that to use this fixture, but don't want to do it in this PR. Anyway, the majority of tests so far still use unittest instead of pytest.

So far, only actual `Process` subclasses were supported, however,
process functions can be turned into a `Process` subclass just as well.
The wrapped function gets a new attribute `spec`, which when called
returns the `ProcessSpec` that is dynamically built based on the
function signature of the decorated function.
@sphuber sphuber force-pushed the fix/4115/verdi-plugin-list-process-functions branch from 22ed5f6 to 57a7bed Compare June 3, 2020 06:56
@codecov
Copy link

codecov bot commented Jun 3, 2020

Codecov Report

Merging #4117 into develop will increase coverage by 0.12%.
The diff coverage is 75.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4117      +/-   ##
===========================================
+ Coverage    78.74%   78.85%   +0.12%     
===========================================
  Files          467      467              
  Lines        34466    34468       +2     
===========================================
+ Hits         27138    27178      +40     
+ Misses        7328     7290      -38     
Flag Coverage Δ
#django 70.78% <75.00%> (+0.12%) ⬆️
#sqlalchemy 71.66% <75.00%> (+0.12%) ⬆️
Impacted Files Coverage Δ
aiida/cmdline/commands/cmd_plugin.py 92.69% <66.67%> (+67.69%) ⬆️
aiida/engine/processes/functions.py 92.95% <100.00%> (+0.05%) ⬆️
aiida/cmdline/utils/common.py 66.67% <0.00%> (+1.12%) ⬆️
aiida/workflows/arithmetic/multiply_add.py 68.97% <0.00%> (+27.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9a3e95...6842a61. Read the comment docs.

tests/cmdline/commands/conftest.py Show resolved Hide resolved

def test_plugin_list_group(run_cli_command):
"""Test the `verdi plugin list` command for entry point group."""
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP
Copy link
Member

Choose a reason for hiding this comment

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

Since the MAP is imported twice, it may be better to import it once in the beginning of file.

tests/cmdline/commands/test_plugin.py Show resolved Hide resolved
@unkcpz
Copy link
Member

unkcpz commented Jun 3, 2020

I just wondering is there any particular reason you create a new fixture for cli testing? If so, is that all cmdline cli run test should be transformed to this strategy?

The reason I added this is because I think it makes the typical CLI tests written in pytest really concise and clear. It does all the logic that the current tests typically do, such as check for exception, and get output in lines with whitespace stripped. Currently, all tests are doing all these things a bit ad-hoc and makes the code a bit inconsistent. Ideally we would convert all tests like that to use this fixture, but don't want to do it in this PR. Anyway, the majority of tests so far still use unittest instead of pytest.

I see, I recomend to create a issue for future improvement. And since the raise part of this fixture is not being tested, would be better to first include that kinds of tests.

@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

Thanks for the second review @unkcpz , I have updated the run_cli_command fixture and added a test that uses the raises argument. If you approve this PR, I will open the issue to start replacing existing tests with this new fixture and link it here.

@unkcpz
Copy link
Member

unkcpz commented Jun 3, 2020

Thanks! @sphuber

@unkcpz
Copy link
Member

unkcpz commented Jun 3, 2020

As a reviewer, I guess it is also my duty to close #4115 ?

@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

As a reviewer, I guess it is also my duty to close #4115 ?

No, because I have marked my OP that this closes that issue and upon merging into develop Github will automatically close it

@sphuber sphuber merged commit 2a0d11e into aiidateam:develop Jun 3, 2020
@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

Thanks a lot for the reviews @unkcpz

@sphuber sphuber deleted the fix/4115/verdi-plugin-list-process-functions branch June 3, 2020 09:31
@sphuber
Copy link
Contributor Author

sphuber commented Jun 3, 2020

Opened #4142 to address the refactoring of existing CLI tests to use the new fixture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for process function in verdi plugin list
2 participants