Skip to content

Commit f234495

Browse files
committed
Add a commment to the shebang, using /usr/bin/env
This is a terrible, horrible, no-good, very-bad idea. I kind of like it. --- Shebang files can't have comments, so instead this passes `--unset VAR`, where the variable name itself is the comment. Here's an example run of `py` on Windows: ``` PS C:\Users\Joshua Nelson\src\rust> py x.py Unable to create process using '/usr/bin/env -S -u If_this_file_fails_to_run,read_README_ENTRYPOINT.md bash ./x.py' ``` This doesn't break anyone using python/python2/python3 directly, and still handles trying all three on distros where they might not exist.
1 parent 7425fb2 commit f234495

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: README_ENTRYPOINT.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
There is no file shebang for python that works on all platforms (#71818).
2+
To minimize breakage we have chosen to make this work when `env` is in path, or when using python/python2/python3 directly.
3+
Unfortunately, this breaks users using the `py` wrapper on Windows, where env isn't supported outside of MingW shells.
4+
5+
You can do one of the following things to get x.py working:
6+
1. Use any of `python`, `python2`, `python3`, `py -2`, or `py -3` to invoke x.py.
7+
2. Use a MingW shell (often installed as "Git Bash", or through Cygwin).
8+
3. Set the default file handler for .py files, which will allow using `./x.py` directly: `ftype Python.File="C:\Windows\py.exe" "-3" "%L" %*`.
9+
`py` may be installed in a different location; use `where py` to determine where.
10+
4. Set a default python interpreter for the `py` wrapper: Add
11+
```ini
12+
[commands]
13+
bash=python
14+
```
15+
to `%APPDATA%\py.ini`.
16+
17+
5. Wait until October and update to the latest `py` wrapper, which fixes this bug: https://github.com/python/cpython/issues/94399#issuecomment-1170649407

Diff for: x.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env -S -u If_this_file_fails_to_run,read_README_ENTRYPOINT.md bash
2+
# `py` fails when using a shebang other than /usr/bin/python{,2,3}.
3+
# Try and give a better error by embedding a comment in the shebang.
24

35
# Modern Linux and macOS systems commonly only have a thing called `python3` and
46
# not `python`, while Windows commonly does not have `python3`, so we cannot

0 commit comments

Comments
 (0)