mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 13:43:45 +00:00
![]() ## Summary This PR enables something like the "final boss" of PyTorch setups -- explicit support for CPU vs. GPU-enabled variants via extras: ```toml [project] name = "project" version = "0.1.0" requires-python = ">=3.13.0" dependencies = [] [project.optional-dependencies] cpu = [ "torch==2.5.1+cpu", ] gpu = [ "torch==2.5.1", ] [tool.uv.sources] torch = [ { index = "torch-cpu", extra = "cpu" }, { index = "torch-gpu", extra = "gpu" }, ] [[tool.uv.index]] name = "torch-cpu" url = "https://download.pytorch.org/whl/cpu" explicit = true [[tool.uv.index]] name = "torch-gpu" url = "https://download.pytorch.org/whl/cu124" explicit = true [tool.uv] conflicts = [ [ { extra = "cpu" }, { extra = "gpu" }, ], ] ``` It builds atop the conflicting extras work to allow sources to be marked as specific to a dedicated extra being enabled or disabled. As part of this work, sources now have an `extra` field. If a source has an `extra`, it means that the source is only applied to the requirement when defined within that optional group. For example, `{ index = "torch-cpu", extra = "cpu" }` above only applies to `"torch==2.5.1+cpu"`. The `extra` field does _not_ mean that the source is "enabled" when the extra is activated. For example, this wouldn't work: ```toml [project] name = "project" version = "0.1.0" requires-python = ">=3.13.0" dependencies = ["torch"] [tool.uv.sources] torch = [ { index = "torch-cpu", extra = "cpu" }, { index = "torch-gpu", extra = "gpu" }, ] [[tool.uv.index]] name = "torch-cpu" url = "https://download.pytorch.org/whl/cpu" explicit = true [[tool.uv.index]] name = "torch-gpu" url = "https://download.pytorch.org/whl/cu124" explicit = true ``` In this case, the sources would effectively be ignored. Extras are really confusing... but I think this is correct? We don't want enabling or disabling extras to affect resolution information that's _outside_ of the relevant optional group. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |