Apply PEP 486 changes from Paul Moore

This commit is contained in:
Chris Angelico 2015-02-15 02:33:55 +11:00
parent 72478f7d5f
commit eb73a3b869
1 changed files with 19 additions and 19 deletions

View File

@ -83,6 +83,7 @@ will always be used (as at present).
Impact on Script Launching Impact on Script Launching
========================== ==========================
As well as interactive use, the launcher is used as the Windows file As well as interactive use, the launcher is used as the Windows file
association for Python scripts. In that case, a "shebang" (``#!``) association for Python scripts. In that case, a "shebang" (``#!``)
line at the start of the script is used to identify the interpreter to line at the start of the script is used to identify the interpreter to
@ -90,26 +91,18 @@ run. A fully-qualified path can be used, or a version-specific Python
(``python3`` or ``python2``, or even ``python3.5``), or the generic (``python3`` or ``python2``, or even ``python3.5``), or the generic
``python``, which means to use the default interpreter. ``python``, which means to use the default interpreter.
With the proposed change, scripts that start with ``#!python`` (or one The launcher also looks for the specific shebang line
of its equivalent forms) will be run using an active virtualenv. This ``#!/usr/bin/env python``. On Unix, the ``env`` program searches for a
is a change in behaviour, although it will only affect users running command on ``$PATH`` and runs the command so located. Similarly, with
scripts from the command line with a virtualenv activated. this shebang line, the launcher will look for a copy of ``python.exe``
on the user's current ``%PATH%`` and will run that copy.
Under Unix, the ``#!/usr/bin/env python`` shebang line will use the As activating a virtualenv means that it is added to ``PATH``, no
version of Python found on ``$PATH``, whereas ``#!/usr/bin/python`` special handling is needed to run scripts with the active virtualenv -
will use the system Python. In order to match Unix behaviour as they just need to use the ``#!/usr/bin/env python`` shebang line,
closely as possible, it is proposed that the two shebang forms:: exactly as on Unix. (If there is no activated virtualenv, and no
``python.exe`` on ``PATH``, the launcher will look for a default
#!/usr/bin/env python Python exactly as if the shebang line had said ``#!python``).
#!python
use an active virtualenv, if present, whereas the forms::
#!/usr/bin/python
#!/usr/local/bin/python
use *only* the default system Python, and ignore the ``VIRTUAL_ENV``
environment variable.
Exclusions Exclusions
@ -126,6 +119,13 @@ dealing with their system Python installations, to be able to continue
to do so when using virtual environments. to do so when using virtual environments.
Reference Implementation
========================
A patch implementing the proposed behaviour is available at
http://bugs.python.org/issue23465
References References
========== ==========