mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-18 14:29:57 +00:00
Add dedicated cache method for creating build directories (#8910)
## Summary Based on feedback from https://github.com/astral-sh/uv/pull/8905/files#r1833531812.
This commit is contained in:
parent
88033610b5
commit
9cd51c8a57
5 changed files with 18 additions and 12 deletions
|
@ -261,7 +261,7 @@ impl SourceBuild {
|
||||||
level: BuildOutput,
|
level: BuildOutput,
|
||||||
concurrent_builds: usize,
|
concurrent_builds: usize,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let temp_dir = build_context.cache().environment()?;
|
let temp_dir = build_context.cache().venv_dir()?;
|
||||||
|
|
||||||
let source_tree = if let Some(subdir) = subdirectory {
|
let source_tree = if let Some(subdir) = subdirectory {
|
||||||
source.join(subdir)
|
source.join(subdir)
|
||||||
|
|
|
@ -188,8 +188,14 @@ impl Cache {
|
||||||
self.bucket(CacheBucket::Archive).join(id)
|
self.bucket(CacheBucket::Archive).join(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an ephemeral Python environment in the cache.
|
/// Create a temporary directory to be used as a Python virtual environment.
|
||||||
pub fn environment(&self) -> io::Result<tempfile::TempDir> {
|
pub fn venv_dir(&self) -> io::Result<tempfile::TempDir> {
|
||||||
|
fs_err::create_dir_all(self.bucket(CacheBucket::Builds))?;
|
||||||
|
tempfile::tempdir_in(self.bucket(CacheBucket::Builds))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a temporary directory to be used for executing PEP 517 source distribution builds.
|
||||||
|
pub fn build_dir(&self) -> io::Result<tempfile::TempDir> {
|
||||||
fs_err::create_dir_all(self.bucket(CacheBucket::Builds))?;
|
fs_err::create_dir_all(self.bucket(CacheBucket::Builds))?;
|
||||||
tempfile::tempdir_in(self.bucket(CacheBucket::Builds))
|
tempfile::tempdir_in(self.bucket(CacheBucket::Builds))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1720,10 +1720,10 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build into a temporary directory, to prevent partial builds.
|
// Build into a temporary directory, to prevent partial builds.
|
||||||
let build = self
|
let temp_dir = self
|
||||||
.build_context
|
.build_context
|
||||||
.cache()
|
.cache()
|
||||||
.environment()
|
.build_dir()
|
||||||
.map_err(Error::CacheWrite)?;
|
.map_err(Error::CacheWrite)?;
|
||||||
|
|
||||||
// Build the wheel.
|
// Build the wheel.
|
||||||
|
@ -1748,13 +1748,13 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(Error::Build)?
|
.map_err(Error::Build)?
|
||||||
.wheel(build.path())
|
.wheel(temp_dir.path())
|
||||||
.await
|
.await
|
||||||
.map_err(Error::Build)?;
|
.map_err(Error::Build)?;
|
||||||
|
|
||||||
// Move the wheel to the cache.
|
// Move the wheel to the cache.
|
||||||
rename_with_retry(
|
rename_with_retry(
|
||||||
build.path().join(&disk_filename),
|
temp_dir.path().join(&disk_filename),
|
||||||
cache_shard.join(&disk_filename),
|
cache_shard.join(&disk_filename),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl CachedEnvironment {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the environment in the cache, then relocate it to its content-addressed location.
|
// Create the environment in the cache, then relocate it to its content-addressed location.
|
||||||
let temp_dir = cache.environment()?;
|
let temp_dir = cache.venv_dir()?;
|
||||||
let venv = uv_virtualenv::create_venv(
|
let venv = uv_virtualenv::create_venv(
|
||||||
temp_dir.path(),
|
temp_dir.path(),
|
||||||
interpreter,
|
interpreter,
|
||||||
|
|
|
@ -323,7 +323,7 @@ pub(crate) async fn run(
|
||||||
Some(environment.into_interpreter())
|
Some(environment.into_interpreter())
|
||||||
} else {
|
} else {
|
||||||
// Create a virtual environment.
|
// Create a virtual environment.
|
||||||
temp_dir = cache.environment()?;
|
temp_dir = cache.venv_dir()?;
|
||||||
let environment = uv_virtualenv::create_venv(
|
let environment = uv_virtualenv::create_venv(
|
||||||
temp_dir.path(),
|
temp_dir.path(),
|
||||||
interpreter,
|
interpreter,
|
||||||
|
@ -538,7 +538,7 @@ pub(crate) async fn run(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a virtual environment
|
// Create a virtual environment
|
||||||
temp_dir = cache.environment()?;
|
temp_dir = cache.venv_dir()?;
|
||||||
uv_virtualenv::create_venv(
|
uv_virtualenv::create_venv(
|
||||||
temp_dir.path(),
|
temp_dir.path(),
|
||||||
interpreter,
|
interpreter,
|
||||||
|
@ -741,7 +741,7 @@ pub(crate) async fn run(
|
||||||
debug!("Creating isolated virtual environment");
|
debug!("Creating isolated virtual environment");
|
||||||
|
|
||||||
// If we're isolating the environment, use an ephemeral virtual environment.
|
// If we're isolating the environment, use an ephemeral virtual environment.
|
||||||
temp_dir = cache.environment()?;
|
temp_dir = cache.venv_dir()?;
|
||||||
let venv = uv_virtualenv::create_venv(
|
let venv = uv_virtualenv::create_venv(
|
||||||
temp_dir.path(),
|
temp_dir.path(),
|
||||||
interpreter,
|
interpreter,
|
||||||
|
@ -791,7 +791,7 @@ pub(crate) async fn run(
|
||||||
Some(match spec.filter(|spec| !spec.is_empty()) {
|
Some(match spec.filter(|spec| !spec.is_empty()) {
|
||||||
None => {
|
None => {
|
||||||
// Create a virtual environment
|
// Create a virtual environment
|
||||||
temp_dir = cache.environment()?;
|
temp_dir = cache.venv_dir()?;
|
||||||
uv_virtualenv::create_venv(
|
uv_virtualenv::create_venv(
|
||||||
temp_dir.path(),
|
temp_dir.path(),
|
||||||
base_interpreter.clone(),
|
base_interpreter.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue