From c9d3d60a189ef087c8ce82a4a85ff9e181e254c7 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 30 Jul 2025 10:44:06 -0500 Subject: [PATCH] Implement `CacheKey` for all `Pep508Url` variants (#14978) Closes #14973 --- Cargo.lock | 1 + crates/uv-pep508/src/lib.rs | 9 +++------ crates/uv-pep508/src/verbatim_url.rs | 7 +++++++ crates/uv-pypi-types/Cargo.toml | 1 + crates/uv-pypi-types/src/parsed_url.rs | 7 +++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 396b77bea..37cc267e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5646,6 +5646,7 @@ dependencies = [ "toml_edit", "tracing", "url", + "uv-cache-key", "uv-distribution-filename", "uv-git-types", "uv-normalize", diff --git a/crates/uv-pep508/src/lib.rs b/crates/uv-pep508/src/lib.rs index dd516f570..9167d0964 100644 --- a/crates/uv-pep508/src/lib.rs +++ b/crates/uv-pep508/src/lib.rs @@ -252,10 +252,7 @@ impl Serialize for Requirement { } } -impl CacheKey for Requirement -where - T: Display, -{ +impl CacheKey for Requirement { fn cache_key(&self, state: &mut CacheKeyHasher) { self.name.as_str().cache_key(state); @@ -280,7 +277,7 @@ where } VersionOrUrl::Url(url) => { 1u8.cache_key(state); - url.to_string().cache_key(state); + url.cache_key(state); } } } else { @@ -330,7 +327,7 @@ impl Requirement { } /// Type to parse URLs from `name @ ` into. Defaults to [`Url`]. -pub trait Pep508Url: Display + Debug + Sized { +pub trait Pep508Url: Display + Debug + Sized + CacheKey { /// String to URL parsing error type Err: Error + Debug; diff --git a/crates/uv-pep508/src/verbatim_url.rs b/crates/uv-pep508/src/verbatim_url.rs index 9f0e9a5ee..480d4fb67 100644 --- a/crates/uv-pep508/src/verbatim_url.rs +++ b/crates/uv-pep508/src/verbatim_url.rs @@ -10,6 +10,7 @@ use arcstr::ArcStr; use regex::Regex; use thiserror::Error; use url::{ParseError, Url}; +use uv_cache_key::{CacheKey, CacheKeyHasher}; #[cfg_attr(not(feature = "non-pep508-extensions"), allow(unused_imports))] use uv_fs::{normalize_absolute_path, normalize_url_path}; @@ -37,6 +38,12 @@ impl Hash for VerbatimUrl { } } +impl CacheKey for VerbatimUrl { + fn cache_key(&self, state: &mut CacheKeyHasher) { + self.url.as_str().cache_key(state); + } +} + impl PartialEq for VerbatimUrl { fn eq(&self, other: &Self) -> bool { self.url == other.url diff --git a/crates/uv-pypi-types/Cargo.toml b/crates/uv-pypi-types/Cargo.toml index 31a532d6e..e5ceef631 100644 --- a/crates/uv-pypi-types/Cargo.toml +++ b/crates/uv-pypi-types/Cargo.toml @@ -16,6 +16,7 @@ doctest = false workspace = true [dependencies] +uv-cache-key = { workspace = true } uv-distribution-filename = { workspace = true } uv-git-types = { workspace = true } uv-normalize = { workspace = true } diff --git a/crates/uv-pypi-types/src/parsed_url.rs b/crates/uv-pypi-types/src/parsed_url.rs index 57afbcdf9..3b3b21f17 100644 --- a/crates/uv-pypi-types/src/parsed_url.rs +++ b/crates/uv-pypi-types/src/parsed_url.rs @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf}; use thiserror::Error; use url::{ParseError, Url}; +use uv_cache_key::{CacheKey, CacheKeyHasher}; use uv_distribution_filename::{DistExtension, ExtensionError}; use uv_git_types::{GitUrl, GitUrlParseError}; @@ -45,6 +46,12 @@ pub struct VerbatimParsedUrl { pub verbatim: VerbatimUrl, } +impl CacheKey for VerbatimParsedUrl { + fn cache_key(&self, state: &mut CacheKeyHasher) { + self.verbatim.cache_key(state); + } +} + impl VerbatimParsedUrl { /// Returns `true` if the URL is editable. pub fn is_editable(&self) -> bool {