From 4aae07e914996c8d33fd9a21ece101cb6a54cfe7 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Thu, 15 Feb 2024 23:39:20 -0600 Subject: [PATCH] feat(pip-install): add `--dry-run` flag --- crates/uv/src/commands/pip_install.rs | 9 +++++++++ crates/uv/src/main.rs | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/crates/uv/src/commands/pip_install.rs b/crates/uv/src/commands/pip_install.rs index 54c68e5d4..8d816034c 100644 --- a/crates/uv/src/commands/pip_install.rs +++ b/crates/uv/src/commands/pip_install.rs @@ -64,6 +64,7 @@ pub(crate) async fn pip_install( exclude_newer: Option>, cache: Cache, mut printer: Printer, + dry_run: bool, ) -> Result { let start = std::time::Instant::now(); @@ -237,6 +238,14 @@ pub(crate) async fn pip_install( Err(err) => return Err(err.into()), }; + if dry_run { + println!("Would have installed:"); + for package in resolution.packages() { + println!(" {}", package); + } + return Ok(ExitStatus::Success); + } + // Re-initialize the in-flight map. let in_flight = InFlight::default(); diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 338ef7a02..818bffb87 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -591,6 +591,11 @@ struct PipInstallArgs { /// format (e.g., `2006-12-02`). #[arg(long, value_parser = date_or_datetime, hide = true)] exclude_newer: Option>, + + /// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and + /// print the resulting plan. + #[clap(long)] + dry_run: bool, } #[derive(Args)] @@ -979,6 +984,7 @@ async fn run() -> Result { args.exclude_newer, cache, printer, + args.dry_run, ) .await }