Skip to content

uv sync tries to resolve optional source packages even though environment markers exclude the package from the environment #8389

@benniekiss

Description

@benniekiss

When running uv sync on a project that contains platform-specific optional dependencies built from source, the sync fails when those dependencies cannot be built for the platform during package resolution. uv sync does not respect the environment marker during package resolution, and since all optional dependencies are included in the resolution, the environment cannot be synced.

Is it possible to exclude certain packages during resolution?

In the below example, flash-attention requires CUDA, which is not available for macOS, but when trying to sync the project, resolution fails because it attempts to build flash-attention first.

mkdir -p test_uv_sync
cd test_uv_sync

## make pyproject.toml
cat <<EOF > pyproject.toml
[project]
name = "test_uv_sync"
version = "0.0.1"

dependencies = [
    "torch>=2.4.0,<2.5.0",
    "torchaudio>=2.4.0,<2.5.0",
    "torchvision>=0.19.0,<0.20.0",
]
readme = "README.md"
requires-python = ">= 3.12"

[project.optional-dependencies]
flash = [
    "flash-attn @ git+https://github.com/Dao-AILab/flash-attention ; platform_system == 'Darwin'"
]
EOF

## try to sync project
uv sync --python 3.12

Metadata

Metadata

Assignees

Labels

questionAsking for clarification or support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions