Skip to content

Commit

Permalink
remove deprecated missing_runtime_behavior flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 5, 2023
1 parent 7b91d99 commit adc64c3
Show file tree
Hide file tree
Showing 31 changed files with 34 additions and 253 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
runs-on: ubuntu-22.04
needs: [build-linux]
env:
RTX_MISSING_RUNTIME_BEHAVIOR: autoinstall
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
fail-fast: false
Expand Down
7 changes: 1 addition & 6 deletions e2e/cd/test_bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ set -euo pipefail

orig_path="$PATH"

rtx trust
rtx trust ../.e2e.rtx.toml
rtx trust 18/.e2e.rtx.toml
rtx i tiny@latest

# shellcheck disable=SC1090
eval "$(rtx activate bash --status)" && _rtx_hook

Expand Down Expand Up @@ -39,7 +34,7 @@ test "$(node -v)" = "v20.0.0"
assert_path "/root:ROOT/e2e/cwd:INSTALLS/node/20.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin"
assert "$FOO" "cd"

cd 18 && _rtx_hook
cd 18 && rtx i && _rtx_hook
test "$(node -v)" = "v18.0.0"
assert_path "/root:ROOT/e2e/cwd:INSTALLS/node/18.0.0/bin:INSTALLS/python/3.12.0/bin:INSTALLS/tiny/3.1.0/bin:INSTALLS/poetry/1.7.1/bin:INSTALLS/shellcheck/0.9.0/bin:INSTALLS/shfmt/3.6.0/bin"
assert "$FOO" "18"
Expand Down
4 changes: 0 additions & 4 deletions e2e/cd/test_zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
set -euo pipefail
orig_path="$PATH"

rtx trust
rtx trust ../.e2e.rtx.toml
rtx trust 18/.e2e.rtx.toml

assert_path() {
local expected="${1//$HOME/\~}"
local actual="${PATH/%$orig_path/}"
Expand Down
3 changes: 1 addition & 2 deletions e2e/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ setup_env() {
export ROOT
export PATH="$ROOT/target/debug:$PATH"
export RTX_USE_TOML="0"
export RTX_MISSING_RUNTIME_BEHAVIOR="autoinstall"
export RTX_DATA_DIR="$HOME/.rtx/e2e"
export RTX_CACHE_DIR="$HOME/.rtx/e2e/cache"
export RTX_CONFIG_DIR="$HOME/.rtx/e2e/config"
Expand All @@ -31,8 +30,8 @@ setup_config_files() {
run_test() {
echo "Running $TEST"
rm -f "$RTX_CONFIG_FILE"
rtx trust "$ROOT/e2e/.e2e.rtx.toml" >/dev/null
cd "$(dirname "$TEST")"
rtx i

"./$(basename "$TEST")"
}
Expand Down
2 changes: 0 additions & 2 deletions e2e/test_local
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ assert_raises() {
fi
}

export RTX_MISSING_RUNTIME_BEHAVIOR=autoinstall

assert_raises "rtx uninstall shfmt@3.6.0"

assert "rtx local" "#:schema ../../schema/rtx.json
Expand Down
5 changes: 2 additions & 3 deletions e2e/test_poetry
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ export POETRY_HOME=".poetry"

eval "$(rtx activate bash)"
rtx i python
rtx i poetry
rtx i poetry && _rtx_hook

_rtx_hook
assert "poetry --version" "Poetry (version 1.7.1)"
python3 -V
poetry install
poetry install && _rtx_hook
poetry env info
assert "$(poetry env info -e) --version" "Python 3.12.0"
assert "echo \$VIRTUAL_ENV" "$(poetry env info -p)"
Expand Down
2 changes: 1 addition & 1 deletion e2e/test_tiny
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source "$(dirname "$0")/assert.sh"

rtx cache clean
rm -rf "$RTX_DATA_DIR/installs/tiny"
RTX_CONFIRM=y rtx ls # auto-trust
rtx ls

# this will fail when calling bin/list-all, but it won't stop it from executing
RTX_TINY_LIST_ALL_FAIL=1 RTX_TINY_VERSION=latest rtx env >/dev/null
Expand Down
1 change: 0 additions & 1 deletion e2e/test_tool_versions_alt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail

export RTX_MISSING_RUNTIME_BEHAVIOR=autoinstall
export RTX_DEFAULT_TOOL_VERSIONS_FILENAME=.alternate-tool-versions
export RTX_DEFAULT_CONFIG_FILENAME=.MISSING

Expand Down
1 change: 0 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set shell := ["bash", "-uc"]

export RTX_DATA_DIR := "/tmp/rtx"
export PATH := env_var_or_default("CARGO_TARGET_DIR", justfile_directory() / "target") / "debug:" + env_var("PATH")
export RTX_MISSING_RUNTIME_BEHAVIOR := "autoinstall"
export RUST_TEST_THREADS := "1"

# defaults to `just test`
Expand Down
1 change: 0 additions & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pre-commit:
commands:
pre-commit:
run: just -v pre-commit
interactive: true
skip_output:
- meta
- summary
7 changes: 3 additions & 4 deletions src/cli/bin_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub struct BinPaths {}

impl BinPaths {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
.build(&mut config)?;
let ts = ToolsetBuilder::new().build(&mut config)?;
for p in ts.list_paths(&config) {
rtxprintln!(out, "{}", p.display());
}
Expand All @@ -23,10 +21,11 @@ impl BinPaths {

#[cfg(test)]
mod tests {
use crate::assert_cli_snapshot;
use crate::{assert_cli, assert_cli_snapshot};

#[test]
fn test_bin_paths() {
assert_cli!("i");
assert_cli_snapshot!("bin-paths");
}
}
5 changes: 2 additions & 3 deletions src/cli/direnv/envrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ pub struct Envrc {}

impl Envrc {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
.build(&mut config)?;
let ts = ToolsetBuilder::new().build(&mut config)?;

let envrc_path = env::RTX_TMP_DIR
.join("direnv")
.join(hash_to_str(dirs::CURRENT.deref()) + ".envrc");
Expand Down
5 changes: 2 additions & 3 deletions src/cli/direnv/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ struct DirenvWatches {

impl DirenvExec {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
.build(&mut config)?;
let ts = ToolsetBuilder::new().build(&mut config)?;

let mut cmd = env_cmd();

for (k, v) in ts.env_with_path(&config) {
Expand Down
5 changes: 3 additions & 2 deletions src/cli/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ pub struct Env {

impl Env {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;

if self.json {
self.output_json(config, out, ts)
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ pub struct Exec {

impl Exec {
pub fn run(self, mut config: Config, _out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.with_install_missing()
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;

let (program, args) = parse_command(&env::SHELL, &self.command, &self.c);
let env = ts.env_with_path(&config);

Expand Down
4 changes: 1 addition & 3 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ pub struct HookEnv {

impl HookEnv {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
.build(&mut config)?;
let ts = ToolsetBuilder::new().build(&mut config)?;
let shell = get_shell(self.shell).expect("no shell provided, use `--shell=zsh`");
out.stdout.write(hook_env::clear_old_env(&*shell));
let mut env = ts.env(&config);
Expand Down
17 changes: 0 additions & 17 deletions src/cli/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use console::style;
use itertools::Itertools;

use crate::cli::args::tool::{ToolArg, ToolArgParser};
use crate::config::config_file::ConfigFile;
use crate::config::{config_file, Config};
use crate::env::{RTX_DEFAULT_CONFIG_FILENAME, RTX_DEFAULT_TOOL_VERSIONS_FILENAME};
use crate::file::display_path;
use crate::output::Output;
use crate::plugins::PluginName;
use crate::ui::multi_progress_report::MultiProgressReport;
use crate::{dirs, env, file};

/// Sets/gets tool version in local .tool-versions or .rtx.toml
Expand Down Expand Up @@ -127,7 +125,6 @@ pub fn local(
if !runtime.is_empty() {
let runtimes = ToolArg::double_tool_condition(&runtime.clone());
if cf.display_runtime(out, &runtimes)? {
install_missing_runtimes(&mut config, cf.as_ref())?;
return Ok(());
}
let pin = pin || (config.settings.asdf_compat && !fuzzy);
Expand All @@ -140,8 +137,6 @@ pub fn local(
display_path(path),
style(tools).cyan()
);
} else {
install_missing_runtimes(&mut config, cf.as_ref())?;
}

if !runtime.is_empty() || remove.is_some() {
Expand All @@ -153,18 +148,6 @@ pub fn local(
Ok(())
}

fn install_missing_runtimes(config: &mut Config, cf: &dyn ConfigFile) -> Result<()> {
let mut ts = cf.to_toolset().clone();
ts.latest_versions = true;
ts.resolve(config);
if !ts.list_missing_versions(config).is_empty() {
let mpr = MultiProgressReport::new(config.show_progress_bars());
ts.install_missing(config, mpr)?;
}

Ok(())
}

static AFTER_LONG_HELP: &str = color_print::cstr!(
r#"<bold><underline>Examples:</underline></bold>
# set the current version of node to 20.x for the current directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ experimental = true
jobs = 2
legacy_version_file = true
legacy_version_file_disable_tools = []
missing_runtime_behavior = autoinstall
plugin_autoupdate_last_check_duration = 20
raw = false
trusted_config_paths = []
verbose = true
yes = true

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ experimental = true
jobs = 2
legacy_version_file = false
legacy_version_file_disable_tools = []
missing_runtime_behavior = autoinstall
plugin_autoupdate_last_check_duration = 1
raw = false
trusted_config_paths = []
verbose = true
yes = true

1 change: 0 additions & 1 deletion src/cli/settings/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ mod tests {
jobs = 2
legacy_version_file = true
legacy_version_file_disable_tools = []
missing_runtime_behavior = autoinstall
plugin_autoupdate_last_check_duration = 20
raw = false
trusted_config_paths = []
Expand Down
10 changes: 6 additions & 4 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ pub struct Shell {

impl Shell {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let ts = ToolsetBuilder::new()
.with_install_missing()
.with_args(&self.tool)
.build(&mut config)?;
if !config.is_activated() {
err_inactive()?;
}

let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;

let shell = get_shell(None).expect("no shell detected");

for (p, tv) in ts.list_current_installed_versions(&config) {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ impl Use {
pub fn run(self, mut config: Config, out: &mut Output) -> Result<()> {
let mut ts = ToolsetBuilder::new()
.with_args(&self.tool)
.with_install_missing()
.build(&mut config)?;
ts.install_arg_versions(&mut config)?;

ts.versions
.retain(|_, tvl| self.tool.iter().any(|t| t.plugin == tvl.plugin_name));

Expand Down
34 changes: 1 addition & 33 deletions src/config/config_file/rtx_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use toml_edit::{table, value, Array, Document, Item, Value};

use crate::config::config_file::{ConfigFile, ConfigFileType};
use crate::config::settings::SettingsBuilder;
use crate::config::{config_file, AliasMap, MissingRuntimeBehavior};
use crate::config::{config_file, AliasMap};
use crate::errors::Error::UntrustedConfig;
use crate::file::{create_dir_all, display_path};
use crate::plugins::{unalias_plugin, PluginName};
Expand Down Expand Up @@ -377,10 +377,6 @@ impl RtxToml {
let k = format!("{}.{}", key, config_key);
match config_key.to_lowercase().as_str() {
"experimental" => settings.experimental = Some(self.parse_bool(&k, v)?),
"missing_runtime_behavior" => {
settings.missing_runtime_behavior =
Some(self.parse_missing_runtime_behavior(&k, v)?)
}
"legacy_version_file" => {
settings.legacy_version_file = Some(self.parse_bool(&k, v)?)
}
Expand Down Expand Up @@ -512,16 +508,6 @@ impl RtxToml {
}
}

fn parse_string(&mut self, k: &str, v: &Item) -> Result<String> {
match v.as_value().map(|v| v.as_str()) {
Some(Some(v)) => {
let v = self.parse_template(k, v)?;
Ok(v)
}
_ => parse_error!(k, v, "string")?,
}
}

fn parse_string_array(&self, k: &String, v: &Item) -> Result<Vec<String>> {
match v
.as_array()
Expand All @@ -532,24 +518,6 @@ impl RtxToml {
}
}

fn parse_missing_runtime_behavior(
&mut self,
k: &str,
v: &Item,
) -> Result<MissingRuntimeBehavior> {
let v = self.parse_string("missing_runtime_behavior", v)?;
warn!("The 'missing_runtime_behavior' setting is deprecated. Use '--yes' instead.");
match v.to_lowercase().as_str() {
"warn" => Ok(MissingRuntimeBehavior::Warn),
"ignore" => Ok(MissingRuntimeBehavior::Ignore),
"prompt" => Ok(MissingRuntimeBehavior::Prompt),
"autoinstall" => Ok(MissingRuntimeBehavior::AutoInstall),
_ => Err(eyre!(
"expected {k} to be one of: 'warn', 'ignore', 'prompt', 'autoinstall'. Got: {v}"
)),
}
}

pub fn update_setting<V: Into<Value>>(&mut self, key: &str, value: V) {
let key = key.split('.').collect::<Vec<&str>>();
let mut settings = self
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use itertools::Itertools;
use once_cell::sync::OnceCell;
use rayon::prelude::*;

pub use settings::{MissingRuntimeBehavior, Settings};
pub use settings::Settings;

use crate::config::config_file::legacy_version::LegacyVersionFile;
use crate::config::config_file::rtx_toml::RtxToml;
Expand Down
Loading

0 comments on commit adc64c3

Please sign in to comment.