mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Remove unused local wheel types (#2906)
## Summary No behavior changes. Just removing unused code.
This commit is contained in:
parent
1daa35176f
commit
31a67f539f
5 changed files with 34 additions and 198 deletions
|
@ -19,7 +19,6 @@ use uv_cache::{ArchiveTarget, ArchiveTimestamp, CacheBucket, CacheEntry, WheelCa
|
|||
use uv_client::{CacheControl, CachedClientError, Connectivity, RegistryClient};
|
||||
use uv_types::{BuildContext, NoBinary, NoBuild};
|
||||
|
||||
use crate::download::UnzippedWheel;
|
||||
use crate::locks::Locks;
|
||||
use crate::{Error, LocalWheel, Reporter, SourceDistributionBuilder};
|
||||
|
||||
|
@ -121,11 +120,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
let path = editable_wheel_dir.join(&disk_filename);
|
||||
let target = editable_wheel_dir.join(cache_key::digest(&editable.path));
|
||||
let archive = self.unzip_wheel(&path, &target).await?;
|
||||
let wheel = LocalWheel::Unzipped(UnzippedWheel {
|
||||
let wheel = LocalWheel {
|
||||
dist,
|
||||
filename,
|
||||
archive,
|
||||
});
|
||||
};
|
||||
|
||||
Ok((wheel, metadata))
|
||||
}
|
||||
|
@ -175,11 +174,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
.stream_wheel(url.clone(), &wheel.filename, &wheel_entry, dist)
|
||||
.await
|
||||
{
|
||||
Ok(archive) => Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(archive) => Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive,
|
||||
filename: wheel.filename.clone(),
|
||||
})),
|
||||
}),
|
||||
Err(Error::Extract(err)) if err.is_http_streaming_unsupported() => {
|
||||
warn!(
|
||||
"Streaming unsupported for {dist}; downloading wheel to disk ({err})"
|
||||
|
@ -190,11 +189,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
let archive = self
|
||||
.download_wheel(url, &wheel.filename, &wheel_entry, dist)
|
||||
.await?;
|
||||
Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive,
|
||||
filename: wheel.filename.clone(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
|
@ -213,11 +212,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
.stream_wheel(wheel.url.raw().clone(), &wheel.filename, &wheel_entry, dist)
|
||||
.await
|
||||
{
|
||||
Ok(archive) => Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(archive) => Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive,
|
||||
filename: wheel.filename.clone(),
|
||||
})),
|
||||
}),
|
||||
Err(Error::Client(err)) if err.is_http_streaming_unsupported() => {
|
||||
warn!(
|
||||
"Streaming unsupported for {dist}; downloading wheel to disk ({err})"
|
||||
|
@ -233,11 +232,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
dist,
|
||||
)
|
||||
.await?;
|
||||
Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive,
|
||||
filename: wheel.filename.clone(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
|
@ -271,24 +270,24 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
// cached under a unique build ID, so unzipped directories are never stale.
|
||||
match built_wheel.target.canonicalize() {
|
||||
Ok(archive) => {
|
||||
return Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
return Ok(LocalWheel {
|
||||
dist: Dist::Source(dist.clone()),
|
||||
archive,
|
||||
filename: built_wheel.filename,
|
||||
}));
|
||||
});
|
||||
}
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
|
||||
Err(err) => return Err(Error::CacheRead(err)),
|
||||
}
|
||||
|
||||
// Otherwise, unzip the wheel.
|
||||
Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(LocalWheel {
|
||||
dist: Dist::Source(dist.clone()),
|
||||
archive: self
|
||||
.unzip_wheel(&built_wheel.path, &built_wheel.target)
|
||||
.await?,
|
||||
filename: built_wheel.filename,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
/// Fetch the wheel metadata from the index, or from the cache if possible.
|
||||
|
@ -480,11 +479,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
if ArchiveTimestamp::up_to_date_with(path, ArchiveTarget::Cache(&archive))
|
||||
.map_err(Error::CacheRead)?
|
||||
{
|
||||
return Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
return Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive,
|
||||
filename: filename.clone(),
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {}
|
||||
|
@ -492,11 +491,11 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
|
|||
}
|
||||
|
||||
// Otherwise, unzip the wheel.
|
||||
Ok(LocalWheel::Unzipped(UnzippedWheel {
|
||||
Ok(LocalWheel {
|
||||
dist: Dist::Built(dist.clone()),
|
||||
archive: self.unzip_wheel(path, wheel_entry.path()).await?,
|
||||
filename: filename.clone(),
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
/// Unzip a wheel into the cache, returning the path to the unzipped directory.
|
||||
|
|
|
@ -6,9 +6,9 @@ use pypi_types::Metadata23;
|
|||
|
||||
use crate::Error;
|
||||
|
||||
/// A wheel that's been unzipped while downloading
|
||||
/// A locally available wheel.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UnzippedWheel {
|
||||
pub struct LocalWheel {
|
||||
/// The remote distribution from which this wheel was downloaded.
|
||||
pub(crate) dist: Dist,
|
||||
/// The parsed filename.
|
||||
|
@ -18,113 +18,32 @@ pub struct UnzippedWheel {
|
|||
pub(crate) archive: PathBuf,
|
||||
}
|
||||
|
||||
/// A downloaded wheel that's stored on-disk.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DiskWheel {
|
||||
/// The remote distribution from which this wheel was downloaded.
|
||||
pub(crate) dist: Dist,
|
||||
/// The parsed filename.
|
||||
pub(crate) filename: WheelFilename,
|
||||
/// The path to the downloaded wheel.
|
||||
pub(crate) path: PathBuf,
|
||||
/// The expected path to the downloaded wheel's entry in the cache.
|
||||
/// Typically, a symlink within the wheels or built wheels bucket.
|
||||
pub(crate) target: PathBuf,
|
||||
}
|
||||
|
||||
/// A wheel built from a source distribution that's stored on-disk.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BuiltWheel {
|
||||
/// The remote source distribution from which this wheel was built.
|
||||
pub(crate) dist: Dist,
|
||||
/// The parsed filename.
|
||||
pub(crate) filename: WheelFilename,
|
||||
/// The path to the built wheel.
|
||||
pub(crate) path: PathBuf,
|
||||
/// The expected path to the downloaded wheel's entry in the cache.
|
||||
/// Typically, a symlink within the wheels or built wheels bucket.
|
||||
pub(crate) target: PathBuf,
|
||||
}
|
||||
|
||||
/// A downloaded or built wheel.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum LocalWheel {
|
||||
Unzipped(UnzippedWheel),
|
||||
Disk(DiskWheel),
|
||||
Built(BuiltWheel),
|
||||
}
|
||||
|
||||
impl LocalWheel {
|
||||
/// Return the path to the downloaded wheel's entry in the cache.
|
||||
pub fn target(&self) -> &Path {
|
||||
match self {
|
||||
Self::Unzipped(wheel) => &wheel.archive,
|
||||
Self::Disk(wheel) => &wheel.target,
|
||||
Self::Built(wheel) => &wheel.target,
|
||||
}
|
||||
&self.archive
|
||||
}
|
||||
|
||||
/// Return the [`Dist`] from which this wheel was downloaded.
|
||||
pub fn remote(&self) -> &Dist {
|
||||
match self {
|
||||
Self::Unzipped(wheel) => wheel.remote(),
|
||||
Self::Disk(wheel) => wheel.remote(),
|
||||
Self::Built(wheel) => wheel.remote(),
|
||||
}
|
||||
&self.dist
|
||||
}
|
||||
|
||||
/// Return the [`WheelFilename`] of this wheel.
|
||||
pub fn filename(&self) -> &WheelFilename {
|
||||
match self {
|
||||
Self::Unzipped(wheel) => &wheel.filename,
|
||||
Self::Disk(wheel) => &wheel.filename,
|
||||
Self::Built(wheel) => &wheel.filename,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert a [`LocalWheel`] into a [`CachedDist`].
|
||||
pub fn into_cached_dist(self, archive: PathBuf) -> CachedDist {
|
||||
match self {
|
||||
Self::Unzipped(wheel) => CachedDist::from_remote(wheel.dist, wheel.filename, archive),
|
||||
Self::Disk(wheel) => CachedDist::from_remote(wheel.dist, wheel.filename, archive),
|
||||
Self::Built(wheel) => CachedDist::from_remote(wheel.dist, wheel.filename, archive),
|
||||
}
|
||||
&self.filename
|
||||
}
|
||||
|
||||
/// Read the [`Metadata23`] from a wheel.
|
||||
pub fn metadata(&self) -> Result<Metadata23, Error> {
|
||||
match self {
|
||||
Self::Unzipped(wheel) => read_flat_wheel_metadata(&wheel.filename, &wheel.archive),
|
||||
Self::Disk(wheel) => read_built_wheel_metadata(&wheel.filename, &wheel.path),
|
||||
Self::Built(wheel) => read_built_wheel_metadata(&wheel.filename, &wheel.path),
|
||||
}
|
||||
read_flat_wheel_metadata(&self.filename, &self.archive)
|
||||
}
|
||||
}
|
||||
|
||||
impl UnzippedWheel {
|
||||
/// Return the [`Dist`] from which this wheel was downloaded.
|
||||
pub fn remote(&self) -> &Dist {
|
||||
&self.dist
|
||||
}
|
||||
|
||||
/// Convert an [`UnzippedWheel`] into a [`CachedDist`].
|
||||
pub fn into_cached_dist(self) -> CachedDist {
|
||||
CachedDist::from_remote(self.dist, self.filename, self.archive)
|
||||
}
|
||||
}
|
||||
|
||||
impl DiskWheel {
|
||||
/// Return the [`Dist`] from which this wheel was downloaded.
|
||||
pub fn remote(&self) -> &Dist {
|
||||
&self.dist
|
||||
}
|
||||
}
|
||||
|
||||
impl BuiltWheel {
|
||||
/// Return the [`Dist`] from which this source distribution that this wheel was built from was
|
||||
/// downloaded.
|
||||
pub fn remote(&self) -> &Dist {
|
||||
&self.dist
|
||||
/// Convert a [`LocalWheel`] into a [`CachedDist`].
|
||||
impl From<LocalWheel> for CachedDist {
|
||||
fn from(wheel: LocalWheel) -> CachedDist {
|
||||
CachedDist::from_remote(wheel.dist, wheel.filename, wheel.archive)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,18 +53,6 @@ impl std::fmt::Display for LocalWheel {
|
|||
}
|
||||
}
|
||||
|
||||
/// Read the [`Metadata23`] from a built wheel.
|
||||
fn read_built_wheel_metadata(
|
||||
filename: &WheelFilename,
|
||||
wheel: impl AsRef<Path>,
|
||||
) -> Result<Metadata23, Error> {
|
||||
let file = fs_err::File::open(wheel.as_ref()).map_err(Error::CacheRead)?;
|
||||
let reader = std::io::BufReader::new(file);
|
||||
let mut archive = zip::ZipArchive::new(reader)?;
|
||||
let metadata = install_wheel_rs::metadata::read_archive_metadata(filename, &mut archive)?;
|
||||
Ok(Metadata23::parse_metadata(&metadata)?)
|
||||
}
|
||||
|
||||
/// Read the [`Metadata23`] from an unzipped wheel.
|
||||
fn read_flat_wheel_metadata(
|
||||
filename: &WheelFilename,
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
pub use distribution_database::DistributionDatabase;
|
||||
pub use download::{BuiltWheel, DiskWheel, LocalWheel};
|
||||
pub use download::LocalWheel;
|
||||
pub use error::Error;
|
||||
pub use git::{is_same_reference, to_precise};
|
||||
pub use index::{BuiltWheelIndex, RegistryWheelIndex};
|
||||
pub use reporter::Reporter;
|
||||
pub use source::SourceDistributionBuilder;
|
||||
pub use unzip::Unzip;
|
||||
|
||||
mod distribution_database;
|
||||
mod download;
|
||||
|
@ -15,4 +14,3 @@ mod index;
|
|||
mod locks;
|
||||
mod reporter;
|
||||
mod source;
|
||||
mod unzip;
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
use std::path::Path;
|
||||
|
||||
use tracing::instrument;
|
||||
|
||||
use uv_extract::Error;
|
||||
|
||||
use crate::download::BuiltWheel;
|
||||
use crate::{DiskWheel, LocalWheel};
|
||||
|
||||
pub trait Unzip {
|
||||
/// Unzip a wheel into the target directory.
|
||||
fn unzip(&self, target: &Path) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl Unzip for DiskWheel {
|
||||
fn unzip(&self, target: &Path) -> Result<(), Error> {
|
||||
uv_extract::unzip(fs_err::File::open(&self.path)?, target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Unzip for BuiltWheel {
|
||||
fn unzip(&self, target: &Path) -> Result<(), Error> {
|
||||
uv_extract::unzip(fs_err::File::open(&self.path)?, target)
|
||||
}
|
||||
}
|
||||
|
||||
impl Unzip for LocalWheel {
|
||||
#[instrument(skip_all, fields(filename=self.filename().to_string()))]
|
||||
fn unzip(&self, target: &Path) -> Result<(), Error> {
|
||||
match self {
|
||||
Self::Unzipped(_) => Ok(()),
|
||||
Self::Disk(wheel) => wheel.unzip(target),
|
||||
Self::Built(wheel) => wheel.unzip(target),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue