-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users to provide pre-defined metadata for resolution #7442
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3cd899a
Allow users to provide pre-defined metadata for resolution
charliermarsh e9e349c
We might need to make this a generic setting rather than project data
charliermarsh aba68fa
Treat as settings
charliermarsh 76aa2af
Treat as settings
charliermarsh 19beb4a
Rename to metadata-overrides
charliermarsh 42d8b5f
Rebrand as dependency metadata
charliermarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 [`StaticMetadata`] entries, indexed by [`PackageName`] and [`Version`]. | ||
#[derive(Debug, Clone, Default)] | ||
pub struct DependencyMetadata(FxHashMap<PackageName, Vec<StaticMetadata>>); | ||
|
||
impl DependencyMetadata { | ||
/// Index a set of [`StaticMetadata`] entries by [`PackageName`] and [`Version`]. | ||
pub fn from_entries(entries: impl IntoIterator<Item = StaticMetadata>) -> Self { | ||
let mut map = Self::default(); | ||
for entry in entries { | ||
map.0.entry(entry.name.clone()).or_default().push(entry); | ||
} | ||
map | ||
} | ||
|
||
/// Retrieve a [`StaticMetadata`] 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 [`StaticMetadata`] entries. | ||
pub fn values(&self) -> impl Iterator<Item = &StaticMetadata> { | ||
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 StaticMetadata { | ||
// 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 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just to avoid a
use serde::Serialize;
?