From 6b7471bbbdce7fd4d3e5bf64830c0f05bf3ae203 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sun, 24 Nov 2024 19:43:59 -0600 Subject: [PATCH] fix: move semver cmp errors to debug --- e2e/backend/test_pipx_deep_dependencies | 3 ++ src/backend/mod.rs | 1 - src/backend/pipx.rs | 72 ++++++++++++++++++++----- src/cli/upgrade.rs | 7 +++ src/config/mod.rs | 14 ++++- src/toolset/tool_version.rs | 4 ++ 6 files changed, 86 insertions(+), 15 deletions(-) diff --git a/e2e/backend/test_pipx_deep_dependencies b/e2e/backend/test_pipx_deep_dependencies index 97a9a9d391..e2889804fe 100644 --- a/e2e/backend/test_pipx_deep_dependencies +++ b/e2e/backend/test_pipx_deep_dependencies @@ -35,3 +35,6 @@ mise install # Assert that mkdocs 1.6.0 has been installed with pipx and uses python 3.12 # (mkdocs conveniently returns its installation path in with --version) assert_contains "mise x -- mkdocs --version" "/mise/installs/pipx-mkdocs/1.6.0/venvs/mkdocs/lib/python3.12/" + +assert "mise up --bump python" +assert_contains "mise x -- mkdocs --version" "mkdocs, version 1.6.0" diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 42f193d1db..739dd52a5d 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -180,7 +180,6 @@ pub trait Backend: Debug + Send + Sync { } fn list_remote_versions(&self) -> eyre::Result> { - self.warn_if_dependencies_missing()?; self.get_remote_version_cache() .get_or_try_init(|| { trace!("Listing remote versions for {}", self.ba().to_string()); diff --git a/src/backend/pipx.rs b/src/backend/pipx.rs index 1ab769490b..381d32a712 100644 --- a/src/backend/pipx.rs +++ b/src/backend/pipx.rs @@ -7,7 +7,10 @@ use crate::config::{Config, SETTINGS}; use crate::github; use crate::http::HTTP_FETCH; use crate::install_context::InstallContext; -use crate::toolset::{ToolVersion, ToolVersionOptions}; +use crate::toolset::{ToolVersion, ToolVersionOptions, Toolset, ToolsetBuilder}; +use crate::ui::multi_progress_report::MultiProgressReport; +use crate::ui::progress_report::SingleReport; +use eyre::Result; use indexmap::IndexMap; use itertools::Itertools; use std::fmt::Debug; @@ -109,17 +112,14 @@ impl Backend for PIPXBackend { } cmd.execute()?; } else { - let mut cmd = CmdLineRunner::new("pipx") - .arg("install") - .arg(pipx_request) - .with_pr(ctx.pr.as_ref()) - .env("PIPX_HOME", tv.install_path()) - .env("PIPX_BIN_DIR", tv.install_path().join("bin")) - .envs(ctx.ts.env_with_path(&config)?) - .prepend_path(ctx.ts.list_paths())? - // Prepend install path so pipx doesn't issue a warning about missing path - .prepend_path(vec![tv.install_path().join("bin")])? - .prepend_path(self.dependency_toolset()?.list_paths())?; + let mut cmd = Self::pipx_cmd( + &config, + &["install", &pipx_request], + self, + &tv, + ctx.ts, + &*ctx.pr, + )?; if let Some(args) = tv.request.options().get("pipx_args") { cmd = cmd.args(shell_words::split(args)?); } @@ -145,6 +145,54 @@ impl PIPXBackend { ba, } } + + pub fn reinstall_all() -> Result<()> { + if SETTINGS.pipx.uvx { + debug!("skipping pipx reinstall because uvx is enabled"); + return Ok(()); + } + let config = Config::load()?; + let ts = ToolsetBuilder::new().build(&config)?; + let pipx_tools = ts + .list_installed_versions()? + .into_iter() + .filter(|(b, _tv)| b.ba().backend_type() == BackendType::Pipx) + .collect_vec(); + let pr = MultiProgressReport::get().add("reinstalling pipx tools"); + for (b, tv) in pipx_tools { + Self::pipx_cmd( + &config, + &["reinstall", &tv.ba().tool_name], + &*b, + &tv, + &ts, + &*pr, + )? + .execute()?; + } + Ok(()) + } + + fn pipx_cmd<'a>( + config: &Config, + args: &[&str], + b: &dyn Backend, + tv: &ToolVersion, + ts: &Toolset, + pr: &'a dyn SingleReport, + ) -> Result> { + let mut cmd = CmdLineRunner::new("pipx"); + for arg in args { + cmd = cmd.arg(arg); + } + cmd.with_pr(pr) + .env("PIPX_HOME", tv.install_path()) + .env("PIPX_BIN_DIR", tv.install_path().join("bin")) + .envs(ts.env_with_path(config)?) + .prepend_path(ts.list_paths())? + .prepend_path(vec![tv.install_path().join("bin")])? + .prepend_path(b.dependency_toolset()?.list_paths()) + } } enum PipxRequest { diff --git a/src/cli/upgrade.rs b/src/cli/upgrade.rs index 8f99ee0c5a..d9a18caba2 100644 --- a/src/cli/upgrade.rs +++ b/src/cli/upgrade.rs @@ -1,3 +1,4 @@ +use crate::backend::pipx::PIPXBackend; use crate::cli::args::ToolArg; use crate::config::{config_file, Config}; use crate::file::display_path; @@ -158,6 +159,12 @@ impl Upgrade { } config::rebuild_shims_and_runtime_symlinks(&versions)?; + + if versions.iter().any(|v| v.short() == "python") { + PIPXBackend::reinstall_all().unwrap_or_else(|err| { + warn!("failed to reinstall pipx tools: {err}"); + }) + } Ok(()) } diff --git a/src/config/mod.rs b/src/config/mod.rs index 3f9fb8e4ef..8e6ac15100 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -23,7 +23,7 @@ use crate::file::display_path; use crate::shorthands::{get_shorthands, Shorthands}; use crate::task::Task; use crate::toolset::{ - install_state, ToolRequestSet, ToolRequestSetBuilder, ToolVersion, ToolsetBuilder, + install_state, ToolRequestSet, ToolRequestSetBuilder, ToolVersion, Toolset, ToolsetBuilder, }; use crate::ui::style; use crate::{backend, dirs, env, file, lockfile, registry, runtime_symlinks, shims}; @@ -53,6 +53,7 @@ pub struct Config { shorthands: OnceLock, tasks: OnceCell>, tool_request_set: OnceCell, + toolset: OnceCell, } #[derive(Debug, Clone, Default)] @@ -190,6 +191,14 @@ impl Config { .get_or_try_init(|| ToolRequestSetBuilder::new().build()) } + pub fn get_toolset(&self) -> eyre::Result<&Toolset> { + self.toolset.get_or_try_init(|| { + let mut ts = Toolset::from(self.get_tool_request_set()?.clone()); + ts.resolve()?; + Ok(ts) + }) + } + pub fn get_repo_url(&self, plugin_name: &str) -> Option { let plugin_name = self .all_aliases @@ -903,9 +912,9 @@ fn default_task_includes() -> Vec { } pub fn rebuild_shims_and_runtime_symlinks(new_versions: &[ToolVersion]) -> Result<()> { + install_state::reset(); let config = Config::load()?; let ts = ToolsetBuilder::new().build(&config)?; - install_state::reset(); trace!("rebuilding shims"); shims::reshim(&ts, false).wrap_err("failed to rebuild shims")?; trace!("rebuilding runtime symlinks"); @@ -913,6 +922,7 @@ pub fn rebuild_shims_and_runtime_symlinks(new_versions: &[ToolVersion]) -> Resul trace!("updating lockfiles"); lockfile::update_lockfiles(&config, &ts, new_versions) .wrap_err("failed to update lockfiles")?; + Ok(()) } diff --git a/src/toolset/tool_version.rs b/src/toolset/tool_version.rs index 90f2ac29c6..625970eb86 100644 --- a/src/toolset/tool_version.rs +++ b/src/toolset/tool_version.rs @@ -72,6 +72,10 @@ impl ToolVersion { self.ba().backend() } + pub fn short(&self) -> &str { + &self.ba().short + } + pub fn install_path(&self) -> PathBuf { let pathname = match &self.request { ToolRequest::Path { path: p, .. } => p.to_string_lossy().to_string(),