Skip to content

Commit 03059db

Browse files
Use relocatable shebang with space-in-path robustness (astral-sh#395)
## Summary The current shebang seems to fail when the path itself contains spaces. For example: ``` ❯ "/Users/crmarsh/Library/Application Support/uv/python/cpython-3.13.0-macos-aarch64-none/bin/pydoc3" /Users/crmarsh/Library/Application Support/uv/python/cpython-3.13.0-macos-aarch64-none/bin/pydoc3: line 2: /Users/crmarsh/Library Support/uv/python/cpython-3.13.0-macos-aarch64-none/bin/python3.13: No such file or directory /Users/crmarsh/Library/Application Support/uv/python/cpython-3.13.0-macos-aarch64-none/bin/pydoc3: line 2: exec: /Users/crmarsh/Library Support/uv/python/cpython-3.13.0-macos-aarch64-none/bin/python3.13: cannot execute: No such file or directory ``` This PR replaces it with the shebang that we use in uv for relocatable environments, which is outlined in the following series of PRs and issues: - https://github.com/astral-sh/uv/pull/5515/files#r1694358328 - astral-sh/uv#5640 - astral-sh/uv#8079 Closes astral-sh#394. Closes astral-sh/uv#9348.
1 parent 4a8625d commit 03059db

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cpython-unix/build-cpython.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,8 @@ def fix_shebang(full):
858858
859859
lines.extend([
860860
b"#!/bin/sh\n",
861-
b'"exec" "\$(dirname \$0)/python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}" "\$0" "\$@"\n',
861+
b"'''exec' \"\$(dirname -- \"\$(realpath -- \"\$0\")\")/python${PYTHON_MAJMIN_VERSION}${PYTHON_BINARY_SUFFIX}\" \"\$0\" \"\$@\"\n",
862+
b"' '''\n",
862863
])
863864
864865
lines.extend(fh)

0 commit comments

Comments
 (0)