Improve message when updater receipt is for a different uv executable (#9487)

Attempts to improve confusing messaging in cases like
https://github.com/astral-sh/uv/issues/6774#issuecomment-2504950681,
when the receipt is for a different uv executable.

```
❯ cargo run --all-features -q -- self update
warning: Self-update is only available for uv binaries installed via the standalone installation scripts.

The current executable is at `/Users/zb/workspace/uv/target/debug/uv` but the standalone installer was used to install uv to `/Users/zb/.cargo`. Are multiple copies of uv installed?
```

Requires https://github.com/axodotdev/axoupdater/pull/221
Closes https://github.com/astral-sh/uv/issues/6774
This commit is contained in:
Zanie Blue 2024-12-03 19:26:32 -06:00 committed by GitHub
parent 1ecdc1a31e
commit ae033e2d3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

View file

@ -6,6 +6,7 @@ use owo_colors::OwoColorize;
use tracing::debug;
use uv_client::WrappedReqwestError;
use uv_fs::Simplified;
use crate::commands::ExitStatus;
use crate::printer::Printer;
@ -48,9 +49,9 @@ pub(crate) async fn self_update(
// uv binaries installed, and the current binary was _not_ installed via the standalone
// installation scripts.
if !updater.check_receipt_is_for_this_executable()? {
debug!(
"receipt is not for this executable; assuming uv was installed via a package manager"
);
let current_exe = std::env::current_exe()?;
let receipt_prefix = updater.install_prefix_root()?;
writeln!(
printer.stderr(),
"{}",
@ -59,10 +60,12 @@ pub(crate) async fn self_update(
"{}{} Self-update is only available for uv binaries installed via the standalone installation scripts.",
"\n",
"\n",
"If you installed uv with pip, brew, or another package manager, update uv with `pip install --upgrade`, `brew upgrade`, or similar."
"The current executable is at `{}` but the standalone installer was used to install uv to `{}`. Are multiple copies of uv installed?"
),
"warning".yellow().bold(),
":".bold()
":".bold(),
current_exe.simplified_display().bold().cyan(),
receipt_prefix.simplified_display().bold().cyan()
)
)?;
return Ok(ExitStatus::Error);