Repository navigation
PEP 394: Allow the python command to not be installed, and other minor edits
#630
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Address Guido's review comments
- Loading branch information
commit 43ce4266bc1c0bb71b61038d0a9b65bbf710ddfd
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,8 @@ Python interpreter (i.e. the version invoked by the ``python`` command). | |
| * ``python2`` will refer to some version of Python 2.x. | ||
| * ``python3`` will refer to some version of Python 3.x. | ||
| * for the time being, all distributions *should* ensure that ``python``, | ||
| if installed, refers to the same target as ``python2``, unless the system | ||
| administrator or user deliberately override this. | ||
| if installed, refers to the same target as ``python2``, unless the user | ||
| deliberately overrides this or a virtual environment is active. | ||
| * however, end users should be aware that ``python`` refers to ``python3`` | ||
| on at least Arch Linux (that change is what prompted the creation of this | ||
| PEP), so ``python`` should be used in the shebang line only for scripts | ||
|
|
@@ -47,11 +47,7 @@ Recommendation | |
| * If the ``python`` command is installed, it should invoke the same version of | ||
| Python as the ``python2`` command (however, note that some distributions | ||
| have already chosen to have ``python`` implement the ``python3`` | ||
| command, and system administrators may be allowed to change the default; | ||
| see further recommendations and the `Rationale`_ and `Migration Notes`_ | ||
| below). | ||
| * The ``python`` command should be available whenever ``python2`` is available, | ||
| except in controlled environments as discussed below. | ||
| command; see the `Rationale`_ and `Migration Notes`_ below). | ||
| * The Python 2.x ``idle``, ``pydoc``, and ``python-config`` commands should | ||
| likewise be available as ``idle2``, ``pydoc2``, and ``python2-config``, | ||
| with the original commands invoking these versions by default, but possibly | ||
|
|
@@ -68,8 +64,8 @@ Recommendation | |
| compatible with both Python 2.x and 3.x. Such scripts may continue to use | ||
| ``python`` on their shebang line. | ||
| * When packaging software that is source compatible with both versions, | ||
| distributions may change such ``python`` shebangs to ``python3`` (or | ||
| ``python2``). This ensures software is used with the latest version of | ||
| distributions may change such ``python`` shebangs to ``python3``. | ||
| This ensures software is used with the latest version of | ||
| Python available, and it can remove a dependency on Python 2. | ||
| * When reinvoking the interpreter from a Python script, querying | ||
| ``sys.executable`` to avoid hardcoded assumptions regarding the | ||
|
|
@@ -81,11 +77,6 @@ Recommendation | |
| (All software in such a controlled environment must use ``python3`` or | ||
| ``python2`` rather than ``python``, which means scripts that deliberately | ||
| use ``python`` need to be modified for such environments.) | ||
| * System administrators and users may be empowered to change the meaning of | ||
| the ``python`` command to ``python3``. This should be a deliberate action | ||
| by the administrator. Related documentation should include a discussion | ||
| of the effects -- for example, a link to the "Migration Notes" section of | ||
| this PEP. | ||
| * When a virtual environment (created by the PEP 405 ``venv`` package or a | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes on this bullet. |
||
| similar tool) is active, the ``python`` command should refer to the | ||
| virtual environment's interpreter. In other words, activating a virtual | ||
|
|
@@ -94,7 +85,7 @@ Recommendation | |
|
|
||
| These recommendations are the outcome of the relevant python-dev discussions | ||
| in March and July 2011 ([1]_, [2]_), February 2012 ([4]_), | ||
| September 2014 ([6]_), and April 2018 (XXX). | ||
| September 2014 ([6]_), and discussion on GitHub in April 2018 ([7]_). | ||
|
|
||
|
|
||
| Rationale | ||
|
|
@@ -116,11 +107,6 @@ on the part of distribution maintainers. | |
| Future Changes to this Recommendation | ||
| ===================================== | ||
|
|
||
| It is anticipated that there will eventually come a time where the third | ||
| party ecosystem surrounding Python 2 becomes irrelevant in most use cases, | ||
| at which point this recommendation should be updated to suggest that the | ||
| ``python`` symlink refer to ``python3`` rather than ``python2``. | ||
|
|
||
| This recommendation will be periodically reviewed over the next few years, | ||
| and updated when the core development team judges it appropriate. As a | ||
| point of reference, regular maintenance releases for the Python 2.7 series | ||
|
|
@@ -175,15 +161,13 @@ making such a change. | |
| * When the ``pythonX.X`` binaries are provided by a distribution, the | ||
| ``python2`` and ``python3`` commands should refer to one of those files | ||
| rather than being provided as a separate binary file. | ||
| * It is suggested that distribution-specific packages use ``python2`` or | ||
| ``python3`` rather than ``python``, even in code that is not intended to | ||
| * It is strongly encouraged that distribution-specific packages use ``python2`` | ||
| or ``python3`` rather than ``python``, even in code that is not intended to | ||
| operate on other distributions. This will reduce problems if the | ||
| distribution later decides to change the version of the Python interpreter | ||
| that the ``python`` command invokes, or if a sysadmin installs a custom | ||
| ``python`` command with a different major version than the distribution | ||
| default. Distributions can test whether they are fully following this | ||
| convention by changing or removing the ``python`` command on a test box | ||
| and checking to see if anything breaks. | ||
| default. | ||
| * If the above point is adhered to and sysadmins are permitted to change the | ||
| ``python`` command, then the ``python`` command should always be implemented | ||
| as a link to the interpreter binary (or a link to a link) and not vice | ||
|
|
@@ -212,16 +196,6 @@ attempting to execute a script containing Python 2 specific syntax with a | |
| Python 3 interpreter. | ||
|
|
||
|
|
||
| Forward Compatibility | ||
| ===================== | ||
|
|
||
| A problem can arise if a script compatible with both Python 2 and 3, which | ||
| has ``python`` in its shebang line, is invoked on a system that does not have | ||
| Python 2 (and thus, the ``python`` command) installed. | ||
| This is mostly a non-issue -- as with any other case of a required interpreter | ||
| not being installed, the sysadmin can install the ``python`` command. | ||
|
|
||
|
|
||
| Application to the CPython Reference Interpreter | ||
| ================================================ | ||
|
|
||
|
|
@@ -302,6 +276,9 @@ References | |
| .. [6] PEP 394 - Clarification of what "python" command should invoke | ||
| (https://mail.python.org/pipermail/python-dev/2014-September/136374.html) | ||
|
|
||
| .. [7] PEP 394: Allow changing the `python` command in some cases | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest changing the PR title to match the contents. |
||
| (https://github.com/python/peps/pull/630) | ||
|
|
||
| Copyright | ||
| =========== | ||
| This document has been placed in the public domain. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(Then why the "or
python2" ?)