mirror of
https://github.com/astral-sh/uv.git
synced 2025-12-10 11:59:07 +00:00
Make cache non-optional in most crates (#293)
This PR makes the cache non-optional in most of Puffin, which simplifies the code, allows us to reuse the cache within a single command (even with `--no-cache`), and also allows us to use the cache for disk storage across an invocation. I left the cache as optional for the `Virtualenv` and `InterpreterInfo` abstractions, since those are generic enough that it seems nice to have a non-cached version, but it's kind of arbitrary.
This commit is contained in:
parent
a02bf2e415
commit
a4002fe132
21 changed files with 140 additions and 160 deletions
|
|
@ -24,7 +24,7 @@ use puffin_traits::BuildContext;
|
|||
/// documentation.
|
||||
pub struct BuildDispatch {
|
||||
client: RegistryClient,
|
||||
cache: Option<PathBuf>,
|
||||
cache: PathBuf,
|
||||
interpreter_info: InterpreterInfo,
|
||||
base_python: PathBuf,
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ pub struct BuildDispatch {
|
|||
impl BuildDispatch {
|
||||
pub fn new(
|
||||
client: RegistryClient,
|
||||
cache: Option<PathBuf>,
|
||||
cache: PathBuf,
|
||||
interpreter_info: InterpreterInfo,
|
||||
base_python: PathBuf,
|
||||
) -> Self {
|
||||
|
|
@ -46,8 +46,8 @@ impl BuildDispatch {
|
|||
}
|
||||
|
||||
impl BuildContext for BuildDispatch {
|
||||
fn cache(&self) -> Option<&Path> {
|
||||
self.cache.as_deref()
|
||||
fn cache(&self) -> &Path {
|
||||
self.cache.as_path()
|
||||
}
|
||||
|
||||
fn interpreter_info(&self) -> &InterpreterInfo {
|
||||
|
|
@ -105,11 +105,7 @@ impl BuildContext for BuildDispatch {
|
|||
local,
|
||||
remote,
|
||||
extraneous,
|
||||
} = PartitionedRequirements::try_from_requirements(
|
||||
requirements,
|
||||
self.cache.as_deref(),
|
||||
venv,
|
||||
)?;
|
||||
} = PartitionedRequirements::try_from_requirements(requirements, &self.cache, venv)?;
|
||||
|
||||
let tags = Tags::from_env(
|
||||
self.interpreter_info.platform(),
|
||||
|
|
@ -141,14 +137,13 @@ impl BuildContext for BuildDispatch {
|
|||
if remote.len() == 1 { "" } else { "s" },
|
||||
remote.iter().map(ToString::to_string).join(", ")
|
||||
);
|
||||
Downloader::new(&self.client, self.cache.as_deref())
|
||||
Downloader::new(&self.client, &self.cache)
|
||||
.download(remote)
|
||||
.await
|
||||
.context("Failed to download build dependencies")?
|
||||
};
|
||||
|
||||
// Unzip any downloaded distributions.
|
||||
let staging = tempfile::tempdir()?;
|
||||
let unzips = if downloads.is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
|
|
@ -158,7 +153,7 @@ impl BuildContext for BuildDispatch {
|
|||
downloads.iter().map(ToString::to_string).join(", ")
|
||||
);
|
||||
Unzipper::default()
|
||||
.unzip(downloads, self.cache.as_deref().unwrap_or(staging.path()))
|
||||
.unzip(downloads, &self.cache)
|
||||
.await
|
||||
.context("Failed to unpack build dependencies")?
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue