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
==========================
As well as interactive use, the launcher is used as the Windows file
association for Python scripts. In that case, a "shebang" (``#!``)
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
``python``, which means to use the default interpreter.
With the proposed change, scripts that start with ``#!python`` (or one
of its equivalent forms) will be run using an active virtualenv. This
is a change in behaviour, although it will only affect users running
scripts from the command line with a virtualenv activated.
The launcher also looks for the specific shebang line
``#!/usr/bin/env python``. On Unix, the ``env`` program searches for a
command on ``$PATH`` and runs the command so located. Similarly, with
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
version of Python found on ``$PATH``, whereas ``#!/usr/bin/python``
will use the system Python. In order to match Unix behaviour as
closely as possible, it is proposed that the two shebang forms::
#!/usr/bin/env 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.
As activating a virtualenv means that it is added to ``PATH``, no
special handling is needed to run scripts with the active virtualenv -
they just need to use the ``#!/usr/bin/env python`` shebang line,
exactly as on Unix. (If there is no activated virtualenv, and no
``python.exe`` on ``PATH``, the launcher will look for a default
Python exactly as if the shebang line had said ``#!python``).
Exclusions
@ -126,6 +119,13 @@ dealing with their system Python installations, to be able to continue
to do so when using virtual environments.
Reference Implementation
========================
A patch implementing the proposed behaviour is available at
http://bugs.python.org/issue23465
References
==========