uv icon indicating copy to clipboard operation
uv copied to clipboard

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

Open benniekiss opened this issue 4 months ago • 8 comments

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

benniekiss avatar Oct 20 '24 18:10 benniekiss