Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create temporary environments in dedicated cache bucket #4223

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/uv-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ distribution-types = { workspace = true }
pep440_rs = { workspace = true }
pep508_rs = { workspace = true }
pypi-types = { workspace = true }
uv-cache = { workspace = true }
uv-configuration = { workspace = true }
uv-fs = { workspace = true }
uv-toolchain = { workspace = true }
uv-types = { workspace = true }
uv-configuration = { workspace = true }
uv-virtualenv = { workspace = true }

anyhow = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions crates/uv-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use distribution_types::Resolution;
use pep440_rs::Version;
use pep508_rs::PackageName;
use pypi_types::{Requirement, VerbatimParsedUrl};
use uv_cache::CacheBucket;
use uv_configuration::{BuildKind, ConfigSettings, SetupPyStrategy};
use uv_fs::{PythonExt, Simplified};
use uv_toolchain::{Interpreter, PythonEnvironment};
Expand Down Expand Up @@ -413,7 +414,7 @@ impl SourceBuild {
mut environment_variables: FxHashMap<OsString, OsString>,
concurrent_builds: usize,
) -> Result<Self, Error> {
let temp_dir = tempdir_in(build_context.cache().root())?;
let temp_dir = tempdir_in(build_context.cache().bucket(CacheBucket::Environments))?;

let source_tree = if let Some(subdir) = subdirectory {
source.join(subdir)
Expand All @@ -431,7 +432,7 @@ impl SourceBuild {
// Create a virtual environment, or install into the shared environment if requested.
let venv = match build_isolation {
BuildIsolation::Isolated => uv_virtualenv::create_venv(
&temp_dir.path().join(".venv"),
temp_dir.path(),
interpreter.clone(),
uv_virtualenv::Prompt::None,
false,
Expand Down
23 changes: 15 additions & 8 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ pub enum CacheBucket {
/// that cache entries can be atomically replaced and removed, as storing directories in the
/// other buckets directly would make atomic operations impossible.
Archive,
/// Ephemeral virtual environments used to execute PEP 517 builds and other operations.
Environments,
}

impl CacheBucket {
Expand All @@ -640,6 +642,7 @@ impl CacheBucket {
Self::Simple => "simple-v8",
Self::Wheels => "wheels-v1",
Self::Archive => "archive-v0",
Self::Environments => "environments-v0",
}
}

Expand Down Expand Up @@ -750,20 +753,24 @@ impl CacheBucket {
Self::Archive => {
// Nothing to do.
}
Self::Environments => {
// Nothing to do.
}
}
Ok(summary)
}

/// Return an iterator over all cache buckets.
pub fn iter() -> impl Iterator<Item = CacheBucket> {
pub fn iter() -> impl Iterator<Item = Self> {
[
CacheBucket::Wheels,
CacheBucket::BuiltWheels,
CacheBucket::FlatIndex,
CacheBucket::Git,
CacheBucket::Interpreter,
CacheBucket::Simple,
CacheBucket::Archive,
Self::Wheels,
Self::BuiltWheels,
Self::FlatIndex,
Self::Git,
Self::Interpreter,
Self::Simple,
Self::Archive,
Self::Environments,
]
.iter()
.copied()
Expand Down
11 changes: 4 additions & 7 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tempfile::tempdir_in;
use tokio::process::Command;
use tracing::debug;

use uv_cache::Cache;
use uv_cache::{Cache, CacheBucket};
use uv_client::{BaseClientBuilder, Connectivity};
use uv_configuration::{ExtrasSpecification, PreviewMode, Upgrade};
use uv_distribution::{ProjectWorkspace, Workspace};
Expand Down Expand Up @@ -107,7 +107,7 @@ pub(crate) async fn run(
};

// If necessary, create an environment for the ephemeral requirements.
let tmpdir;
let temp_dir;
let ephemeral_env = if requirements.is_empty() {
None
} else {
Expand Down Expand Up @@ -135,12 +135,9 @@ pub(crate) async fn run(
// environment.

// Create a virtual environment
// TODO(zanieb): Move this path derivation elsewhere
let uv_state_path = std::env::current_dir()?.join(".uv");
fs_err::create_dir_all(&uv_state_path)?;
tmpdir = tempdir_in(uv_state_path)?;
temp_dir = tempdir_in(cache.bucket(CacheBucket::Environments))?;
let venv = uv_virtualenv::create_venv(
tmpdir.path(),
temp_dir.path(),
interpreter,
uv_virtualenv::Prompt::None,
false,
Expand Down
11 changes: 4 additions & 7 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tempfile::tempdir_in;
use tokio::process::Command;
use tracing::debug;

use uv_cache::Cache;
use uv_cache::{Cache, CacheBucket};
use uv_client::Connectivity;
use uv_configuration::PreviewMode;
use uv_requirements::RequirementsSource;
Expand Down Expand Up @@ -61,13 +61,10 @@ pub(crate) async fn run(
)?
.into_interpreter();

// Create a virtual environment1
// TODO(zanieb): Move this path derivation elsewhere
let uv_state_path = std::env::current_dir()?.join(".uv");
fs_err::create_dir_all(&uv_state_path)?;
let tmpdir = tempdir_in(uv_state_path)?;
// Create a virtual environment.
let temp_dir = tempdir_in(cache.bucket(CacheBucket::Environments))?;
let venv = uv_virtualenv::create_venv(
tmpdir.path(),
temp_dir.path(),
interpreter,
uv_virtualenv::Prompt::None,
false,
Expand Down
Loading