Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shebangs in (e.g.) pydoc3 fail for paths with spaces on macOS #394

Closed
charliermarsh opened this issue Nov 24, 2024 · 1 comment · Fixed by #395
Closed

Shebangs in (e.g.) pydoc3 fail for paths with spaces on macOS #394

charliermarsh opened this issue Nov 24, 2024 · 1 comment · Fixed by #395
Assignees
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

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

The script looks like:

#!/bin/sh
"exec" "$(dirname $0)/python3.13" "$0" "$@"

import pydoc
if __name__ == '__main__':
    pydoc.cli()

In uv, however, our relocatable shebang looks like:

#!/bin/sh
'''exec' "$(dirname -- "$(realpath -- "$0")")"/'python3' "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re
import sys
from black import patched_main
if __name__ == "__main__":
    sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
    sys.exit(patched_main())

(\ht to @paveldikov who authored it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant