Skip to content

Conversation

@pavoljuhas
Copy link
Collaborator

@pavoljuhas pavoljuhas commented Jun 16, 2022

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 #4394

Implement using shell_tools.run instead of run_cmd slated for removal.
@pavoljuhas pavoljuhas requested review from a team, cduck and vtomole as code owners June 16, 2022 23:17
@pavoljuhas pavoljuhas requested a review from dabacon June 16, 2022 23:17
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jun 16, 2022
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]
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

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.
Copy link
Collaborator

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]?

Copy link
Collaborator Author

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.
@pavoljuhas
Copy link
Collaborator Author

@verult - updated and ready for review.

Copy link
Collaborator

@verult verult left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Pavol!

@pavoljuhas pavoljuhas added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 17, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 17, 2022
@CirqBot CirqBot merged commit c58dd4d into quantumlib:master Jun 17, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jun 17, 2022
@pavoljuhas pavoljuhas deleted the update-shell_tools.output_of branch June 17, 2022 20:21
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants