Skip to content

Commit

Permalink
fix: only create 1 venv (#3610)
Browse files Browse the repository at this point in the history
Fixes #3609
  • Loading branch information
jdx authored Dec 16, 2024
1 parent 48c95c6 commit 7efdb9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 24 additions & 6 deletions src/config/env_directive/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::env;
use std::cmp::PartialEq;
use std::collections::{BTreeSet, HashMap};
use std::fmt::{Debug, Display, Formatter};
use std::path::{Path, PathBuf};
Expand All @@ -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),
Expand Down Expand Up @@ -144,10 +145,27 @@ 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",
Expand Down
1 change: 0 additions & 1 deletion src/config/env_directive/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ mod tests {
@r#"
[
"~/bin",
"/bin",
]
"#
);
Expand Down

0 comments on commit 7efdb9f

Please sign in to comment.