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 70a034d
Show file tree
Hide file tree
Showing 26 changed files with 315 additions and 301 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
16 changes: 8 additions & 8 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Debug, num::NonZeroUsize, path::PathBuf};

use serde::{Deserialize, Serialize};

use distribution_types::{FlatIndexLocation, IndexUrl, MetadataOverride};
use distribution_types::{FlatIndexLocation, IndexUrl, StaticMetadata};
use install_wheel_rs::linker::LinkMode;
use pep508_rs::Requirement;
use pypi_types::{SupportedEnvironments, VerbatimParsedUrl};
Expand Down Expand Up @@ -288,7 +288,7 @@ pub struct ResolverOptions {
pub allow_insecure_host: Option<Vec<TrustedHost>>,
pub resolution: Option<ResolutionMode>,
pub prerelease: Option<PrereleaseMode>,
pub metadata_override: Option<Vec<MetadataOverride>>,
pub dependency_metadata: Option<Vec<StaticMetadata>>,
pub config_settings: Option<ConfigSettings>,
pub exclude_newer: Option<ExcludeNewer>,
pub link_mode: Option<LinkMode>,
Expand Down Expand Up @@ -463,7 +463,7 @@ pub struct ResolverInstallerOptions {
]
"#
)]
pub metadata_override: Option<Vec<MetadataOverride>>,
pub dependency_metadata: Option<Vec<StaticMetadata>>,
/// Settings to pass to the [PEP 517](https://peps.python.org/pep-0517/) build backend,
/// specified as `KEY=VALUE` pairs.
#[option(
Expand Down Expand Up @@ -995,7 +995,7 @@ pub struct PipOptions {
]
"#
)]
pub metadata_override: Option<Vec<MetadataOverride>>,
pub dependency_metadata: Option<Vec<StaticMetadata>>,
/// Write the requirements generated by `uv pip compile` to the given `requirements.txt` file.
///
/// If the file already exists, the existing versions will be preferred when resolving
Expand Down Expand Up @@ -1337,7 +1337,7 @@ impl From<ResolverInstallerOptions> for ResolverOptions {
allow_insecure_host: value.allow_insecure_host,
resolution: value.resolution,
prerelease: value.prerelease,
metadata_override: value.metadata_override,
dependency_metadata: value.dependency_metadata,
config_settings: value.config_settings,
exclude_newer: value.exclude_newer,
link_mode: value.link_mode,
Expand Down Expand Up @@ -1399,7 +1399,7 @@ pub struct ToolOptions {
pub allow_insecure_host: Option<Vec<TrustedHost>>,
pub resolution: Option<ResolutionMode>,
pub prerelease: Option<PrereleaseMode>,
pub metadata_override: Option<Vec<MetadataOverride>>,
pub dependency_metadata: Option<Vec<StaticMetadata>>,
pub config_settings: Option<ConfigSettings>,
pub no_build_isolation: Option<bool>,
pub no_build_isolation_package: Option<Vec<PackageName>>,
Expand All @@ -1425,7 +1425,7 @@ impl From<ResolverInstallerOptions> for ToolOptions {
allow_insecure_host: value.allow_insecure_host,
resolution: value.resolution,
prerelease: value.prerelease,
metadata_override: value.metadata_override,
dependency_metadata: value.dependency_metadata,
config_settings: value.config_settings,
no_build_isolation: value.no_build_isolation,
no_build_isolation_package: value.no_build_isolation_package,
Expand Down Expand Up @@ -1453,7 +1453,7 @@ impl From<ToolOptions> for ResolverInstallerOptions {
allow_insecure_host: value.allow_insecure_host,
resolution: value.resolution,
prerelease: value.prerelease,
metadata_override: value.metadata_override,
dependency_metadata: value.dependency_metadata,
config_settings: value.config_settings,
no_build_isolation: value.no_build_isolation,
no_build_isolation_package: value.no_build_isolation_package,
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-types/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use anyhow::Result;

use distribution_types::{
CachedDist, IndexCapabilities, IndexLocations, InstalledDist, MetadataOverrides, Resolution,
CachedDist, DependencyMetadata, IndexCapabilities, IndexLocations, InstalledDist, Resolution,
SourceDist,
};
use pep508_rs::PackageName;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub trait BuildContext {
fn capabilities(&self) -> &IndexCapabilities;

/// Return a reference to any pre-defined static metadata.
fn metadata_override(&self) -> &MetadataOverrides;
fn dependency_metadata(&self) -> &DependencyMetadata;

/// Whether source distribution building or pre-built wheels is disabled.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async fn build_impl(
allow_insecure_host,
resolution: _,
prerelease: _,
metadata_override,
dependency_metadata,
config_setting,
no_build_isolation,
no_build_isolation_package,
Expand Down Expand Up @@ -300,7 +300,7 @@ async fn build_impl(
&interpreter,
index_locations,
&flat_index,
metadata_override,
dependency_metadata,
&state.index,
&state.git,
&state.capabilities,
Expand Down
Loading

0 comments on commit 70a034d

Please sign in to comment.