Avoid downgrading packages when --upgrade is provided (#10097)

## Summary

When `--upgrade` is provided, we should retain already-installed
packages _if_ they're newer than whatever is available from the
registry.

Closes https://github.com/astral-sh/uv/issues/10089.
This commit is contained in:
Charlie Marsh 2025-01-06 17:41:43 -05:00 committed by GitHub
parent eaaf8896ed
commit 0d57d298e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 180 additions and 62 deletions

View file

@ -47,6 +47,15 @@ impl Reinstall {
matches!(self, Self::All)
}
/// Returns `true` if the specified package should be reinstalled.
pub fn contains(&self, package_name: &PackageName) -> bool {
match &self {
Self::None => false,
Self::All => true,
Self::Packages(packages) => packages.contains(package_name),
}
}
/// Combine a set of [`Reinstall`] values.
#[must_use]
pub fn combine(self, other: Self) -> Self {