From d95c57cc7891b794b02c6fcb6317e8a71323c223 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Sat, 2 Oct 2021 13:12:39 -0500 Subject: [PATCH] Using `shlex.join()` when logging a command (#490) * Using `shlex.join()` when logging a command * Backport `shlex.join()` * Fix copy-pasta --- nox/command.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nox/command.py b/nox/command.py index 5f215096..b26f58df 100644 --- a/nox/command.py +++ b/nox/command.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import shlex import sys from typing import Any, Iterable, List, Optional, Sequence, Union @@ -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], *, @@ -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)}" cmd_path = which(cmd, paths)