mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Merge 2b52539194
into f609e1ddaf
This commit is contained in:
commit
9d9eabeb60
1 changed files with 60 additions and 30 deletions
|
@ -1,7 +1,7 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axoupdater::{AxoUpdater, AxoupdateError, UpdateRequest};
|
use axoupdater::{AxoUpdater, AxoupdateError, UpdateRequest, Version};
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use crate::settings::NetworkSettings;
|
||||||
|
|
||||||
/// Attempt to update the uv binary.
|
/// Attempt to update the uv binary.
|
||||||
pub(crate) async fn self_update(
|
pub(crate) async fn self_update(
|
||||||
version: Option<String>,
|
requested_version: Option<String>,
|
||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
dry_run: bool,
|
dry_run: bool,
|
||||||
printer: Printer,
|
printer: Printer,
|
||||||
|
@ -66,10 +66,8 @@ pub(crate) async fn self_update(
|
||||||
// If we know what our version is, ignore whatever the receipt thinks it is!
|
// If we know what our version is, ignore whatever the receipt thinks it is!
|
||||||
// This makes us behave better if someone manually installs a random version of uv
|
// This makes us behave better if someone manually installs a random version of uv
|
||||||
// in a way that doesn't update the receipt.
|
// in a way that doesn't update the receipt.
|
||||||
if let Ok(version) = env!("CARGO_PKG_VERSION").parse() {
|
let current_version: Version = env!("CARGO_PKG_VERSION").parse()?;
|
||||||
// This is best-effort, it's fine if it fails (also it can't actually fail)
|
let _ = updater.set_current_version(current_version.clone());
|
||||||
let _ = updater.set_current_version(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the receipt is for the current binary. If it's not, then the user likely has multiple
|
// Ensure the receipt is for the current binary. If it's not, then the user likely has multiple
|
||||||
// uv binaries installed, and the current binary was _not_ installed via the standalone
|
// uv binaries installed, and the current binary was _not_ installed via the standalone
|
||||||
|
@ -107,41 +105,73 @@ pub(crate) async fn self_update(
|
||||||
)
|
)
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let update_request = if let Some(version) = version {
|
let update_request = if let Some(version) = requested_version {
|
||||||
UpdateRequest::SpecificTag(version)
|
UpdateRequest::SpecificTag(version)
|
||||||
} else {
|
} else {
|
||||||
UpdateRequest::Latest
|
UpdateRequest::Latest
|
||||||
};
|
};
|
||||||
|
|
||||||
updater.configure_version_specifier(update_request.clone());
|
updater.configure_version_specifier(update_request);
|
||||||
|
|
||||||
|
let new_version = if let Some(queried_version) = updater.query_new_version().await? {
|
||||||
|
queried_version.to_owned()
|
||||||
|
} else {
|
||||||
|
// AxoUpdater interface is not clear when this would happen, and its current version would never hit this code path.
|
||||||
|
writeln!(printer.stderr(), "Could not determine version to update.",)?;
|
||||||
|
return Ok(ExitStatus::Error);
|
||||||
|
};
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
printer.stderr(),
|
||||||
|
"{}",
|
||||||
|
format_args!(
|
||||||
|
"{}{} Current version: {}",
|
||||||
|
"info".cyan().bold(),
|
||||||
|
":".bold(),
|
||||||
|
format!("v{current_version}").bold().cyan(),
|
||||||
|
)
|
||||||
|
)?;
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
printer.stderr(),
|
||||||
|
"{}",
|
||||||
|
format_args!(
|
||||||
|
"{}{} Latest/requested version: {}",
|
||||||
|
"info".cyan().bold(),
|
||||||
|
":".bold(),
|
||||||
|
format!("v{new_version}").bold().cyan(),
|
||||||
|
)
|
||||||
|
)?;
|
||||||
|
|
||||||
if dry_run {
|
if dry_run {
|
||||||
// TODO(charlie): `updater.fetch_release` isn't public, so we can't say what the latest
|
|
||||||
// version is.
|
|
||||||
if updater.is_update_needed().await? {
|
if updater.is_update_needed().await? {
|
||||||
let version = match update_request {
|
|
||||||
UpdateRequest::Latest | UpdateRequest::LatestMaybePrerelease => {
|
|
||||||
"the latest version".to_string()
|
|
||||||
}
|
|
||||||
UpdateRequest::SpecificTag(version) | UpdateRequest::SpecificVersion(version) => {
|
|
||||||
format!("v{version}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
writeln!(
|
|
||||||
printer.stderr(),
|
|
||||||
"Would update uv from {} to {}",
|
|
||||||
format!("v{}", env!("CARGO_PKG_VERSION")).bold().white(),
|
|
||||||
version.bold().white(),
|
|
||||||
)?;
|
|
||||||
} else {
|
|
||||||
writeln!(
|
writeln!(
|
||||||
printer.stderr(),
|
printer.stderr(),
|
||||||
"{}",
|
"{}",
|
||||||
format_args!(
|
format_args!("{}{} Would update uv.", "info".cyan().bold(), ":".bold())
|
||||||
"You're on the latest version of uv ({})",
|
|
||||||
format!("v{}", env!("CARGO_PKG_VERSION")).bold().white()
|
|
||||||
)
|
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
if current_version == new_version {
|
||||||
|
writeln!(
|
||||||
|
printer.stderr(),
|
||||||
|
"{}",
|
||||||
|
format_args!(
|
||||||
|
"{}{} Would not update uv. Already on the latest/requested version of uv.",
|
||||||
|
"info".cyan().bold(),
|
||||||
|
":".bold(),
|
||||||
|
)
|
||||||
|
)?;
|
||||||
|
} else {
|
||||||
|
writeln!(
|
||||||
|
printer.stderr(),
|
||||||
|
"{}",
|
||||||
|
format_args!(
|
||||||
|
"{}{} Would not update uv. Executable was not determined to be eligible.",
|
||||||
|
"info".cyan().bold(),
|
||||||
|
":".bold(),
|
||||||
|
)
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Ok(ExitStatus::Success);
|
return Ok(ExitStatus::Success);
|
||||||
}
|
}
|
||||||
|
@ -194,7 +224,7 @@ pub(crate) async fn self_update(
|
||||||
"{}{} You're on the latest version of uv ({})",
|
"{}{} You're on the latest version of uv ({})",
|
||||||
"success".green().bold(),
|
"success".green().bold(),
|
||||||
":".bold(),
|
":".bold(),
|
||||||
format!("v{}", env!("CARGO_PKG_VERSION")).bold().cyan()
|
format!("v{current_version}").bold().cyan()
|
||||||
)
|
)
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue