Skip to content

Commit

Permalink
fix: trim final exe suffix for stable sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Sep 27, 2024
1 parent 775eca8 commit 0c9f450
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
15 changes: 5 additions & 10 deletions crates/uv/src/commands/tool/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,17 @@ pub(crate) fn install_executables(
)
}

let mut names = BTreeSet::new();
for (name, source_path, target_path) in &target_entry_points {
debug!("Installing executable: `{name}`");
#[cfg(unix)]
replace_symlink(source_path, target_path).context("Failed to install executable")?;
#[cfg(windows)]
fs_err::copy(source_path, target_path).context("Failed to install entrypoint")?;
names.insert(name.trim_end_matches(".exe"));
}

let s = if target_entry_points.len() == 1 {
""
} else {
"s"
};
let s = if names.len() == 1 { "" } else { "s" };
let from_pkg = if tool_name == name {
String::new()
} else {
Expand All @@ -180,11 +178,8 @@ pub(crate) fn install_executables(
writeln!(
printer.stderr(),
"Installed {} executable{s}{from_pkg}: {}",
target_entry_points.len(),
target_entry_points
.iter()
.map(|(name, _, _)| name.bold())
.join(", ")
names.len(),
names.iter().map(|name| name.bold()).join(", ")
)?;

debug!("Adding receipt for tool `{tool_name}`");
Expand Down
6 changes: 5 additions & 1 deletion crates/uv/src/commands/tool/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ async fn do_uninstall(
}
entrypoints
};
entrypoints.sort_unstable_by(|a, b| a.name.cmp(&b.name));
entrypoints.sort_unstable_by(|a, b| {
let a_trimmed = a.name.trim_end_matches(".exe");
let b_trimmed = b.name.trim_end_matches(".exe");
a_trimmed.cmp(b_trimmed)
});

if entrypoints.is_empty() {
// If we removed at least one dangling environment, there's no need to summarize.
Expand Down
3 changes: 3 additions & 0 deletions crates/uv/tests/tool_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,9 @@ fn tool_install_additional_entrypoints() {
Installed 1 executable: ansible-community
"###);

// NOTE(lucab): on Windows `name` values contain an `.exe` suffix,
// which is hidden in the snapshot but results in a different sorting.
#[cfg(not(target_family = "windows"))]
insta::with_settings!({
filters => context.filters(),
}, {
Expand Down

0 comments on commit 0c9f450

Please sign in to comment.