From a0023b0a8cf93118098ae51be2b1c319baa32234 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 16 Sep 2024 18:22:11 -0400 Subject: [PATCH] Avoid erroneous version warning for .dist-info --- crates/uv-metadata/src/lib.rs | 62 +++++++---------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/crates/uv-metadata/src/lib.rs b/crates/uv-metadata/src/lib.rs index 997737ff05eac..2993e391b0505 100644 --- a/crates/uv-metadata/src/lib.rs +++ b/crates/uv-metadata/src/lib.rs @@ -4,16 +4,13 @@ //! specification](https://packaging.python.org/en/latest/specifications/core-metadata/). use distribution_filename::WheelFilename; -use pep440_rs::Version; use pypi_types::Metadata23; use std::io; use std::io::{Read, Seek}; use std::path::Path; -use std::str::FromStr; use thiserror::Error; use tokio::io::AsyncReadExt; use tokio_util::compat::{FuturesAsyncReadCompatExt, TokioAsyncReadCompatExt}; -use tracing::warn; use uv_normalize::{DistInfoName, InvalidNameError}; use zip::ZipArchive; @@ -32,8 +29,6 @@ pub enum Error { MissingDistInfoSegments(String), #[error("The .dist-info directory {0} does not start with the normalized package name: {1}")] MissingDistInfoPackageName(String, String), - #[error("The .dist-info directory {0} does not start with the normalized version: {1}")] - MissingDistInfoVersion(String, String), #[error("The .dist-info directory name contains invalid characters")] InvalidName(#[from] InvalidNameError), #[error("The metadata at {0} is invalid")] @@ -85,28 +80,17 @@ pub fn find_archive_dist_info<'a, T: Copy>( }; // Like `pip`, validate that the `.dist-info` directory is prefixed with the canonical - // package name, but only warn if the version is not the normalized version. + // package name. let normalized_prefix = DistInfoName::new(dist_info_prefix); - let Some(rest) = normalized_prefix + if !normalized_prefix .as_ref() - .strip_prefix(filename.name.as_str()) - else { + .starts_with(filename.name.as_str()) + { return Err(Error::MissingDistInfoPackageName( dist_info_prefix.to_string(), filename.name.to_string(), )); }; - if !rest.strip_prefix('-').is_some_and(|version| { - Version::from_str(version).is_ok_and(|version| version == filename.version) - }) { - warn!( - "{}", - Error::MissingDistInfoVersion( - dist_info_prefix.to_string(), - filename.version.to_string(), - ) - ); - } Ok((payload, dist_info_prefix)) } @@ -125,28 +109,17 @@ pub fn is_metadata_entry(path: &str, filename: &WheelFilename) -> Result