Add `--refresh` to `tool run` warning for `--with` dependencies (#6609)

## Summary

Closes https://github.com/astral-sh/uv/issues/6576.
This commit is contained in:
Charlie Marsh 2024-08-25 11:15:41 -04:00 committed by GitHub
parent 5b3e654dc9
commit 5076f325cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 3 deletions

View File

@ -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 {

View File

@ -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.