I’m trying to automate how users will get their pytorch version in the pyproject, using uv
.
Currently, the sources look like this:
[tool.uv.sources]
torch = [
{ index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
{ index = "pytorch-cu124", extra = "cu124", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
]
[[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
which installs the correct torch on windows, linux, macos and also mac os on docker containers which may use linux/arm64.
but I want to install the pre-release as well, from a specific index. I can do it with pip using:
(pkg) a@b pkg % python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
My idea was to add an extra index, without any extra:
[project.optional-dependencies]
prelease = ["torch"]
cpu = ["torch>=2.5.1"]
cu124 = ["torch>=2.5.1"]
[tool.uv]
conflicts = [[{ extra = "prelease" }, { extra = "cpu" }, { extra = "cu124" }]]
[tool.uv.sources]
torch = [
{ index = "pytorch-prelease", extra = "prelease", marker = "platform_system=='Darwin' and platform_machine=='aarch64'" },
{ index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
{ index = "pytorch-cu124", extra = "cu124", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
]
[[tool.uv.index]]
name = "pytorch-prelease"
url = "https://download.pytorch.org/whl/nightly/cpu"
explicit = true
[[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
However, this downloads multiple dev versions.
How should this be done?