diff --git a/crates/puffin-cli/src/commands/venv.rs b/crates/puffin-cli/src/commands/venv.rs index f05107d5c..f3f6ca61a 100644 --- a/crates/puffin-cli/src/commands/venv.rs +++ b/crates/puffin-cli/src/commands/venv.rs @@ -8,15 +8,23 @@ use crate::commands::ExitStatus; use crate::printer::Printer; /// Create a virtual environment. -pub(crate) async fn venv(path: &Path, mut printer: Printer) -> Result { +pub(crate) async fn venv( + path: &Path, + base_python: Option<&Path>, + mut printer: Printer, +) -> Result { // Locate the Python interpreter. // TODO(charlie): Look at how Maturin discovers and ranks all the available Python interpreters. - let executable = which::which("python3").or_else(|_| which::which("python"))?; - let interpreter_info = gourgeist::get_interpreter_info(&executable)?; + let base_python = if let Some(base_python) = base_python { + base_python.to_path_buf() + } else { + which::which("python3").or_else(|_| which::which("python"))? + }; + let interpreter_info = gourgeist::get_interpreter_info(&base_python)?; writeln!( printer, "Using Python interpreter: {}", - format!("{}", executable.display()).cyan() + format!("{}", base_python.display()).cyan() )?; // If the path already exists, remove it. @@ -30,7 +38,7 @@ pub(crate) async fn venv(path: &Path, mut printer: Printer) -> Result, /// The path to the virtual environment to create. name: PathBuf, } @@ -143,7 +148,7 @@ async fn main() -> ExitCode { ) .await } - Commands::Venv(args) => commands::venv(&args.name, printer).await, + Commands::Venv(args) => commands::venv(&args.name, args.python.as_deref(), printer).await, }; match result {