Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a target version for uv self update #7252

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,15 @@ pub struct SelfNamespace {
#[derive(Subcommand)]
#[cfg(feature = "self-update")]
pub enum SelfCommand {
/// Update uv to the latest version.
Update,
/// Update uv.
Update(SelfUpdateArgs),
}

#[derive(Args, Debug)]
#[cfg(feature = "self-update")]
pub struct SelfUpdateArgs {
/// Update to the specified version. If not provided, uv will update to the latest version.
pub target_version: Option<String>,
}

#[derive(Args)]
Expand Down
12 changes: 10 additions & 2 deletions crates/uv/src/commands/self_update.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Write;

use anyhow::Result;
use axoupdater::{AxoUpdater, AxoupdateError};
use axoupdater::{AxoUpdater, AxoupdateError, UpdateRequest};
use owo_colors::OwoColorize;
use tracing::debug;

Expand All @@ -11,7 +11,7 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;

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

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

let update_request = if let Some(version) = version {
UpdateRequest::SpecificTag(version)
} else {
UpdateRequest::Latest
};

updater.configure_version_specifier(update_request);

// Run the updater. This involves a network request, since we need to determine the latest
// available version of uv.
match updater.run().await {
Expand Down
6 changes: 3 additions & 3 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use uv_cli::{
};
use uv_cli::{PythonCommand, PythonNamespace, ToolCommand, ToolNamespace};
#[cfg(feature = "self-update")]
use uv_cli::{SelfCommand, SelfNamespace};
use uv_cli::{SelfCommand, SelfNamespace, SelfUpdateArgs};
use uv_fs::CWD;
use uv_requirements::RequirementsSource;
use uv_scripts::Pep723Script;
Expand Down Expand Up @@ -766,8 +766,8 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
}
#[cfg(feature = "self-update")]
Commands::Self_(SelfNamespace {
command: SelfCommand::Update,
}) => commands::self_update(printer).await,
command: SelfCommand::Update(SelfUpdateArgs { target_version }),
}) => commands::self_update(target_version, printer).await,
Commands::Version { output_format } => {
commands::version(output_format, &mut stdout())?;
Ok(ExitStatus::Success)
Expand Down
Loading