Skip to content

Commit bbccee8

Browse files
authored
Allow setting a target version for uv self update (#7252)
## Summary Resolves #6642 ## Test Plan ```console ❯ cargo build --bin uv --features self-update Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.78s ❯ cp target/debug/uv ~/.cargo/bin ❯ uv self update 0.3.4 info: Checking for updates... success: Upgraded uv from v0.4.8 to v0.3.4! https://github.com/astral-sh/uv/releases/tag/0.3.4 ❯ uv --version uv 0.3.4 (39f3cd2 2024-08-26) ❯ cp target/debug/uv ~/.cargo/bin ❯ uv self update info: Checking for updates... success: Upgraded uv from v0.3.4 to v0.4.8! https://github.com/astral-sh/uv/releases/tag/0.4.8 ❯ uv --version uv 0.4.8 (956cadd 2024-09-09) ```
1 parent 2b3890f commit bbccee8

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

crates/uv-cli/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,15 @@ pub struct SelfNamespace {
418418
#[derive(Subcommand)]
419419
#[cfg(feature = "self-update")]
420420
pub enum SelfCommand {
421-
/// Update uv to the latest version.
422-
Update,
421+
/// Update uv.
422+
Update(SelfUpdateArgs),
423+
}
424+
425+
#[derive(Args, Debug)]
426+
#[cfg(feature = "self-update")]
427+
pub struct SelfUpdateArgs {
428+
/// Update to the specified version. If not provided, uv will update to the latest version.
429+
pub target_version: Option<String>,
423430
}
424431

425432
#[derive(Args)]

crates/uv/src/commands/self_update.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Write;
22

33
use anyhow::Result;
4-
use axoupdater::{AxoUpdater, AxoupdateError};
4+
use axoupdater::{AxoUpdater, AxoupdateError, UpdateRequest};
55
use owo_colors::OwoColorize;
66
use tracing::debug;
77

@@ -11,7 +11,7 @@ use crate::commands::ExitStatus;
1111
use crate::printer::Printer;
1212

1313
/// Attempt to update the uv binary.
14-
pub(crate) async fn self_update(printer: Printer) -> Result<ExitStatus> {
14+
pub(crate) async fn self_update(version: Option<String>, printer: Printer) -> Result<ExitStatus> {
1515
let mut updater = AxoUpdater::new_for("uv");
1616
updater.disable_installer_output();
1717

@@ -70,6 +70,14 @@ pub(crate) async fn self_update(printer: Printer) -> Result<ExitStatus> {
7070
)
7171
)?;
7272

73+
let update_request = if let Some(version) = version {
74+
UpdateRequest::SpecificTag(version)
75+
} else {
76+
UpdateRequest::Latest
77+
};
78+
79+
updater.configure_version_specifier(update_request);
80+
7381
// Run the updater. This involves a network request, since we need to determine the latest
7482
// available version of uv.
7583
match updater.run().await {

crates/uv/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use uv_cli::{
1818
};
1919
use uv_cli::{PythonCommand, PythonNamespace, ToolCommand, ToolNamespace};
2020
#[cfg(feature = "self-update")]
21-
use uv_cli::{SelfCommand, SelfNamespace};
21+
use uv_cli::{SelfCommand, SelfNamespace, SelfUpdateArgs};
2222
use uv_fs::CWD;
2323
use uv_requirements::RequirementsSource;
2424
use uv_scripts::Pep723Script;
@@ -766,8 +766,8 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
766766
}
767767
#[cfg(feature = "self-update")]
768768
Commands::Self_(SelfNamespace {
769-
command: SelfCommand::Update,
770-
}) => commands::self_update(printer).await,
769+
command: SelfCommand::Update(SelfUpdateArgs { target_version }),
770+
}) => commands::self_update(target_version, printer).await,
771771
Commands::Version { output_format } => {
772772
commands::version(output_format, &mut stdout())?;
773773
Ok(ExitStatus::Success)

0 commit comments

Comments
 (0)