Add CACHEDIR.TAG to uv-created virtualenvs (#1653)

## 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
```
This commit is contained in:
Charlie Marsh 2024-02-18 13:32:11 -05:00 committed by GitHub
parent c04f597fae
commit 5cdc6de4a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 0 deletions

1
Cargo.lock generated
View file

@ -1237,6 +1237,7 @@ name = "gourgeist"
version = "0.0.4"
dependencies = [
"anstream",
"cachedir",
"camino",
"clap",
"directories",

View file

@ -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 }

View file

@ -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