uv icon indicating copy to clipboard operation
uv copied to clipboard

Restricting universal lock by OS still downloads wheels from all OSes

Open tmct opened this issue 1 year ago • 7 comments

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

tmct avatar Aug 23 '24 13:08 tmct

Thanks for the report!

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

cc @charliermarsh

zanieb avatar Aug 23 '24 13:08 zanieb

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.

konstin avatar Aug 23 '24 13:08 konstin

Thanks for the additional context. Is this hard?

zanieb avatar Aug 23 '24 13:08 zanieb

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.

konstin avatar Aug 23 '24 14:08 konstin

This would be a good improvement.

charliermarsh avatar Aug 23 '24 14:08 charliermarsh

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

tmct avatar Aug 23 '24 15:08 tmct

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 avatar Aug 29 '24 15:08 charliermarsh

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

charliermarsh avatar Sep 04 '24 20:09 charliermarsh

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

tmct avatar Sep 04 '24 21:09 tmct

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

tmct avatar Sep 04 '24 21:09 tmct

Apologies, I linked the wrong PR!

charliermarsh avatar Sep 04 '24 21:09 charliermarsh

~Hi, quick question, which caches do I need to clear to make this happen if I forgot to restrict by OS before first sync? Thanks~

Apologies, was using an old version of uv 😂

tmct avatar Oct 15 '24 07:10 tmct