Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow conflicting extras in explicit index assignments #9160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Nov 16, 2024

Summary

This PR enables something like the "final boss" of PyTorch setups -- explicit support for CPU vs. GPU-enabled variants via extras:

[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:

[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.

@charliermarsh charliermarsh added the enhancement New feature or improvement to existing functionality label Nov 16, 2024
@charliermarsh charliermarsh force-pushed the charlie/ex branch 2 times, most recently from 7a9cb14 to 479be8f Compare November 16, 2024 02:50
@charliermarsh charliermarsh marked this pull request as ready for review November 16, 2024 02:50
@charliermarsh
Copy link
Member Author

This needs documentation, but I'm gonna wait for approval.

@charliermarsh charliermarsh force-pushed the charlie/ex branch 2 times, most recently from 54e1960 to b15ad5b Compare November 16, 2024 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant