Skip to content
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

Documentation to mention pyproject.toml and build requirements #9796

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions docs/html/cli/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Installation Order
.. note::

This section is only about installation order of runtime dependencies, and
does not apply to build dependencies (those are specified using PEP 518).
does not apply to build dependencies (those are specified using `PEP_518`_).

As of v6.1.0, pip installs dependencies before their dependents, i.e. in
"topological order." This is the only commitment pip currently makes related
Expand Down Expand Up @@ -137,16 +137,17 @@ step. This has two main practical benefits:
an improvement.

Although the new install order is not intended to replace (and does not replace)
the use of ``setup_requires`` to declare build dependencies, it may help certain
projects install from sdist (that might previously fail) that fit the following
profile:
the use of build dependencies, using either ``setup_requires`` (discouraged) and
``build.requires``. The latter was proposed in `PEP_518`_ and will be the
prefered way to specify build dependencies in the future.

Using these methods may help certain projects install from sdist (that might
previously fail) that fit the following profile:

1. They have build dependencies that are also declared as install dependencies
using ``install_requires``.
2. ``python setup.py egg_info`` works without their build dependencies being
installed.
3. For whatever reason, they don't or won't declare their build dependencies using
``setup_requires``.
benjaoming marked this conversation as resolved.
Show resolved Hide resolved


.. _`Requirements File Format`:
Expand Down Expand Up @@ -732,14 +733,6 @@ Hash-checking mode also works with :ref:`pip download` and :ref:`pip wheel`. A
:ref:`comparison of hash-checking mode with other repeatability strategies
<Repeatability>` is available in the User Guide.

.. warning::

Beware of the ``setup_requires`` keyword arg in :file:`setup.py`. The
(rare) packages that use it will cause those dependencies to be downloaded
by setuptools directly, skipping pip's hash-checking. If you need to use
such a package, see :ref:`Controlling
setup_requires<controlling-setup-requires>`.

.. warning::

Be careful not to nullify all your security work when you install your
Expand Down Expand Up @@ -856,39 +849,47 @@ the project path. This is one advantage over just using ``setup.py develop``,
which creates the "egg-info" directly relative the current working directory.


.. _`controlling-setup-requires`:
.. _`build-dependencies`:

Controlling setup_requires
--------------------------
Build dependencies
------------------

Setuptools offers the ``setup_requires`` `setup() keyword
<https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords>`_
for specifying dependencies that need to be present in order for the
``setup.py`` script to run. Internally, Setuptools uses ``easy_install``
to fulfill these dependencies.
The encouraged way of specifying build dependencies is `PEP_518`_, which gives
us one unique choice of configuration file for a Python project: ``pyproject.toml``.
This file replaces the older standard ``setup.cfg``. A list of projects using
this are available on `Awesome pyproject.toml <https://github.com/carlosperate/awesome-pyproject>`__

pip has no way to control how these dependencies are located. None of the
package index options have an effect.
.. code-block:: toml

The solution is to configure a "system" or "personal" `Distutils configuration
file
<https://docs.python.org/3/install/index.html#distutils-configuration-files>`_ to
manage the fulfillment.
# The implicit default pyproject.toml

For example, to have the dependency located at an alternate index, add this:
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"] # PEP 508 specifications.

::

[easy_install]
index_url = https://my.index-mirror.com

To have the dependency located from a local directory and not crawl PyPI, add this:
.. _`controlling-setup-requires`:

::
Controlling setup_requires (deprecated)
---------------------------------------

.. warning::
As of
`setuptools>=0.42 <https://setuptools.readthedocs.io/en/latest/history.html#v42-0-0>`__,
using ``setup_requires`` will prefer pip (and not easy_install or setuptools)
to satisfy build requirements. Using older versions bypasses pip and is a
security risk.

.. warning::
As of
`setuptools>=0.52 <https://setuptools.readthedocs.io/en/latest/history.html#v52-0-0>`__,
using ``setup_requires`` will require pip already available on the target system.

[easy_install]
allow_hosts = ''
find_links = file:///path/to/local/archives/
Setuptools offers the ``setup_requires`` `setup() keyword
<https://setuptools.readthedocs.io/en/latest/setuptools.html#new-and-changed-setup-keywords>`_
for specifying dependencies that need to be present in order for the
``setup.py`` script to run.


Build System Interface
Expand Down Expand Up @@ -1225,3 +1226,6 @@ Examples

.. [1] This is true with the exception that pip v7.0 and v7.0.1 required quotes
around specifiers containing environment markers in requirement files.


.. _PEP_518: https://github.com/django-money/django-money/issues/595
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some kind of copy-paste error here - should have been https://www.python.org/dev/peps/pep-0518/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duly noted! The original reference can be updated to be:

:pep:`518`

Which is much easier to maintain, and avoid errors like this. :)

1 change: 1 addition & 0 deletions news/9796.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updates documentation to address concerns of mentioning setup_requires without the new encouraged alternatives in pyproject.toml