From e40c551b8070356bea0984d497870f38142f90cb Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 18 Mar 2025 18:41:04 -0700 Subject: [PATCH] Use resolver-returned wheel over alternate cached wheel (#12301) ## Summary I think this is reasonable to change. Right now, if you're on Python 3.11, the resolver returns `multiprocess-0.70.17-py311-none-any.whl`, but `multiprocess-0.70.17-py310-none-any.whl` is in the cache, we'll reuse `multiprocess-0.70.17-py310-none-any.whl` (since it _is_ compatible with Python 3.11). Instead, we now _require_ the cached wheel to match the wheel returned by the resolver. Closes https://github.com/astral-sh/uv/issues/12273. --- crates/uv-installer/src/plan.rs | 4 +-- crates/uv/tests/it/pip_install.rs | 58 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/crates/uv-installer/src/plan.rs b/crates/uv-installer/src/plan.rs index 26bcf933c..67ac5c26e 100644 --- a/crates/uv-installer/src/plan.rs +++ b/crates/uv-installer/src/plan.rs @@ -142,9 +142,9 @@ impl<'a> Planner<'a> { if *entry.index.url() != wheel.best_wheel().index { return None; } - if entry.dist.filename.version != wheel.best_wheel().filename.version { + if entry.dist.filename != wheel.best_wheel().filename { return None; - }; + } if entry.built && no_build { return None; } diff --git a/crates/uv/tests/it/pip_install.rs b/crates/uv/tests/it/pip_install.rs index b49951232..cf25c1af7 100644 --- a/crates/uv/tests/it/pip_install.rs +++ b/crates/uv/tests/it/pip_install.rs @@ -8493,6 +8493,64 @@ fn stale_egg_info() -> Result<()> { Ok(()) } +/// Avoid using a compatible, cached wheel if there's another, more compatible wheel returned by +/// the resolver. +/// +/// See: +#[test] +fn avoid_cached_wheel() { + let context = TestContext::new_with_versions(&["3.10", "3.11"]); + + // Create a Python 3.10 environment. + context + .venv() + .arg("--python") + .arg("3.10") + .assert() + .success(); + + uv_snapshot!(context.filters(), context.pip_install() + .arg("multiprocess"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + Prepared 2 packages in [TIME] + Installed 2 packages in [TIME] + + dill==0.3.8 + + multiprocess==0.70.16 + " + ); + + // Create a Python 3.11 environment. + context + .venv() + .arg("--python") + .arg("3.11") + .assert() + .success(); + + // `multiprocessing` should be re-downloaded (i.e., we should have a `Prepare` step here). + uv_snapshot!(context.filters(), context.pip_install() + .arg("--python") + .arg("3.11") + .arg("multiprocess"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + Prepared 1 package in [TIME] + Installed 2 packages in [TIME] + + dill==0.3.8 + + multiprocess==0.70.16 + " + ); +} + /// `suds-community` has an incorrect layout whereby the wheel includes `suds_community.egg-info` at /// the top-level. We're then under the impression that `suds` is installed twice, but when we go to /// uninstall the second "version", we can't find the `egg-info` directory.