Skip to content

Commit bb9cc30

Browse files
authored
Merge pull request #2087 from Trenza1ore/main
Document self-referential extras now that pip officially supports it
2 parents 1e6a8a8 + 3b98cee commit bb9cc30

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,33 @@ 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 current project with
181+
other extras. This is useful for convenience extras that combine several
182+
optional features (such as an ``all`` extra hosting dependencies from both
183+
``gui`` and ``cli``):
184+
185+
.. code-block:: toml
186+
187+
all = ["your-project-name[gui, cli]"]
188+
189+
The combined extra does not need its own manually maintained copy of each
190+
referenced extra's dependencies, which can otherwise fall out of sync after
191+
a few years of maintenance and bug fixes:
192+
193+
.. code-block:: toml
194+
195+
gui = ["PyQt5"]
196+
cli = [
197+
"rich>=14.2", # version range is added after last "all" extra update
198+
"textual", # dependency newly added since last "all" extra update
199+
"click",
200+
]
201+
all = ["PyQt5", "rich", "click"]
202+
203+
Most package managers now support this kind of extra, including
204+
:ref:`pip`, :ref:`uv`, :ref:`poetry`, :ref:`hatch`, :ref:`pdm` and :ref:`pipenv`.
178205

179206
.. _requires-python:
180207
.. _python_requires:
@@ -555,6 +582,7 @@ A full example
555582
"rich",
556583
"click",
557584
]
585+
all = ["spam-eggs[gui, cli]"]
558586
559587
[project.urls]
560588
Homepage = "https://example.com"

‎source/specifications/pyproject-toml.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ marker clause on the related ``Requires-Dist`` entries to check the extra name.
505505
Optional dependencies are thus only considered for installation if installation
506506
if the associated extra name is requested.
507507

508+
Dependency specifiers in an extra may self-reference other extras from the
509+
current project (e.g. ``all = ["your-project-name[gui, cli]"]``). See
510+
:ref:`self-referential extras <self-referential-extras>` for an example.
511+
Most package managers now support this kind of extra, including
512+
:ref:`pip`, :ref:`uv`, :ref:`poetry`, :ref:`hatch`, :ref:`pdm` and :ref:`pipenv`.
508513

509514
.. _pyproject-toml-import-names:
510515

@@ -714,4 +719,7 @@ History
714719
as listed in ``dynamic``, with build back-ends only able to append
715720
entries, through :pep:`808`.
716721

722+
- August 2026: Document self-referential extra as a supported feature by many
723+
modern package managers of Python.
724+
717725
.. _TOML: https://toml.io

0 commit comments

Comments
 (0)