diff --git a/crates/uv/src/commands/venv.rs b/crates/uv/src/commands/venv.rs index 43b7214aa..490e98bdd 100644 --- a/crates/uv/src/commands/venv.rs +++ b/crates/uv/src/commands/venv.rs @@ -195,5 +195,22 @@ async fn venv_impl( } } + if cfg!(windows) { + writeln!( + printer, + // This should work whether the user is on CMD or PowerShell: + "Activate with: {}\\Scripts\\activate", + path.normalized_display().cyan() + ) + .into_diagnostic()?; + } else { + writeln!( + printer, + "Activate with: source {}/bin/activate", + path.normalized_display().cyan() + ) + .into_diagnostic()?; + }; + Ok(ExitStatus::Success) } diff --git a/crates/uv/tests/venv.rs b/crates/uv/tests/venv.rs index 2a9c37360..1567d44d6 100644 --- a/crates/uv/tests/venv.rs +++ b/crates/uv/tests/venv.rs @@ -20,12 +20,17 @@ fn create_venv() -> Result<()> { // Create a virtual environment at `.venv`. let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -45,6 +50,7 @@ fn create_venv() -> Result<()> { ----- stderr ----- Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: /home/ferris/project/.venv + Activate with: source /home/ferris/project/.venv/bin/activate "### ); @@ -52,12 +58,17 @@ fn create_venv() -> Result<()> { // Create a virtual environment at the same location, which should replace it. let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -78,6 +89,7 @@ fn create_venv() -> Result<()> { ----- stderr ----- Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: /home/ferris/project/.venv + Activate with: source /home/ferris/project/.venv/bin/activate "### ); @@ -94,12 +106,14 @@ fn create_venv_defaults_to_cwd() -> Result<()> { let venv = temp_dir.child(".venv"); let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + (&filter_prompt, "Activate with: source .venv/bin/activate"), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -119,6 +133,7 @@ fn create_venv_defaults_to_cwd() -> Result<()> { ----- stderr ----- Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: .venv + Activate with: source .venv/bin/activate "### ); @@ -135,12 +150,17 @@ fn seed() -> Result<()> { let venv = temp_dir.child(".venv"); let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -163,6 +183,7 @@ fn seed() -> Result<()> { Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: /home/ferris/project/.venv + pip==23.3.1 + Activate with: source /home/ferris/project/.venv/bin/activate "### ); @@ -179,12 +200,17 @@ fn seed_older_python_version() -> Result<()> { let venv = temp_dir.child(".venv"); let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -209,6 +235,7 @@ fn seed_older_python_version() -> Result<()> { + setuptools==68.2.2 + pip==23.3.1 + wheel==0.41.3 + Activate with: source /home/ferris/project/.venv/bin/activate "### ); @@ -317,9 +344,14 @@ fn create_venv_python_patch() -> Result<()> { let venv = temp_dir.child(".venv"); let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ (r"interpreter at .+", "interpreter at [PATH]"), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -406,12 +438,17 @@ fn empty_dir_exists() -> Result<()> { venv.create_dir_all()?; let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -432,6 +469,7 @@ fn empty_dir_exists() -> Result<()> { ----- stderr ----- Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: /home/ferris/project/.venv + Activate with: source /home/ferris/project/.venv/bin/activate "### ); @@ -497,12 +535,17 @@ fn virtualenv_compatibility() -> Result<()> { // Create a virtual environment at `.venv`, passing the redundant `--clear` flag. let filter_venv = regex::escape(&venv.normalized_display().to_string()); + let filter_prompt = r"Activate with: (?:.*)\\Scripts\\activate"; let filters = &[ ( r"Using Python 3\.\d+\.\d+ interpreter at .+", "Using Python [VERSION] interpreter at [PATH]", ), (&filter_venv, "/home/ferris/project/.venv"), + ( + &filter_prompt, + "Activate with: source /home/ferris/project/.venv/bin/activate", + ), ]; uv_snapshot!(filters, Command::new(get_bin()) .arg("venv") @@ -524,6 +567,7 @@ fn virtualenv_compatibility() -> Result<()> { warning: virtualenv's `--clear` has no effect (uv always clears the virtual environment). Using Python [VERSION] interpreter at [PATH] Creating virtualenv at: /home/ferris/project/.venv + Activate with: source /home/ferris/project/.venv/bin/activate "### );