-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add a comment to the x.py
shebang, using /usr/bin/env
#98747
Conversation
I feel like it might be simpler (and more instructive) to name the file something like "please_read_this_file.sh", and embed actual suggestions into the file. My sense was that the auto-discovery mechanism planned(?) or already implemented for the Windows py tooling will look in the Windows equivalent of /usr/bin for the file here -- will that work with a current-directory relative path? Will that work when invoking x.py from a different working directory (e.g., |
Linux: $ ../x.py
/bin/sh: 0: cannot open ./src/bootstrap/if_this_file_fails_to_run_try_using_python3_x.py_instead.sh: No such file |
The auto-discovery behavior of The goal in this PR is to use a shebang which is meaningful to POSIXy shells but will consistently fail and show a kinda-useful error message when run under
It at least looks like for MINGW, the first space (after a non-space) is split to get the program and a singular argument string. To recover split arguments you need to use
In MINGW, a relative path in the shebang is relative to cwd, not the file being interpreted. Footnotes
|
Independently: if this technique can be made to work, it's probably better to recommend |
fa04454
to
8d13dbe
Compare
I pushed a modified version of this that respects the current directory. Unfortunately it's a little less portable because it requires |
src/bootstrap/if_this_file_fails_to_run_try_using_python3_x.py_instead.sh
x.py
shebang, using /usr/bin/env
8d13dbe
to
23dcc32
Compare
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.
23dcc32
to
f234495
Compare
Co-authored-by: Christopher Durham <cad97@cad97.com>
|
|
``` | ||
to `%APPDATA%\py.ini`. | ||
|
||
5. Wait until October and update to the latest `py` wrapper, which fixes this bug: https://github.com/python/cpython/issues/94399#issuecomment-1170649407 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a year to this in case someone forgets to update this and it remains in place next year?
|
x.py
shebang, using /usr/bin/envx.py
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:This doesn't break anyone using python/python2/python3 directly, and still handles trying all three on distros where they might not exist. Unfortunately it's slightly less portable since not all
env
commands support -S and -u.Happy to take improvements on the file name - I'm slightly reluctant to use spaces or punctuation since lots of shell scripts are bad at handling those, but since nothing should be invoking this file directly other than the kernel, it's probably fine.
Helps with #98650.
r? @Mark-Simulacrum cc @dtolnay @CAD97 @yoshuawuyts