Skip to content

Commit ab07e44

Browse files
committed
Document self-referential extras now that pip officially supports it
Relevant PR: pypa/pip#14157 Relevant Issue: pypa/pip#11296
1 parent e0c56aa commit ab07e44

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎source/guides/writing-pyproject-toml.rst‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ Each of the keys defines a "packaging extra". In the example above, one
175175
could use, e.g., ``pip install your-project-name[gui]`` to install your
176176
project with GUI support, adding the PyQt5 dependency.
177177

178+
.. _self-referential-extras:
179+
180+
You can also define an extra that refers back to the same project with
181+
other extras. This is useful for convenience extras that combine several
182+
optional features without duplicating their dependency lists:
183+
184+
.. code-block:: toml
185+
186+
all = ["your-project-name[gui, cli]"]
187+
188+
Installing ``your-project-name[all]`` then installs both the ``gui`` and
189+
``cli`` dependencies. You can also list extras separately, for example
190+
``["your-project-name[gui]", "your-project-name[cli]"]``. The name in the
191+
requirement must match the project's ``name`` field. Installers such as
192+
:ref:`pip` and :ref:`uv` support this pattern already (pip since v21.2).
193+
178194

179195
.. _requires-python:
180196
.. _python_requires:
@@ -555,6 +571,7 @@ A full example
555571
"rich",
556572
"click",
557573
]
574+
all = ["spam-eggs[gui, cli]"]
558575
559576
[project.urls]
560577
Homepage = "https://example.com"

‎source/specifications/pyproject-toml.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ marker clause on the related ``Requires-Dist`` entries to check the extra name.
498498
Optional dependencies are thus only considered for installation if installation
499499
if the associated extra name is requested.
500500

501+
A dependency specifier in an extra MAY name the project itself with other extras
502+
(for example, ``all = ["spam[gui, cli]"]``). That way a combined extra does not
503+
need its own manually maintained copy of each referenced extra's dependencies,
504+
which can otherwise fall out of sync. Installers that support self-referential
505+
extras will be able to install the union of these extras' dependencies. See
506+
:ref:`self-referential extras <self-referential-extras>` for examples.
507+
501508

502509
.. _pyproject-toml-import-names:
503510

0 commit comments

Comments
 (0)