Print activation instructions for a venv after one has been created (#1580)

This commit is contained in:
обоо 2024-02-20 23:39:42 +11:00 committed by GitHub
parent d05cb8464a
commit 7741e1c51a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 0 deletions

View File

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

View File

@ -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
"###
);