Skip to content

multiple versions of the same package can be installed in some cases when using conflicting extras #10985

@BurntSushi

Description

@BurntSushi

I found the problem by trying to reproduce the problem on a new repo. The problem is with package torchmetrics. When it is in the workspace package/dependency this case exists. I have yet not inspect what can be wrong with that package configuration.

Minimal example:

Child:

[project]
name = "child-surface"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "torchmetrics>=1.1.0",
]


[project.optional-dependencies]
cpu = [
    "torch==2.4.1", 
    "torchvision==0.19.1"
]
gpu = [
    "torch==2.4.1", 
    "torchvision==0.19.1",
    "nvidia-dali-cuda120==1.30.0",
]
[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "gpu" },
  ],
]

[tool.uv.sources]
torch = [
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-cu124", extra = "gpu" },
]
torchvision = [
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-cu124", extra = "gpu" },
]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true

Parent:

[project]
name = "parent-surface"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[tool.uv.sources]
child-surface = [{ workspace = true  },]

[tool.uv.workspace]
members = ["child-surface"]


[project.optional-dependencies]
cpu = [
    "child-surface[cpu]>=0.0.1", 
]
gpu = [
    "child-surface[gpu]>=0.0.1", 
]

[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "gpu" },
  ],
]

Full zipped example with lock file:
parent-surface.zip


Edit: Looking at their repo and build system in setup.py I see that they define base requirements which is just torch >=2.0.0, <2.7.0

So uv resolver has installed torch==2.4.1+cu124 and then installs torch==2.4.1 which is strange having two different versions of the same package

This behavior changed after introducing this change

Originally posted by @mchalecki in #10590

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions