mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-26 20:19:08 +00:00
Rename MetadataResolver
to ResolutionMetadata
(#7661)
This commit is contained in:
parent
16a6fd2c42
commit
5da73a24cb
12 changed files with 78 additions and 73 deletions
|
@ -1,6 +1,6 @@
|
|||
use pep440_rs::{Version, VersionSpecifiers};
|
||||
use pep508_rs::Requirement;
|
||||
use pypi_types::{MetadataResolver, VerbatimParsedUrl};
|
||||
use pypi_types::{ResolutionMetadata, VerbatimParsedUrl};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uv_normalize::{ExtraName, PackageName};
|
||||
|
@ -20,7 +20,7 @@ impl DependencyMetadata {
|
|||
}
|
||||
|
||||
/// Retrieve a [`StaticMetadata`] entry by [`PackageName`] and [`Version`].
|
||||
pub fn get(&self, package: &PackageName, version: &Version) -> Option<MetadataResolver> {
|
||||
pub fn get(&self, package: &PackageName, version: &Version) -> Option<ResolutionMetadata> {
|
||||
let versions = self.0.get(package)?;
|
||||
|
||||
// Search for an exact, then a global match.
|
||||
|
@ -29,7 +29,7 @@ impl DependencyMetadata {
|
|||
.find(|v| v.version.as_ref() == Some(version))
|
||||
.or_else(|| versions.iter().find(|v| v.version.is_none()))?;
|
||||
|
||||
Some(MetadataResolver {
|
||||
Some(ResolutionMetadata {
|
||||
name: metadata.name.clone(),
|
||||
version: version.clone(),
|
||||
requires_dist: metadata.requires_dist.clone(),
|
||||
|
|
|
@ -285,13 +285,13 @@ impl InstalledDist {
|
|||
}
|
||||
|
||||
/// Read the `METADATA` file from a `.dist-info` directory.
|
||||
pub fn metadata(&self) -> Result<pypi_types::MetadataResolver> {
|
||||
pub fn metadata(&self) -> Result<pypi_types::ResolutionMetadata> {
|
||||
match self {
|
||||
Self::Registry(_) | Self::Url(_) => {
|
||||
let path = self.path().join("METADATA");
|
||||
let contents = fs::read(&path)?;
|
||||
// TODO(zanieb): Update this to use thiserror so we can unpack parse errors downstream
|
||||
pypi_types::MetadataResolver::parse_metadata(&contents).with_context(|| {
|
||||
pypi_types::ResolutionMetadata::parse_metadata(&contents).with_context(|| {
|
||||
format!(
|
||||
"Failed to parse `METADATA` file at: {}",
|
||||
path.user_display()
|
||||
|
@ -306,7 +306,7 @@ impl InstalledDist {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
let contents = fs::read(path.as_ref())?;
|
||||
pypi_types::MetadataResolver::parse_metadata(&contents).with_context(|| {
|
||||
pypi_types::ResolutionMetadata::parse_metadata(&contents).with_context(|| {
|
||||
format!(
|
||||
"Failed to parse `PKG-INFO` file at: {}",
|
||||
path.user_display()
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::{metadata, LenientVersionSpecifiers, MetadataError, VerbatimParsedUrl
|
|||
/// Core Metadata 2.3 is specified in <https://packaging.python.org/specifications/core-metadata/>.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct MetadataResolver {
|
||||
pub struct ResolutionMetadata {
|
||||
// Mandatory fields
|
||||
pub name: PackageName,
|
||||
pub version: Version,
|
||||
|
@ -32,8 +32,8 @@ pub struct MetadataResolver {
|
|||
}
|
||||
|
||||
/// From <https://github.com/PyO3/python-pkginfo-rs/blob/d719988323a0cfea86d4737116d7917f30e819e2/src/metadata.rs#LL78C2-L91C26>
|
||||
impl MetadataResolver {
|
||||
/// Parse the [`MetadataResolver`] from a `METADATA` file, as included in a built distribution (wheel).
|
||||
impl ResolutionMetadata {
|
||||
/// Parse the [`ResolutionMetadata`] from a `METADATA` file, as included in a built distribution (wheel).
|
||||
pub fn parse_metadata(content: &[u8]) -> Result<Self, MetadataError> {
|
||||
let headers = Headers::parse(content)?;
|
||||
|
||||
|
@ -78,7 +78,7 @@ impl MetadataResolver {
|
|||
})
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from a source distribution's `PKG-INFO` file, if it uses Metadata 2.2
|
||||
/// Read the [`ResolutionMetadata`] from a source distribution's `PKG-INFO` file, if it uses Metadata 2.2
|
||||
/// or later _and_ none of the required fields (`Requires-Python`, `Requires-Dist`, and
|
||||
/// `Provides-Extra`) are marked as dynamic.
|
||||
pub fn parse_pkg_info(content: &[u8]) -> Result<Self, MetadataError> {
|
||||
|
@ -167,61 +167,61 @@ mod tests {
|
|||
#[test]
|
||||
fn test_parse_metadata() {
|
||||
let s = "Metadata-Version: 1.0";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes());
|
||||
assert!(matches!(meta, Err(MetadataError::FieldNotFound("Name"))));
|
||||
|
||||
let s = "Metadata-Version: 1.0\nName: asdf";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes());
|
||||
assert!(matches!(meta, Err(MetadataError::FieldNotFound("Version"))));
|
||||
|
||||
let s = "Metadata-Version: 1.0\nName: asdf\nVersion: 1.0";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes()).unwrap();
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes()).unwrap();
|
||||
assert_eq!(meta.name, PackageName::from_str("asdf").unwrap());
|
||||
assert_eq!(meta.version, Version::new([1, 0]));
|
||||
|
||||
let s = "Metadata-Version: 1.0\nName: asdf\nVersion: 1.0\nAuthor: 中文\n\n一个 Python 包";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes()).unwrap();
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes()).unwrap();
|
||||
assert_eq!(meta.name, PackageName::from_str("asdf").unwrap());
|
||||
assert_eq!(meta.version, Version::new([1, 0]));
|
||||
|
||||
let s = "Metadata-Version: 1.0\nName: =?utf-8?q?foobar?=\nVersion: 1.0";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes()).unwrap();
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes()).unwrap();
|
||||
assert_eq!(meta.name, PackageName::from_str("foobar").unwrap());
|
||||
assert_eq!(meta.version, Version::new([1, 0]));
|
||||
|
||||
let s = "Metadata-Version: 1.0\nName: =?utf-8?q?=C3=A4_space?= <x@y.org>\nVersion: 1.0";
|
||||
let meta = MetadataResolver::parse_metadata(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_metadata(s.as_bytes());
|
||||
assert!(matches!(meta, Err(MetadataError::InvalidName(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_pkg_info() {
|
||||
let s = "Metadata-Version: 2.1";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes());
|
||||
assert!(matches!(
|
||||
meta,
|
||||
Err(MetadataError::UnsupportedMetadataVersion(_))
|
||||
));
|
||||
|
||||
let s = "Metadata-Version: 2.2\nName: asdf";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes());
|
||||
assert!(matches!(meta, Err(MetadataError::FieldNotFound("Version"))));
|
||||
|
||||
let s = "Metadata-Version: 2.3\nName: asdf";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes());
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes());
|
||||
assert!(matches!(meta, Err(MetadataError::FieldNotFound("Version"))));
|
||||
|
||||
let s = "Metadata-Version: 2.3\nName: asdf\nVersion: 1.0";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes()).unwrap();
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes()).unwrap();
|
||||
assert_eq!(meta.name, PackageName::from_str("asdf").unwrap());
|
||||
assert_eq!(meta.version, Version::new([1, 0]));
|
||||
|
||||
let s = "Metadata-Version: 2.3\nName: asdf\nVersion: 1.0\nDynamic: Requires-Dist";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes()).unwrap_err();
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes()).unwrap_err();
|
||||
assert!(matches!(meta, MetadataError::DynamicField("Requires-Dist")));
|
||||
|
||||
let s = "Metadata-Version: 2.3\nName: asdf\nVersion: 1.0\nRequires-Dist: foo";
|
||||
let meta = MetadataResolver::parse_pkg_info(s.as_bytes()).unwrap();
|
||||
let meta = ResolutionMetadata::parse_pkg_info(s.as_bytes()).unwrap();
|
||||
assert_eq!(meta.name, PackageName::from_str("asdf").unwrap());
|
||||
assert_eq!(meta.version, Version::new([1, 0]));
|
||||
assert_eq!(meta.requires_dist, vec!["foo".parse().unwrap()]);
|
||||
|
|
|
@ -16,7 +16,7 @@ use uv_normalize::InvalidNameError;
|
|||
pub use metadata10::Metadata10;
|
||||
pub use metadata12::Metadata12;
|
||||
pub use metadata23::Metadata23;
|
||||
pub use metadata_resolver::MetadataResolver;
|
||||
pub use metadata_resolver::ResolutionMetadata;
|
||||
pub use pyproject_toml::RequiresDist;
|
||||
pub use requires_txt::RequiresTxt;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
LenientRequirement, LenientVersionSpecifiers, MetadataError, MetadataResolver,
|
||||
LenientRequirement, LenientVersionSpecifiers, MetadataError, ResolutionMetadata,
|
||||
VerbatimParsedUrl,
|
||||
};
|
||||
use indexmap::IndexMap;
|
||||
|
@ -12,7 +12,7 @@ use std::str::FromStr;
|
|||
use uv_normalize::{ExtraName, PackageName};
|
||||
|
||||
/// Extract the metadata from a `pyproject.toml` file, as specified in PEP 621.
|
||||
pub(crate) fn parse_pyproject_toml(contents: &str) -> Result<MetadataResolver, MetadataError> {
|
||||
pub(crate) fn parse_pyproject_toml(contents: &str) -> Result<ResolutionMetadata, MetadataError> {
|
||||
let pyproject_toml = PyProjectToml::from_toml(contents)?;
|
||||
|
||||
let project = pyproject_toml
|
||||
|
@ -77,7 +77,7 @@ pub(crate) fn parse_pyproject_toml(contents: &str) -> Result<MetadataResolver, M
|
|||
provides_extras.push(extra);
|
||||
}
|
||||
|
||||
Ok(MetadataResolver {
|
||||
Ok(ResolutionMetadata {
|
||||
name,
|
||||
version,
|
||||
requires_dist,
|
||||
|
@ -149,7 +149,7 @@ struct ToolPoetry {}
|
|||
/// Python Package Metadata 2.3 as specified in
|
||||
/// <https://packaging.python.org/specifications/core-metadata/>.
|
||||
///
|
||||
/// This is a subset of [`MetadataResolver`]; specifically, it omits the `version` and `requires-python`
|
||||
/// This is a subset of [`ResolutionMetadata`]; specifically, it omits the `version` and `requires-python`
|
||||
/// fields, which aren't necessary when extracting the requirements of a package without installing
|
||||
/// the package itself.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
@ -11,7 +11,7 @@ use tracing::debug;
|
|||
|
||||
pub use archive::ArchiveId;
|
||||
use distribution_types::InstalledDist;
|
||||
use pypi_types::MetadataResolver;
|
||||
use pypi_types::ResolutionMetadata;
|
||||
use uv_cache_info::Timestamp;
|
||||
use uv_fs::{cachedir, directories};
|
||||
use uv_normalize::PackageName;
|
||||
|
@ -789,7 +789,7 @@ impl CacheBucket {
|
|||
let Ok(metadata) = fs_err::read(path.join("metadata.msgpack")) else {
|
||||
return false;
|
||||
};
|
||||
let Ok(metadata) = rmp_serde::from_slice::<MetadataResolver>(&metadata) else {
|
||||
let Ok(metadata) = rmp_serde::from_slice::<ResolutionMetadata>(&metadata) else {
|
||||
return false;
|
||||
};
|
||||
metadata.name == *name
|
||||
|
|
|
@ -19,7 +19,7 @@ use distribution_types::{
|
|||
use pep440_rs::Version;
|
||||
use pep508_rs::MarkerEnvironment;
|
||||
use platform_tags::Platform;
|
||||
use pypi_types::{MetadataResolver, SimpleJson};
|
||||
use pypi_types::{ResolutionMetadata, SimpleJson};
|
||||
use uv_cache::{Cache, CacheBucket, CacheEntry, WheelCache};
|
||||
use uv_configuration::KeyringProviderType;
|
||||
use uv_configuration::{IndexStrategy, TrustedHost};
|
||||
|
@ -405,7 +405,7 @@ impl RegistryClient {
|
|||
&self,
|
||||
built_dist: &BuiltDist,
|
||||
capabilities: &IndexCapabilities,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
let metadata = match &built_dist {
|
||||
BuiltDist::Registry(wheels) => {
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -455,7 +455,7 @@ impl RegistryClient {
|
|||
.map_err(|err| {
|
||||
ErrorKind::Metadata(path.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
MetadataResolver::parse_metadata(&contents).map_err(|err| {
|
||||
ResolutionMetadata::parse_metadata(&contents).map_err(|err| {
|
||||
ErrorKind::MetadataParseError(
|
||||
wheel.filename.clone(),
|
||||
built_dist.to_string(),
|
||||
|
@ -489,7 +489,7 @@ impl RegistryClient {
|
|||
.map_err(|err| {
|
||||
ErrorKind::Metadata(wheel.install_path.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
MetadataResolver::parse_metadata(&contents).map_err(|err| {
|
||||
ResolutionMetadata::parse_metadata(&contents).map_err(|err| {
|
||||
ErrorKind::MetadataParseError(
|
||||
wheel.filename.clone(),
|
||||
built_dist.to_string(),
|
||||
|
@ -516,7 +516,7 @@ impl RegistryClient {
|
|||
file: &File,
|
||||
url: &Url,
|
||||
capabilities: &IndexCapabilities,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
// If the metadata file is available at its own url (PEP 658), download it from there.
|
||||
let filename = WheelFilename::from_str(&file.filename).map_err(ErrorKind::WheelFilename)?;
|
||||
if file.dist_info_metadata {
|
||||
|
@ -541,7 +541,7 @@ impl RegistryClient {
|
|||
let bytes = response.bytes().await.map_err(ErrorKind::from)?;
|
||||
|
||||
info_span!("parse_metadata21")
|
||||
.in_scope(|| MetadataResolver::parse_metadata(bytes.as_ref()))
|
||||
.in_scope(|| ResolutionMetadata::parse_metadata(bytes.as_ref()))
|
||||
.map_err(|err| {
|
||||
Error::from(ErrorKind::MetadataParseError(
|
||||
filename,
|
||||
|
@ -582,7 +582,7 @@ impl RegistryClient {
|
|||
index: Option<&'data IndexUrl>,
|
||||
cache_shard: WheelCache<'data>,
|
||||
capabilities: &'data IndexCapabilities,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
let cache_entry = self.cache.entry(
|
||||
CacheBucket::Wheels,
|
||||
cache_shard.wheel_dir(filename.name.as_ref()),
|
||||
|
@ -630,14 +630,14 @@ impl RegistryClient {
|
|||
trace!("Getting metadata for {filename} by range request");
|
||||
let text = wheel_metadata_from_remote_zip(filename, url, &mut reader).await?;
|
||||
let metadata =
|
||||
MetadataResolver::parse_metadata(text.as_bytes()).map_err(|err| {
|
||||
ResolutionMetadata::parse_metadata(text.as_bytes()).map_err(|err| {
|
||||
Error::from(ErrorKind::MetadataParseError(
|
||||
filename.clone(),
|
||||
url.to_string(),
|
||||
Box::new(err),
|
||||
))
|
||||
})?;
|
||||
Ok::<MetadataResolver, CachedClientError<Error>>(metadata)
|
||||
Ok::<ResolutionMetadata, CachedClientError<Error>>(metadata)
|
||||
}
|
||||
.boxed_local()
|
||||
.instrument(info_span!("read_metadata_range_request", wheel = %filename))
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
|||
use crate::Error;
|
||||
use distribution_filename::WheelFilename;
|
||||
use distribution_types::{CachedDist, Dist, Hashed};
|
||||
use pypi_types::{HashDigest, MetadataResolver};
|
||||
use pypi_types::{HashDigest, ResolutionMetadata};
|
||||
use uv_metadata::read_flat_wheel_metadata;
|
||||
|
||||
use uv_cache_info::CacheInfo;
|
||||
|
@ -40,8 +40,8 @@ impl LocalWheel {
|
|||
&self.filename
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from a wheel.
|
||||
pub fn metadata(&self) -> Result<MetadataResolver, Error> {
|
||||
/// Read the [`ResolutionMetadata`] from a wheel.
|
||||
pub fn metadata(&self) -> Result<ResolutionMetadata, Error> {
|
||||
read_flat_wheel_metadata(&self.filename, &self.archive)
|
||||
.map_err(|err| Error::WheelMetadata(self.archive.clone(), Box::new(err)))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::path::Path;
|
|||
use thiserror::Error;
|
||||
|
||||
use pep440_rs::{Version, VersionSpecifiers};
|
||||
use pypi_types::{HashDigest, MetadataResolver};
|
||||
use pypi_types::{HashDigest, ResolutionMetadata};
|
||||
use uv_configuration::SourceStrategy;
|
||||
use uv_normalize::{ExtraName, GroupName, PackageName};
|
||||
use uv_workspace::WorkspaceError;
|
||||
|
@ -39,7 +39,7 @@ pub struct Metadata {
|
|||
impl Metadata {
|
||||
/// Lower without considering `tool.uv` in `pyproject.toml`, used for index and other archive
|
||||
/// dependencies.
|
||||
pub fn from_metadata23(metadata: MetadataResolver) -> Self {
|
||||
pub fn from_metadata23(metadata: ResolutionMetadata) -> Self {
|
||||
Self {
|
||||
name: metadata.name,
|
||||
version: metadata.version,
|
||||
|
@ -57,7 +57,7 @@ impl Metadata {
|
|||
/// Lower by considering `tool.uv` in `pyproject.toml` if present, used for Git and directory
|
||||
/// dependencies.
|
||||
pub async fn from_workspace(
|
||||
metadata: MetadataResolver,
|
||||
metadata: ResolutionMetadata,
|
||||
install_path: &Path,
|
||||
sources: SourceStrategy,
|
||||
) -> Result<Self, MetadataError> {
|
||||
|
@ -102,7 +102,7 @@ pub struct ArchiveMetadata {
|
|||
impl ArchiveMetadata {
|
||||
/// Lower without considering `tool.uv` in `pyproject.toml`, used for index and other archive
|
||||
/// dependencies.
|
||||
pub fn from_metadata23(metadata: MetadataResolver) -> Self {
|
||||
pub fn from_metadata23(metadata: ResolutionMetadata) -> Self {
|
||||
Self {
|
||||
metadata: Metadata::from_metadata23(metadata),
|
||||
hashes: vec![],
|
||||
|
|
|
@ -20,7 +20,7 @@ use distribution_types::{
|
|||
use fs_err::tokio as fs;
|
||||
use futures::{FutureExt, TryStreamExt};
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::{HashDigest, Metadata12, MetadataResolver, RequiresTxt};
|
||||
use pypi_types::{HashDigest, Metadata12, RequiresTxt, ResolutionMetadata};
|
||||
use reqwest::Response;
|
||||
use tokio_util::compat::FuturesAsyncReadCompatExt;
|
||||
use tracing::{debug, info_span, instrument, warn, Instrument};
|
||||
|
@ -1583,7 +1583,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
|||
source_root: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
cache_shard: &CacheShard,
|
||||
) -> Result<(String, WheelFilename, MetadataResolver), Error> {
|
||||
) -> Result<(String, WheelFilename, ResolutionMetadata), Error> {
|
||||
debug!("Building: {source}");
|
||||
|
||||
// Guard against build of source distributions when disabled.
|
||||
|
@ -1641,7 +1641,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
|||
source: &BuildableSource<'_>,
|
||||
source_root: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
) -> Result<Option<MetadataResolver>, Error> {
|
||||
) -> Result<Option<ResolutionMetadata>, Error> {
|
||||
debug!("Preparing metadata for: {source}");
|
||||
|
||||
// Set up the builder.
|
||||
|
@ -1673,7 +1673,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
|||
let content = fs::read(dist_info.join("METADATA"))
|
||||
.await
|
||||
.map_err(Error::CacheRead)?;
|
||||
let metadata = MetadataResolver::parse_metadata(&content)?;
|
||||
let metadata = ResolutionMetadata::parse_metadata(&content)?;
|
||||
|
||||
// Validate the metadata.
|
||||
validate(source, &metadata)?;
|
||||
|
@ -1685,7 +1685,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
|||
source: &BuildableSource<'_>,
|
||||
source_root: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
) -> Result<Option<MetadataResolver>, Error> {
|
||||
) -> Result<Option<ResolutionMetadata>, Error> {
|
||||
// Attempt to read static metadata from the `pyproject.toml`.
|
||||
match read_pyproject_toml(source_root, subdirectory).await {
|
||||
Ok(metadata) => {
|
||||
|
@ -1858,7 +1858,7 @@ pub fn prune(cache: &Cache) -> Result<Removal, Error> {
|
|||
}
|
||||
|
||||
/// Validate that the source distribution matches the built metadata.
|
||||
fn validate(source: &BuildableSource<'_>, metadata: &MetadataResolver) -> Result<(), Error> {
|
||||
fn validate(source: &BuildableSource<'_>, metadata: &ResolutionMetadata) -> Result<(), Error> {
|
||||
if let Some(name) = source.name() {
|
||||
if metadata.name != *name {
|
||||
return Err(Error::NameMismatch {
|
||||
|
@ -1955,7 +1955,7 @@ impl LocalRevisionPointer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] by combining a source distribution's `PKG-INFO` file with a
|
||||
/// Read the [`ResolutionMetadata`] by combining a source distribution's `PKG-INFO` file with a
|
||||
/// `requires.txt`.
|
||||
///
|
||||
/// `requires.txt` is a legacy concept from setuptools. For example, here's
|
||||
|
@ -1988,7 +1988,7 @@ impl LocalRevisionPointer {
|
|||
async fn read_egg_info(
|
||||
source_tree: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
fn find_egg_info(source_tree: &Path) -> std::io::Result<Option<PathBuf>> {
|
||||
for entry in fs_err::read_dir(source_tree)? {
|
||||
let entry = entry?;
|
||||
|
@ -2048,7 +2048,7 @@ async fn read_egg_info(
|
|||
let metadata = Metadata12::parse_metadata(&content).map_err(Error::PkgInfo)?;
|
||||
|
||||
// Combine the sources.
|
||||
Ok(MetadataResolver {
|
||||
Ok(ResolutionMetadata {
|
||||
name: metadata.name,
|
||||
version: metadata.version,
|
||||
requires_python: metadata.requires_python,
|
||||
|
@ -2057,13 +2057,13 @@ async fn read_egg_info(
|
|||
})
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from a source distribution's `PKG-INFO` file, if it uses Metadata 2.2
|
||||
/// Read the [`ResolutionMetadata`] from a source distribution's `PKG-INFO` file, if it uses Metadata 2.2
|
||||
/// or later _and_ none of the required fields (`Requires-Python`, `Requires-Dist`, and
|
||||
/// `Provides-Extra`) are marked as dynamic.
|
||||
async fn read_pkg_info(
|
||||
source_tree: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
// Read the `PKG-INFO` file.
|
||||
let pkg_info = match subdirectory {
|
||||
Some(subdirectory) => source_tree.join(subdirectory).join("PKG-INFO"),
|
||||
|
@ -2078,17 +2078,17 @@ async fn read_pkg_info(
|
|||
};
|
||||
|
||||
// Parse the metadata.
|
||||
let metadata = MetadataResolver::parse_pkg_info(&content).map_err(Error::PkgInfo)?;
|
||||
let metadata = ResolutionMetadata::parse_pkg_info(&content).map_err(Error::PkgInfo)?;
|
||||
|
||||
Ok(metadata)
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from a source distribution's `pyproject.toml` file, if it defines static
|
||||
/// Read the [`ResolutionMetadata`] from a source distribution's `pyproject.toml` file, if it defines static
|
||||
/// metadata consistent with PEP 621.
|
||||
async fn read_pyproject_toml(
|
||||
source_tree: &Path,
|
||||
subdirectory: Option<&Path>,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
// Read the `pyproject.toml` file.
|
||||
let pyproject_toml = match subdirectory {
|
||||
Some(subdirectory) => source_tree.join(subdirectory).join("pyproject.toml"),
|
||||
|
@ -2104,7 +2104,7 @@ async fn read_pyproject_toml(
|
|||
|
||||
// Parse the metadata.
|
||||
let metadata =
|
||||
MetadataResolver::parse_pyproject_toml(&content).map_err(Error::PyprojectToml)?;
|
||||
ResolutionMetadata::parse_pyproject_toml(&content).map_err(Error::PyprojectToml)?;
|
||||
|
||||
Ok(metadata)
|
||||
}
|
||||
|
@ -2128,8 +2128,10 @@ async fn read_requires_dist(project_root: &Path) -> Result<pypi_types::RequiresD
|
|||
Ok(requires_dist)
|
||||
}
|
||||
|
||||
/// Read an existing cached [`MetadataResolver`], if it exists.
|
||||
async fn read_cached_metadata(cache_entry: &CacheEntry) -> Result<Option<MetadataResolver>, Error> {
|
||||
/// Read an existing cached [`ResolutionMetadata`], if it exists.
|
||||
async fn read_cached_metadata(
|
||||
cache_entry: &CacheEntry,
|
||||
) -> Result<Option<ResolutionMetadata>, Error> {
|
||||
match fs::read(&cache_entry.path()).await {
|
||||
Ok(cached) => Ok(Some(rmp_serde::from_slice(&cached)?)),
|
||||
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),
|
||||
|
@ -2137,14 +2139,17 @@ async fn read_cached_metadata(cache_entry: &CacheEntry) -> Result<Option<Metadat
|
|||
}
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from a built wheel.
|
||||
fn read_wheel_metadata(filename: &WheelFilename, wheel: &Path) -> Result<MetadataResolver, Error> {
|
||||
/// Read the [`ResolutionMetadata`] from a built wheel.
|
||||
fn read_wheel_metadata(
|
||||
filename: &WheelFilename,
|
||||
wheel: &Path,
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
let file = fs_err::File::open(wheel).map_err(Error::CacheRead)?;
|
||||
let reader = std::io::BufReader::new(file);
|
||||
let mut archive = ZipArchive::new(reader)?;
|
||||
let dist_info = read_archive_metadata(filename, &mut archive)
|
||||
.map_err(|err| Error::WheelMetadata(wheel.to_path_buf(), Box::new(err)))?;
|
||||
Ok(MetadataResolver::parse_metadata(&dist_info)?)
|
||||
Ok(ResolutionMetadata::parse_metadata(&dist_info)?)
|
||||
}
|
||||
|
||||
/// Apply an advisory lock to a [`CacheShard`] to prevent concurrent builds.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! specification](https://packaging.python.org/en/latest/specifications/core-metadata/).
|
||||
|
||||
use distribution_filename::WheelFilename;
|
||||
use pypi_types::MetadataResolver;
|
||||
use pypi_types::ResolutionMetadata;
|
||||
use std::io;
|
||||
use std::io::{Read, Seek};
|
||||
use std::path::Path;
|
||||
|
@ -233,7 +233,7 @@ pub async fn read_metadata_async_stream<R: futures::AsyncRead + Unpin>(
|
|||
filename: &WheelFilename,
|
||||
debug_path: &str,
|
||||
reader: R,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
let reader = futures::io::BufReader::with_capacity(128 * 1024, reader);
|
||||
let mut zip = async_zip::base::read::stream::ZipFileReader::new(reader);
|
||||
|
||||
|
@ -246,7 +246,7 @@ pub async fn read_metadata_async_stream<R: futures::AsyncRead + Unpin>(
|
|||
let mut contents = Vec::new();
|
||||
reader.read_to_end(&mut contents).await.unwrap();
|
||||
|
||||
let metadata = MetadataResolver::parse_metadata(&contents)
|
||||
let metadata = ResolutionMetadata::parse_metadata(&contents)
|
||||
.map_err(|err| Error::InvalidMetadata(debug_path.to_string(), Box::new(err)))?;
|
||||
return Ok(metadata);
|
||||
}
|
||||
|
@ -259,14 +259,14 @@ pub async fn read_metadata_async_stream<R: futures::AsyncRead + Unpin>(
|
|||
Err(Error::MissingDistInfo)
|
||||
}
|
||||
|
||||
/// Read the [`MetadataResolver`] from an unzipped wheel.
|
||||
/// Read the [`ResolutionMetadata`] from an unzipped wheel.
|
||||
pub fn read_flat_wheel_metadata(
|
||||
filename: &WheelFilename,
|
||||
wheel: impl AsRef<Path>,
|
||||
) -> Result<MetadataResolver, Error> {
|
||||
) -> Result<ResolutionMetadata, Error> {
|
||||
let dist_info_prefix = find_flat_dist_info(filename, &wheel)?;
|
||||
let metadata = read_dist_info_metadata(&dist_info_prefix, &wheel)?;
|
||||
MetadataResolver::parse_metadata(&metadata).map_err(|err| {
|
||||
ResolutionMetadata::parse_metadata(&metadata).map_err(|err| {
|
||||
Error::InvalidMetadata(
|
||||
format!("{dist_info_prefix}.dist-info/METADATA"),
|
||||
Box::new(err),
|
||||
|
|
|
@ -30,7 +30,7 @@ use locals::Locals;
|
|||
use pep440_rs::{Version, MIN_VERSION};
|
||||
use pep508_rs::MarkerTree;
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::{MetadataResolver, Requirement, VerbatimParsedUrl};
|
||||
use pypi_types::{Requirement, ResolutionMetadata, VerbatimParsedUrl};
|
||||
pub use resolver_markers::ResolverMarkers;
|
||||
pub(crate) use urls::Urls;
|
||||
use uv_configuration::{Constraints, Overrides};
|
||||
|
@ -2583,7 +2583,7 @@ enum Response {
|
|||
/// The returned metadata for an already-installed distribution.
|
||||
Installed {
|
||||
dist: InstalledDist,
|
||||
metadata: MetadataResolver,
|
||||
metadata: ResolutionMetadata,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue