From 22029a657c6c9f44ba26e4dad8c4e45d15da405f Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:33:13 -0600 Subject: [PATCH] fix: automatic reinstall of uvx tools during python upgrades --- docs/dev-tools/backends/pipx.md | 2 + e2e/backend/test_pipx_uvx | 6 ++- settings.toml | 1 + src/backend/pipx.rs | 73 +++++++++++++++++++++------------ 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/docs/dev-tools/backends/pipx.md b/docs/dev-tools/backends/pipx.md index eeb234964b..f57a77a092 100644 --- a/docs/dev-tools/backends/pipx.md +++ b/docs/dev-tools/backends/pipx.md @@ -54,6 +54,8 @@ Or you can reinstall all pipx packages with: mise install -f "pipx:*" ``` +mise _should_ do this automatically when using `mise up python`. + ### Supported Pipx Syntax | Description | Usage | diff --git a/e2e/backend/test_pipx_uvx b/e2e/backend/test_pipx_uvx index 426afbce01..8ef33c57bb 100644 --- a/e2e/backend/test_pipx_uvx +++ b/e2e/backend/test_pipx_uvx @@ -20,8 +20,9 @@ export MISE_PIPX_UVX=1 # Set up a 2-step installation: pipx@1.5.0 > pipx:mkdocs@1.6.0 cat >.mise.toml < 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 @@ -150,21 +142,48 @@ impl PIPXBackend { .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()?; + if SETTINGS.pipx.uvx { + let pr = MultiProgressReport::get().add("reinstalling pipx tools with uvx"); + for (b, tv) in pipx_tools { + for (cmd, tool) in &[ + ("uninstall", tv.ba().tool_name.to_string()), + ("install", format!("{}=={}", tv.ba().tool_name, tv.version)), + ] { + let args = &["tool", cmd, tool]; + Self::uvx_cmd(&config, args, &*b, &tv, &ts, &*pr)?.execute()?; + } + } + } else { + let pr = MultiProgressReport::get().add("reinstalling pipx tools"); + for (b, tv) in pipx_tools { + let args = &["reinstall", &tv.ba().tool_name]; + Self::pipx_cmd(&config, args, &*b, &tv, &ts, &*pr)?.execute()?; + } } Ok(()) } + fn uvx_cmd<'a>( + config: &Config, + args: &[&str], + b: &dyn Backend, + tv: &ToolVersion, + ts: &Toolset, + pr: &'a dyn SingleReport, + ) -> Result> { + let mut cmd = CmdLineRunner::new("uv"); + for arg in args { + cmd = cmd.arg(arg); + } + cmd.with_pr(pr) + .env("UV_TOOL_DIR", tv.install_path()) + .env("UV_TOOL_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()) + } + fn pipx_cmd<'a>( config: &Config, args: &[&str],