Skip to content

Commit

Permalink
env: resolve env vars in order (#1519)
Browse files Browse the repository at this point in the history
* env-man

* Commit from GitHub Actions (test)

* env-man

---------

Co-authored-by: mise[bot] <123107610+mise-en-dev@users.noreply.github.com>
  • Loading branch information
jdx and mise-en-dev authored Jan 26, 2024
1 parent 91b9fc1 commit 7dce359
Show file tree
Hide file tree
Showing 26 changed files with 828 additions and 518 deletions.
2 changes: 1 addition & 1 deletion e2e/test_go_install
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ source "$(dirname "$0")/assert.sh"
export MISE_EXPERIMENTAL=1

assert "mise x go:github.com/DarthSim/hivemind@v1.1.0 -- hivemind --version" "Hivemind version 1.1.0"
chmod -R u+w "$MISE_DATA_DIR/cache/go-"*
chmod -R u+w "$MISE_DATA_DIR/cache/go-"* || true
252 changes: 137 additions & 115 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"description": "mise settings",
"type": "object",
"additionalProperties": false,
"properties": { "$ref": "#/$defs/settings" }
"$ref": "#/$defs/settings"
}
},
"$defs": {
Expand Down Expand Up @@ -221,126 +221,148 @@
]
},
"settings": {
"activate_aggressive": {
"description": "push tools to the front of PATH instead of allowing modifications of PATH after activation to take precedence",
"type": "boolean"
},
"all_compile": {
"description": "do not use precompiled binaries for any tool",
"type": "boolean"
},
"always_keep_download": {
"description": "should mise keep downloaded files after installation",
"type": "boolean"
},
"always_keep_install": {
"description": "should mise keep install files after installation even if the installation fails",
"type": "boolean"
},
"asdf_compat": {
"description": "set to true to ensure .tool-versions will be compatible with asdf",
"type": "boolean"
},
"cargo_binstall": {
"description": "use cargo-binstall to install rust tools if available",
"type": "boolean",
"default": true
},
"color": {
"description": "colorize output",
"type": "boolean",
"default": true
},
"disable_default_shorthands": {
"description": "disables built-in shorthands",
"type": "boolean"
},
"disable_tools": {
"description": "tools that should not be used",
"items": {
"description": "tool name",
"properties": {
"activate_aggressive": {
"description": "push tools to the front of PATH instead of allowing modifications of PATH after activation to take precedence",
"type": "boolean"
},
"all_compile": {
"description": "do not use precompiled binaries for any tool",
"type": "boolean"
},
"always_keep_download": {
"description": "should mise keep downloaded files after installation",
"type": "boolean"
},
"always_keep_install": {
"description": "should mise keep install files after installation even if the installation fails",
"type": "boolean"
},
"asdf_compat": {
"description": "set to true to ensure .tool-versions will be compatible with asdf",
"type": "boolean"
},
"cargo_binstall": {
"description": "use cargo-binstall to install rust tools if available",
"type": "boolean",
"default": true
},
"color": {
"description": "colorize output",
"type": "boolean",
"default": true
},
"disable_default_shorthands": {
"description": "disables built-in shorthands",
"type": "boolean"
},
"disable_tools": {
"description": "tools that should not be used",
"items": {
"description": "tool name",
"type": "string"
},
"type": "array"
},
"experimental": {
"description": "enable experimental features",
"type": "boolean"
},
"jobs": {
"description": "number of tools to install in parallel, default is 4",
"type": "integer"
},
"legacy_version_file": {
"description": "should mise parse legacy version files (e.g. .node-version)",
"type": "boolean"
},
"legacy_version_file_disable_tools": {
"description": "tools that should not have their legacy version files parsed",
"items": {
"description": "tool name",
"type": "string"
},
"type": "array"
},
"node_compile": {
"description": "do not use precompiled binaries for node",
"type": "boolean"
},
"not_found_auto_install": {
"description": "adds a shell hook to `mise activate` and shims to automatically install tools when they need to be installed",
"type": "boolean",
"default": true
},
"paranoid": {
"description": "extra-security mode, see https://mise.jdx.dev/paranoid.html for details",
"type": "boolean"
},
"plugin_autoupdate_last_check_duration": {
"description": "how often to check for plugin updates",
"type": "string"
},
"type": "array"
},
"experimental": {
"description": "enable experimental features",
"type": "boolean"
},
"jobs": {
"description": "number of tools to install in parallel, default is 4",
"type": "integer"
},
"legacy_version_file": {
"description": "should mise parse legacy version files (e.g. .node-version)",
"type": "boolean"
},
"legacy_version_file_disable_tools": {
"description": "tools that should not have their legacy version files parsed",
"items": {
"description": "tool name",
"python_compile": {
"description": "do not use precompiled binaries for python",
"type": "boolean"
},
"python_venv_auto_create": {
"description": "automatically create a virtualenv for python tools",
"type": "boolean"
},
"raw": {
"description": "directly connect plugin scripts to stdin/stdout, implies --jobs=1",
"type": "boolean"
},
"shorthands_file": {
"description": "path to file containing shorthand mappings",
"type": "string"
},
"type": "array"
},
"node_compile": {
"description": "do not use precompiled binaries for node",
"type": "boolean"
},
"not_found_auto_install": {
"description": "adds a shell hook to `mise activate` and shims to automatically install tools when they need to be installed",
"type": "boolean",
"default": true
},
"paranoid": {
"description": "extra-security mode, see https://mise.jdx.dev/paranoid.html for details",
"type": "boolean"
},
"plugin_autoupdate_last_check_duration": {
"description": "how often to check for plugin updates",
"type": "string"
},
"python_compile": {
"description": "do not use precompiled binaries for python",
"type": "boolean"
},
"python_venv_auto_create": {
"description": "automatically create a virtualenv for python tools",
"type": "boolean"
},
"raw": {
"description": "directly connect plugin scripts to stdin/stdout, implies --jobs=1",
"type": "boolean"
},
"shorthands_file": {
"description": "path to file containing shorthand mappings",
"type": "string"
},
"task_output": {
"default": "prefix",
"description": "how to display task output",
"enum": ["prefix", "interleave"],
"type": "string"
},
"trusted_config_paths": {
"description": "config files with these prefixes will be trusted by default",
"items": {
"description": "a path to add to PATH",
"status": {
"description": "configure messages displayed when changing directories or executing tools",
"type": "object",
"additionalProperties": false,
"properties": {
"missing_tools": {
"description": "display warning when a tool is not installed",
"type": "boolean",
"default": true
},
"show_env": {
"description": "display configured mise environment variables",
"type": "boolean"
},
"show_tools": {
"description": "display active tools",
"type": "boolean"
}
}
},
"task_output": {
"default": "prefix",
"description": "how to display task output",
"enum": ["prefix", "interleave"],
"type": "string"
},
"type": "array"
},
"quiet": {
"description": "suppress all non-error output",
"type": "boolean"
},
"verbose": {
"description": "display extra output",
"type": "boolean"
},
"yes": {
"description": "assume yes for all prompts",
"type": "boolean"
"trusted_config_paths": {
"description": "config files with these prefixes will be trusted by default",
"items": {
"description": "a path to add to PATH",
"type": "string"
},
"type": "array"
},
"quiet": {
"description": "suppress all non-error output",
"type": "boolean"
},
"verbose": {
"description": "display extra output",
"type": "boolean"
},
"yes": {
"description": "assume yes for all prompts",
"type": "boolean"
}
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env::{join_paths, split_paths};
use std::ops::Deref;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use console::truncate_str;
use eyre::Result;
Expand Down Expand Up @@ -35,11 +35,7 @@ pub struct HookEnv {
impl HookEnv {
pub fn run(self) -> Result<()> {
let config = Config::try_get()?;
let watch_files: Vec<_> = config
.config_files
.values()
.flat_map(|p| p.watch_files())
.collect();
let watch_files = config.watch_files()?;
if hook_env::should_exit_early(&watch_files) {
return Ok(());
}
Expand All @@ -51,7 +47,7 @@ impl HookEnv {
let mut diff = EnvDiff::new(&env::PRISTINE_ENV, env);
let mut patches = diff.to_patches();

let mut paths = config.path_dirs.clone();
let mut paths = config.path_dirs()?.clone();
if let Some(p) = env_path {
paths.extend(split_paths(&p).collect_vec());
}
Expand Down Expand Up @@ -165,7 +161,10 @@ impl HookEnv {
))
}

fn build_watch_operation(&self, watch_files: &[PathBuf]) -> Result<EnvDiffOperation> {
fn build_watch_operation(
&self,
watch_files: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Result<EnvDiffOperation> {
let watches = hook_env::build_watches(watch_files)?;
Ok(EnvDiffOperation::Add(
"__MISE_WATCH".into(),
Expand Down
Loading

0 comments on commit 7dce359

Please sign in to comment.