Set `VIRTUAL_ENV` in `uv tool run`

This commit is contained in:
Zanie Blue 2025-08-14 11:05:19 -05:00
parent 82d5b6780a
commit 1a32fd44aa
1 changed files with 7 additions and 0 deletions

View File

@ -369,6 +369,13 @@ pub(crate) async fn run(
.context("Failed to build new PATH variable")?;
process.env(EnvVars::PATH, new_path);
// If we're not in a virtual environment already, set `VIRTUAL_ENV`.
// This is a little defense, e.g., we could always set `VIRTUAL_ENV` but it could break a tool
// that you're using to target your current virtual environment.
if std::env::var_os(EnvVars::VIRTUAL_ENV).is_none() {
process.env(EnvVars::VIRTUAL_ENV, environment.root());
}
// Spawn and wait for completion
// Standard input, output, and error streams are all inherited
let space = if args.is_empty() { "" } else { " " };