diff --git a/poetry/utils/_compat.py b/poetry/utils/_compat.py index 24759f5e641..ba291d5f522 100644 --- a/poetry/utils/_compat.py +++ b/poetry/utils/_compat.py @@ -46,15 +46,11 @@ WINDOWS = sys.platform == "win32" -if PY2: - import pipes - - shell_quote = pipes.quote -else: - import shlex - - shell_quote = shlex.quote - +try: + from shlex import quote +except ImportError: + # PY2 + from pipes import quote # noqa if PY34: from importlib.machinery import EXTENSION_SUFFIXES @@ -288,4 +284,18 @@ def to_str(string): def list_to_shell_command(cmd): - return " ".join(shell_quote(token) if " " in token else token for token in cmd) + tokens = [] + + idx = 0 + for idx, token in enumerate(cmd): + if token == "-": + tokens.append(token) + break + tokens.append( + quote(token) if " " in token and token[0] not in {"'", '"'} else token + ) + + if idx < len(cmd) - 1: + tokens.extend(cmd[idx:]) + + return " ".join(tokens)