[Python] uv `required-environments`: only require that some extras build in some environments

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    cross-posted to the uv issue tracker

    As all dependency problems, this one originates from torch.

    I need to support cuda 12.4 on x86_64, and cuda 12.8 on arm64. Importantly, pytorch does not provide builds for cuda 12.4 on arm64 platforms.

    so I wrote my pyproject.toml the following way, using, specifying the extra field in required-environments to limit which version of cuda uv would try to resolve for depending on which platform

    [project]
    name = "minimal_reproduction"
    version = "0.1.0"
    description = ""
    readme = "README.md"
    requires-python = ">=3.13"
    dependencies = []

    [tool.uv]
    conflicts = [
    [{extra="cu128"}, {extra="cu124"}]
    ]
    required-environments = [
    "sys_platform == 'linux' and platform_machine == 'x86_64' and extra == 'cu124'",
    "sys_platform == 'linux' and platform_machine == 'aarch64' and extra == 'cu128'",
    ]
    index-strategy = "unsafe-best-match"



    [project.optional-dependencies]
    cu124 = [
    "torch==2.6.0+cu124",
    ]

    cu128 = [
    "torch==2.7.0+cu128",
    ]

    [[tool.uv.index]]
    name = "torch-cu128"
    url = "https://download.pytorch.org/whl/cu128"

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


    But it seems uv ignores the extra field, and still complains that it cannot build cu124 on arm

    × No solution found when resolving dependencies for split (python_full_version ==
    │ '3.13.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra ==
    │ 'cu128'):
    ╰─▶ Because torch==2.6.0+cu124 has no `python_full_version == '3.13.*' and
    platform_machine == 'aarch64' and sys_platform == 'linux' and extra ==
    'cu128'`-compatible wheels and test[cu124] depends on torch==2.6.0+cu124, we can
    conclude that test[cu124]'s requirements are unsatisfiable.
    And because your project requires test[cu124], we can conclude that your project's
    requirements are unsatisfiable.

    hint: The resolution failed for an environment that is not the current one, consider
    limiting the environments with `tool.uv.environments`.


    Is there a way to limit which extras uv will try to build on certain environments?

    Continue reading...

Compartilhe esta Página