-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38a38fa
commit b14fb9c
Showing
6 changed files
with
175 additions
and
56 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