-
Notifications
You must be signed in to change notification settings - Fork 765
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
Showing
14 changed files
with
706 additions
and
584 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
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::Verbatim; | ||
use pep508_rs::MarkerTree; | ||
use pypi_types::VerbatimParsedUrl; | ||
use uv_normalize::PackageName; | ||
|
||
use crate::ResolveError; | ||
|
||
/// See [`crate::resolver::SolveState`]. | ||
#[derive(Default, Debug, Clone)] | ||
pub(crate) struct ForkUrls(FxHashMap<PackageName, VerbatimParsedUrl>); | ||
|
||
impl ForkUrls { | ||
/// Get the URL previously used for a package in this fork. | ||
pub(crate) fn get(&self, package_name: &PackageName) -> Option<&VerbatimParsedUrl> { | ||
self.0.get(package_name) | ||
} | ||
|
||
/// Check that this is the only URL used for this package in this fork. | ||
pub(crate) fn insert( | ||
&mut self, | ||
package_name: &PackageName, | ||
url: &VerbatimParsedUrl, | ||
fork_markers: &MarkerTree, | ||
) -> Result<(), ResolveError> { | ||
match self.0.entry(package_name.clone()) { | ||
Entry::Occupied(previous) => { | ||
if previous.get() != url { | ||
let mut conflicting_url = vec![ | ||
previous.get().verbatim.verbatim().to_string(), | ||
url.to_string(), | ||
]; | ||
conflicting_url.sort(); | ||
return if fork_markers == &MarkerTree::And(Vec::new()) { | ||
Err(ResolveError::ConflictingUrls( | ||
package_name.clone(), | ||
conflicting_url, | ||
)) | ||
} else { | ||
Err(ResolveError::ConflictingUrlsInFork { | ||
package_name: package_name.clone(), | ||
urls: conflicting_url, | ||
fork_markers: fork_markers.clone(), | ||
}) | ||
}; | ||
} | ||
} | ||
Entry::Vacant(vacant) => { | ||
vacant.insert(url.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
Oops, something went wrong.