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

verdi code create: Do not prompt for --with-mpi #5931

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 15, 2023

Fixes #5930

The --with-mpi/--no-with-mpi flag allows to set the with_mpi
attribute on the code. This attribute is optional and allows None as
a default but since the option is a boolean flag, in interactive mode,
it prompts and forces the user to choose True or False and it is not
possible to leave it unset, which should be the default behavior.

To solve this, DynamicEntryPointCommandGroup.create_option method,
which is used to dynamically generate the CLI options for the various
code subclasses, is updated to remove the prompt for flag options if the
default is None. Now, the option will no longer prompt in interactive
mode (and set None as the default), but the flag can still be used in
non-interactive mode.

Sebastiaan Huber added 2 commits March 15, 2023 16:30
This option prevents linebreaks after keys in dictionaries if the values
exceed the maximum column width. This happens for example in
dictionaries where values are long multiline strings. If the string
exceeds the max length, it is put on the next line, which is not too
bad, but so are all other values in the dictionary, even those that are
not too long. This leads to difficult to read formatting.
The `--with-mpi/--no-with-mpi` flag allows to set the `with_mpi`
attribute on the code. This attribute is optional and allows `None` as
a default but since the option is a boolean flag, in interactive mode,
it prompts and forces the user to choose `True` or `False` and it is not
possible to leave it unset, which should be the default behavior.

To solve this, `DynamicEntryPointCommandGroup.create_option` method,
which is used to dynamically generate the CLI options for the various
code subclasses, is updated to remove the prompt for flag options if the
default is `None`. Now, the option will no longer prompt in interactive
mode (and set `None` as the default), but the flag can still be used in
non-interactive mode.
@sphuber sphuber requested review from ltalirz and unkcpz March 15, 2023 21:22
Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks for the fix @sphuber

I guess there are some tests for interactive mode, right? so one could add a test here. anyhow, it's ok for me if you tested it manually

@sphuber
Copy link
Contributor Author

sphuber commented Mar 16, 2023

Yes, I checked it manually:

(aiida_dev) sph@invader:~/code/aiida/env/dev/aiida-core$ verdi code create core.code.installed 
Report: enter ? for help.
Report: enter ! to ignore the default and set no value.
Computer: localhost
Absolute filepath executable: bash
Label: testing
Description: 
Description: !@
Default `CalcJob` plugin: core.arithmetic.add
Escape using double quotes [y/N]: 
Success: Created InstalledCode<29212>

But indeed there are test for interactive mode, and the fact that I didn't have to add a line in the user input for that test, testifies that the new option is not prompted for.

@sphuber sphuber merged commit 02d834b into aiidateam:main Mar 16, 2023
@sphuber sphuber deleted the fix/5930/verdi-optional-boolean-flag-interactive branch March 16, 2023 13:28
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.

verdi code create should allow not setting --with-mpi in interactive mode
2 participants