feat(pip-install): add `--dry-run` flag

This commit is contained in:
Jacob Coffee 2024-02-15 23:39:20 -06:00
parent 8ef396e849
commit 4aae07e914
No known key found for this signature in database
GPG Key ID: 62D4F8862B277A4D
2 changed files with 15 additions and 0 deletions

View File

@ -64,6 +64,7 @@ pub(crate) async fn pip_install(
exclude_newer: Option<DateTime<Utc>>,
cache: Cache,
mut printer: Printer,
dry_run: bool,
) -> Result<ExitStatus> {
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();

View File

@ -591,6 +591,11 @@ struct PipInstallArgs {
/// format (e.g., `2006-12-02`).
#[arg(long, value_parser = date_or_datetime, hide = true)]
exclude_newer: Option<DateTime<Utc>>,
/// 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<ExitStatus> {
args.exclude_newer,
cache,
printer,
args.dry_run,
)
.await
}