Skip to content

Commit

Permalink
Rebrand as dependency metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Sep 17, 2024
1 parent 3569e1f commit 14df756
Show file tree
Hide file tree
Showing 36 changed files with 325 additions and 311 deletions.
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, MetadataOverrides};
use distribution_types::{DependencyMetadata, IndexCapabilities, IndexLocations};
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 metadata_override = MetadataOverrides::default();
let dependency_metadata = DependencyMetadata::default();

let python_requirement = if universal {
PythonRequirement::from_requires_python(
Expand All @@ -179,7 +179,7 @@ mod resolver {
interpreter,
&index_locations,
&flat_index,
&metadata_override,
&dependency_metadata,
&index,
&git,
&capabilities,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use uv_normalize::{ExtraName, PackageName};

/// Pre-defined [`MetadataOverride`] entries, indexed by [`PackageName`] and [`Version`].
/// Pre-defined [`StaticMetadata`] entries, indexed by [`PackageName`] and [`Version`].
#[derive(Debug, Clone, Default)]
pub struct MetadataOverrides(FxHashMap<PackageName, Vec<MetadataOverride>>);
pub struct DependencyMetadata(FxHashMap<PackageName, Vec<StaticMetadata>>);

impl MetadataOverrides {
/// Index a set of [`MetadataOverride`] entries by [`PackageName`] and [`Version`].
pub fn from_entries(entries: impl IntoIterator<Item = MetadataOverride>) -> Self {
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 [`MetadataOverride`] entry by [`PackageName`] and [`Version`].
/// Retrieve a [`StaticMetadata`] entry by [`PackageName`] and [`Version`].
pub fn get(&self, package: &PackageName, version: &Version) -> Option<Metadata23> {
let versions = self.0.get(package)?;

Expand All @@ -38,8 +38,8 @@ impl MetadataOverrides {
})
}

/// Retrieve all [`MetadataOverride`] entries.
pub fn values(&self) -> impl Iterator<Item = &MetadataOverride> {
/// Retrieve all [`StaticMetadata`] entries.
pub fn values(&self) -> impl Iterator<Item = &StaticMetadata> {
self.0.values().flatten()
}
}
Expand All @@ -49,7 +49,7 @@ impl MetadataOverrides {
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub struct MetadataOverride {
pub struct StaticMetadata {
// Mandatory fields
pub name: PackageName,
#[cfg_attr(
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 @@ -51,14 +51,14 @@ pub use crate::annotation::*;
pub use crate::any::*;
pub use crate::buildable::*;
pub use crate::cached::*;
pub use crate::dependency_metadata::*;
pub use crate::diagnostic::*;
pub use crate::error::*;
pub use crate::file::*;
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::*;
Expand All @@ -69,14 +69,14 @@ mod annotation;
mod any;
mod buildable;
mod cached;
mod dependency_metadata;
mod diagnostic;
mod error;
mod file;
mod hash;
mod id;
mod index_url;
mod installed;
mod metadata_override;
mod prioritized_distribution;
mod resolution;
mod resolved;
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
},
metadata_override: None,
dependency_metadata: 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
},
metadata_override: None,
dependency_metadata: 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
14 changes: 7 additions & 7 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_hash::FxHashMap;
use tracing::{debug, instrument};

use distribution_types::{
CachedDist, IndexCapabilities, IndexLocations, MetadataOverrides, Name, Resolution, SourceDist,
VersionOrUrlRef,
CachedDist, DependencyMetadata, IndexCapabilities, IndexLocations, Name, Resolution,
SourceDist, VersionOrUrlRef,
};
use pypi_types::Requirement;
use uv_build::{SourceBuild, SourceBuildContext};
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct BuildDispatch<'a> {
index: &'a InMemoryIndex,
git: &'a GitResolver,
capabilities: &'a IndexCapabilities,
metadata_override: &'a MetadataOverrides,
dependency_metadata: &'a DependencyMetadata,
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,
metadata_override: &'a MetadataOverrides,
dependency_metadata: &'a DependencyMetadata,
index: &'a InMemoryIndex,
git: &'a GitResolver,
capabilities: &'a IndexCapabilities,
Expand All @@ -93,7 +93,7 @@ impl<'a> BuildDispatch<'a> {
index,
git,
capabilities,
metadata_override,
dependency_metadata,
in_flight,
index_strategy,
config_settings,
Expand Down Expand Up @@ -140,8 +140,8 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.capabilities
}

fn metadata_override(&self) -> &MetadataOverrides {
self.metadata_override
fn dependency_metadata(&self) -> &DependencyMetadata {
self.dependency_metadata
}

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
.metadata_override()
.dependency_metadata()
.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
.metadata_override()
.dependency_metadata()
.get(dist.name(), version)
{
return Ok(ArchiveMetadata::from_metadata23(metadata.clone()));
Expand Down
36 changes: 18 additions & 18 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use url::Url;
use cache_key::RepositoryUrl;
use distribution_filename::{DistExtension, ExtensionError, SourceDistExtension, WheelFilename};
use distribution_types::{
BuiltDist, DirectUrlBuiltDist, DirectUrlSourceDist, DirectorySourceDist, Dist,
DistributionMetadata, FileLocation, FlatIndexLocation, GitSourceDist, HashPolicy,
IndexLocations, IndexUrl, MetadataOverride, MetadataOverrides, Name, PathBuiltDist,
PathSourceDist, RegistryBuiltDist, RegistryBuiltWheel, RegistrySourceDist, RemoteSource,
Resolution, ResolvedDist, ToUrlError, UrlString,
BuiltDist, DependencyMetadata, DirectUrlBuiltDist, DirectUrlSourceDist, DirectorySourceDist,
Dist, DistributionMetadata, FileLocation, FlatIndexLocation, GitSourceDist, HashPolicy,
IndexLocations, IndexUrl, Name, PathBuiltDist, PathSourceDist, RegistryBuiltDist,
RegistryBuiltWheel, RegistrySourceDist, RemoteSource, Resolution, ResolvedDist, StaticMetadata,
ToUrlError, UrlString,
};
use pep440_rs::Version;
use pep508_rs::{split_scheme, MarkerEnvironment, MarkerTree, VerbatimUrl, VerbatimUrlError};
Expand Down Expand Up @@ -795,9 +795,9 @@ impl Lock {
manifest_table.insert("overrides", value(overrides));
}

if !self.manifest.metadata_override.is_empty() {
if !self.manifest.dependency_metadata.is_empty() {
let mut tables = ArrayOfTables::new();
for metadata in &self.manifest.metadata_override {
for metadata in &self.manifest.dependency_metadata {
let mut table = Table::new();
table.insert("name", value(metadata.name.to_string()));
if let Some(version) = metadata.version.as_ref() {
Expand Down Expand Up @@ -915,7 +915,7 @@ impl Lock {
requirements: &[Requirement],
constraints: &[Requirement],
overrides: &[Requirement],
metadata_override: &MetadataOverrides,
dependency_metadata: &DependencyMetadata,
indexes: Option<&IndexLocations>,
build_options: &BuildOptions,
tags: &Tags,
Expand Down Expand Up @@ -1032,8 +1032,11 @@ impl Lock {

// Validate that the lockfile was generated with the same static metadata.
{
let expected = metadata_override.values().cloned().collect::<BTreeSet<_>>();
let actual = &self.manifest.metadata_override;
let expected = dependency_metadata
.values()
.cloned()
.collect::<BTreeSet<_>>();
let actual = &self.manifest.dependency_metadata;
if expected != *actual {
return Ok(SatisfiesResult::MismatchedStaticMetadata(expected, actual));
}
Expand Down Expand Up @@ -1294,10 +1297,7 @@ pub enum SatisfiesResult<'lock> {
/// The lockfile uses a different set of overrides.
MismatchedOverrides(BTreeSet<Requirement>, BTreeSet<Requirement>),
/// The lockfile uses different static metadata.
MismatchedStaticMetadata(
BTreeSet<MetadataOverride>,
&'lock BTreeSet<MetadataOverride>,
),
MismatchedStaticMetadata(BTreeSet<StaticMetadata>, &'lock BTreeSet<StaticMetadata>),
/// The lockfile is missing a workspace member.
MissingRoot(PackageName),
/// The lockfile referenced a remote index that was not provided
Expand Down Expand Up @@ -1353,7 +1353,7 @@ pub struct ResolverManifest {
overrides: BTreeSet<Requirement>,
/// The static metadata provided to the resolver.
#[serde(default)]
metadata_override: BTreeSet<MetadataOverride>,
dependency_metadata: BTreeSet<StaticMetadata>,
}

impl ResolverManifest {
Expand All @@ -1364,14 +1364,14 @@ impl ResolverManifest {
requirements: impl IntoIterator<Item = Requirement>,
constraints: impl IntoIterator<Item = Requirement>,
overrides: impl IntoIterator<Item = Requirement>,
metadata_override: impl IntoIterator<Item = MetadataOverride>,
dependency_metadata: impl IntoIterator<Item = StaticMetadata>,
) -> Self {
Self {
members: members.into_iter().collect(),
requirements: requirements.into_iter().collect(),
constraints: constraints.into_iter().collect(),
overrides: overrides.into_iter().collect(),
metadata_override: metadata_override.into_iter().collect(),
dependency_metadata: dependency_metadata.into_iter().collect(),
}
}

Expand All @@ -1394,7 +1394,7 @@ impl ResolverManifest {
.into_iter()
.map(|requirement| requirement.relative_to(workspace.install_path()))
.collect::<Result<BTreeSet<_>, _>>()?,
metadata_override: self.metadata_override,
dependency_metadata: self.dependency_metadata,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Ok(
requirements: {},
constraints: {},
overrides: {},
metadata_override: {},
dependency_metadata: {},
},
},
)
Loading

0 comments on commit 14df756

Please sign in to comment.