-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Using shlex.join()
when logging a command
#490
Conversation
nox/command.py
Outdated
@@ -84,7 +85,7 @@ def run( | |||
success_codes = [0] | |||
|
|||
cmd, args = args[0], args[1:] | |||
full_cmd = f"{cmd} {' '.join(args)}" | |||
full_cmd = f"{cmd} {shlex.join(args)}" |
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.
Aw man; added in 3.8
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.
Luckily the implementation is dead simple:
def join(split_command):
"""Return a shell-escaped string from *split_command*."""
return ' '.join(quote(arg) for arg in split_command)
and
$ python3.6 -c 'import shlex; print(shlex.quote)'
<function quote at 0x7f9c9e123d08>
$ python3.7 -c 'import shlex; print(shlex.quote)'
<function quote at 0x1023fd710>
nox/command.py
Outdated
@@ -67,6 +68,11 @@ def _clean_env(env: Optional[dict]) -> Optional[dict]: | |||
return clean_env | |||
|
|||
|
|||
def _shlex_join(args: Sequence[str]) -> str: | |||
# shlex.join() was added in Python 3.8 | |||
return " ".join(shlex.quote(arg) for arg in split_command) |
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.
Whoops, copy-pasta life
@@ -84,7 +90,7 @@ def run( | |||
success_codes = [0] | |||
|
|||
cmd, args = args[0], args[1:] | |||
full_cmd = f"{cmd} {' '.join(args)}" | |||
full_cmd = f"{cmd} {_shlex_join(args)}" |
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 occurs to me I should probably do a docs search for python -m pip
and see what should be updated.
(As reviewers may already see from the branch name, I made this PR fully from the browser.)
Thanks @dhermes! |
No description provided.