INNER CODE UNIT · Python
_split_pip_args
pypa/pipx · src/pipx/main.py:222
def _split_pip_args(value: str) -> list[str]:
# cmd.exe and PowerShell hand the quotes over verbatim, so drop a pair wrapping the whole value; any other pair
# belongs to one argument, as in --find-links '/tmp/foo bar'
if len(value) > 1 and value[0] == "'" and value.find("'", 1) == len(value) - 1:
value = value[1:-1]
lexer: Final[shlex.shlex] = shlex.shlex(value, posix=True)
lexer.whitespace_split = True
lexer.commenters = ""
if WINDOWS:
# posix=False leaves the quotes inside each token and pip then reads them as part of the path; posix quoting
# without escapes keeps the backslash a path separator instead
lexer.escape = ""
try:
return list(lexer)
except ValueError as exc:
msg = f"invalid pip arguments: {exc}"
raise PipxError(msg) from exc