Skip to content

Commit

Permalink
Rename to metadata-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 17, 2024
1 parent 2fa8a42 commit 3569e1f
Show file tree
Hide file tree
Showing 42 changed files with 539 additions and 308 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions crates/bench/benches/uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ mod resolver {

use anyhow::Result;

use distribution_types::{IndexCapabilities, IndexLocations, StaticMetadata};
use distribution_types::{IndexCapabilities, IndexLocations, MetadataOverrides};
use install_wheel_rs::linker::LinkMode;
use pep440_rs::Version;
use pep508_rs::{MarkerEnvironment, MarkerEnvironmentBuilder};
Expand Down Expand Up @@ -161,7 +161,7 @@ mod resolver {
let installed_packages = EmptyInstalledPackages;
let options = OptionsBuilder::new().exclude_newer(exclude_newer).build();
let sources = SourceStrategy::default();
let static_metadata = StaticMetadata::default();
let metadata_override = MetadataOverrides::default();

let python_requirement = if universal {
PythonRequirement::from_requires_python(
Expand All @@ -179,7 +179,7 @@ mod resolver {
interpreter,
&index_locations,
&flat_index,
&static_metadata,
&metadata_override,
&index,
&git,
&capabilities,
Expand Down
4 changes: 2 additions & 2 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ pub use crate::hash::*;
pub use crate::id::*;
pub use crate::index_url::*;
pub use crate::installed::*;
pub use crate::metadata_override::*;
pub use crate::prioritized_distribution::*;
pub use crate::resolution::*;
pub use crate::resolved::*;
pub use crate::specified_requirement::*;
pub use crate::static_metadata::*;
pub use crate::traits::*;

mod annotation;
Expand All @@ -76,11 +76,11 @@ mod hash;
mod id;
mod index_url;
mod installed;
mod metadata_override;
mod prioritized_distribution;
mod resolution;
mod resolved;
mod specified_requirement;
mod static_metadata;
mod traits;

#[derive(Debug, Clone)]
Expand Down
76 changes: 76 additions & 0 deletions crates/distribution-types/src/metadata_override.rs
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>,
}
32 changes: 0 additions & 32 deletions crates/distribution-types/src/static_metadata.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/pypi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jiff = { workspace = true, features = ["serde"] }
mailparse = { workspace = true }
regex = { workspace = true }
rkyv = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }
Expand Down
19 changes: 1 addition & 18 deletions crates/pypi-types/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,15 @@ use crate::{LenientVersionSpecifiers, VerbatimParsedUrl};
/// fields that are relevant to dependency resolution.
///
/// At present, we support up to version 2.3 of the metadata specification.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Metadata23 {
// 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: 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>,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn resolver_options(
} else {
prerelease
},
static_metadata: None,
metadata_override: None,
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
Expand Down Expand Up @@ -365,7 +365,7 @@ pub fn resolver_installer_options(
} else {
prerelease
},
static_metadata: None,
metadata_override: None,
config_settings: config_setting
.map(|config_settings| config_settings.into_iter().collect::<ConfigSettings>()),
no_build_isolation: flag(no_build_isolation, build_isolation),
Expand Down
12 changes: 6 additions & 6 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_hash::FxHashMap;
use tracing::{debug, instrument};

use distribution_types::{
CachedDist, IndexCapabilities, IndexLocations, Name, Resolution, SourceDist, StaticMetadata,
CachedDist, IndexCapabilities, IndexLocations, MetadataOverrides, Name, Resolution, SourceDist,
VersionOrUrlRef,
};
use pypi_types::Requirement;
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct BuildDispatch<'a> {
index: &'a InMemoryIndex,
git: &'a GitResolver,
capabilities: &'a IndexCapabilities,
static_metadata: &'a StaticMetadata,
metadata_override: &'a MetadataOverrides,
in_flight: &'a InFlight,
build_isolation: BuildIsolation<'a>,
link_mode: install_wheel_rs::linker::LinkMode,
Expand All @@ -68,7 +68,7 @@ impl<'a> BuildDispatch<'a> {
interpreter: &'a Interpreter,
index_locations: &'a IndexLocations,
flat_index: &'a FlatIndex,
static_metadata: &'a StaticMetadata,
metadata_override: &'a MetadataOverrides,
index: &'a InMemoryIndex,
git: &'a GitResolver,
capabilities: &'a IndexCapabilities,
Expand All @@ -93,7 +93,7 @@ impl<'a> BuildDispatch<'a> {
index,
git,
capabilities,
static_metadata,
metadata_override,
in_flight,
index_strategy,
config_settings,
Expand Down Expand Up @@ -140,8 +140,8 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.capabilities
}

fn static_metadata(&self) -> &StaticMetadata {
self.static_metadata
fn metadata_override(&self) -> &MetadataOverrides {
self.metadata_override
}

fn build_options(&self) -> &BuildOptions {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-distribution/src/distribution_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
// If the metadata was provided by the user directly, prefer it.
if let Some(metadata) = self
.build_context
.static_metadata()
.metadata_override()
.get(dist.name(), dist.version())
{
return Ok(ArchiveMetadata::from_metadata23(metadata.clone()));
Expand Down Expand Up @@ -429,7 +429,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
if let Some(version) = dist.version() {
if let Some(metadata) = self
.build_context
.static_metadata()
.metadata_override()
.get(dist.name(), version)
{
return Ok(ArchiveMetadata::from_metadata23(metadata.clone()));
Expand Down
Loading

0 comments on commit 3569e1f

Please sign in to comment.