File tree Expand file tree Collapse file tree
tests/execute/local_subprocess Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Shebang parsing now uses ``shlex ``, so a quoted interpreter path that contains spaces is kept as one argument when
2+ ``TOX_LIMITED_SHEBANG `` rewrites the invocation - by :user: `r3wretrhy `.
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import shlex
34from pathlib import Path
45
56
@@ -25,7 +26,11 @@ def shebang(exe: str) -> list[str] | None:
2526 decoded = shebang_line .decode ("UTF-8" )
2627 except UnicodeDecodeError :
2728 return None
28- return [i .strip () for i in decoded .strip ().split () if i .strip ()]
29+ try :
30+ parts = shlex .split (decoded .strip (), posix = True )
31+ except ValueError :
32+ return None
33+ return parts or None
2934
3035
3136__all__ = [
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ def test_shebang_found(tmp_path: Path) -> None:
1414 assert shebang (str (script_path )) == ["/bin/python" , "-c" ]
1515
1616
17+ def test_shebang_quoted_interpreter_path (tmp_path : Path ) -> None :
18+ script_path = tmp_path / "a"
19+ script_path .write_text ('#! "/Program Files/Python/python.exe" -c\n ' , encoding = "utf-8" )
20+ assert shebang (str (script_path )) == ["/Program Files/Python/python.exe" , "-c" ]
21+
22+
1723def test_shebang_file_missing (tmp_path : Path ) -> None :
1824 script_path = tmp_path / "a"
1925 assert shebang (str (script_path )) is None
You can’t perform that action at this time.
0 commit comments