From 6e67b4ac1b25ff09fae61a15a41ce30407e17437 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Mon, 16 Dec 2024 11:25:30 -0600 Subject: [PATCH 1/2] fix: only create 1 venv Fixes #3609 --- src/config/env_directive/mod.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/config/env_directive/mod.rs b/src/config/env_directive/mod.rs index 79a1912056..b74b1c78c6 100644 --- a/src/config/env_directive/mod.rs +++ b/src/config/env_directive/mod.rs @@ -1,3 +1,4 @@ +use std::cmp::PartialEq; use crate::env; use std::collections::{BTreeSet, HashMap}; use std::fmt::{Debug, Display, Formatter}; @@ -17,12 +18,12 @@ mod path; mod source; mod venv; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct EnvDirectiveOptions { pub(crate) tools: bool, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub enum EnvDirective { /// simple key/value pair Val(String, String, EnvDirectiveOptions), @@ -144,10 +145,26 @@ impl EnvResults { } }; let mut paths: Vec<(PathBuf, PathBuf)> = Vec::new(); - for (directive, source) in input.clone() { - if directive.options().tools != tools { - continue; - } + let last_python_venv = input.iter().rev().find_map(|(d, _)| match d { + EnvDirective::PythonVenv { .. } => Some(d), + _ => None, + }); + let input = input.iter() + .fold(Vec::new(), |mut acc, (directive, source)| { + // remove directives that need tools if we're not processing tool directives, or vice versa + if directive.options().tools != tools { + return acc; + } + if let Some(d) = &last_python_venv { + if matches!(directive, EnvDirective::PythonVenv { .. }) && **d != *directive { + // skip venv directives if it's not the last one + return acc; + } + } + acc.push((directive.clone(), source.clone())); + acc + }); + for (directive, source) in input { let mut tera = get_tera(source.parent()); tera.register_function( "exec", From 67bd1f3a998dd79759b845c37079906fea69e720 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:30:34 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- src/config/env_directive/mod.rs | 5 +++-- src/config/env_directive/venv.rs | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/env_directive/mod.rs b/src/config/env_directive/mod.rs index b74b1c78c6..729e36ee01 100644 --- a/src/config/env_directive/mod.rs +++ b/src/config/env_directive/mod.rs @@ -1,5 +1,5 @@ -use std::cmp::PartialEq; use crate::env; +use std::cmp::PartialEq; use std::collections::{BTreeSet, HashMap}; use std::fmt::{Debug, Display, Formatter}; use std::path::{Path, PathBuf}; @@ -149,7 +149,8 @@ impl EnvResults { EnvDirective::PythonVenv { .. } => Some(d), _ => None, }); - let input = input.iter() + let input = input + .iter() .fold(Vec::new(), |mut acc, (directive, source)| { // remove directives that need tools if we're not processing tool directives, or vice versa if directive.options().tools != tools { diff --git a/src/config/env_directive/venv.rs b/src/config/env_directive/venv.rs index 2d1a26b5fe..e01ff67dcc 100644 --- a/src/config/env_directive/venv.rs +++ b/src/config/env_directive/venv.rs @@ -193,7 +193,6 @@ mod tests { @r#" [ "~/bin", - "/bin", ] "# );