Skip to content

feat: new "enable-tools" option #4784

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::path::{Path, PathBuf};
use std::{env, fs};

fn main() {
// Tell Cargo that if the given file changes, to rerun this build script.
println!("cargo::rerun-if-changed=settings.toml");

cfg_aliases::cfg_aliases! {
asdf: { any(feature = "asdf", not(target_os = "windows")) },
macos: { target_os = "macos" },
Expand Down
4 changes: 4 additions & 0 deletions mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ backend = "aqua:BurntSushi/ripgrep"
"ripgrep-14.1.1-x86_64-pc-windows-msvc.zip" = "sha256:d0f534024c42afd6cb4d38907c25cd2b249b79bbe6cc1dbee8e3e37c2b6e25a1"
"ripgrep-14.1.1-x86_64-unknown-linux-musl.tar.gz" = "sha256:4cf9f2741e6c465ffdb7c26f38056a59e2a2544b51f7cc128ef28337eeae4d8e"

[tools.rust]
version = "1.85.1"
backend = "core:rust"

[tools.shellcheck]
version = "0.10.0"
backend = "aqua:koalaman/shellcheck"
Expand Down
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cosign = "latest"
pre-commit = "latest"
#"python" = { version = "latest", virtualenv = "{{env.HOME}}/.cache/venv" }
"ripgrep" = "latest"
rust = "latest"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take this out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the intended way to get the correct version of rust?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took it out for now

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should just use the latest stable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.86.0 is stable as of yesterday 😄

"shellcheck" = "latest"
"shfmt" = "latest"
slsa-verifier = "latest"
Expand Down
8 changes: 8 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@
}
}
},
"enable_tools": {
"default": [],
"description": "Tools defined in mise.toml that should be used - all other tools are ignored",
"type": "array",
"items": {
"type": "string"
}
},
"env": {
"default": [],
"description": "Env to use for mise.<MISE_ENV>.toml files.",
Expand Down
8 changes: 8 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ By default, mise will use the [nuget](https://api.nuget.org/v3/index.json) API t
However, you can set this to a different URL if you have a custom feed or want to use a different source.
"""

[enable_tools]
env = "MISE_ENABLE_TOOLS"
type = "ListString"
rust_type = "BTreeSet<String>"
default = []
parse_env = "list_by_comma"
description = "Tools defined in mise.toml that should be used - all other tools are ignored"

[env]
env = "MISE_ENV"
type = "ListString"
Expand Down
10 changes: 8 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::file::{display_path, remove_all, remove_all_with_warning};
use crate::install_context::InstallContext;
use crate::plugins::core::CORE_PLUGINS;
use crate::plugins::{Plugin, PluginType, VERSION_REGEX};
use crate::registry::REGISTRY;
use crate::registry::{REGISTRY, tool_disabled};
use crate::runtime_symlinks::is_runtime_symlink;
use crate::toolset::outdated_info::OutdatedInfo;
use crate::toolset::{ToolRequest, ToolVersion, Toolset, install_state, is_outdated_version};
Expand Down Expand Up @@ -76,7 +76,13 @@ fn load_tools() -> Arc<BackendMap> {
.flat_map(|ist| arg_to_backend(ist.clone().into())),
);
time!("load_tools install_state");
tools.retain(|backend| !SETTINGS.disable_tools().contains(backend.id()));
tools.retain(|backend| {
!tool_disabled(
&SETTINGS.enable_tools(),
&SETTINGS.disable_tools(),
&backend.id().to_string(),
)
});
tools.retain(|backend| {
!SETTINGS
.disable_backends
Expand Down
14 changes: 11 additions & 3 deletions src/cli/registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::backend::backend_type::BackendType;
use crate::config::SETTINGS;
use crate::registry::{REGISTRY, RegistryTool};
use crate::registry::{REGISTRY, RegistryTool, tool_disabled};
use crate::ui::table::MiseTable;
use eyre::{Result, bail};
use itertools::Itertools;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Registry {
let mut table = MiseTable::new(false, &["Tool", "Backends"]);
let data = REGISTRY
.iter()
.filter(|(short, _)| !SETTINGS.disable_tools.contains(**short))
.filter(|(short, _)| filter_disabled(short))
.filter(|(short, rt)| !self.hide_aliased || **short == rt.short)
.map(|(short, rt)| (short.to_string(), filter_backend(rt).join(" ")))
.filter(|(_, backends)| !backends.is_empty())
Expand All @@ -76,7 +76,7 @@ impl Registry {
fn complete(&self) -> Result<()> {
REGISTRY
.iter()
.filter(|(short, _)| !SETTINGS.disable_tools.contains(**short))
.filter(|(short, _)| filter_disabled(short))
.filter(|(short, rt)| !self.hide_aliased || **short == rt.short)
.map(|(short, rt)| {
(
Expand Down Expand Up @@ -110,3 +110,11 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
asdf:mise-plugins/mise-poetry
"#
);

fn filter_disabled(short: &str) -> bool {
tool_disabled(
&SETTINGS.enable_tools,
&SETTINGS.disable_tools,
&short.to_string(),
)
}
7 changes: 7 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ impl Settings {
.collect()
}

pub fn enable_tools(&self) -> BTreeSet<String> {
self.enable_tools
.iter()
.map(|t| t.trim().to_string())
.collect()
}

pub fn partial_as_dict(partial: &SettingsPartial) -> eyre::Result<toml::Table> {
let s = toml::to_string(partial)?;
let table = toml::from_str(&s)?;
Expand Down
4 changes: 2 additions & 2 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config::{Config, SETTINGS};
use crate::file;
use crate::file::display_path;
use crate::registry::REGISTRY;
use crate::registry::{REGISTRY, tool_disabled};
use crate::toolset::{ToolSource, ToolVersion, ToolVersionList, Toolset};
use eyre::{Report, Result, bail};
use itertools::Itertools;
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn update_lockfiles(config: &Config, ts: &Toolset, new_versions: &[ToolVersi
// * tools inside a parent config but are overridden by a child config (we just keep what was in the lockfile before, if anything)
existing_lockfile.tools.retain(|k, _| {
all_tool_names.contains(k)
|| SETTINGS.disable_tools().contains(k)
|| tool_disabled(&SETTINGS.enable_tools(), &SETTINGS.disable_tools(), k)
|| REGISTRY
.get(&k.as_str())
.is_some_and(|rt| !rt.is_supported_os())
Expand Down
35 changes: 34 additions & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::backend::backend_type::BackendType;
use crate::cli::args::BackendArg;
use crate::config::SETTINGS;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::env::consts::{ARCH, OS};
use std::fmt::Display;
use std::iter::Iterator;
Expand Down Expand Up @@ -137,3 +137,36 @@ impl Display for RegistryTool {
write!(f, "{}", self.short)
}
}

pub fn tool_disabled<T: Ord>(
enable_tools: &BTreeSet<T>,
disable_tools: &BTreeSet<T>,
name: &T,
) -> bool {
if enable_tools.is_empty() {
disable_tools.contains(name)
} else {
!enable_tools.contains(name)
}
}

#[cfg(test)]
mod tests {
#[test]
fn test_tool_disabled() {
use super::*;
let name = "cargo";

assert!(!tool_disabled(&BTreeSet::new(), &BTreeSet::new(), &name));
assert!(!tool_disabled(
&BTreeSet::from(["cargo"]),
&BTreeSet::new(),
&name
));
assert!(tool_disabled(
&BTreeSet::new(),
&BTreeSet::from(["cargo"]),
&name
));
}
}
8 changes: 7 additions & 1 deletion src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::errors::Error;
use crate::hooks::Hooks;
use crate::install_context::InstallContext;
use crate::path_env::PathEnv;
use crate::registry::tool_disabled;
use crate::ui::multi_progress_report::MultiProgressReport;
use crate::uv::UV_VENV;
use crate::{backend, config, env, hooks};
Expand Down Expand Up @@ -695,7 +696,12 @@ impl Toolset {
}

fn is_disabled(&self, ba: &BackendArg) -> bool {
!ba.is_os_supported() || SETTINGS.disable_tools().contains(&ba.short)
!ba.is_os_supported()
|| tool_disabled(
&SETTINGS.enable_tools(),
&SETTINGS.disable_tools(),
&ba.short.to_string(),
)
}

fn load_post_env(
Expand Down
7 changes: 5 additions & 2 deletions src/toolset/tool_request_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::backend::backend_type::BackendType;
use crate::cli::args::{BackendArg, ToolArg};
use crate::config::{Config, Settings};
use crate::env;
use crate::registry::REGISTRY;
use crate::registry::{REGISTRY, tool_disabled};
use crate::toolset::{ToolRequest, ToolSource, Toolset};
use indexmap::IndexMap;
use itertools::Itertools;
Expand Down Expand Up @@ -127,13 +127,16 @@ pub struct ToolRequestSetBuilder {
default_to_latest: bool,
/// tools which will be disabled
disable_tools: BTreeSet<BackendArg>,
/// tools which will be enabled
enable_tools: BTreeSet<BackendArg>,
}

impl ToolRequestSetBuilder {
pub fn new() -> Self {
let settings = Settings::get();
Self {
disable_tools: settings.disable_tools().iter().map(|s| s.into()).collect(),
enable_tools: settings.enable_tools().iter().map(|s| s.into()).collect(),
..Default::default()
}
}
Expand Down Expand Up @@ -172,7 +175,7 @@ impl ToolRequestSetBuilder {
backend_type == BackendType::Unknown
|| (cfg!(windows) && backend_type == BackendType::Asdf)
|| !ba.is_os_supported()
|| self.disable_tools.contains(ba)
|| tool_disabled(&self.enable_tools, &self.disable_tools, ba)
}

fn load_config_files(&self, trs: &mut ToolRequestSet) -> eyre::Result<()> {
Expand Down
Loading