Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: refactor/enhance dependency groups section #11690

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 57 additions & 35 deletions docs/concepts/projects/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,23 @@ url = "https://download.pytorch.org/whl/cu124"

## Development dependencies

uv uses the `[dependency-groups]` table (as defined in [PEP 735](https://peps.python.org/pep-0735/))
for declaration of development dependencies.

Unlike optional dependencies, development dependencies are local-only and will _not_ be included in
the project requirements when published to PyPI or other indexes. As such, development dependencies
are not included in the `[project]` table.

Development dependencies can have entries in `tool.uv.sources` the same as normal dependencies.
### "Dev" group

To add a development dependency, use the `--dev` flag:
uv has special handling for the "dev" dependency group. To add a development dependency, use the
`--dev` flag:

```console
$ uv add --dev pytest
```

uv uses the `[dependency-groups]` table (as defined in [PEP 735](https://peps.python.org/pep-0735/))
for declaration of development dependencies. The above command will create a `dev` group:
which creates a `dev` group in the project's config:

```toml title="pyproject.toml"
[dependency-groups]
Expand All @@ -607,65 +610,84 @@ dev = [
]
```

The `dev` group is special-cased; there are `--dev`, `--only-dev`, and `--no-dev` flags to toggle
inclusion or exclusion of its dependencies. See `--no-default-groups` to disable all default groups
instead. Additionally, the `dev` group is [synced by default](#default-groups).
### Default group(s)

### Dependency groups
By default, uv includes the `dev` dependency group in the environment, e.g. during `uv run` or
`uv sync`.

Development dependencies can be divided into multiple groups, using the `--group` flag.
The default groups to include can be changed using the `tool.uv.default-groups` setting:

For example, to add a development dependency in the `lint` group:

```console
$ uv add --group lint ruff
```toml title="pyproject.toml"
[tool.uv]
default-groups = ["dev", "foo"]
```

Which results in the following `[dependency-groups]` definition:
!!! tip

To disable this behaviour during `uv run` or `uv sync`, use `--no-default-groups`.

### Additional groups

Support for dependency groups extends beyond the `dev` group:

```toml title="pyproject.toml"
[dependency-groups]
dev = [
"pytest"
{include-group = "lint"},
"pytest",
]
lint = [
"ruff"
]
```

Once groups are defined, the `--all-groups`, `--no-default-groups`, `--group`, `--only-group`, and
`--no-group` options can be used to include or exclude their dependencies.

!!! tip

The `--dev`, `--only-dev`, and `--no-dev` flags are equivalent to `--group dev`,
`--only-group dev`, and `--no-group dev` respectively.

uv requires that all dependency groups are compatible with each other and resolves all groups
together when creating the lockfile.

If dependencies declared in one group are not compatible with those in another group, uv will fail
to resolve the requirements of the project with an error.
to resolve the requirements of the project with an error unless you explicitly
[declare them as conflicting](./config.md#conflicting-dependencies).

!!! note
### CLI Options

If you have dependency groups that conflict with one another, resolution will fail
unless you explicitly [declare them as conflicting](./config.md#conflicting-dependencies).
Development dependencies added from the CLI can be directed to a particular group using the
`--group` flag:

### Default groups
```console
$ uv add --group ci tox pip-audit
```

By default, uv includes the `dev` dependency group in the environment (e.g., during `uv run` or
`uv sync`). The default groups to include can be changed using the `tool.uv.default-groups` setting.
Which results in:

```toml title="pyproject.toml"
[tool.uv]
default-groups = ["dev", "foo"]
[dependency-groups]
ci = [
"pip-audit",
"tox",
]
dev = [
# NOTE: include-group is set by editing the file, not with `uv add` (see #9054)
{include-group = "lint"},
"pytest",
]
lint = [
"ruff"
]
```

!!! tip
The CLI has multiple dependency group related options including:

To disable this behaviour during `uv run` or `uv sync`, use `--no-default-groups`.
To exclude a specific default group, use `--no-group <name>`.
- `--group <group>`
- `--only-group <group>`
- `--no-group <group>`
- `--dev`, `--only-dev`, and `--no-dev` which are aliases for the `dev` group and the above commands
- `--all-groups`
- `--no-default-groups`

See [`uv run --help`][uv-run] or [`uv sync --help`][uv-sync] for an explanation of the options.

[uv-run]: https://docs.astral.sh/uv/reference/cli/#uv-run
[uv-sync]: https://docs.astral.sh/uv/reference/cli/#uv-sync

### Legacy `dev-dependencies`

Expand Down
Loading