mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-22 19:44:11 +00:00
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:
parent
4d9098a1d7
commit
d0919329fd
10 changed files with 114 additions and 23 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue