Skip to content

Bug Report for Optional PyTorch Dependencies in pyproject.toml #9221

@orkhank

Description

@orkhank

Issue Description

The example configuration for optional PyTorch dependencies introduced in #9210 is causing errors during execution. Specifically, uv does not recognize the extra key used for specifying sources, resulting in a TOML parse error.

Steps to Reproduce

  1. Create the problematic pyproject.toml file:

    [project]
    name = "project"
    version = "0.1.0"
    requires-python = ">=3.12.0"
    dependencies = []
    
    [project.optional-dependencies]
    cpu = [
    "torch>=2.5.1",
    "torchvision>=0.20.1",
    ]
    cu124 = [
    "torch>=2.5.1",
    "torchvision>=0.20.1",
    ]
    
    [tool.uv]
    conflicts = [
    [
        { extra = "cpu" },
        { extra = "cu124" },
    ],
    ]
    
    [tool.uv.sources]
    torch = [
    { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
    { index = "pytorch-cu124", extra = "cu124" },
    ]
    torchvision = [
    { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
    { index = "pytorch-cu124", extra = "cu124" },
    ]
    
    [[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
  2. Use the following command to sync with the optional PyTorch dependencies:

    $ uv sync --extra cpu --verbose
  3. Observe the debug output:

    DEBUG uv 0.5.2
    DEBUG Found project root: `/home/user/dev/project`
    error: Failed to parse: `pyproject.toml`
    Caused by: TOML parse error at line 16, column 30
    |
    16 |     { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
    |                              ^^^^^
    unknown field `extra`, expected one of `git`, `subdirectory`, `rev`, `tag`, `branch`, `url`, `path`, `editable`, `index`, `workspace`, `marker`

Problematic Code Snippet

The part of the pyproject.toml file that causes the error is as follows:

[tool.uv.dependencies]
my_package = { index = "pytorch-cu124", extra = "cu124" }

For reference, you can find the original example in the documentation here: PyTorch Integration Guide.

Environment Details

  • Current uv platform: WSL

    • Distributor ID: Ubuntu
    • Description: Ubuntu 24.04.1 LTS
    • Release: 24.04
    • Codename: noble
  • Current uv version:

    $ uv --version
    uv 0.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions