Skip to content

Commit

Permalink
Add Dependency Groups to user guide doc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirosen committed Jan 28, 2025
1 parent 5c82ad8 commit a7dcec9
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions docs/html/user_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,98 @@ Same as requirements files, constraints files can also be served via a URL,
e.g. http://example.com/constraints.txt, so that your organization can store and
serve them in a centralized place.


.. _`Dependency Groups`:


Dependency Groups
=================

"Dependency Groups" are lists of items to be installed stored in a
``pyproject.toml`` file.

A dependency group is logically just a list of requirements, similar to the
contents of :ref:`Requirements Files`. Unlike requirements files, dependency
groups cannot contain non-package arguments for :ref:`pip install`.

Groups can be declared like so:

.. code-block:: toml
# pyproject.toml
[dependency-groups]
groupA = [
"pkg1",
"pkg2",
]
and installed with :ref:`pip install` like so:

.. tab:: Unix/macOS

.. code-block:: shell
python -m pip install --group groupA
.. tab:: Windows

.. code-block:: shell
py -m pip install --group groupA
Full details on the contents of ``[dependency-groups]`` and more examples are
available in :ref:`the specification documentation <pypug:dependency-groups>`.

.. note::

Dependency Groups are defined by a standard, and therefore do not support
``pip``-specific syntax for requirements, only :ref:`standard dependency
specifiers <pypug:dependency-specifiers>`.

``pip`` does not search projects or directories to discover ``pyproject.toml``
files. The ``--group`` option is used to pass the path to the file,
and if the path is omitted, as in the example above, it defaults to
``pyproject.toml`` in the current directory. Using explicit paths,
:ref:`pip install` can use a file from another directory. For example:

.. tab:: Unix/macOS

.. code-block:: shell
python -m pip install --group './project/subproject/pyproject.toml:groupA'
.. tab:: Windows

.. code-block:: shell
py -m pip install --group './project/subproject/pyproject.toml:groupA'
This also makes it possible to install groups from multiple different projects
at once. For example, with a directory structure like so::

+ project/
+ sub1/
- pyproject.toml
+ sub2/
- pyproject.toml

it is possible to install, from the ``project/`` directory, groups from the
subprojects thusly:

.. tab:: Unix/macOS

.. code-block:: shell
python -m pip install --group './sub1/pyproject.toml:groupA' --group './sub2/pyproject.toml:groupB'
.. tab:: Windows

.. code-block:: shell
py -m pip install --group './sub1/pyproject.toml:groupA' --group './sub2/pyproject.toml:groupB'
.. _`Installing from Wheels`:


Expand Down

0 comments on commit a7dcec9

Please sign in to comment.