-
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
Containerized code: double quotes setting of computer and code setup #5478
Containerized code: double quotes setting of computer and code setup #5478
Conversation
Thanks @unkcpz . At a high level, I'm just wondering: do we really need to push this choice to the user? I.e. can't we be clever about using double quotes where necessary (if we detect some environment variable / ...)? This will be yet another option in the computer an code setup and I wonder whether people really need to actively care about this. |
Hi @ltalirz, yes ideally it should be intelligent enough to know when to use double quotes and not. But I think it is hard to decide by what criteria we escape it with double or single quotes. Setting it manually might be a safe way to keep the backward compatibility. |
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 @unkcpz . Mostly minor comments, but one fundamental question: is the separate control of quoting in the Code
and Computer
necessary? And if so, why should the quoting for the Computer
only apply to the argument before the executable and not any that follows, such as the input and output redirection?
aiida/orm/computers.py
Outdated
def get_use_double_quotes(self) -> bool: | ||
return self.get_property('use_double_quotes', False) | ||
|
||
def set_use_double_quotes(self, val: bool) -> None: | ||
self.set_property('use_double_quotes', bool(val)) |
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.
Instead of type coercion, I think you should check the type.
from aiida.common.lang import type_check
type_check(val, bool)
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, changed.
aiida/orm/nodes/data/code.py
Outdated
""" | ||
Set whether a code cmdline is escape with double quotes. | ||
""" |
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.
""" | |
Set whether a code cmdline is escape with double quotes. | |
""" | |
"""Set whether the command line invocation of this code should be escaped with double quotes. | |
:param use_double_quotes: boolean, True if to escape with double quotes, False otherwise. | |
""" |
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 was resolved, but I don't see the changes?
aiida/orm/nodes/data/code.py
Outdated
def get_use_double_quotes(self): | ||
""" | ||
Return whether a code is escape with double quotes (False, default) or not (True). | ||
""" |
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.
"""Return whether the command line invocation of this code should be escaped with double quotes.
:returns: boolean, True if to escape with double quotes, False otherwise which is also the default.
"""
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 here. Don't see the changes.
is_eager=False, | ||
default=False, | ||
cls=InteractiveOption, | ||
prompt='Whether use double quotes for prepend cmdline params?', |
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.
prompt='Whether use double quotes for prepend cmdline params?', | |
prompt='Escape CLI arguments in double quotes', |
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.
@sphuber thanks for the review and sorry for the delay of changes and reply, suffer from COVID last week.
I implement most of your suggestions and also docstring of use_double_quotes
of JobTemplateCodeInfo
.
but one fundamental question: is the separate control of quoting in the Code and Computer necessary?
I think there are two reasons to apply it independently: 1. it is more flexible and more possible for backward compatibility if it can be controlled separately. 2. with initial containerized code implementation (the PR after this PR) the specific suffix for using containerized code is independent of cmdline_params
parts of code and double quotes escape needed since I want to use $PWD
to map working directory to the directory where the inputs locate. While for the code part it can keep the same.
aiida/orm/computers.py
Outdated
def get_use_double_quotes(self) -> bool: | ||
return self.get_property('use_double_quotes', False) | ||
|
||
def set_use_double_quotes(self, val: bool) -> None: | ||
self.set_property('use_double_quotes', bool(val)) |
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, changed.
aiida/schedulers/datastructures.py
Outdated
cmdline_params: list[str] = field(default_factory=list) | ||
use_double_quotes: list[bool] = field(default_factory=list) |
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.
prepend_cmdine_params
is to collect all computer related params (mpi parameters, scheduler parameters) that are shown in front of the executable and arguments of code.
exec 2> _scheduler-stderr.txt | ||
|
||
|
||
"mpirun" "-np" "1" '/bin/bash' < 'aiida.in' > 'aiida.out' 2> 'aiida.err' |
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.
Yes, I think so. I didn't implement it since it is not relevant to the following up features. It makes sense to also call these the computer related parameters. Changed.
codeinfo.stderr_name = 'aiida.err' | ||
|
||
calcinfo = CalcInfo() | ||
calcinfo.codes_info = [codeinfo] |
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.
Yes, it is affected. test added.
tests/cmdline/commands/test_code.py
Outdated
'--on-computer', | ||
f'--computer={aiida_localhost.label}', | ||
'--remote-abs-path=/remote/abs/path', | ||
'--use-double-quotes', |
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.
It was added to check if this option can be used and take effect. But rather not test it here. Removed.
24eabaf
to
964ba11
Compare
Thanks @unkcpz . Hope you are feeling better. I noticed that you resolved a few comments that don't seem to actually have been addressed. At least I cannot see the changes of the suggestions I made. Also the tests and pre-commit are failing. Please fix those and update the branch. |
1797d75
to
4a21ea5
Compare
@sphuber sorry for the carelessness, I wrongly mix up commits and push to the actual container code implementation branch locally previously. Now it is rebased a bit and passes all the tests. |
So far, the command line arguments of the code exeuction line in the submit script written by the `Scheduler` plugin, would be wrapped by single quotes to prevent special characters, such as spaces, from being interpreted incorrectly. However, for certain use cases, the quoting has an undesirable effect. For example, if an argument contains a bash variable, indicated by a `$` sign, the single quotes will prevent it from being dereferenced correctly. A concrete use-case is the requested feature of being able to define a Docker container as a `Code`, which needs certain arguments to be quoted in double quotes. This PR adds a new property `use_double_quotes` to the `Code` and `Computer` classes that determines whether arguments should be quoted using single or double quotes. The settings are communicated through the `cmdline_params` attribute of a `JobTemplateCodeInfo` instance to the scheduler plugin. The plugin is then responsible for respecting these booleans. To be able to distinguish between the command line arguments of the computer and the code, they are passed separately in `prepend_cmdline_params` and `cmdline_params`, respectively.
4be3c8b
to
38b14dc
Compare
Thanks @unkcpz ! |
The PR is a part required for containerized code implementation (also for hyperqueue without hacky workaround to evaluate command-line variable by
$
properly) and is separated from #5250. It allows users to set up computer and code with an extra option--use-double-quotes
to using double quotes for the command run line of job script.