Skip to content

Commit e602bfc

Browse files
committed
Add Dependency Groups to user guide doc
The new section comes after `requirements.txt` and `constraints.txt` documentation but before documentation about wheels. The doc attempts to be beginner-friendly and balance - clarity about the path behavior - explanation of `[dependency-groups]` itself - justification of the path-oriented design -- in the form of an example of installing from two different subprojects simultaneously There is therefore ample material not covered in the new section -- e.g., there is no mention of `include-group`, which is explained at length in the specification doc.
1 parent f61af95 commit e602bfc

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

docs/html/user_guide.rst

+92
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,98 @@ Same as requirements files, constraints files can also be served via a URL,
256256
e.g. http://example.com/constraints.txt, so that your organization can store and
257257
serve them in a centralized place.
258258

259+
260+
.. _`Dependency Groups`:
261+
262+
263+
Dependency Groups
264+
=================
265+
266+
"Dependency Groups" are lists of items to be installed stored in a
267+
``pyproject.toml`` file.
268+
269+
A dependency group is logically just a list of requirements, similar to the
270+
contents of :ref:`Requirements Files`. Unlike requirements files, dependency
271+
groups cannot contain non-package arguments for :ref:`pip install`.
272+
273+
Groups can be declared like so:
274+
275+
.. code-block:: toml
276+
277+
# pyproject.toml
278+
[dependency-groups]
279+
groupA = [
280+
"pkg1",
281+
"pkg2",
282+
]
283+
284+
and installed with :ref:`pip install` like so:
285+
286+
.. tab:: Unix/macOS
287+
288+
.. code-block:: shell
289+
290+
python -m pip install --group groupA
291+
292+
.. tab:: Windows
293+
294+
.. code-block:: shell
295+
296+
py -m pip install --group groupA
297+
298+
Full details on the contents of ``[dependency-groups]`` and more examples are
299+
available in :ref:`the specification documentation <pypug:dependency-groups>`.
300+
301+
.. note::
302+
303+
Dependency Groups are defined by a standard, and therefore do not support
304+
``pip``-specific syntax for requirements, only :ref:`standard dependency
305+
specifiers <pypug:dependency-specifiers>`.
306+
307+
``pip`` does not search projects or directories to discover ``pyproject.toml``
308+
files. The ``--group`` option is used to pass the path to the file,
309+
and if the path is omitted, as in the example above, it defaults to
310+
``pyproject.toml`` in the current directory. Using explicit paths,
311+
:ref:`pip install` can use a file from another directory. For example:
312+
313+
.. tab:: Unix/macOS
314+
315+
.. code-block:: shell
316+
317+
python -m pip install --group './project/subproject/pyproject.toml:groupA'
318+
319+
.. tab:: Windows
320+
321+
.. code-block:: shell
322+
323+
py -m pip install --group './project/subproject/pyproject.toml:groupA'
324+
325+
326+
This also makes it possible to install groups from multiple different projects
327+
at once. For example, with a directory structure like so::
328+
329+
+ project/
330+
+ sub1/
331+
- pyproject.toml
332+
+ sub2/
333+
- pyproject.toml
334+
335+
it is possible to install, from the ``project/`` directory, groups from the
336+
subprojects thusly:
337+
338+
.. tab:: Unix/macOS
339+
340+
.. code-block:: shell
341+
342+
python -m pip install --group './sub1/pyproject.toml:groupA' --group './sub2/pyproject.toml:groupB'
343+
344+
.. tab:: Windows
345+
346+
.. code-block:: shell
347+
348+
py -m pip install --group './sub1/pyproject.toml:groupA' --group './sub2/pyproject.toml:groupB'
349+
350+
259351
.. _`Installing from Wheels`:
260352

261353

0 commit comments

Comments
 (0)