-
Notifications
You must be signed in to change notification settings - Fork 624
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
e5dd67f
commit 35df820
Showing
18 changed files
with
363 additions
and
50 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
use url::Url; | ||
|
||
#[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
pub struct IndexSource { | ||
pub name: String, | ||
pub index: Url, | ||
#[serde(default)] | ||
pub kind: IndexKind, | ||
} | ||
|
||
#[derive( | ||
Default, Debug, Copy, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize, | ||
)] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
pub enum IndexKind { | ||
/// A PEP 503 and/or PEP 691-compliant index. | ||
#[default] | ||
Simple, | ||
/// An index containing a list of links to distributions (e.g., `--find-links`). | ||
Flat, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::{DependencyMode, Manifest, ResolveError, ResolverMarkers}; | ||
use distribution_types::IndexUrl; | ||
use pep508_rs::{PackageName, VerbatimUrl}; | ||
use pypi_types::RequirementSource; | ||
use rustc_hash::FxHashMap; | ||
use std::collections::hash_map::Entry; | ||
|
||
/// A map of package names to their explicit index across all forks. | ||
#[derive(Debug, Default, Clone)] | ||
pub(crate) struct Indexes(FxHashMap<PackageName, IndexUrl>); | ||
|
||
impl Indexes { | ||
/// Determine the set of explicit, pinned indexes in the [`Manifest`]. | ||
pub(crate) fn from_manifest( | ||
manifest: &Manifest, | ||
markers: &ResolverMarkers, | ||
dependencies: DependencyMode, | ||
) -> Result<Self, ResolveError> { | ||
let mut indexes = FxHashMap::<PackageName, IndexUrl>::default(); | ||
|
||
for requirement in manifest.requirements(markers, dependencies) { | ||
let RequirementSource::Registry { | ||
index: Some(index), .. | ||
} = &requirement.source | ||
else { | ||
continue; | ||
}; | ||
let index = IndexUrl::from(VerbatimUrl::from_url(index.clone())); | ||
match indexes.entry(requirement.name.clone()) { | ||
Entry::Occupied(entry) => { | ||
let existing = entry.get(); | ||
if *existing != index { | ||
return Err(ResolveError::ConflictingIndexes( | ||
requirement.name.clone(), | ||
existing.to_string(), | ||
index.to_string(), | ||
)); | ||
} | ||
} | ||
Entry::Vacant(entry) => { | ||
entry.insert(index); | ||
} | ||
} | ||
} | ||
|
||
Ok(Self(indexes)) | ||
} | ||
|
||
/// Return the explicit index for a given [`PackageName`]. | ||
pub(crate) fn get(&self, package_name: &PackageName) -> Option<&IndexUrl> { | ||
self.0.get(package_name) | ||
} | ||
} |
Oops, something went wrong.