-
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
verdi code setup
: validate the uniqueness of the full label
#5205
verdi code setup
: validate the uniqueness of the full label
#5205
Conversation
fad194e
to
856c3e7
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5205 +/- ##
===========================================
+ Coverage 81.20% 81.21% +0.02%
===========================================
Files 532 532
Lines 37307 37322 +15
===========================================
+ Hits 30290 30307 +17
+ Misses 7017 7015 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@ltalirz you might be interested in this one |
Thanks @sphuber !
Just to check: this only happens when using
This could probably be clarified (I don't quite follow). In general, this is a very useful change; I will go through the code now. |
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 for this @sphuber !
Just a suggestion for rephrasing the comments.
One thing to keep in mind is that this needs to be documented in the migration guide since some scripts may rely on the order of prompts in code setup
(just as our tests do)
aiida/cmdline/commands/cmd_code.py
Outdated
# Note that the ``COMPUTER`` option needs to be specified before the ``LABEL`` option, since the latter has a callback | ||
# that relies on the former and so that needs to be prompted for first, which is the case if it is defined first. This | ||
# only works guaranteed for the interactive case, however, and so the callback needs to be called manually for the | ||
# non-interactive case in the case the label is specified before the computer and so when its callback is invoked, the | ||
# computer is not known yet and so cannot be validated. |
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.
Below my go at unwinding these sentences a bit
# Note that the ``COMPUTER`` option needs to be specified before the ``LABEL`` option, since the latter has a callback | |
# that relies on the former and so that needs to be prompted for first, which is the case if it is defined first. This | |
# only works guaranteed for the interactive case, however, and so the callback needs to be called manually for the | |
# non-interactive case in the case the label is specified before the computer and so when its callback is invoked, the | |
# computer is not known yet and so cannot be validated. | |
# Defining the ``COMPUTER`` option first guarantees that the user is prompted for the computer first. | |
# This is necessary because the ``LABEL`` option has a callback that relies on the computer being already set. | |
# Execution order is guaranteed only for the interactive case, however. | |
# For the non-interactive case, the callback is called explicitly once more to cover the case when the label is specified before the computer. |
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.
Yeah, that is better, thanks. I will adapt the comment.
aiida/cmdline/commands/cmd_code.py
Outdated
@@ -97,13 +105,18 @@ def setup_code(non_interactive, **kwargs): | |||
echo.echo_success(f'Code<{code.pk}> {code.full_label} created') | |||
|
|||
|
|||
# Note that the ``COMPUTER`` option needs to be specified before the ``LABEL`` option, since the latter has a callback |
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.
same as above
Sure, will add it to the guide, but then I will also add that people should use the |
The full label of a `Code` instance is defined as `label@computer.label`. Recently, the uniqueness of the full label was not even checked and it was possible to create codes with duplicate full labels. Since this was fixed though, `verdi code setup` would only fail when all parameters are parsed and it would try to store the code. In interactive mode, this is pretty annoying as the command will not fail until all parameters have been specified. Here, a validator is added to the `--label` option to check the uniqueness of the full label. In order to check this, it needs the selected computer. To ensure the computer is parsed before the label, the option is defined before the label when the command is defined. At least for the interactive mode, this guarantees that the computer is prompted for before the label, so the callback of the label can check for uniqueness. If it fails, the user is shown the reason why and prompted again. Note that the parsing order of parameters in the non-interactive mode is not guaranteed by the definition order but by the order in which they are passed by the caller. Therefore, the callback of the label cannot be relied upon, because if the label is specified first, the callback won't know the computer and will have to exit. Therefore, the callback has to be called manually once again in the body of the command when it is guaranteed that both the label and computer will have been defined. There is a slight overhead in the sense that the callback is called twice, but the first call will exit almost instantly and so the overhead will be minimal.
856c3e7
to
10782f5
Compare
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 @sphuber !
Fixes #3303
The full label of a
Code
instance is defined aslabel@computer.label
.Recently, the uniqueness of the full label was not even checked and it
was possible to create codes with duplicate full labels. Since this was
fixed though,
verdi code setup
would only fail when all parameters areparsed and it would try to store the code. In interactive mode, this is
pretty annoying as the command will not fail until all parameters have
been specified.
Here, a validator is added to the
--label
option to check theuniqueness of the full label. In order to check this, it needs the
selected computer. To ensure the computer is parsed before the label, the
option is defined before the label when the command is defined. At least
for the interactive mode, this guarantees that the computer is prompted
for before the label, so the callback of the label can check for
uniqueness. If it fails, the user is shown the reason why and prompted
again.
Note that the parsing order of parameters in the non-interactive mode is
not guaranteed by the definition order but by the order in which they
are passed by the caller. Therefore, the callback of the label cannot be
relied upon, because if the label is specified first, the callback won't
know the computer and will have to exit. Therefore, the callback has to
be called manually once again in the body of the command when it is
guaranteed that both the label and computer will have been defined.
There is a slight overhead in the sense that the callback is called
twice, but the first call will exit almost instantly and so the overhead
will be minimal.