diff options
author | Donald Stufft <donald@stufft.io> | 2014-11-11 15:24:11 (GMT) |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2014-11-11 15:24:11 (GMT) |
commit | 8aaff54db30b902702feb99344e60d77ddd6a551 (patch) | |
tree | 7654ff5d04bcc726cac393f72f62cedff2f0a05c /Doc | |
parent | 04eee639499f3d643e14099b7374bc8a259af015 (diff) | |
download | cpython-8aaff54db30b902702feb99344e60d77ddd6a551.zip cpython-8aaff54db30b902702feb99344e60d77ddd6a551.tar.gz cpython-8aaff54db30b902702feb99344e60d77ddd6a551.tar.bz2 |
Implement PEP 477 - Backport ensurepip (PEP 453) to 2.7
* Backports ensurepip to the 2.7 branch
* Backports some of the improved documentation to the 2.7 branch.
* Adds a private backport of the 3.x mock library as test._mock_backport
to enable saner testing of ensurepip.
Key Differences from 3.x:
* Ensurepip does not have any Makefile integration, specifically
it is not ran by default in the Makefile.
* There is no venv module in 2.7, so downstream distributors can
completely disable ensurepip, ideally with a message redirecting
to the correct way to install pip.
* To match the ``python`` command in 2.7, ensurepip will install
the unversioned ``pip`` command as well.
* No-op and hide --default-pip and add --no-default-pip to restore
the 3.x behavor on 2.7.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/distribution.rst | 13 | ||||
-rw-r--r-- | Doc/library/ensurepip.rst | 130 | ||||
-rw-r--r-- | Doc/library/index.rst | 1 | ||||
-rw-r--r-- | Doc/library/python.rst | 1 | ||||
-rw-r--r-- | Doc/whatsnew/2.7.rst | 59 |
5 files changed, 203 insertions, 1 deletions
diff --git a/Doc/library/distribution.rst b/Doc/library/distribution.rst new file mode 100644 index 0000000..b560999 --- /dev/null +++ b/Doc/library/distribution.rst @@ -0,0 +1,13 @@ +*********************************** +Software Packaging and Distribution +*********************************** + +These libraries help you with publishing and installing Python software. +While these modules are designed to work in conjunction with the +`Python Package Index <https://pypi.python.org>`__, they can also be used +with a local index server, or without any index server at all. + +.. toctree:: + + distutils.rst + ensurepip.rst diff --git a/Doc/library/ensurepip.rst b/Doc/library/ensurepip.rst new file mode 100644 index 0000000..7206300 --- /dev/null +++ b/Doc/library/ensurepip.rst @@ -0,0 +1,130 @@ +:mod:`ensurepip` --- Bootstrapping the ``pip`` installer +======================================================== + +.. module:: ensurepip + :synopsis: Bootstrapping the ``pip`` installer into an existing Python + installation or virtual environment. + +.. versionadded:: 2.7.9 + +The :mod:`ensurepip` package provides support for bootstrapping the ``pip`` +installer into an existing Python installation or virtual environment. This +bootstrapping approach reflects the fact that ``pip`` is an independent +project with its own release cycle, and the latest available stable version +is bundled with maintenance and feature releases of the CPython reference +interpreter. + +In most cases, end users of Python shouldn't need to invoke this module +directly (as ``pip`` should be bootstrapped by default), but it may be +needed if installing ``pip`` was skipped when installing Python (or +when creating a virtual environment) or after explicitly uninstalling ``pip``. + +.. note:: + + This module *does not* access the internet. All of the components + needed to bootstrap ``pip`` are included as internal parts of the + package. + +.. seealso:: + + :ref:`installing-index` + The end user guide for installing Python packages + + :pep:`453`: Explicit bootstrapping of pip in Python installations + The original rationale and specification for this module. + + :pep:`477`: Backport ensurepip (PEP 453) to Python 2.7 + The rationale and specification for backporting PEP 453 to Python 2.7. + + +Command line interface +---------------------- + +The command line interface is invoked using the interpreter's ``-m`` switch. + +The simplest possible invocation is:: + + python -m ensurepip + +This invocation will install ``pip`` if it is not already installed, +but otherwise does nothing. To ensure the installed version of ``pip`` +is at least as recent as the one bundled with ``ensurepip``, pass the +``--upgrade`` option:: + + python -m ensurepip --upgrade + +By default, ``pip`` is installed into the current virtual environment +(if one is active) or into the system site packages (if there is no +active virtual environment). The installation location can be controlled +through two additional command line options: + +* ``--root <dir>``: Installs ``pip`` relative to the given root directory + rather than the root of the currently active virtual environment (if any) + or the default root for the current Python installation. +* ``--user``: Installs ``pip`` into the user site packages directory rather + than globally for the current Python installation (this option is not + permitted inside an active virtual environment). + +By default, the scripts ``pip``, ``pipX``, and ``pipX.Y`` will be installed +(where X.Y stands for the version of Python used to invoke ``ensurepip``). The +scripts installed can be controlled through two additional command line +options: + +* ``--altinstall``: if an alternate installation is requested, the ``pip`` and + ``pipX`` script will *not* be installed. + +* ``--no-default-pip``: if a non-default installation is request, the ``pip`` + script will *not* be installed. + + +Module API +---------- + +:mod:`ensurepip` exposes two functions for programmatic use: + +.. function:: version() + + Returns a string specifying the bundled version of pip that will be + installed when bootstrapping an environment. + +.. function:: bootstrap(root=None, upgrade=False, user=False, \ + altinstall=False, default_pip=True, \ + verbosity=0) + + Bootstraps ``pip`` into the current or designated environment. + + *root* specifies an alternative root directory to install relative to. + If *root* is None, then installation uses the default install location + for the current environment. + + *upgrade* indicates whether or not to upgrade an existing installation + of an earlier version of ``pip`` to the bundled version. + + *user* indicates whether to use the user scheme rather than installing + globally. + + By default, the scripts ``pip``, ``pipX``, and ``pipX.Y`` will be installed + (where X.Y stands for the current version of Python). + + If *altinstall* is set, then ``pip`` and ``pipX`` will *not* be installed. + + If *default_pip* is set to ``False``, then ``pip`` will *not* be installed. + + Setting both *altinstall* and *default_pip* will trigger + :exc:`ValueError`. + + *verbosity* controls the level of output to :data:`sys.stdout` from the + bootstrapping operation. + + .. note:: + + The bootstrapping process has side effects on both ``sys.path`` and + ``os.environ``. Invoking the command line interface in a subprocess + instead allows these side effects to be avoided. + + .. note:: + + The bootstrapping process may install additional modules required by + ``pip``, but other software should not assume those dependencies will + always be present by default (as the dependencies may be removed in a + future version of ``pip``). diff --git a/Doc/library/index.rst b/Doc/library/index.rst index 5d335e4..4b465d9 100644 --- a/Doc/library/index.rst +++ b/Doc/library/index.rst @@ -63,6 +63,7 @@ the `Python Package Index <https://pypi.python.org/pypi>`_. tk.rst development.rst debug.rst + distribution.rst python.rst custominterp.rst restricted.rst diff --git a/Doc/library/python.rst b/Doc/library/python.rst index aaf1abd..1ebc329 100644 --- a/Doc/library/python.rst +++ b/Doc/library/python.rst @@ -28,4 +28,3 @@ overview: site.rst user.rst fpectl.rst - distutils.rst diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst index 9d26893..3fde2d8 100644 --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -2575,6 +2575,65 @@ with the first of those changes appearing in the Python 2.7.7 release. Gaynor; :issue:`21305`.) +PEP 477: Backport ensurepip (PEP 453) to Python 2.7 +--------------------------------------------------- + +:pep:`477` approves the inclusion of the :pep:`453` ensurepip module and the +improved documentation that was enabled by it in the Python 2.7 maintenance +releases, appearing first in the the Python 2.7.9 release. + + +Bootstrapping pip By Default +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The new :mod:`ensurepip` module (defined in :pep:`453`) provides a standard +cross-platform mechanism to bootstrap the pip installer into Python +installations. The version of ``pip`` included with Python 2.7.9 is ``pip`` +1.5.6, and future 2.7.x maintenance releases will update the bundled version to +the latest version of ``pip`` that is available at the time of creating the +release candidate. + +By default, the commands ``pip``, ``pipX`` and ``pipX.Y`` will be installed on +all platforms (where X.Y stands for the version of the Python installation), +along with the ``pip`` Python package and its dependencies. + +On Windows and Mac OS X, the CPython installers now default to installing +``pip`` along with CPython itself (users may opt out of installing it +during the installation process). Window users will need to opt in to the +automatic ``PATH`` modifications to have ``pip`` available from the command +line by default, otherwise it can still be accessed through the Python +launcher for Windows as ``py -m pip``. + +As `discussed in the PEP`__, platform packagers may choose not to install +these commands by default, as long as, when invoked, they provide clear and +simple directions on how to install them on that platform (usually using +the system package manager). + +__ https://www.python.org/dev/peps/pep-0477/#disabling-ensurepip-by-downstream-distributors + + +Documentation Changes +~~~~~~~~~~~~~~~~~~~~~ + +As part of this change, the :ref:`installing-index` and +:ref:`distributing-index` sections of the documentation have been +completely redesigned as short getting started and FAQ documents. Most +packaging documentation has now been moved out to the Python Packaging +Authority maintained `Python Packaging User Guide +<http://packaging.python.org>`__ and the documentation of the individual +projects. + +However, as this migration is currently still incomplete, the legacy +versions of those guides remaining available as :ref:`install-index` +and :ref:`distutils-index`. + +.. seealso:: + + :pep:`453` -- Explicit bootstrapping of pip in Python installations + PEP written by Donald Stufft and Nick Coghlan, implemented by + Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily. + + .. ====================================================================== .. _acks27: |