mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Avoid re-parsing wheel filename in source distribution tree (#265)
This commit is contained in:
parent
aff26f2301
commit
bee1b0f5ad
1 changed files with 26 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -36,6 +36,7 @@ impl<'a, T: BuildContext> SourceDistributionBuildTree<'a, T> {
|
||||||
tags: &Tags,
|
tags: &Tags,
|
||||||
) -> Result<Option<Metadata21>> {
|
) -> Result<Option<Metadata21>> {
|
||||||
self.find_wheel(distribution, tags)
|
self.find_wheel(distribution, tags)
|
||||||
|
.as_ref()
|
||||||
.map(read_dist_info)
|
.map(read_dist_info)
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
@ -69,14 +70,22 @@ impl<'a, T: BuildContext> SourceDistributionBuildTree<'a, T> {
|
||||||
.build_source_distribution(&sdist_file, &wheel_dir)
|
.build_source_distribution(&sdist_file, &wheel_dir)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let metadata21 = read_dist_info(wheel_dir.join(disk_filename))?;
|
let wheel = CachedWheel {
|
||||||
|
path: wheel_dir.join(&disk_filename),
|
||||||
|
filename: WheelFilename::from_str(&disk_filename)?,
|
||||||
|
};
|
||||||
|
let metadata21 = read_dist_info(&wheel)?;
|
||||||
|
|
||||||
debug!("Finished building: {}", distribution.file().filename);
|
debug!("Finished building: {}", distribution.file().filename);
|
||||||
Ok(metadata21)
|
Ok(metadata21)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search for a wheel matching the tags that was built from the given source distribution.
|
/// Search for a wheel matching the tags that was built from the given source distribution.
|
||||||
fn find_wheel(&self, distribution: &RemoteDistributionRef<'_>, tags: &Tags) -> Option<PathBuf> {
|
fn find_wheel(
|
||||||
|
&self,
|
||||||
|
distribution: &RemoteDistributionRef<'_>,
|
||||||
|
tags: &Tags,
|
||||||
|
) -> Option<CachedWheel> {
|
||||||
let wheel_dir = self
|
let wheel_dir = self
|
||||||
.0
|
.0
|
||||||
.cache()?
|
.cache()?
|
||||||
|
@ -89,33 +98,30 @@ impl<'a, T: BuildContext> SourceDistributionBuildTree<'a, T> {
|
||||||
let Ok(entry) = entry else {
|
let Ok(entry) = entry else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let Ok(wheel) = WheelFilename::from_str(entry.file_name().to_string_lossy().as_ref())
|
let Ok(filename) =
|
||||||
|
WheelFilename::from_str(entry.file_name().to_string_lossy().as_ref())
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
if filename.is_compatible(tags) {
|
||||||
if wheel.is_compatible(tags) {
|
let path = entry.path().clone();
|
||||||
return Some(entry.path().clone());
|
return Some(CachedWheel { path, filename });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct CachedWheel {
|
||||||
|
path: PathBuf,
|
||||||
|
filename: WheelFilename,
|
||||||
|
}
|
||||||
|
|
||||||
/// Read the [`Metadata21`] from a wheel.
|
/// Read the [`Metadata21`] from a wheel.
|
||||||
fn read_dist_info(wheel: impl AsRef<Path>) -> Result<Metadata21> {
|
fn read_dist_info(wheel: &CachedWheel) -> Result<Metadata21> {
|
||||||
let mut archive = ZipArchive::new(std::fs::File::open(&wheel)?)?;
|
let mut archive = ZipArchive::new(fs_err::File::open(&wheel.path)?)?;
|
||||||
let dist_info_prefix = install_wheel_rs::find_dist_info(
|
let dist_info_prefix = install_wheel_rs::find_dist_info(&wheel.filename, &mut archive)?;
|
||||||
&WheelFilename::from_str(
|
|
||||||
wheel
|
|
||||||
.as_ref()
|
|
||||||
.file_name()
|
|
||||||
.unwrap()
|
|
||||||
.to_string_lossy()
|
|
||||||
.as_ref(),
|
|
||||||
)?,
|
|
||||||
&mut archive,
|
|
||||||
)?;
|
|
||||||
let dist_info = std::io::read_to_string(
|
let dist_info = std::io::read_to_string(
|
||||||
archive.by_name(&format!("{dist_info_prefix}.dist-info/METADATA"))?,
|
archive.by_name(&format!("{dist_info_prefix}.dist-info/METADATA"))?,
|
||||||
)?;
|
)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue