Skip to content

Commit ed130b0

Browse files
BurntSushizanieb
andauthored
docs: add some words about specifying conflicting extras/groups (#9120)
This doesn't cover the optional `package` key since I wasn't quite sure how to articulate its utility in a digestible way. --------- Co-authored-by: Zanie Blue <[email protected]>
1 parent 3a7db17 commit ed130b0

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

docs/concepts/dependencies.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ To add an optional dependency, use the `--optional <extra>` option:
389389
$ uv add httpx --optional network
390390
```
391391

392+
!!! note
393+
394+
If you have optional dependencies that conflict with one another, resolution will fail
395+
unless you explicitly [declare them as conflicting](./projects.md#optional-dependencies).
396+
392397
## Development dependencies
393398

394399
Unlike optional dependencies, development dependencies are local-only and will _not_ be included in
@@ -455,8 +460,8 @@ to resolve the requirements of the project with an error.
455460

456461
!!! note
457462

458-
There is currently no way to declare conflicting dependency groups. See
459-
[astral.sh/uv#6981](https://github.com/astral-sh/uv/issues/6981) to track support.
463+
If you have dependency groups that conflict with one another, resolution will fail
464+
unless you explicitly [declare them as conflicting](./projects.md#optional-dependencies).
460465

461466
### Default groups
462467

docs/concepts/projects.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,67 @@ each other and resolves all optional dependencies together when creating the loc
484484
If optional dependencies declared in one extra are not compatible with those in another extra, uv
485485
will fail to resolve the requirements of the project with an error.
486486

487-
!!! note
487+
To work around this, uv supports declaring conflicting extras. For example, consider two sets of
488+
optional dependencies that conflict with one another:
489+
490+
```toml title="pyproject.toml"
491+
[project.optional-dependencies]
492+
extra1 = ["numpy==2.1.2"]
493+
extra2 = ["numpy==2.0.0"]
494+
```
495+
496+
If you run `uv lock` with the above dependencies, resolution will fail:
497+
498+
```console
499+
$ uv lock
500+
x No solution found when resolving dependencies:
501+
`-> Because myproject[extra2] depends on numpy==2.0.0 and myproject[extra1] depends on numpy==2.1.2, we can conclude that myproject[extra1] and
502+
myproject[extra2] are incompatible.
503+
And because your project requires myproject[extra1] and myproject[extra2], we can conclude that your projects's requirements are unsatisfiable.
504+
```
505+
506+
But if you specify that `extra1` and `extra2` are conflicting, uv will resolve them separately.
507+
Specify conflicts in the `tool.uv` section:
508+
509+
```toml title="pyproject.toml"
510+
[tool.uv]
511+
conflicts = [
512+
[
513+
{ extra = "extra1" },
514+
{ extra = "extra2" },
515+
],
516+
]
517+
```
518+
519+
Now, running `uv lock` will succeed. Note though, that now you cannot install both `extra1` and
520+
`extra2` at the same time:
521+
522+
```console
523+
$ uv sync --extra extra1 --extra extra2
524+
Resolved 3 packages in 14ms
525+
error: extra `extra1`, extra `extra2` are incompatible with the declared conflicts: {`myproject[extra1]`, `myproject[extra2]`}
526+
```
527+
528+
This error occurs because installing both `extra1` and `extra2` would result in installing two
529+
different versions of a package into the same environment.
530+
531+
The above strategy for dealing with conflicting extras also works with dependency groups:
532+
533+
```toml title="pyproject.toml"
534+
[dependency-groups]
535+
group1 = ["numpy==2.1.2"]
536+
group2 = ["numpy==2.0.0"]
537+
538+
[tool.uv]
539+
conflicts = [
540+
[
541+
{ group = "group1" },
542+
{ group = "group2" },
543+
],
544+
]
545+
```
488546

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

492549
## Managing dependencies
493550

0 commit comments

Comments
 (0)