-
Notifications
You must be signed in to change notification settings - Fork 224
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
Make --prepend-text
and --append-text
options properly interactive
#4318
Make --prepend-text
and --append-text
options properly interactive
#4318
Conversation
Even though this fixes the problem described in the issue, I still think there potentially is some counter-intuitive behavior. With this change the |
Codecov Report
@@ Coverage Diff @@
## develop #4318 +/- ##
===========================================
+ Coverage 79.08% 79.09% +0.02%
===========================================
Files 468 468
Lines 34642 34608 -34
===========================================
- Hits 27394 27371 -23
+ Misses 7248 7237 -11
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Thanks @sphuber I just checked the behavior on label: "daint-mc23"
hostname: "daint.cscs.ch"
description: Piz Daint supercomputer at CSCS Lugano, Switzerland, multicore partition.
transport: ssh
scheduler: "slurm"
work_dir: "/scratch/snx3000/{username}/aiida_run/"
shebang: "#!/bin/bash"
mpirun_command: "srun -n {tot_num_mpiprocs}"
mpiprocs_per_machine: "36"
prepend_text: |
### computer prepend_text start ###
#SBATCH --partition=normal
#SBATCH --account=mr0
#SBATCH --constraint=mc
#SBATCH --cpus-per-task=1
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
source $MODULESHOME/init/bash
module load daint-mc
ulimit -s unlimited
### computer prepend_text end ###
append_text: "" I find that
After checking out your changes, 2. works without prompting as well, but as you mention, it disables prompting for the pre/postpend scripts altogether (which is not what we want). I see two ways to resolve this: P.S.
I think you meant |
I forgot about this and agree, this is definitely not what we want. Before trying to continue to add patches, I think we first need to make absolutely sure how we want the commands with the
As you can see, it has two options, both required, but one with a default and one without. In addition, there are the
and
We now have the following (meaningful) permutations of possible commands to use:
To me, the results are actually what I would expect, as long as the
If we agree on this definition and the current behavior, then the current problem is simply with the implementation of the Let me know if you agree with this assessment @ltalirz and I will update this PR. |
Thanks @sphuber for the detailed writeup - I agree with the description of the desired behavior entirely (perhaps we could put it somewhere into the documentation, e.g. starting a "command line interface" section under "internal architecture). If that behavior can be attained, then great! |
@ltalirz, maybe I misunderstood something, but I believe this is exactly what we want when in the |
Correct, with the current code, the user would never be prompted for append/prepend texts. |
Alright, thanks indeed @sphuber for the detailed explanation. I completely agree with your proposed solution. |
45effaf
to
5e352ce
Compare
@ltalirz and @yakutovicha I have implemented the discussed changes and this should be good to go for a new review |
verdi computer setup
: accept empty string in pre- and append text--prepend-text
and --append-text
options properly interactive
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 - I think this is exactly the behavior we want, and the code has become cleaner as well.
I noticed a minor issue, then it should be good to merge.
P.S. As mentioned, you may want to consider adding what you wrote here somewhere into the documentation, e.g. starting a "command line interface" section under "internal architecture". |
Thanks for the review, I will address the changes.
I know that is what I suggested, but really that was just to hash out where exactly the error in the code was. I don't see what information is there that is still worth having in terms of describing of how things should work. The difference between defining parameters inline or via config file ultimately had nothing to do with this issue. The only thing that we could describe is the intended working of the
but that is more for the user manual than the internal workings. What exactly do you think would have to go in the internal architecture? |
If you think it's self-explanatory enough, perhaps it's indeed not needed to add to the documentation.
Yes, perhaps we can just expand the help string of the option a bit
My suggestion would be to focus a bit more on what the user can do
|
5e352ce
to
d2eed94
Compare
The `--prepend-text` and `--append-text` options, used for both the `verdi computer setup` and `verdi code setup` commands were normal options as opposed to all other options that are interactive options. The `InteractiveOption` is a custom option class type we developed that will present the user with a prompt if it was not explicitly provided on the command line. The `--non-interactive` flag can be used by the user to prevent prompting, as long as a default value is defined. The two options in question were implemented differently, presumably because they take a potentially multiline string, which is not easily defined on a prompt and therefore instead these options would be defined through a text editor. The prompting of this text editor, if necessary, was however not performed in the option itself, but in the command body. At this point, the prompt cycle of the parameter cycle controlled by click is already over. Additionally, since the function checking whether the option had been defined also considered an empty string as undefined, despite it being the default, a specified empty string would still lead to the user to be prompted, even when specifying `--non-interactive`. The fix is to make both options proper interactive options just like the rest. To this end, we create the `TemplateInteractiveOption` that works just like the `InteractiveOption` with the only difference being that it uses a file editor instead of an inline prompt. This change does force us to have both options pop up their own file editor, whereas before they were joined in a single file and both files were specified in the same file, separated by a header that we defined.
d2eed94
to
b95e092
Compare
I took your suggestion but adapted it a bit and removed the mention of the configuration file. Although usable together, the
|
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 , latest version works fine
Fixes #4300
The
--prepend-text
and--append-text
options, used for both theverdi computer setup
andverdi code setup
commands were normaloptions as opposed to all other options that are interactive options.
The
InteractiveOption
is a custom option class type we developed thatwill present the user with a prompt if it was not explicitly provided on
the command line. The
--non-interactive
flag can be used by the userto prevent prompting, as long as a default value is defined.
The two options in question were implemented differently, presumably
because they take a potentially multiline string, which is not easily
defined on a prompt and therefore instead these options would be defined
through a text editor. The prompting of this text editor, if necessary,
was however not performed in the option itself, but in the command body.
At this point, the prompt cycle of the parameter cycle controlled by
click is already over.
Additionally, since the function checking whether the option had been
defined also considered an empty string as undefined, despite it being
the default, a specified empty string would still lead to the user to
be prompted, even when specifying
--non-interactive
.The fix is to make both options proper interactive options just like the
rest. To this end, we create the
TemplateInteractiveOption
that worksjust like the
InteractiveOption
with the only difference being that ituses a file editor instead of an inline prompt. This change does force
us to have both options pop up their own file editor, whereas before
they were joined in a single file and both files were specified in the
same file, separated by a header that we defined.