From 899505c0666387b94f4c3c165fd066700b40f136 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:32:14 -0600 Subject: [PATCH] fix(python): check only if first or specified python is installed for _.venv --- src/config/env_directive.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/config/env_directive.rs b/src/config/env_directive.rs index 610e3efc48..3412f3ac2d 100644 --- a/src/config/env_directive.rs +++ b/src/config/env_directive.rs @@ -8,6 +8,7 @@ use heck::ToKebabCase; use indexmap::IndexMap; use serde::{Deserialize, Deserializer}; +use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::config_file::{config_root, trust_check}; use crate::config::{Config, SETTINGS}; @@ -17,7 +18,7 @@ use crate::file::{display_path, which_non_pristine}; use crate::plugins::vfox_plugin::VfoxPlugin; use crate::tera::{get_tera, BASE_CONTEXT}; use crate::toolset::ToolsetBuilder; -use crate::{dirs, env}; +use crate::{backend, dirs, env}; #[derive(Debug, Clone)] pub enum PathEntry { @@ -290,11 +291,27 @@ impl EnvResults { .into_iter() .chain(env::split_paths(&env_vars[&*PATH_KEY])) .collect::>(); - let missing = ts - .list_missing_versions() - .iter() - .any(|tv| tv.ba().tool_name == "python"); - if missing { + let ba = BackendArg::from("python"); + let installed = ts + .versions + .get(&ba) + .and_then(|tv| { + // if a python version is specified, check if that version is installed + // otherwise use the first since that's what `python3` will refer to + if let Some(v) = &python { + tv.versions.iter().find(|t| t.version.starts_with(v)) + } else { + tv.versions.first() + } + }) + .map(|tv| { + let backend = backend::get(&ba).unwrap(); + backend.is_version_installed(tv, false) + }) + // if no version is specified, we're assuming python3 is provided outside of mise + // so return "true" here + .unwrap_or(true); + if !installed { warn!( "no venv found at: {p}\n\n\ mise will automatically create the venv once all requested python versions are installed.\n\