From 5cdc6de4a972c2835b5dfd0f504b228aa896b3e7 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 18 Feb 2024 13:32:11 -0500 Subject: [PATCH] Add `CACHEDIR.TAG` to uv-created virtualenvs (#1653) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Just as we mark virtualenvs as `gitignore`d by default, we should also mark them as `CACHEDIR.TAG`, to ensure that they aren't included in backups, etc. Closes https://github.com/astral-sh/uv/issues/1648. ## Test Plan Ran `cargo run venv` and: ``` ❯ ls .venv CACHEDIR.TAG bin lib pyvenv.cfg ``` --- Cargo.lock | 1 + crates/gourgeist/Cargo.toml | 1 + crates/gourgeist/src/bare.rs | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5466f637e..dafa75f56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,6 +1237,7 @@ name = "gourgeist" version = "0.0.4" dependencies = [ "anstream", + "cachedir", "camino", "clap", "directories", diff --git a/crates/gourgeist/Cargo.toml b/crates/gourgeist/Cargo.toml index a0d7a97ec..91e6b5bd6 100644 --- a/crates/gourgeist/Cargo.toml +++ b/crates/gourgeist/Cargo.toml @@ -26,6 +26,7 @@ uv-cache = { path = "../uv-cache" } uv-interpreter = { path = "../uv-interpreter" } anstream = { workspace = true } +cachedir = { workspace = true } camino = { workspace = true } clap = { workspace = true, features = ["derive"], optional = true } directories = { workspace = true } diff --git a/crates/gourgeist/src/bare.rs b/crates/gourgeist/src/bare.rs index efb2e0355..91831af95 100644 --- a/crates/gourgeist/src/bare.rs +++ b/crates/gourgeist/src/bare.rs @@ -108,6 +108,10 @@ pub fn create_bare_venv(location: &Utf8Path, interpreter: &Interpreter) -> io::R }; let bin_dir = location.join(bin_name); + // Add the CACHEDIR.TAG. + cachedir::ensure_tag(&location)?; + + // Create a `.gitignore` file to ignore all files in the venv. fs::write(location.join(".gitignore"), "*")?; // Different names for the python interpreter