Skip to content

Commit bb6f6cc

Browse files
committed
Refine dependency-groups documentation
This is a significant revision from the PEP content to make the content appropriate for the packaging specs. In particular, the following changes are made: - references to "this PEP" are all removed - "Dependency Object Specifiers" are a layer of indirection around includes, and are removed from the documentation -- instead, the doc jumps straight to the (only) specific case now: the includes - the section on install UX and extras has been rewritten for brevity, removing the hypothetical example `pip` interface and folding together the install notes and the notes about extras - the section on validation/linting has been reorganized around an example, and the note on linters has been moved to a `note` admonition block
1 parent 99af225 commit bb6f6cc

File tree

1 file changed

+66
-88
lines changed

1 file changed

+66
-88
lines changed

source/specifications/dependency-groups.rst

Lines changed: 66 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -36,142 +36,120 @@ and a similar table which defines ``test`` and ``coverage`` groups::
3636
The ``[dependency-groups]`` Table
3737
---------------------------------
3838

39-
This PEP defines a new section (table) in ``pyproject.toml`` files named
39+
Dependency Groups are defined as a table in ``pyproject.toml`` named
4040
``dependency-groups``. The ``dependency-groups`` table contains an arbitrary
4141
number of user-defined keys, each of which has, as its value, a list of
42-
requirements (defined below). These keys must be
43-
`valid non-normalized names <https://packaging.python.org/en/latest/specifications/name-normalization/#valid-non-normalized-names>`__,
44-
and must be
45-
`normalized <https://packaging.python.org/en/latest/specifications/name-normalization/#normalization>`__
46-
before comparisons.
42+
requirements.
4743

48-
Tools SHOULD prefer to present the original, non-normalized name to users by
49-
default. If duplicate names, after normalization, are encountered, tools SHOULD
50-
emit an error.
44+
``[dependency-groups]`` keys, sometimes also called "group names", must be
45+
:ref:`valid non-normalized names <name-format>`. Tools which handle Dependency
46+
Groups MUST :ref:`normalize <name-normalization>` these names before
47+
comparisons.
5148

52-
Requirement lists under ``dependency-groups`` may contain strings, tables
53-
("dicts" in Python), or a mix of strings and tables.
49+
Tools SHOULD prefer to present the original, non-normalized name to users, and
50+
if duplicate names are detected after normalization, tools SHOULD emit an
51+
error.
5452

55-
Strings in requirement lists must be valid
56-
`Dependency Specifiers <https://packaging.python.org/en/latest/specifications/dependency-specifiers/>`__,
57-
as defined in :pep:`508`.
58-
59-
Tables in requirement lists must be valid Dependency Object Specifiers.
60-
61-
Dependency Object Specifiers
62-
----------------------------
63-
64-
Dependency Object Specifiers are tables which define zero or more dependencies.
65-
66-
This PEP standardizes only one type of Dependency Object Specifier, a
67-
"Dependency Group Include". Other types may be added in future standards.
53+
Requirement lists, the values in ``[dependency-groups]``, may contain strings,
54+
tables (``dict`` in Python), or a mix of strings and tables. Strings must be
55+
valid :ref:`dependency specifiers <dependency-specifiers>`, and tables must be
56+
valid Dependency Group Includes.
6857

6958
Dependency Group Include
70-
''''''''''''''''''''''''
71-
72-
A Dependency Group Include includes the dependencies of another Dependency
73-
Group in the current Dependency Group.
59+
------------------------
7460

75-
An include is defined as a table with exactly one key, ``"include-group"``,
76-
whose value is a string, the name of another Dependency Group.
61+
A Dependency Group Include includes another Dependency Group in the current
62+
group.
7763

78-
For example, ``{include-group = "test"}`` is an include which expands to the
79-
contents of the ``test`` Dependency Group.
64+
An include is a table with exactly one key, ``"include-group"``, whose value is
65+
a string, the name of another Dependency Group.
8066

8167
Includes are defined to be exactly equivalent to the contents of the named
8268
Dependency Group, inserted into the current group at the location of the include.
8369
For example, if ``foo = ["a", "b"]`` is one group, and
8470
``bar = ["c", {include-group = "foo"}, "d"]`` is another, then ``bar`` should
8571
evaluate to ``["c", "a", "b", "d"]`` when Dependency Group Includes are expanded.
8672

87-
Dependency Group Includes may specify the same package multiple times. Tools
88-
SHOULD NOT deduplicate or otherwise alter the list contents produced by the
73+
Dependency Group Includes may specify the same package multiple times.
74+
Tools SHOULD NOT deduplicate or otherwise alter the list contents produced by the
8975
include. For example, given the following table:
9076

91-
.. code:: toml
77+
.. code-block:: toml
9278
9379
[dependency-groups]
9480
group-a = ["foo"]
9581
group-b = ["foo>1.0"]
9682
group-c = ["foo<1.0"]
97-
all = ["foo", {include-group = "group-a"}, {include-group = "group-b"}, {include-group = "group-c"}]
83+
all = [
84+
"foo",
85+
{include-group = "group-a"},
86+
{include-group = "group-b"},
87+
{include-group = "group-c"},
88+
]
9889
9990
The resolved value of ``all`` SHOULD be ``["foo", "foo", "foo>1.0", "foo<1.0"]``.
10091
Tools should handle such a list exactly as they would handle any other case in
10192
which they are asked to process the same requirement multiple times with
10293
different version constraints.
10394

104-
Dependency Group Includes may include lists containing Dependency Group
105-
Includes, in which case those includes should be expanded as well. Dependency
106-
Group Includes MUST NOT include cycles, and tools SHOULD report an error if
107-
they detect a cycle.
95+
Dependency Group Includes may include groups containing Dependency Group Includes,
96+
in which case those includes should be expanded as well. Dependency Group Includes
97+
MUST NOT include cycles, and tools SHOULD report an error if they detect a cycle.
10898

10999
Package Building
110100
----------------
111101

112102
Build backends MUST NOT include Dependency Group data in built distributions as
113-
package metadata. This means that PKG-INFO in sdists and METADATA in wheels
114-
do not include any referencable fields containing Dependency Groups.
115-
116-
It is valid to use Dependency Groups in the evaluation of dynamic metadata, and
117-
``pyproject.toml`` files included in sdists will naturally still contain the
118-
``[dependency-groups]`` table. However, the table contents are not part of a
119-
published package's interfaces.
120-
121-
Installing Dependency Groups
122-
----------------------------
123-
124-
Tools which support Dependency Groups are expected to provide new options and
125-
interfaces to allow users to install from Dependency Groups.
126-
127-
No syntax is defined for expressing the Dependency Group of a package, for two
128-
reasons:
103+
package metadata. This means that sdist ``PKG-INFO`` and wheel ``METADATA``
104+
files should not include referenceable fields containing Dependency Groups.
129105

130-
* it would not be valid to refer to the Dependency Groups of a third-party
131-
package from PyPI (because the data is defined to be unpublished)
106+
It is, however, valid to use Dependency Groups in the evaluation of dynamic
107+
metadata, and ``pyproject.toml`` files included in sdists will still contain
108+
``[dependency-groups]``. However, the table's contents are not part of a built
109+
package's interfaces.
132110

133-
* there is not guaranteed to be a current package for Dependency Groups -- part
134-
of their purpose is to support non-package projects
111+
Installing Dependency Groups & Extras
112+
-------------------------------------
135113

136-
For example, a possible pip interface for installing Dependency Groups
137-
would be:
114+
There is no syntax or specification-defined interface for installing or
115+
referring to Dependency Groups. Tools are expected to provide dedicated
116+
interfaces for this purpose.
138117

139-
.. code:: shell
140-
141-
pip install --dependency-groups=test,typing
142-
143-
Note that this is only an example. This PEP does not declare any requirements
144-
for how tools support the installation of Dependency Groups.
145-
146-
Overlapping Install UX with Extras
147-
''''''''''''''''''''''''''''''''''
148-
149-
Tools MAY choose to provide the same interfaces for installing Dependency
150-
Groups as they do for installing extras.
151-
152-
Note that this specification does not forbid having an extra whose name matches
153-
a Dependency Group.
154-
155-
Users are advised to avoid creating Dependency Groups whose names match extras.
156-
Tools MAY treat such matching as an error.
118+
Tools MAY choose to provide the same or similar interfaces for interacting
119+
with Dependency Groups as they do for managing extras. Tools authors are
120+
advised that the specification does not forbid having an extra whose name
121+
matches a Dependency Group. Separately, users are advised to avoid creating
122+
Dependency Groups whose names match extras, and tools MAY treat such matching
123+
as an error.
157124

158125
Validation and Compatibility
159126
----------------------------
160127

161128
Tools supporting Dependency Groups may want to validate data before using it.
162-
However, tools implementing such validation behavior should be careful to allow
163-
for future expansions to this spec, so that they do not unnecessarily emit
164-
errors or warnings in the presence of new syntax.
129+
When implementing such validation, authors should be aware of the possibility
130+
of future extensions to the specification, so that they do not unnecessarily
131+
emit errors or warnings.
165132

166133
Tools SHOULD error when evaluating or processing unrecognized data in
167134
Dependency Groups.
168135

169-
Tools SHOULD NOT eagerly validate the list contents of **all** Dependency
170-
Groups.
136+
Tools SHOULD NOT eagerly validate the contents of *all* Dependency Groups
137+
unless they have a need to do so.
138+
139+
This means that in the presence of the following data, most tools should allow
140+
the ``foo`` group to be used and only error if the ``bar`` group is used:
141+
142+
.. code-block:: toml
143+
144+
[dependency-groups]
145+
foo = ["pyparsing"]
146+
bar = [{set-phasers-to = "stun"}]
147+
148+
.. note::
171149

172-
This means that in the presence of the following data, most tools will allow
173-
the ``foo`` group to be used, and will only error when the ``bar`` group is
174-
used:
150+
There are several known cases of tools which have good cause to be
151+
stricter. Linters and validators are an example, as their purpose is to
152+
validate the contents of all Dependency Groups.
175153

176154
Reference Implementation
177155
========================

0 commit comments

Comments
 (0)