Skip to content

Add --dry-run support to uv self update #9829

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

Merged
merged 3 commits into from
May 4, 2025
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
4 changes: 4 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ pub struct SelfUpdateArgs {
/// A token is not required but can be used to reduce the chance of encountering rate limits.
#[arg(long, env = EnvVars::UV_GITHUB_TOKEN)]
pub token: Option<String>,

/// Run without performing the update.
#[arg(long)]
pub dry_run: bool,
}

#[derive(Args)]
Expand Down
34 changes: 33 additions & 1 deletion crates/uv/src/commands/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::printer::Printer;
pub(crate) async fn self_update(
version: Option<String>,
token: Option<String>,
dry_run: bool,
printer: Printer,
) -> Result<ExitStatus> {
let mut updater = AxoUpdater::new_for("uv");
Expand Down Expand Up @@ -87,7 +88,38 @@ pub(crate) async fn self_update(
UpdateRequest::Latest
};

updater.configure_version_specifier(update_request);
updater.configure_version_specifier(update_request.clone());

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? {
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!(
printer.stderr(),
"{}",
format_args!(
"You're on the latest version of uv ({})",
format!("v{}", env!("CARGO_PKG_VERSION")).bold().white()
)
)?;
}
return Ok(ExitStatus::Success);
}

// Run the updater. This involves a network request, since we need to determine the latest
// available version of uv.
Expand Down
3 changes: 2 additions & 1 deletion crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,9 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
SelfCommand::Update(SelfUpdateArgs {
target_version,
token,
dry_run,
}),
}) => commands::self_update(target_version, token, printer).await,
}) => commands::self_update(target_version, token, dry_run, printer).await,
Commands::Self_(SelfNamespace {
command:
SelfCommand::Version {
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -9371,6 +9371,8 @@ uv self update [OPTIONS] [TARGET_VERSION]

<p>See <code>--project</code> to only change the project root directory.</p>

</dd><dt id="uv-self-update--dry-run"><a href="#uv-self-update--dry-run"><code>--dry-run</code></a></dt><dd><p>Run without performing the update</p>

</dd><dt id="uv-self-update--help"><a href="#uv-self-update--help"><code>--help</code></a>, <code>-h</code></dt><dd><p>Display the concise help for this command</p>

</dd><dt id="uv-self-update--managed-python"><a href="#uv-self-update--managed-python"><code>--managed-python</code></a></dt><dd><p>Require use of uv-managed Python versions.</p>
Expand Down
Loading