Skip to content

Commit

Permalink
docs: add some words about specifying conflicting extras/groups
Browse files Browse the repository at this point in the history
This doesn't cover the optional `package` key since I wasn't quite sure
how to articulate its utility in a digestible way.
  • Loading branch information
BurntSushi committed Nov 14, 2024
1 parent 57ff533 commit 8871d2e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
11 changes: 9 additions & 2 deletions docs/concepts/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ To add an optional dependency, use the `--optional <extra>` option:
$ uv add httpx --optional network
```

!!! note

If you have optional dependencies that conflict with one another and are using uv in
project mode with universal resolution, then resolution will fail. To work around this,
it's possible to [declare them as conflicting](./projects.md#optional-dependencies).

## Development dependencies

Unlike optional dependencies, development dependencies are local-only and will _not_ be included in
Expand Down Expand Up @@ -455,8 +461,9 @@ to resolve the requirements of the project with an error.

!!! note

There is currently no way to declare conflicting dependency groups. See
[astral.sh/uv#6981](https://github.com/astral-sh/uv/issues/6981) to track support.
If you have dependency groups that conflict with one another and are using uv in
project mode with universal resolution, then resolution will fail. To work around this,
it's possible to [declare them as conflicting](./projects.md#optional-dependencies).

### Default groups

Expand Down
62 changes: 59 additions & 3 deletions docs/concepts/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,66 @@ each other and resolves all optional dependencies together when creating the loc
If optional dependencies declared in one extra are not compatible with those in another extra, uv
will fail to resolve the requirements of the project with an error.

!!! note
To work around this, uv supports declaring conflicting extras. For example, consider two sets of
optional dependencies that conflict with one another:

```toml title="pyproject.toml"
[project.optional-dependencies]
project1 = ["numpy==2.1.2"]
project2 = ["numpy==2.0.0"]
```

If you try to run `uv lock` with the above dependencies, you should get an error like this:

```
x No solution found when resolving dependencies:
`-> Because myproject[project2] depends on numpy==2.0.0 and myproject[project1] depends on numpy==2.1.2, we can conclude that myproject[project1] and
myproject[project2] are incompatible.
And because your project requires myproject[project1] and myproject[project2], we can conclude that your projects's requirements are unsatisfiable.
```

But if we specify that `project1` and `project2` are conflicting, uv will resolve them in different
forks. We can specify conflicts in the `tool.uv` section:

```toml title="pyproject.toml"
[tool.uv]
conflicts = [
[
{ extra = "project1" },
{ extra = "project2" },
],
]
```

And now running `uv lock` will succeed. Note though, that this will prevent you from enabling
both `project1` and `project2` simultaneously:

```console
$ uv sync --extra project1 --extra project2
Resolved 3 packages in 14ms
error: extra `project1`, extra `project2` are incompatible with the declared conflicts: {`myproject[project1]`, `myproject[project2]`}
```

This error occurs because installing both `project1` and `project2` simultaneously could result
in installing two different versions of the same package into the same environment.

The above strategy for dealing with conflicting extras also works with groups:

```toml title="pyproject.toml"
[dependency-groups]
project1 = ["numpy==2.1.2"]
project2 = ["numpy==2.0.0"]

[tool.uv]
conflicts = [
[
{ group = "project1" },
{ group = "project2" },
],
]
```

There is currently no way to declare conflicting optional dependencies. See
[astral.sh/uv#6981](https://github.com/astral-sh/uv/issues/6981) to track support.
The only difference with conflicting extras is that you need to use `group` instead of `extra`.

## Managing dependencies

Expand Down

0 comments on commit 8871d2e

Please sign in to comment.