Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored and jdx committed Dec 21, 2024
1 parent 0cb597c commit 4a0c7db
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
13 changes: 13 additions & 0 deletions e2e/env/test_env_template
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ env.BAZ = "{{ env.BAR }}"
run = "printf '\$BAZ: %s\n' \$BAZ"
EOF
assert "mise run --trace foo" "\$BAZ: foo"


cat <<EOF >mise.toml
[env]
FOO = "/foo"
_.source = { path = "env.sh", tools = true }
_.path = "{{ env.FOO }}"
EOF
cat <<EOF >env.sh
#!/usr/bin/env bash
export BAR="\$PATH"
EOF
assert_contains "mise env -s bash | grep BAR" "export BAR='/foo:"
2 changes: 1 addition & 1 deletion src/backend/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl AsdfBackend {
}
let script = sm.get_script_path(&ExecEnv);
let dir = dirs::CWD.clone().unwrap_or_default();
let ed = EnvDiff::from_bash_script(&script, &dir, &sm.env, Default::default())?;
let ed = EnvDiff::from_bash_script(&script, &dir, &sm.env, &Default::default())?;
let env = ed
.to_patches()
.into_iter()
Expand Down
14 changes: 5 additions & 9 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, };
use std::collections::BTreeMap;
use std::io::Write;
use std::iter::once;
use std::ops::Deref;
Expand Down Expand Up @@ -370,7 +370,9 @@ impl Run {
if let Some(file) = &task.file {
self.exec_file(file, task, &env, &prefix)?;
} else {
for (script, args) in task.render_run_scripts_with_args(self.cd.clone(), &task.args, &env)? {
for (script, args) in
task.render_run_scripts_with_args(self.cd.clone(), &task.args, &env)?
{
self.exec_script(&script, &args, task, &env, &prefix)?;
}
}
Expand Down Expand Up @@ -480,13 +482,7 @@ impl Run {
}
}

fn exec_file(
&self,
file: &Path,
task: &Task,
env: &EnvMap,
prefix: &str,
) -> Result<()> {
fn exec_file(&self, file: &Path, task: &Task, env: &EnvMap, prefix: &str) -> Result<()> {
let config = Config::get();
let mut env = env.clone();
let command = file.to_string_lossy().to_string();
Expand Down
9 changes: 8 additions & 1 deletion src/config/env_directive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::file::display_path;
use crate::tera::{get_tera, tera_exec};
use eyre::{eyre, Context};
use indexmap::IndexMap;
use itertools::Itertools;
use std::cmp::PartialEq;
use std::collections::{BTreeSet, HashMap};
use std::fmt::{Debug, Display, Formatter};
Expand Down Expand Up @@ -224,7 +225,13 @@ impl EnvResults {
r.env_remove.insert(k);
}
EnvDirective::Path(input_str, _opts) => {
Self::path(&mut ctx, &mut tera, &mut r, &mut paths, source, input_str)?;
let path = Self::path(&mut ctx, &mut tera, &mut r, &source, input_str)?;
paths.push((path.clone(), source.clone()));
let env_path = env.get(&*env::PATH_KEY).cloned().unwrap_or_default().0;
let mut env_path = env::split_paths(&env_path).collect_vec();
env_path.insert(0, path);
let env_path = env::join_paths(&env_path)?.to_string_lossy().to_string();
env.insert(env::PATH_KEY.to_string(), (env_path, None));
}
EnvDirective::File(input, _opts) => {
let files = Self::file(
Expand Down
17 changes: 4 additions & 13 deletions src/config/env_directive/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ impl EnvResults {
ctx: &mut tera::Context,
tera: &mut tera::Tera,
r: &mut EnvResults,
paths: &mut Vec<(PathBuf, PathBuf)>,
source: PathBuf,
source: &PathBuf,
input: String,
) -> result::Result<()> {
// trace!("resolve: input_str: {:#?}", input_str);
// trace!(
// "resolve: normal: input: {:?}, input.to_string(): {:?}",
// &input,
// input.to_string_lossy().as_ref()
// );
let s = r.parse_template(ctx, tera, &source, &input)?;
// trace!("resolve: s: {:?}", &s);
paths.push((s.into(), source));
Ok(())
) -> result::Result<PathBuf> {
r.parse_template(ctx, tera, source, &input)
.map(PathBuf::from)
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/config/env_directive/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ impl EnvResults {
) -> Result<IndexMap<PathBuf, IndexMap<String, String>>> {
let mut out = IndexMap::new();
let s = r.parse_template(ctx, tera, source, &input)?;
let orig_path = env_vars.get(&*env::PATH_KEY).cloned().unwrap_or_default();
let mut env_diff_opts = EnvDiffOptions::default();
env_diff_opts.ignore_keys.shift_remove(&*env::PATH_KEY); // allow modifying PATH
for p in xx::file::glob(normalize_path(config_root, s.into())).unwrap_or_default() {
if !p.exists() {
continue;
}
let env = out.entry(p.clone()).or_insert_with(IndexMap::new);
let orig_path = env_vars.get(&*env::PATH_KEY).cloned().unwrap_or_default();
let mut env_diff_opts = EnvDiffOptions::default();
env_diff_opts.ignore_keys.shift_remove(&*env::PATH_KEY); // allow modifying PATH
let env_diff =
EnvDiff::from_bash_script(&p, config_root, env_vars.clone(), env_diff_opts)
.unwrap_or_default();
EnvDiff::from_bash_script(&p, config_root, env_vars.clone(), &env_diff_opts)?;
for p in env_diff.to_patches() {
match p {
EnvDiffOperation::Add(k, v) | EnvDiffOperation::Change(k, v) => {
Expand Down
4 changes: 2 additions & 2 deletions src/env_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl EnvDiff {
script: &Path,
dir: &Path,
env: T,
opts: EnvDiffOptions,
opts: &EnvDiffOptions,
) -> Result<Self>
where
T: IntoIterator<Item = (U, V)>,
Expand Down Expand Up @@ -387,7 +387,7 @@ mod tests {
.map(|(k, v)| (k.into(), v.into()))
.collect::<Vec<(String, String)>>();
let cwd = dirs::CWD.clone().unwrap();
let ed = EnvDiff::from_bash_script(path.as_path(), &cwd, orig, Default::default()).unwrap();
let ed = EnvDiff::from_bash_script(path.as_path(), &cwd, orig, &Default::default()).unwrap();
assert_debug_snapshot!(ed);
}

Expand Down
2 changes: 1 addition & 1 deletion src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl Task {
.filter(|(_, v)| v.0 == Either::Right(EitherIntOrBool(Either::Right(false))))
.map(|(k, _)| k)
.collect::<HashSet<_>>();

Ok(env
.into_iter()
.filter(|(k, _)| !rm_env.contains(k))
Expand Down
5 changes: 4 additions & 1 deletion src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,10 @@ impl Toolset {
let mut tera_env = env::PRISTINE_ENV.clone().into_iter().collect::<EnvMap>();
tera_env.extend(env.clone());
let mut path_env = PathEnv::from_iter(env::PATH.clone());
for p in self.list_paths().into_iter() {
for p in self.list_paths() {
path_env.add(p);
}
for p in config.path_dirs()?.clone() {
path_env.add(p);
}
tera_env.insert(PATH_KEY.to_string(), path_env.to_string());
Expand Down

0 comments on commit 4a0c7db

Please sign in to comment.