Fix relocatable nushell activation script (#17036)

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
Nushell activation now computes the venv root dynamically via path self
for relocatable venvs, while non-relocatable venvs still embed a quoted
absolute path

Still keep `activate.csh` (maybe delete is also an option)

close https://github.com/astral-sh/uv/issues/16973

<!-- How was it tested? -->
This commit is contained in:
chisato 2025-12-09 22:39:55 +08:00 committed by GitHub
parent 77df5887e4
commit 9774f8f1d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -68,7 +68,7 @@ export-env {
} }
} }
let virtual_env = '{{ VIRTUAL_ENV_DIR }}' let virtual_env = {{ VIRTUAL_ENV_DIR }}
let bin = '{{ BIN_NAME }}' let bin = '{{ BIN_NAME }}'
let path_name = if (has-env 'Path') { 'Path' } else { 'PATH' } let path_name = if (has-env 'Path') { 'Path' } else { 'PATH' }
let venv_path = ([$virtual_env $bin] | path join) let venv_path = ([$virtual_env $bin] | path join)

View File

@ -463,8 +463,15 @@ pub(crate) fn create(
(true, "activate.fish") => { (true, "activate.fish") => {
r#"'"$(dirname -- "$(cd "$(dirname -- "$(status -f)")"; and pwd)")"'"#.to_string() r#"'"$(dirname -- "$(cd "$(dirname -- "$(status -f)")"; and pwd)")"'"#.to_string()
} }
(true, "activate.nu") => r"(path self | path dirname | path dirname)".to_string(),
(false, "activate.nu") => {
format!(
"'{}'",
escape_posix_for_single_quotes(location.simplified().to_str().unwrap())
)
}
// Note: // Note:
// * relocatable activate scripts appear not to be possible in csh and nu shell // * relocatable activate scripts appear not to be possible in csh.
// * `activate.ps1` is already relocatable by default. // * `activate.ps1` is already relocatable by default.
_ => escape_posix_for_single_quotes(location.simplified().to_str().unwrap()), _ => escape_posix_for_single_quotes(location.simplified().to_str().unwrap()),
}; };

View File

@ -1296,6 +1296,12 @@ fn verify_pyvenv_cfg_relocatable() {
let activate_fish = scripts.child("activate.fish"); let activate_fish = scripts.child("activate.fish");
activate_fish.assert(predicates::path::is_file()); activate_fish.assert(predicates::path::is_file());
activate_fish.assert(predicates::str::contains(r#"set -gx VIRTUAL_ENV ''"$(dirname -- "$(cd "$(dirname -- "$(status -f)")"; and pwd)")"''"#)); activate_fish.assert(predicates::str::contains(r#"set -gx VIRTUAL_ENV ''"$(dirname -- "$(cd "$(dirname -- "$(status -f)")"; and pwd)")"''"#));
let activate_nu = scripts.child("activate.nu");
activate_nu.assert(predicates::path::is_file());
activate_nu.assert(predicates::str::contains(
r"let virtual_env = (path self | path dirname | path dirname)",
));
} }
/// Ensure that a nested virtual environment uses the same `home` directory as the parent. /// Ensure that a nested virtual environment uses the same `home` directory as the parent.