Normalize VIRTUAL_ENV path in activation scripts (#1817)

This commit is contained in:
Micha Reiser 2024-02-21 16:52:32 +01:00 committed by GitHub
parent cff16f5736
commit fac9d843dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 2 deletions

1
Cargo.lock generated
View file

@ -1293,6 +1293,7 @@ dependencies = [
"tracing",
"tracing-subscriber",
"uv-cache",
"uv-fs",
"uv-interpreter",
"which",
]

View file

@ -23,6 +23,7 @@ workspace = true
[dependencies]
platform-host = { path = "../platform-host" }
uv-cache = { path = "../uv-cache" }
uv-fs = { path = "../uv-fs" }
uv-interpreter = { path = "../uv-interpreter" }
anstream = { workspace = true }

View file

@ -9,6 +9,7 @@ use camino::{FromPathBufError, Utf8Path, Utf8PathBuf};
use fs_err as fs;
use fs_err::File;
use tracing::info;
use uv_fs::Normalized;
use uv_interpreter::Interpreter;
@ -183,9 +184,16 @@ pub fn create_bare_venv(
// cross-platform.
for (name, template) in ACTIVATE_TEMPLATES {
let activator = template
.replace("{{ VIRTUAL_ENV_DIR }}", location.as_str())
.replace(
"{{ VIRTUAL_ENV_DIR }}",
// SAFETY: `unwrap` is guaranteed to succeed because `location` is an `Utf8PathBuf`.
location.normalized().to_str().unwrap(),
)
.replace("{{ BIN_NAME }}", bin_name)
.replace("{{ VIRTUAL_PROMPT }}", prompt.as_deref().unwrap_or(""))
.replace(
"{{ VIRTUAL_PROMPT }}",
prompt.as_deref().unwrap_or_default(),
)
.replace(
"{{ RELATIVE_SITE_PACKAGES }}",
&format!(