-
Notifications
You must be signed in to change notification settings - Fork 739
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
2fa8a42
commit 3569e1f
Showing
42 changed files
with
539 additions
and
308 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
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,76 @@ | ||
use pep440_rs::{Version, VersionSpecifiers}; | ||
use pep508_rs::Requirement; | ||
use pypi_types::{Metadata23, VerbatimParsedUrl}; | ||
use rustc_hash::FxHashMap; | ||
use serde::{Deserialize, Serialize}; | ||
use uv_normalize::{ExtraName, PackageName}; | ||
|
||
/// Pre-defined [`MetadataOverride`] entries, indexed by [`PackageName`] and [`Version`]. | ||
#[derive(Debug, Clone, Default)] | ||
pub struct MetadataOverrides(FxHashMap<PackageName, Vec<MetadataOverride>>); | ||
|
||
impl MetadataOverrides { | ||
/// Index a set of [`MetadataOverride`] entries by [`PackageName`] and [`Version`]. | ||
pub fn from_entries(entries: impl IntoIterator<Item = MetadataOverride>) -> Self { | ||
let mut map = Self::default(); | ||
for entry in entries { | ||
map.0.entry(entry.name.clone()).or_default().push(entry); | ||
} | ||
map | ||
} | ||
|
||
/// Retrieve a [`MetadataOverride`] entry by [`PackageName`] and [`Version`]. | ||
pub fn get(&self, package: &PackageName, version: &Version) -> Option<Metadata23> { | ||
let versions = self.0.get(package)?; | ||
|
||
// Search for an exact, then a global match. | ||
let metadata = versions | ||
.iter() | ||
.find(|v| v.version.as_ref() == Some(version)) | ||
.or_else(|| versions.iter().find(|v| v.version.is_none()))?; | ||
|
||
Some(Metadata23 { | ||
name: metadata.name.clone(), | ||
version: version.clone(), | ||
requires_dist: metadata.requires_dist.clone(), | ||
requires_python: metadata.requires_python.clone(), | ||
provides_extras: metadata.provides_extras.clone(), | ||
}) | ||
} | ||
|
||
/// Retrieve all [`MetadataOverride`] entries. | ||
pub fn values(&self) -> impl Iterator<Item = &MetadataOverride> { | ||
self.0.values().flatten() | ||
} | ||
} | ||
|
||
/// A subset of the Python Package Metadata 2.3 standard as specified in | ||
/// <https://packaging.python.org/specifications/core-metadata/>. | ||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
#[serde(rename_all = "kebab-case")] | ||
pub struct MetadataOverride { | ||
// Mandatory fields | ||
pub name: PackageName, | ||
#[cfg_attr( | ||
feature = "schemars", | ||
schemars( | ||
with = "String", | ||
description = "PEP 440-style package version, e.g., `1.2.3`" | ||
) | ||
)] | ||
pub version: Option<Version>, | ||
// Optional fields | ||
#[serde(default)] | ||
pub requires_dist: Vec<Requirement<VerbatimParsedUrl>>, | ||
#[cfg_attr( | ||
feature = "schemars", | ||
schemars( | ||
with = "Option<String>", | ||
description = "PEP 508-style Python requirement, e.g., `>=3.10`" | ||
) | ||
)] | ||
pub requires_python: Option<VersionSpecifiers>, | ||
#[serde(default)] | ||
pub provides_extras: Vec<ExtraName>, | ||
} |
This file was deleted.
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
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.