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 all commits
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
8 changes: 7 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 @@ -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 args)


def run(
args: Sequence[str],
*,
Expand All @@ -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)}"
Copy link
Collaborator Author

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.)


cmd_path = which(cmd, paths)

Expand Down