diff --git a/crates/uv-distribution/src/distribution_database.rs b/crates/uv-distribution/src/distribution_database.rs index 3b22dfbaa..ab1475153 100644 --- a/crates/uv-distribution/src/distribution_database.rs +++ b/crates/uv-distribution/src/distribution_database.rs @@ -151,35 +151,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context> WheelCache::Url(&url).wheel_dir(wheel.name().as_ref()), wheel.filename.stem(), ); - - // If the file is already unzipped, and the unzipped directory is fresh, - // return it. - match cache_entry.path().canonicalize() { - Ok(archive) => { - if ArchiveTimestamp::up_to_date_with( - path, - ArchiveTarget::Cache(&archive), - ) - .map_err(Error::CacheRead)? - { - return Ok(LocalWheel::Unzipped(UnzippedWheel { - dist: Dist::Built(dist.clone()), - archive, - filename: wheel.filename.clone(), - })); - } - } - Err(err) if err.kind() == io::ErrorKind::NotFound => {} - Err(err) => return Err(Error::CacheRead(err)), - } - - // Otherwise, unzip the file. - return Ok(LocalWheel::Disk(DiskWheel { - dist: Dist::Built(dist.clone()), - path: path.clone(), - target: cache_entry.into_path_buf(), - filename: wheel.filename.clone(), - })); + return Self::load_wheel(path, &wheel.filename, cache_entry, dist); } }; @@ -269,34 +241,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context> WheelCache::Url(&wheel.url).wheel_dir(wheel.name().as_ref()), wheel.filename.stem(), ); - - // If the file is already unzipped, and the unzipped directory is fresh, - // return it. - match cache_entry.path().canonicalize() { - Ok(archive) => { - if ArchiveTimestamp::up_to_date_with( - &wheel.path, - ArchiveTarget::Cache(&archive), - ) - .map_err(Error::CacheRead)? - { - return Ok(LocalWheel::Unzipped(UnzippedWheel { - dist: Dist::Built(dist.clone()), - archive, - filename: wheel.filename.clone(), - })); - } - } - Err(err) if err.kind() == io::ErrorKind::NotFound => {} - Err(err) => return Err(Error::CacheRead(err)), - } - - Ok(LocalWheel::Disk(DiskWheel { - dist: Dist::Built(dist.clone()), - path: wheel.path.clone(), - target: cache_entry.into_path_buf(), - filename: wheel.filename.clone(), - })) + Self::load_wheel(&wheel.path, &wheel.filename, cache_entry, dist) } } } @@ -506,6 +451,40 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context> Ok(archive) } + /// Load a wheel from a local path. + fn load_wheel( + path: &Path, + filename: &WheelFilename, + wheel_entry: CacheEntry, + dist: &BuiltDist, + ) -> Result { + // If the file is already unzipped, and the unzipped directory is fresh, + // return it. + match wheel_entry.path().canonicalize() { + Ok(archive) => { + if ArchiveTimestamp::up_to_date_with(path, ArchiveTarget::Cache(&archive)) + .map_err(Error::CacheRead)? + { + return Ok(LocalWheel::Unzipped(UnzippedWheel { + dist: Dist::Built(dist.clone()), + archive, + filename: filename.clone(), + })); + } + } + Err(err) if err.kind() == io::ErrorKind::NotFound => {} + Err(err) => return Err(Error::CacheRead(err)), + } + + // Otherwise, return the path to the file. + Ok(LocalWheel::Disk(DiskWheel { + dist: Dist::Built(dist.clone()), + path: path.to_path_buf(), + target: wheel_entry.into_path_buf(), + filename: filename.clone(), + })) + } + /// Returns a GET [`reqwest::Request`] for the given URL. fn request(&self, url: Url) -> Result { self.client diff --git a/scripts/requirements/all-kinds.in b/scripts/requirements/all-kinds.in index 1fe196b8d..4b48f77a3 100644 --- a/scripts/requirements/all-kinds.in +++ b/scripts/requirements/all-kinds.in @@ -10,4 +10,3 @@ django_allauth==0.51.0 werkzeug @ https://files.pythonhosted.org/packages/0d/cc/ff1904eb5eb4b455e442834dabf9427331ac0fa02853bf83db817a7dd53d/werkzeug-3.0.1.tar.gz # git source dist pydantic-extra-types @ git+https://github.com/pydantic/pydantic-extra-types.git -