astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
19.95k stars 591 forks source link

Restricting universal lock by OS still downloads wheels from all OSes #6512

Closed tmct closed 1 week ago

tmct commented 3 weeks ago

Hi - I'm very glad to see uv's recent universal locking features, and engagement with the lockfile standard - but I've found one behaviour that seems a little odd.

Perhaps I have misunderstood how environment markers are used in universal resolution, but I am surprised by this behaviour:

mkdir temp
cd temp
uv init -p 3.10

# I only want to produce a lockfile for Linux, across Python versions
cat <<EOL >> pyproject.toml

[tool.uv]
environments = ["sys_platform == 'linux'"]
EOL

uv add torch==2.1.0 -p 3.10

Result: I still get plently Windows-specific wheels in my uv.lock lockfile, e.g. torch-2.1.0-cp310-cp310-win_amd64.whl - presumably these have all still been downloaded.

Would it be possible please not to download these Mac/Windows-only wheels for linux-only universal locks, as an example?

Many thanks, Tom

zanieb commented 3 weeks ago

Thanks for the report!

@konstin you marked this as an enhancement, is this not a bug?

cc @charliermarsh

konstin commented 3 weeks ago

We already never install those wheels, but we're missing the pruning of the wheels list for platforms. We're currently only prune the wheels list for the python version (#4696), but we can extend this to the platform markers also. It may not work 100% for platform marker them since markers and wheels tags don't have a perfect 1:1 mapping, but we would still trim the lockfile down by a lot.

zanieb commented 3 weeks ago

Thanks for the additional context. Is this hard?

konstin commented 3 weeks ago

Hard to tell, hopefully it's a just a lookup table and some filtering. Ideally, you create a mapping from a marker to what tags it supports, e.g. sys_platform == 'linux' -> manylinux, musllinnux and linux, and then filter the wheels by that wheel tag.

charliermarsh commented 3 weeks ago

This would be a good improvement.

tmct commented 3 weeks ago

Thanks very much all - would be very happy to see this enhancement - none of the other "universal" lockfile tools seems to support this filtering...

charliermarsh commented 2 weeks ago

This is a bit more tedious because we don't track "all the markers under which this package could be relevant" in the lockfile directly -- you have to compute it by propagating markers. So at this point in the lockfile:

// Remove wheels that don't match `requires-python` and can't be selected for
// installation.
if let Some(requires_python) = &requires_python {
    package
        .wheels
        .retain(|wheel| requires_python.matches_wheel_tag(&wheel.filename));
}

We'd need to track the supported platforms.

charliermarsh commented 1 week ago

Closed by https://github.com/astral-sh/uv/pull/6957.

tmct commented 1 week ago

Thank you! Though that PR is described as "Prep for fixing https://github.com/astral-sh/uv/issues/6512. No functional changes."?

tmct commented 1 week ago

Ah, now I see the subsequent #6961 and #6959 in the release notes. Very nice

charliermarsh commented 1 week ago

Apologies, I linked the wrong PR!