diff --git a/e2e/plugins/core/test_python_uv_venv b/e2e/plugins/core/test_python_uv_venv index c26016c111..bc522d331e 100644 --- a/e2e/plugins/core/test_python_uv_venv +++ b/e2e/plugins/core/test_python_uv_venv @@ -18,36 +18,36 @@ assert "mise env -s bash | grep VIRTUAL_ENV" "export VIRTUAL_ENV=$PWD/my_venv" assert "mise x -- which python" "$PWD/my_venv/bin/python" assert_not_contains "ls $PWD/my_venv/" "include" # stdlib virtual venv has an "include" folder while uv doesn't -# Allows opt-out uv's venv -mkdir -p subdir -cat >subdir/.mise.toml <.mise.toml <subdir/.mise.toml <.mise.toml < de::Deserialize<'de> for EnvList { python: venv.python, uv_create_args: venv.uv_create_args, python_create_args: venv.python_create_args, - options: Default::default(), + options: EnvDirectiveOptions { tools: true }, }); } } diff --git a/src/config/env_directive/venv.rs b/src/config/env_directive/venv.rs index e01ff67dcc..4db32a092f 100644 --- a/src/config/env_directive/venv.rs +++ b/src/config/env_directive/venv.rs @@ -1,14 +1,13 @@ +use crate::backend; use crate::cli::args::BackendArg; use crate::cmd::CmdLineRunner; use crate::config::config_file::trust_check; use crate::config::env_directive::EnvResults; use crate::config::{Config, SETTINGS}; -use crate::env::PATH_KEY; use crate::env_diff::EnvMap; use crate::file::{display_path, which_non_pristine}; use crate::toolset::ToolsetBuilder; use crate::Result; -use crate::{backend, env}; use indexmap::IndexMap; use std::path::{Path, PathBuf}; @@ -38,11 +37,6 @@ impl EnvResults { // TODO: in fact this should probably be moved to execute at the same time as src/uv.rs runs in ts.env() instead of config.env() let config = Config::get(); let ts = ToolsetBuilder::new().build(&config)?; - let path = ts - .list_paths() - .into_iter() - .chain(env::split_paths(&env_vars[&*PATH_KEY])) - .collect::>(); let ba = BackendArg::from("python"); let installed = ts .versions @@ -114,11 +108,7 @@ impl EnvResults { .args(["-m", "venv", &venv.to_string_lossy()]) .args(extra) } - .envs(env_vars) - .env( - PATH_KEY.to_string(), - env::join_paths(&path)?.to_string_lossy().to_string(), - ); + .envs(env_vars); cmd.execute()?; } } @@ -134,9 +124,9 @@ impl EnvResults { } else if !create { // The create "no venv found" warning is handled elsewhere warn!( - "no venv found at: {p}\n\n\ - To create a virtualenv manually, run:\n\ - python -m venv {p}", + "no venv found at: {p} +To create a virtualenv manually, run: +python -m venv {p}", p = display_path(&venv) ); } @@ -148,7 +138,7 @@ impl EnvResults { #[cfg(unix)] mod tests { use super::*; - use crate::config::env_directive::EnvDirective; + use crate::config::env_directive::{EnvDirective, EnvDirectiveOptions}; use crate::tera::BASE_CONTEXT; use crate::test::replace_path; use insta::assert_debug_snapshot; @@ -168,7 +158,7 @@ mod tests { python: None, uv_create_args: None, python_create_args: None, - options: Default::default(), + options: EnvDirectiveOptions { tools: true }, }, Default::default(), ), @@ -179,12 +169,12 @@ mod tests { python: None, uv_create_args: None, python_create_args: None, - options: Default::default(), + options: EnvDirectiveOptions { tools: true }, }, Default::default(), ), ], - false, + true, ) .unwrap(); // expect order to be reversed as it processes directives from global to dir specific diff --git a/src/toolset/mod.rs b/src/toolset/mod.rs index 837588de3f..bf0cfaeebc 100644 --- a/src/toolset/mod.rs +++ b/src/toolset/mod.rs @@ -544,14 +544,21 @@ impl Toolset { } let config = Config::get(); let mut env = self.env(&config)?; - env.insert( - PATH_KEY.to_string(), - env::join_paths(paths.iter())?.to_string_lossy().to_string(), - ); + let mut path_env = PathEnv::from_iter(env::PATH.clone()); + for p in paths.clone().into_iter() { + path_env.add(p); + } + env.insert(PATH_KEY.to_string(), path_env.to_string()); let mut ctx = config.tera_ctx.clone(); ctx.insert("env", &env); - paths.extend(self.load_post_env(ctx, &env)?.env_paths); - Ok(paths.into_iter().collect()) + // these are returned in order, but we need to run the post_env stuff last and then put the results in the front + let paths = self + .load_post_env(ctx, &env)? + .env_paths + .into_iter() + .chain(paths) + .collect(); + Ok(paths) } pub fn which(&self, bin_name: &str) -> Option<(Arc, ToolVersion)> { self.list_current_installed_versions()