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

Using shlex.join() when logging a command #490

Merged
merged 3 commits into from Oct 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion nox/command.py
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import shlex
import sys
from typing import Any, Iterable, List, Optional, Sequence, Union

Expand Down Expand Up @@ -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)}"
Copy link
Collaborator Author

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

Copy link
Collaborator Author

@dhermes dhermes Oct 2, 2021

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>


cmd_path = which(cmd, paths)

Expand Down