From 5076f325cd74a124718820867dc508a0828fcb97 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 25 Aug 2024 11:15:41 -0400 Subject: [PATCH] Add `--refresh` to `tool run` warning for `--with` dependencies (#6609) ## Summary Closes https://github.com/astral-sh/uv/issues/6576. --- crates/uv/src/settings.rs | 12 ++++++++++-- crates/uv/tests/tool_run.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 2b9e9c487..c56763f0c 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -296,12 +296,20 @@ impl ToolRunSettings { // If `--upgrade` was passed explicitly, warn. if installer.upgrade || !installer.upgrade_package.is_empty() { - warn_user_once!("Tools cannot be upgraded via `{invocation_source}`; use `uv tool upgrade --all` to upgrade all installed tools, or `{invocation_source} package@latest` to run the latest version of a tool"); + if with.is_empty() && with_requirements.is_empty() { + warn_user_once!("Tools cannot be upgraded via `{invocation_source}`; use `uv tool upgrade --all` to upgrade all installed tools, or `{invocation_source} package@latest` to run the latest version of a tool."); + } else { + warn_user_once!("Tools cannot be upgraded via `{invocation_source}`; use `uv tool upgrade --all` to upgrade all installed tools, `{invocation_source} package@latest` to run the latest version of a tool, or `{invocation_source} --refresh package` to upgrade any `--with` dependencies."); + } } // If `--reinstall` was passed explicitly, warn. if installer.reinstall || !installer.reinstall_package.is_empty() { - warn_user_once!("Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --reinstall` to reinstall all installed tools, or `{invocation_source} package@latest` to run the latest version of a tool"); + if with.is_empty() && with_requirements.is_empty() { + warn_user_once!("Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --reinstall` to reinstall all installed tools, or `{invocation_source} package@latest` to run the latest version of a tool."); + } else { + warn_user_once!("Tools cannot be reinstalled via `{invocation_source}`; use `uv tool upgrade --reinstall` to reinstall all installed tools, `{invocation_source} package@latest` to run the latest version of a tool, or `{invocation_source} --refresh package` to reinstall any `--with` dependencies."); + } } Self { diff --git a/crates/uv/tests/tool_run.rs b/crates/uv/tests/tool_run.rs index e76358553..2012edb9e 100644 --- a/crates/uv/tests/tool_run.rs +++ b/crates/uv/tests/tool_run.rs @@ -870,7 +870,7 @@ fn tool_run_upgrade_warn() { pytest 8.1.1 ----- stderr ----- - warning: Tools cannot be upgraded via `uv tool run`; use `uv tool upgrade --all` to upgrade all installed tools, or `uv tool run package@latest` to run the latest version of a tool + warning: Tools cannot be upgraded via `uv tool run`; use `uv tool upgrade --all` to upgrade all installed tools, or `uv tool run package@latest` to run the latest version of a tool. Resolved [N] packages in [TIME] Prepared [N] packages in [TIME] Installed [N] packages in [TIME] @@ -879,6 +879,31 @@ fn tool_run_upgrade_warn() { + pluggy==1.4.0 + pytest==8.1.1 "###); + + uv_snapshot!(context.filters(), context.tool_run() + .arg("--upgrade") + .arg("--with") + .arg("typing-extensions") + .arg("pytest") + .arg("--version") + .env("UV_TOOL_DIR", tool_dir.as_os_str()) + .env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###" + success: true + exit_code: 0 + ----- stdout ----- + pytest 8.1.1 + + ----- stderr ----- + warning: Tools cannot be upgraded via `uv tool run`; use `uv tool upgrade --all` to upgrade all installed tools, `uv tool run package@latest` to run the latest version of a tool, or `uv tool run --refresh package` to upgrade any `--with` dependencies. + Resolved [N] packages in [TIME] + Prepared [N] packages in [TIME] + Installed [N] packages in [TIME] + + iniconfig==2.0.0 + + packaging==24.0 + + pluggy==1.4.0 + + pytest==8.1.1 + + typing-extensions==4.10.0 + "###); } /// If we fail to resolve the tool, we should include "tool" in the error message.