Avoid removing local wheels when unzipping (#560)

## Summary

When installing a local wheel, we need to avoid removing the zipped
wheel (since it lives outside of the cache), _and_ need to ensure that
we unzip the wheel into the cache (rather than replacing the zipped
wheel, which may even live outside of the project).

Closes https://github.com/astral-sh/puffin/issues/553.
This commit is contained in:
Charlie Marsh 2023-12-05 12:50:08 -05:00 committed by GitHub
parent 6f055ecf3b
commit a15da36d74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 53 deletions

View file

@ -184,7 +184,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
dist: dist.clone(),
filename,
buffer,
path: cache_entry.path(),
target: cache_entry.path(),
})
} else {
let size =
@ -201,6 +201,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
dist: dist.clone(),
filename,
path: cache_entry.path(),
target: cache_entry.path(),
})
};
@ -212,7 +213,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
}
Dist::Built(BuiltDist::DirectUrl(wheel)) => {
debug!("Fetching disk-based wheel from URL: {}", &wheel.url);
debug!("Fetching disk-based wheel from URL: {}", wheel.url);
// Create a directory for the wheel.
let wheel_filename = wheel.filename()?;
@ -235,6 +236,7 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
dist: dist.clone(),
filename: wheel.filename.clone(),
path: cache_entry.path(),
target: cache_entry.path(),
});
if let Some(reporter) = self.reporter.as_ref() {
@ -244,11 +246,20 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
Ok(local_wheel)
}
Dist::Built(BuiltDist::Path(wheel)) => Ok(LocalWheel::Disk(DiskWheel {
dist: dist.clone(),
path: wheel.path.clone(),
filename: wheel.filename.clone(),
})),
Dist::Built(BuiltDist::Path(wheel)) => {
let cache_entry = self.cache.entry(
CacheBucket::Wheels,
WheelCache::Url(&wheel.url).wheel_dir(),
wheel.filename.to_string(),
);
Ok(LocalWheel::Disk(DiskWheel {
dist: dist.clone(),
filename: wheel.filename.clone(),
path: wheel.path.clone(),
target: cache_entry.path(),
}))
}
Dist::Source(source_dist) => {
let lock = self.locks.acquire(&dist).await;
@ -258,7 +269,8 @@ impl<'a, Context: BuildContext + Send + Sync> DistributionDatabase<'a, Context>
Ok(LocalWheel::Built(BuiltWheel {
dist: dist.clone(),
filename: built_wheel.filename,
path: built_wheel.path,
path: built_wheel.path.clone(),
target: built_wheel.path,
}))
}
}

View file

@ -19,8 +19,8 @@ pub struct InMemoryWheel {
pub(crate) filename: WheelFilename,
/// The contents of the wheel.
pub(crate) buffer: Vec<u8>,
/// The path where the downloaded wheel would have been stored, if it wasn't an in-memory wheel.
pub(crate) path: PathBuf,
/// The expected path to the downloaded wheel's entry in the cache.
pub(crate) target: PathBuf,
}
/// A downloaded wheel that's stored on-disk.
@ -32,6 +32,8 @@ pub struct DiskWheel {
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.
pub(crate) target: PathBuf,
}
/// A wheel built from a source distribution that's stored on-disk.
@ -43,6 +45,8 @@ pub struct BuiltWheel {
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.
pub(crate) target: PathBuf,
}
/// A downloaded or built wheel.
@ -54,11 +58,12 @@ pub enum LocalWheel {
}
impl LocalWheel {
pub fn path(&self) -> &Path {
/// Return the path to the downloaded wheel's entry in the cache.
pub fn target(&self) -> &Path {
match self {
LocalWheel::InMemory(wheel) => &wheel.path,
LocalWheel::Disk(wheel) => &wheel.path,
LocalWheel::Built(wheel) => &wheel.path,
LocalWheel::InMemory(wheel) => &wheel.target,
LocalWheel::Disk(wheel) => &wheel.target,
LocalWheel::Built(wheel) => &wheel.target,
}
}
}