-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
port shebang of tools from python2 to python3 #85792
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
Comments
After the EOL of python2, the shebang of tools should be ported from python2 to python3. some files like: https://github.com/python/cpython/blob/master/Objects/typeslots.py#L1 |
This is a minor thing, and not a particularly visible bug, but it could create confusion about how to run scripts so could be fixed. 1) For stdlib modules, I think the intended usage is 1.1) There may be some exceptions: for Lib/idlelib/pyshell.py for example, maybe the IDLE entry point is just a symlink to that file, and removing the executable bit would break it. So this can’t be a mass update but each case should be reviewed. 2) Some of the files in the PR are used during development of CPython: Tools/clinic/clinic.py Python/makeopcodetargets.py Parser/asdl_c.py Objects/typeslots.py Modules/_sha3/cleanup.py Lib/ctypes/macholib/fetch_macholib Mac/BuildScript/build-installer.py 2.1) One recent example, Tools/peg_generator/pegen/__main__.py is documented to work with Python 3.8+, and confusingly is both a __main__ module (to support python3 -m pegen and an executable script with shebang!) 2.2) In Tools/ssl, we have 3) The files in Tools/scripts are documented as «useful for building Python» or «generally useful scripts». They nearly all executable and nearly all use 3.1) For Tools/gdb/libpython.py I don’t know how it’s meant to be used; if it’s not distributed but only for debugging a locally built CPython, then removing the shebang seems correct. (Oh and by the way, Tools/scripts/fixps.py is a tool to replace So if things are changed (let’s get a couple opinions here), maybe this needs separate PRs for 1/2/3, and make sure to get reviews to ensure we don’t break IDLE / Mac installers / pegen / etc. |
To address some of the concerns:
#![install-prefix]/bin/python3.[n] from idlelib.pyshell import main
if __name__ == '__main__':
main() So there is an absolute link to the correct interpreter and the shebang in pyshell.py is not used. |
Thoughts I wrote on the PR that belong here. (Thanks for the reminder, Éric.):
-- I was not really aware of idlelib.pyshell. Running with an explicit binary seems particularly important for IDLE. About once a month on SO, some beginner posts about not being able to import a module they downloaded when running IDLE (maybe only sometimes). Nearly always, they have 2 pythons, such as from Anaconda and python.org. I may want or need to deprecate using pyshell as entry instead of idle.py/idlew.py/idle.bat as I want to move startup code from pyshell to either idle.py or a separate startup only file. I am not sure how to get from here to there, partly because I don't really know what 'here' is in practice.
|
Sorry for my delay~
I update Objects/typeslots.py in #PR21913 recently and using f-format in this script(it means that just local python or python3 can run). So I will accept your suggestion from this file after this PR merged:)
Thanks, I will take a look.
Agree. To corner case, a single sepereate PR is good. |
I create PR23581 to remove the inner Tools' shebang. But I am not remove Tools/ssl/make_ssl_data.py, Tools/gdb/libpython.py in PR23581.
|
make_ssl_data.py is an internal tool that generates internal header files. It's rarely used. The tool is not bound to any Python version, too. Feel free to change the shebang or leave it as it is. I don't care. |
As near as I can tell, encodings.rot_13 is currently the only$ /Lib module with a shebang line with 'python' rather than 'python3'. #108273 proposes to modify this one file. Does this seem appropriate? $ idlelib/idletest/example_noext has the same line (with a harmless bug), but it is a dummy file for testing whether IDLE recognizes an extensionless file with a python shebang line as python source. I intend to change it for consistency, but as part of a PR making other changes and changing other files and backporting them. As noted above, idlelib.pyshell has a 'python3' shebang line. It has not been the official initial startup file for at least a decade. idlelib.idle does not have such a line, so it seems to be unneeded. I will think about removing that line (and exec bit?) in 3.13. There seems to be as many /Lib files with |
I think that today, it's best to close this issue without action. python2/python3 confusion should be history now. |
This wasn’t only about 2 vs 3 ‑ there were also notes about stdlib modules having executable bit and shebang needlessly |
OK, I'll only close the PR for internal tools. |
That last part is handled in #118673 |
According to PEP 394, python may or may not be installed depending on a distribution or system configuration, so update the shebang to python3 [1] https://peps.python.org/pep-0394/ Signed-off-by: Changqing Li <[email protected]>
There are still several files using shebang "/usr/bin/env python", add a pull request to fix them. |
According to PEP 394, python may or may not be installed depending on a distribution or system configuration, so update the shebang to python3 [1] https://peps.python.org/pep-0394/ Signed-off-by: Changqing Li <[email protected]>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: