Skip to content

Commit

Permalink
Avoid spurious 'Upgraded tool environment' in uv tool upgrade (#9870)
Browse files Browse the repository at this point in the history
## Summary

Closes #9869.
  • Loading branch information
charliermarsh authored Dec 13, 2024
1 parent 6051a26 commit 5903ce5
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 11 deletions.
24 changes: 13 additions & 11 deletions crates/uv/src/commands/tool/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,19 @@ pub(crate) async fn upgrade(
}

if let Some(python_request) = python_request {
let tools = did_upgrade_environment
.iter()
.map(|name| format!("`{}`", name.cyan()))
.collect::<Vec<_>>();
let s = if tools.len() > 1 { "s" } else { "" };
writeln!(
printer.stderr(),
"Upgraded tool environment{s} for {} to {}",
conjunction(tools),
python_request.cyan(),
)?;
if !did_upgrade_environment.is_empty() {
let tools = did_upgrade_environment
.iter()
.map(|name| format!("`{}`", name.cyan()))
.collect::<Vec<_>>();
let s = if tools.len() > 1 { "s" } else { "" };
writeln!(
printer.stderr(),
"Upgraded tool environment{s} for {} to {}",
conjunction(tools),
python_request.cyan(),
)?;
}
}

Ok(ExitStatus::Success)
Expand Down
85 changes: 85 additions & 0 deletions crates/uv/tests/it/tool_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,91 @@ use uv_static::EnvVars;

use crate::common::{uv_snapshot, TestContext};

#[test]
fn tool_upgrade_empty() {
let context = TestContext::new("3.12")
.with_filtered_counts()
.with_filtered_exe_suffix();
let tool_dir = context.temp_dir.child("tools");
let bin_dir = context.temp_dir.child("bin");

uv_snapshot!(context.filters(), context.tool_upgrade()
.arg("--all")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str())
.env(EnvVars::PATH, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Nothing to upgrade
"###);

uv_snapshot!(context.filters(), context.tool_upgrade()
.arg("--all")
.arg("-p")
.arg("3.13")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str())
.env(EnvVars::PATH, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Nothing to upgrade
"###);

// Install the latest `babel`.
uv_snapshot!(context.filters(), context.tool_install()
.arg("babel")
.arg("--index-url")
.arg("https://pypi.org/simple/")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str())
.env(EnvVars::PATH, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved [N] packages in [TIME]
Prepared [N] packages in [TIME]
Installed [N] packages in [TIME]
+ babel==2.14.0
Installed 1 executable: pybabel
"###);

uv_snapshot!(context.filters(), context.tool_upgrade()
.arg("--all")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str())
.env(EnvVars::PATH, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Nothing to upgrade
"###);

uv_snapshot!(context.filters(), context.tool_upgrade()
.arg("--all")
.arg("-p")
.arg("3.12")
.env(EnvVars::UV_TOOL_DIR, tool_dir.as_os_str())
.env(EnvVars::XDG_BIN_HOME, bin_dir.as_os_str())
.env(EnvVars::PATH, bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Nothing to upgrade
"###);
}

#[test]
fn tool_upgrade_name() {
let context = TestContext::new("3.12")
Expand Down

0 comments on commit 5903ce5

Please sign in to comment.