Skip to content

Commit

Permalink
Add --refresh to tool run warning for --with dependencies (#6609)
Browse files Browse the repository at this point in the history
## Summary

Closes #6576.
  • Loading branch information
charliermarsh authored Aug 25, 2024
1 parent 5b3e654 commit 5076f32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
12 changes: 10 additions & 2 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 26 additions & 1 deletion crates/uv/tests/tool_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
Expand Down

0 comments on commit 5076f32

Please sign in to comment.