-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #10089.
- Loading branch information
1 parent
eaaf889
commit 0d57d29
Showing
6 changed files
with
179 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,27 @@ | ||
use rustc_hash::FxHashSet; | ||
use uv_configuration::{Reinstall, Upgrade}; | ||
use uv_pep508::PackageName; | ||
|
||
/// Tracks locally installed packages that should not be selected during resolution. | ||
#[derive(Debug, Default, Clone)] | ||
pub enum Exclusions { | ||
#[default] | ||
None, | ||
/// Exclude some local packages from consideration, e.g. from `--reinstall-package foo --upgrade-package bar` | ||
Some(FxHashSet<PackageName>), | ||
/// Exclude all local packages from consideration, e.g. from `--reinstall` or `--upgrade` | ||
All, | ||
pub struct Exclusions { | ||
reinstall: Reinstall, | ||
upgrade: Upgrade, | ||
} | ||
|
||
impl Exclusions { | ||
pub fn new(reinstall: Reinstall, upgrade: Upgrade) -> Self { | ||
if upgrade.is_all() || reinstall.is_all() { | ||
Self::All | ||
} else { | ||
let mut exclusions: FxHashSet<PackageName> = | ||
if let Reinstall::Packages(packages) = reinstall { | ||
FxHashSet::from_iter(packages) | ||
} else { | ||
FxHashSet::default() | ||
}; | ||
Self { reinstall, upgrade } | ||
} | ||
|
||
if let Upgrade::Packages(packages) = upgrade { | ||
exclusions.extend(packages.into_keys()); | ||
}; | ||
pub fn reinstall(&self, package: &PackageName) -> bool { | ||
self.reinstall.contains(package) | ||
} | ||
|
||
if exclusions.is_empty() { | ||
Self::None | ||
} else { | ||
Self::Some(exclusions) | ||
} | ||
} | ||
pub fn upgrade(&self, package: &PackageName) -> bool { | ||
self.upgrade.contains(package) | ||
} | ||
|
||
/// Returns true if the package is excluded and a local distribution should not be used. | ||
pub fn contains(&self, package: &PackageName) -> bool { | ||
match self { | ||
Self::None => false, | ||
Self::Some(packages) => packages.contains(package), | ||
Self::All => true, | ||
} | ||
self.reinstall(package) || self.upgrade(package) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters