Make --reinstall imply --refresh (#5425)

## Summary

It's hard for me to imagine a scenario in which a user passed
`--reinstall`, but wanted us to keep respecting cached data for a
package. For example, to actually "rebuild and reinstall" an editable
today, you have to pass both `--reinstall` and `--refresh`.

This PR makes `--reinstall` imply `--refresh`, so we always validate
that the cached data is fresh.

Closes https://github.com/astral-sh/uv/issues/5424.
This commit is contained in:
Charlie Marsh 2024-07-25 09:45:58 -04:00 committed by GitHub
parent 4d9098a1d7
commit d0919329fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 114 additions and 23 deletions

View file

@ -3,6 +3,7 @@ use pep508_rs::PackageName;
use pypi_types::Requirement;
use rustc_hash::FxHashMap;
use uv_cache::Refresh;
/// Whether to reinstall packages.
#[derive(Debug, Default, Clone)]
@ -43,6 +44,32 @@ impl Reinstall {
pub fn is_all(&self) -> bool {
matches!(self, Self::All)
}
/// Create a [`Refresh`] policy by integrating the [`Reinstall`] policy.
pub fn to_refresh(self, refresh: Refresh) -> Refresh {
match (self, refresh) {
// If the policy is `None`, return the existing refresh policy.
(Self::None, Refresh::None(timestamp)) => Refresh::None(timestamp),
(Self::None, Refresh::All(timestamp)) => Refresh::All(timestamp),
(Self::None, Refresh::Packages(packages, timestamp)) => {
Refresh::Packages(packages, timestamp)
}
// If the policy is `All`, refresh all packages.
(Self::All, Refresh::None(timestamp)) => Refresh::All(timestamp),
(Self::All, Refresh::All(timestamp)) => Refresh::All(timestamp),
(Self::All, Refresh::Packages(_packages, timestamp)) => Refresh::All(timestamp),
// If the policy is `Packages`, take the "max" of the two policies.
(Self::Packages(packages), Refresh::None(timestamp)) => {
Refresh::Packages(packages, timestamp)
}
(Self::Packages(_packages), Refresh::All(timestamp)) => Refresh::All(timestamp),
(Self::Packages(packages1), Refresh::Packages(packages2, timestamp)) => {
Refresh::Packages(packages1.into_iter().chain(packages2).collect(), timestamp)
}
}
}
}
/// Whether to allow package upgrades.