Skip to content

Commit d45adcf

Browse files
committed
Rework the writing
1 parent 68c3a77 commit d45adcf

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,28 @@ project with GUI support, adding the PyQt5 dependency.
177177

178178
.. _self-referential-extras:
179179

180-
You can also define an extra that refers back to the same project with
180+
You can also define an extra that refers back to the current project with
181181
other extras. This is useful for convenience extras that combine several
182-
optional features without duplicating their dependency lists:
182+
optional features (such as an ``all`` extra hosting dependencies from both
183+
``gui`` and ``cli``):
183184

184185
.. code-block:: toml
185186
186-
all = ["your-project-name[gui, cli]"]
187+
all = ["your-project-name[gui, cli]"]
187188
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
193-
`version 21.2 <https://pip.pypa.io/en/latest/reference/requirement-specifiers/#self-referential-extras>`_).
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"]
194202
195203
196204
.. _requires-python:

‎source/specifications/pyproject-toml.rst‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,10 @@ 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-
501+
Dependency specifiers in an extra may self-reference other extras from the
502+
current project (e.g. ``all = ["your-project-name[gui, cli]"]``). See
503+
:ref:`self-referential extras <self-referential-extras>` for an example.
504+
Several installers including :ref:`pip` and :ref:`uv` support this pattern.
508505

509506
.. _pyproject-toml-import-names:
510507

0 commit comments

Comments
 (0)