Skip to content

Commit

Permalink
fix(python): check only if first or specified python is installed for…
Browse files Browse the repository at this point in the history
… _.venv
  • Loading branch information
jdx committed Dec 15, 2024
1 parent 30d9e19 commit 899505c
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/config/env_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down Expand Up @@ -290,11 +291,27 @@ impl EnvResults {
.into_iter()
.chain(env::split_paths(&env_vars[&*PATH_KEY]))
.collect::<Vec<_>>();
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\
Expand Down

0 comments on commit 899505c

Please sign in to comment.