-
Notifications
You must be signed in to change notification settings - Fork 772
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
c2f8019
commit ca30bc3
Showing
12 changed files
with
369 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::collections::hash_map::Entry; | ||
|
||
use rustc_hash::FxHashMap; | ||
|
||
use distribution_types::IndexUrl; | ||
use uv_normalize::PackageName; | ||
|
||
use crate::resolver::ResolverMarkers; | ||
use crate::ResolveError; | ||
|
||
/// See [`crate::resolver::ForkState`]. | ||
#[derive(Default, Debug, Clone)] | ||
pub(crate) struct ForkIndexes(FxHashMap<PackageName, IndexUrl>); | ||
|
||
impl ForkIndexes { | ||
/// Get the [`IndexUrl`] previously used for a package in this fork. | ||
pub(crate) fn get(&self, package_name: &PackageName) -> Option<&IndexUrl> { | ||
self.0.get(package_name) | ||
} | ||
|
||
/// Check that this is the only [`IndexUrl`] used for this package in this fork. | ||
pub(crate) fn insert( | ||
&mut self, | ||
package_name: &PackageName, | ||
index: &IndexUrl, | ||
fork_markers: &ResolverMarkers, | ||
) -> Result<(), ResolveError> { | ||
match self.0.entry(package_name.clone()) { | ||
Entry::Occupied(previous) => { | ||
if previous.get() != index { | ||
let mut conflicts = vec![previous.get().to_string(), index.to_string()]; | ||
conflicts.sort(); | ||
return match fork_markers { | ||
ResolverMarkers::Universal { .. } | ||
| ResolverMarkers::SpecificEnvironment(_) => { | ||
Err(ResolveError::ConflictingIndexesUniversal( | ||
package_name.clone(), | ||
conflicts, | ||
)) | ||
} | ||
ResolverMarkers::Fork(fork_markers) => { | ||
Err(ResolveError::ConflictingIndexesFork { | ||
package_name: package_name.clone(), | ||
indexes: conflicts, | ||
fork_markers: fork_markers.clone(), | ||
}) | ||
} | ||
}; | ||
} | ||
} | ||
Entry::Vacant(vacant) => { | ||
vacant.insert(index.clone()); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
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
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
Oops, something went wrong.