Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only create 1 venv #3610

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading