-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change output_of to execute commands with shell_tools.run #5541
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
Change output_of to execute commands with shell_tools.run #5541
Conversation
Implement using shell_tools.run instead of run_cmd slated for removal.
dev_tools/shell_tools.py
Outdated
| code and the `check` flag was True (default). | ||
| """ | ||
| result = cast(str, run_cmd(*cmd, log_run_to_stderr=False, out=TeeCapture(), **kwargs).out) | ||
| cmdpure = [w for w in cmd if w is not None] |
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.
nit: Should this check be inside run()? Do all callers of run() need to check this?
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.
I'd like to have a minimum difference between behavior of shell_tools.run and subprocess.run, so I'd rather not do any filtering of the cmd arguments.
For consistency sake it is perhaps better to have output_of() handle arguments in the same way as run() and do the argument filtering in the caller. I have checked the references to output_of and it seems easily doable.
dev_tools/shell_tools.py
Outdated
| Args: | ||
| *cmd: Components of the command to execute, e.g. ["echo", "dog"]. | ||
| **kwargs: Extra arguments for asyncio.create_subprocess_shell, such as | ||
| Arguments set to None are disregarded in command execution. |
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.
What if we change the type of cmd to str instead of Optional[str]?
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.
Good point - see my previous comment. I am inclined to use the same argument interface in output_of() as is in run().
Will do a follow-up commit.
Pass command arguments to shell_tools.run unmodified. Remove filtering of the None items in command argument list; leave this up to the caller.
output_of requires command-line arguments in a list. Also do the filtering of an optional None items before the call.
|
@verult - updated and ready for review. |
verult
left a comment
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.
LGTM, thanks Pavol!
…#5541) Stop using `shell_tools.run_cmd()` which is slated for removal. Get command output with `shell_tools.run()` instead. Update `output_of()` to receive command-line arguments in a list or string in order to have the same interface as `run()`. Remove filtering of the optional None arguments, leave it up to callers to take care of that. Partially implements quantumlib#4394
Stop using
shell_tools.run_cmd()which is slated for removal.Get command output with
shell_tools.run()instead.Update
output_of()to receive command-line arguments ina list or string in order to have the same interface as
run().Remove filtering of the optional None arguments,
leave it up to callers to take care of that.
Partially implements #4394