Use a `DryRun` enum everywhere (#11303)

## Summary

Rather than Yet Another Bool.
This commit is contained in:
Charlie Marsh 2025-02-06 19:42:49 -05:00 committed by GitHub
parent 51c05df9c9
commit 46a03b5518
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 126 additions and 85 deletions

View File

@ -0,0 +1,24 @@
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum DryRun {
/// The operation should execute in dry run mode.
Enabled,
/// The operation should execute in normal mode.
#[default]
Disabled,
}
impl DryRun {
/// Determine the [`DryRun`] setting based on the command-line arguments.
pub fn from_args(dry_run: bool) -> Self {
if dry_run {
DryRun::Enabled
} else {
DryRun::Disabled
}
}
/// Returns `true` if dry run mode is enabled.
pub const fn enabled(&self) -> bool {
matches!(self, DryRun::Enabled)
}
}

View File

@ -4,6 +4,7 @@ pub use concurrency::*;
pub use config_settings::*; pub use config_settings::*;
pub use constraints::*; pub use constraints::*;
pub use dev::*; pub use dev::*;
pub use dry_run::*;
pub use editable::*; pub use editable::*;
pub use export_format::*; pub use export_format::*;
pub use extras::*; pub use extras::*;
@ -28,6 +29,7 @@ mod concurrency;
mod config_settings; mod config_settings;
mod constraints; mod constraints;
mod dev; mod dev;
mod dry_run;
mod editable; mod editable;
mod export_format; mod export_format;
mod extras; mod extras;

View File

@ -9,7 +9,7 @@ use tracing::{debug, enabled, Level};
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, DryRun,
ExtrasSpecification, HashCheckingMode, IndexStrategy, PreviewMode, Reinstall, SourceStrategy, ExtrasSpecification, HashCheckingMode, IndexStrategy, PreviewMode, Reinstall, SourceStrategy,
TrustedHost, Upgrade, TrustedHost, Upgrade,
}; };
@ -87,7 +87,7 @@ pub(crate) async fn pip_install(
native_tls: bool, native_tls: bool,
allow_insecure_host: &[TrustedHost], allow_insecure_host: &[TrustedHost],
cache: Cache, cache: Cache,
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
preview: PreviewMode, preview: PreviewMode,
) -> anyhow::Result<ExitStatus> { ) -> anyhow::Result<ExitStatus> {
@ -247,7 +247,7 @@ pub(crate) async fn pip_install(
} }
} }
DefaultInstallLogger.on_audit(requirements.len(), start, printer)?; DefaultInstallLogger.on_audit(requirements.len(), start, printer)?;
if dry_run { if dry_run.enabled() {
writeln!(printer.stderr(), "Would make no changes")?; writeln!(printer.stderr(), "Would make no changes")?;
} }
@ -480,7 +480,7 @@ pub(crate) async fn pip_install(
operations::diagnose_resolution(resolution.diagnostics(), printer)?; operations::diagnose_resolution(resolution.diagnostics(), printer)?;
// Notify the user of any environment diagnostics. // Notify the user of any environment diagnostics.
if strict && !dry_run { if strict && !dry_run.enabled() {
operations::diagnose_environment(&resolution, &environment, &marker_env, printer)?; operations::diagnose_environment(&resolution, &environment, &marker_env, printer)?;
} }

View File

@ -13,7 +13,7 @@ use uv_tool::InstalledTools;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{BaseClientBuilder, RegistryClient}; use uv_client::{BaseClientBuilder, RegistryClient};
use uv_configuration::{ use uv_configuration::{
BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, DryRun,
ExtrasSpecification, Overrides, Reinstall, Upgrade, ExtrasSpecification, Overrides, Reinstall, Upgrade,
}; };
use uv_dispatch::BuildDispatch; use uv_dispatch::BuildDispatch;
@ -418,7 +418,7 @@ pub(crate) async fn install(
venv: &PythonEnvironment, venv: &PythonEnvironment,
logger: Box<dyn InstallLogger>, logger: Box<dyn InstallLogger>,
installer_metadata: bool, installer_metadata: bool,
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
) -> Result<Changelog, Error> { ) -> Result<Changelog, Error> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
@ -439,7 +439,7 @@ pub(crate) async fn install(
) )
.context("Failed to determine installation plan")?; .context("Failed to determine installation plan")?;
if dry_run { if dry_run.enabled() {
report_dry_run(resolution, plan, modifications, start, printer)?; report_dry_run(resolution, plan, modifications, start, printer)?;
return Ok(Changelog::default()); return Ok(Changelog::default());
} }

View File

@ -9,7 +9,7 @@ use tracing::debug;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, BuildOptions, Concurrency, ConfigSettings, Constraints, DevGroupsSpecification, DryRun,
ExtrasSpecification, HashCheckingMode, IndexStrategy, PreviewMode, Reinstall, SourceStrategy, ExtrasSpecification, HashCheckingMode, IndexStrategy, PreviewMode, Reinstall, SourceStrategy,
TrustedHost, Upgrade, TrustedHost, Upgrade,
}; };
@ -75,7 +75,7 @@ pub(crate) async fn pip_sync(
native_tls: bool, native_tls: bool,
allow_insecure_host: &[TrustedHost], allow_insecure_host: &[TrustedHost],
cache: Cache, cache: Cache,
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
preview: PreviewMode, preview: PreviewMode,
) -> Result<ExitStatus> { ) -> Result<ExitStatus> {
@ -425,7 +425,7 @@ pub(crate) async fn pip_sync(
operations::diagnose_resolution(resolution.diagnostics(), printer)?; operations::diagnose_resolution(resolution.diagnostics(), printer)?;
// Notify the user of any environment diagnostics. // Notify the user of any environment diagnostics.
if strict && !dry_run { if strict && !dry_run.enabled() {
operations::diagnose_environment(&resolution, &environment, &marker_env, printer)?; operations::diagnose_environment(&resolution, &environment, &marker_env, printer)?;
} }

View File

@ -7,7 +7,7 @@ use tracing::debug;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{BaseClientBuilder, Connectivity}; use uv_client::{BaseClientBuilder, Connectivity};
use uv_configuration::{KeyringProviderType, TrustedHost}; use uv_configuration::{DryRun, KeyringProviderType, TrustedHost};
use uv_distribution_types::{InstalledMetadata, Name, UnresolvedRequirement}; use uv_distribution_types::{InstalledMetadata, Name, UnresolvedRequirement};
use uv_fs::Simplified; use uv_fs::Simplified;
use uv_pep508::UnnamedRequirement; use uv_pep508::UnnamedRequirement;
@ -36,7 +36,7 @@ pub(crate) async fn pip_uninstall(
native_tls: bool, native_tls: bool,
keyring_provider: KeyringProviderType, keyring_provider: KeyringProviderType,
allow_insecure_host: &[TrustedHost], allow_insecure_host: &[TrustedHost],
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
) -> Result<ExitStatus> { ) -> Result<ExitStatus> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
@ -144,7 +144,7 @@ pub(crate) async fn pip_uninstall(
for package in &names { for package in &names {
let installed = site_packages.get_packages(package); let installed = site_packages.get_packages(package);
if installed.is_empty() { if installed.is_empty() {
if !dry_run { if !dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}{} Skipping {} as it is not installed", "{}{} Skipping {} as it is not installed",
@ -162,7 +162,7 @@ pub(crate) async fn pip_uninstall(
for url in &urls { for url in &urls {
let installed = site_packages.get_urls(url); let installed = site_packages.get_urls(url);
if installed.is_empty() { if installed.is_empty() {
if !dry_run { if !dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}{} Skipping {} as it is not installed", "{}{} Skipping {} as it is not installed",
@ -183,7 +183,7 @@ pub(crate) async fn pip_uninstall(
}; };
if distributions.is_empty() { if distributions.is_empty() {
if dry_run { if dry_run.enabled() {
writeln!(printer.stderr(), "Would make no changes")?; writeln!(printer.stderr(), "Would make no changes")?;
} else { } else {
writeln!( writeln!(
@ -197,7 +197,7 @@ pub(crate) async fn pip_uninstall(
} }
// Uninstall each package. // Uninstall each package.
if !dry_run { if !dry_run.enabled() {
for distribution in &distributions { for distribution in &distributions {
let summary = uv_installer::uninstall(distribution).await?; let summary = uv_installer::uninstall(distribution).await?;
debug!( debug!(
@ -213,7 +213,7 @@ pub(crate) async fn pip_uninstall(
let uninstalls = distributions.len(); let uninstalls = distributions.len();
let s = if uninstalls == 1 { "" } else { "s" }; let s = if uninstalls == 1 { "" } else { "s" };
if dry_run { if dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}", "{}",

View File

@ -16,8 +16,8 @@ use uv_cache::Cache;
use uv_cache_key::RepositoryUrl; use uv_cache_key::RepositoryUrl;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
Concurrency, Constraints, DevGroupsSpecification, DevMode, EditableMode, ExtrasSpecification, Concurrency, Constraints, DevGroupsSpecification, DevMode, DryRun, EditableMode,
InstallOptions, PreviewMode, SourceStrategy, TrustedHost, ExtrasSpecification, InstallOptions, PreviewMode, SourceStrategy, TrustedHost,
}; };
use uv_dispatch::BuildDispatch; use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase; use uv_distribution::DistributionDatabase;
@ -235,7 +235,7 @@ pub(crate) async fn add(
no_config, no_config,
active, active,
cache, cache,
false, DryRun::Disabled,
printer, printer,
) )
.await? .await?
@ -882,7 +882,7 @@ async fn lock_and_sync(
native_tls, native_tls,
allow_insecure_host, allow_insecure_host,
cache, cache,
false, DryRun::Disabled,
printer, printer,
preview, preview,
) )

View File

@ -12,8 +12,8 @@ use tracing::debug;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
Concurrency, Constraints, DevGroupsSpecification, ExtrasSpecification, PreviewMode, Reinstall, Concurrency, Constraints, DevGroupsSpecification, DryRun, ExtrasSpecification, PreviewMode,
TrustedHost, Upgrade, Reinstall, TrustedHost, Upgrade,
}; };
use uv_dispatch::BuildDispatch; use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase; use uv_distribution::DistributionDatabase;
@ -79,7 +79,7 @@ pub(crate) async fn lock(
project_dir: &Path, project_dir: &Path,
locked: bool, locked: bool,
frozen: bool, frozen: bool,
dry_run: bool, dry_run: DryRun,
python: Option<String>, python: Option<String>,
install_mirrors: PythonInstallMirrors, install_mirrors: PythonInstallMirrors,
settings: ResolverSettings, settings: ResolverSettings,
@ -146,7 +146,7 @@ pub(crate) async fn lock(
if locked { if locked {
LockMode::Locked(&interpreter) LockMode::Locked(&interpreter)
} else if dry_run { } else if dry_run.enabled() {
LockMode::DryRun(&interpreter) LockMode::DryRun(&interpreter)
} else { } else {
LockMode::Write(&interpreter) LockMode::Write(&interpreter)
@ -174,7 +174,7 @@ pub(crate) async fn lock(
.await .await
{ {
Ok(lock) => { Ok(lock) => {
if dry_run { if dry_run.enabled() {
// In `--dry-run` mode, show all changes. // In `--dry-run` mode, show all changes.
let mut changed = false; let mut changed = false;
if let LockResult::Changed(previous, lock) = &lock { if let LockResult::Changed(previous, lock) = &lock {
@ -1081,13 +1081,13 @@ impl ValidatedLock {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) enum LockEvent<'lock> { pub(crate) enum LockEvent<'lock> {
Update( Update(
bool, DryRun,
PackageName, PackageName,
BTreeSet<Option<&'lock Version>>, BTreeSet<Option<&'lock Version>>,
BTreeSet<Option<&'lock Version>>, BTreeSet<Option<&'lock Version>>,
), ),
Add(bool, PackageName, BTreeSet<Option<&'lock Version>>), Add(DryRun, PackageName, BTreeSet<Option<&'lock Version>>),
Remove(bool, PackageName, BTreeSet<Option<&'lock Version>>), Remove(DryRun, PackageName, BTreeSet<Option<&'lock Version>>),
} }
impl<'lock> LockEvent<'lock> { impl<'lock> LockEvent<'lock> {
@ -1095,7 +1095,7 @@ impl<'lock> LockEvent<'lock> {
pub(crate) fn detect_changes( pub(crate) fn detect_changes(
existing_lock: Option<&'lock Lock>, existing_lock: Option<&'lock Lock>,
new_lock: &'lock Lock, new_lock: &'lock Lock,
dry_run: bool, dry_run: DryRun,
) -> impl Iterator<Item = Self> { ) -> impl Iterator<Item = Self> {
// Identify the package-versions in the existing lockfile. // Identify the package-versions in the existing lockfile.
let mut existing_packages: FxHashMap<&PackageName, BTreeSet<Option<&Version>>> = let mut existing_packages: FxHashMap<&PackageName, BTreeSet<Option<&Version>>> =
@ -1180,7 +1180,13 @@ impl std::fmt::Display for LockEvent<'_> {
write!( write!(
f, f,
"{} {name} {existing_versions} -> {new_versions}", "{} {name} {existing_versions} -> {new_versions}",
if *dry_run { "Update" } else { "Updated" }.green().bold() if dry_run.enabled() {
"Update"
} else {
"Updated"
}
.green()
.bold()
) )
} }
Self::Add(dry_run, name, new_versions) => { Self::Add(dry_run, name, new_versions) => {
@ -1193,7 +1199,9 @@ impl std::fmt::Display for LockEvent<'_> {
write!( write!(
f, f,
"{} {name} {new_versions}", "{} {name} {new_versions}",
if *dry_run { "Add" } else { "Added" }.green().bold() if dry_run.enabled() { "Add" } else { "Added" }
.green()
.bold()
) )
} }
Self::Remove(dry_run, name, existing_versions) => { Self::Remove(dry_run, name, existing_versions) => {
@ -1206,7 +1214,13 @@ impl std::fmt::Display for LockEvent<'_> {
write!( write!(
f, f,
"{} {name} {existing_versions}", "{} {name} {existing_versions}",
if *dry_run { "Remove" } else { "Removed" }.red().bold() if dry_run.enabled() {
"Remove"
} else {
"Removed"
}
.red()
.bold()
) )
} }
} }

View File

@ -11,8 +11,8 @@ use uv_cache::Cache;
use uv_cache_key::cache_digest; use uv_cache_key::cache_digest;
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
Concurrency, Constraints, DevGroupsManifest, DevGroupsSpecification, ExtrasSpecification, Concurrency, Constraints, DevGroupsManifest, DevGroupsSpecification, DryRun,
PreviewMode, Reinstall, TrustedHost, Upgrade, ExtrasSpecification, PreviewMode, Reinstall, TrustedHost, Upgrade,
}; };
use uv_dispatch::{BuildDispatch, SharedState}; use uv_dispatch::{BuildDispatch, SharedState};
use uv_distribution::DistributionDatabase; use uv_distribution::DistributionDatabase;
@ -962,7 +962,7 @@ impl ProjectEnvironment {
no_config: bool, no_config: bool,
active: Option<bool>, active: Option<bool>,
cache: &Cache, cache: &Cache,
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
) -> Result<Self, ProjectError> { ) -> Result<Self, ProjectError> {
// Lock the project environment to avoid synchronization issues. // Lock the project environment to avoid synchronization issues.
@ -1020,7 +1020,7 @@ impl ProjectEnvironment {
}; };
// Under `--dry-run`, avoid modifying the environment. // Under `--dry-run`, avoid modifying the environment.
if dry_run { if dry_run.enabled() {
let environment = PythonEnvironment::from_interpreter(interpreter); let environment = PythonEnvironment::from_interpreter(interpreter);
return Ok(if replace { return Ok(if replace {
Self::Replaced(environment, venv) Self::Replaced(environment, venv)
@ -1508,7 +1508,7 @@ pub(crate) async fn sync_environment(
// optional on the downstream APIs. // optional on the downstream APIs.
let build_constraints = Constraints::default(); let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default(); let build_hasher = HashStrategy::default();
let dry_run = false; let dry_run = DryRun::default();
let hasher = HashStrategy::default(); let hasher = HashStrategy::default();
// Resolve the flat indexes from `--find-links`. // Resolve the flat indexes from `--find-links`.
@ -1715,7 +1715,7 @@ pub(crate) async fn update_environment(
// optional on the downstream APIs. // optional on the downstream APIs.
let build_constraints = Constraints::default(); let build_constraints = Constraints::default();
let build_hasher = HashStrategy::default(); let build_hasher = HashStrategy::default();
let dry_run = false; let dry_run = DryRun::default();
let extras = ExtrasSpecification::default(); let extras = ExtrasSpecification::default();
let groups = DevGroupsSpecification::default(); let groups = DevGroupsSpecification::default();
let hasher = HashStrategy::default(); let hasher = HashStrategy::default();

View File

@ -10,7 +10,7 @@ use tracing::debug;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::Connectivity; use uv_client::Connectivity;
use uv_configuration::{ use uv_configuration::{
Concurrency, DevGroupsSpecification, EditableMode, ExtrasSpecification, InstallOptions, Concurrency, DevGroupsSpecification, DryRun, EditableMode, ExtrasSpecification, InstallOptions,
PreviewMode, TrustedHost, PreviewMode, TrustedHost,
}; };
use uv_fs::Simplified; use uv_fs::Simplified;
@ -233,7 +233,7 @@ pub(crate) async fn remove(
no_config, no_config,
active, active,
cache, cache,
false, DryRun::Disabled,
printer, printer,
) )
.await? .await?
@ -349,7 +349,7 @@ pub(crate) async fn remove(
native_tls, native_tls,
allow_insecure_host, allow_insecure_host,
cache, cache,
false, DryRun::Disabled,
printer, printer,
preview, preview,
) )

View File

@ -17,7 +17,7 @@ use uv_cache::Cache;
use uv_cli::ExternalCommand; use uv_cli::ExternalCommand;
use uv_client::{BaseClientBuilder, Connectivity}; use uv_client::{BaseClientBuilder, Connectivity};
use uv_configuration::{ use uv_configuration::{
Concurrency, DevGroupsSpecification, EditableMode, ExtrasSpecification, InstallOptions, Concurrency, DevGroupsSpecification, DryRun, EditableMode, ExtrasSpecification, InstallOptions,
PreviewMode, SourceStrategy, TrustedHost, PreviewMode, SourceStrategy, TrustedHost,
}; };
use uv_distribution::LoweredRequirement; use uv_distribution::LoweredRequirement;
@ -652,7 +652,7 @@ pub(crate) async fn run(
no_config, no_config,
active, active,
cache, cache,
false, DryRun::Disabled,
printer, printer,
) )
.await? .await?
@ -799,7 +799,7 @@ pub(crate) async fn run(
native_tls, native_tls,
allow_insecure_host, allow_insecure_host,
cache, cache,
false, DryRun::Disabled,
printer, printer,
preview, preview,
) )

View File

@ -9,7 +9,7 @@ use owo_colors::OwoColorize;
use uv_cache::Cache; use uv_cache::Cache;
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder}; use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{ use uv_configuration::{
Concurrency, Constraints, DevGroupsManifest, DevGroupsSpecification, EditableMode, Concurrency, Constraints, DevGroupsManifest, DevGroupsSpecification, DryRun, EditableMode,
ExtrasSpecification, HashCheckingMode, InstallOptions, PreviewMode, TrustedHost, ExtrasSpecification, HashCheckingMode, InstallOptions, PreviewMode, TrustedHost,
}; };
use uv_dispatch::BuildDispatch; use uv_dispatch::BuildDispatch;
@ -49,7 +49,7 @@ pub(crate) async fn sync(
project_dir: &Path, project_dir: &Path,
locked: bool, locked: bool,
frozen: bool, frozen: bool,
dry_run: bool, dry_run: DryRun,
active: Option<bool>, active: Option<bool>,
all_packages: bool, all_packages: bool,
package: Option<PackageName>, package: Option<PackageName>,
@ -139,7 +139,7 @@ pub(crate) async fn sync(
.await? .await?
{ {
ProjectEnvironment::Existing(environment) => { ProjectEnvironment::Existing(environment) => {
if dry_run { if dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}", "{}",
@ -153,7 +153,7 @@ pub(crate) async fn sync(
environment environment
} }
ProjectEnvironment::Replaced(environment, root) => { ProjectEnvironment::Replaced(environment, root) => {
if dry_run { if dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}", "{}",
@ -167,7 +167,7 @@ pub(crate) async fn sync(
environment environment
} }
ProjectEnvironment::New(environment, root) => { ProjectEnvironment::New(environment, root) => {
if dry_run { if dry_run.enabled() {
writeln!( writeln!(
printer.stderr(), printer.stderr(),
"{}", "{}",
@ -190,7 +190,7 @@ pub(crate) async fn sync(
LockMode::Frozen LockMode::Frozen
} else if locked { } else if locked {
LockMode::Locked(environment.interpreter()) LockMode::Locked(environment.interpreter())
} else if dry_run { } else if dry_run.enabled() {
LockMode::DryRun(environment.interpreter()) LockMode::DryRun(environment.interpreter())
} else { } else {
LockMode::Write(environment.interpreter()) LockMode::Write(environment.interpreter())
@ -215,7 +215,7 @@ pub(crate) async fn sync(
.await .await
{ {
Ok(result) => { Ok(result) => {
if dry_run { if dry_run.enabled() {
match result { match result {
LockResult::Unchanged(..) => { LockResult::Unchanged(..) => {
writeln!( writeln!(
@ -364,7 +364,7 @@ pub(super) async fn do_sync(
native_tls: bool, native_tls: bool,
allow_insecure_host: &[TrustedHost], allow_insecure_host: &[TrustedHost],
cache: &Cache, cache: &Cache,
dry_run: bool, dry_run: DryRun,
printer: Printer, printer: Printer,
preview: PreviewMode, preview: PreviewMode,
) -> Result<(), ProjectError> { ) -> Result<(), ProjectError> {

View File

@ -22,10 +22,11 @@ use uv_cli::{
}; };
use uv_client::Connectivity; use uv_client::Connectivity;
use uv_configuration::{ use uv_configuration::{
BuildOptions, Concurrency, ConfigSettings, DevGroupsSpecification, EditableMode, ExportFormat, BuildOptions, Concurrency, ConfigSettings, DevGroupsSpecification, DryRun, EditableMode,
ExtrasSpecification, HashCheckingMode, IndexStrategy, InstallOptions, KeyringProviderType, ExportFormat, ExtrasSpecification, HashCheckingMode, IndexStrategy, InstallOptions,
NoBinary, NoBuild, PreviewMode, ProjectBuildBackend, Reinstall, RequiredVersion, KeyringProviderType, NoBinary, NoBuild, PreviewMode, ProjectBuildBackend, Reinstall,
SourceStrategy, TargetTriple, TrustedHost, TrustedPublishing, Upgrade, VersionControlSystem, RequiredVersion, SourceStrategy, TargetTriple, TrustedHost, TrustedPublishing, Upgrade,
VersionControlSystem,
}; };
use uv_distribution_types::{DependencyMetadata, Index, IndexLocations, IndexUrl}; use uv_distribution_types::{DependencyMetadata, Index, IndexLocations, IndexUrl};
use uv_install_wheel::LinkMode; use uv_install_wheel::LinkMode;
@ -957,7 +958,7 @@ impl PythonPinSettings {
pub(crate) struct SyncSettings { pub(crate) struct SyncSettings {
pub(crate) locked: bool, pub(crate) locked: bool,
pub(crate) frozen: bool, pub(crate) frozen: bool,
pub(crate) dry_run: bool, pub(crate) dry_run: DryRun,
pub(crate) active: Option<bool>, pub(crate) active: Option<bool>,
pub(crate) extras: ExtrasSpecification, pub(crate) extras: ExtrasSpecification,
pub(crate) dev: DevGroupsSpecification, pub(crate) dev: DevGroupsSpecification,
@ -1020,7 +1021,7 @@ impl SyncSettings {
Self { Self {
locked, locked,
frozen, frozen,
dry_run, dry_run: DryRun::from_args(dry_run),
active: flag(active, no_active), active: flag(active, no_active),
extras: ExtrasSpecification::from_args( extras: ExtrasSpecification::from_args(
flag(all_extras, no_all_extras).unwrap_or_default(), flag(all_extras, no_all_extras).unwrap_or_default(),
@ -1064,7 +1065,7 @@ impl SyncSettings {
pub(crate) struct LockSettings { pub(crate) struct LockSettings {
pub(crate) locked: bool, pub(crate) locked: bool,
pub(crate) frozen: bool, pub(crate) frozen: bool,
pub(crate) dry_run: bool, pub(crate) dry_run: DryRun,
pub(crate) script: Option<PathBuf>, pub(crate) script: Option<PathBuf>,
pub(crate) python: Option<String>, pub(crate) python: Option<String>,
pub(crate) install_mirrors: PythonInstallMirrors, pub(crate) install_mirrors: PythonInstallMirrors,
@ -1095,7 +1096,7 @@ impl LockSettings {
Self { Self {
locked: check, locked: check,
frozen: check_exists, frozen: check_exists,
dry_run, dry_run: DryRun::from_args(dry_run),
script, script,
python: python.and_then(Maybe::into_option), python: python.and_then(Maybe::into_option),
refresh: Refresh::from(refresh), refresh: Refresh::from(refresh),
@ -1679,7 +1680,7 @@ pub(crate) struct PipSyncSettings {
pub(crate) src_file: Vec<PathBuf>, pub(crate) src_file: Vec<PathBuf>,
pub(crate) constraints: Vec<PathBuf>, pub(crate) constraints: Vec<PathBuf>,
pub(crate) build_constraints: Vec<PathBuf>, pub(crate) build_constraints: Vec<PathBuf>,
pub(crate) dry_run: bool, pub(crate) dry_run: DryRun,
pub(crate) refresh: Refresh, pub(crate) refresh: Refresh,
pub(crate) settings: PipSettings, pub(crate) settings: PipSettings,
} }
@ -1728,7 +1729,7 @@ impl PipSyncSettings {
.into_iter() .into_iter()
.filter_map(Maybe::into_option) .filter_map(Maybe::into_option)
.collect(), .collect(),
dry_run, dry_run: DryRun::from_args(dry_run),
refresh: Refresh::from(refresh), refresh: Refresh::from(refresh),
settings: PipSettings::combine( settings: PipSettings::combine(
PipOptions { PipOptions {
@ -1767,7 +1768,7 @@ pub(crate) struct PipInstallSettings {
pub(crate) constraints: Vec<PathBuf>, pub(crate) constraints: Vec<PathBuf>,
pub(crate) overrides: Vec<PathBuf>, pub(crate) overrides: Vec<PathBuf>,
pub(crate) build_constraints: Vec<PathBuf>, pub(crate) build_constraints: Vec<PathBuf>,
pub(crate) dry_run: bool, pub(crate) dry_run: DryRun,
pub(crate) constraints_from_workspace: Vec<Requirement>, pub(crate) constraints_from_workspace: Vec<Requirement>,
pub(crate) overrides_from_workspace: Vec<Requirement>, pub(crate) overrides_from_workspace: Vec<Requirement>,
pub(crate) modifications: Modifications, pub(crate) modifications: Modifications,
@ -1861,7 +1862,7 @@ impl PipInstallSettings {
.into_iter() .into_iter()
.filter_map(Maybe::into_option) .filter_map(Maybe::into_option)
.collect(), .collect(),
dry_run, dry_run: DryRun::from_args(dry_run),
constraints_from_workspace, constraints_from_workspace,
overrides_from_workspace, overrides_from_workspace,
modifications: if flag(exact, inexact).unwrap_or(false) { modifications: if flag(exact, inexact).unwrap_or(false) {
@ -1902,7 +1903,7 @@ impl PipInstallSettings {
pub(crate) struct PipUninstallSettings { pub(crate) struct PipUninstallSettings {
pub(crate) package: Vec<String>, pub(crate) package: Vec<String>,
pub(crate) requirements: Vec<PathBuf>, pub(crate) requirements: Vec<PathBuf>,
pub(crate) dry_run: bool, pub(crate) dry_run: DryRun,
pub(crate) settings: PipSettings, pub(crate) settings: PipSettings,
} }
@ -1927,7 +1928,7 @@ impl PipUninstallSettings {
Self { Self {
package, package,
requirements, requirements,
dry_run, dry_run: DryRun::from_args(dry_run),
settings: PipSettings::combine( settings: PipSettings::combine(
PipOptions { PipOptions {
python: python.and_then(Maybe::into_option), python: python.and_then(Maybe::into_option),

View File

@ -5595,7 +5595,7 @@ fn verify_hashes() -> anyhow::Result<()> {
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
.arg("-r") .arg("-r")
.arg("requirements.in") .arg("requirements.in")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -5634,7 +5634,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -5730,14 +5730,14 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
.arg("-r") .arg("-r")
.arg("requirements.in") .arg("requirements.in")
.arg("--no-verify-hashes") .arg("--no-verify-hashes")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -5776,7 +5776,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -5870,14 +5870,14 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
.arg("-r") .arg("-r")
.arg("requirements.in") .arg("requirements.in")
.arg("--require-hashes") .arg("--require-hashes")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -5916,7 +5916,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -6012,14 +6012,14 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
.arg("-r") .arg("-r")
.arg("requirements.in") .arg("requirements.in")
.arg("--no-require-hashes") .arg("--no-require-hashes")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -6058,7 +6058,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -6152,14 +6152,14 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
.arg("-r") .arg("-r")
.arg("requirements.in") .arg("requirements.in")
.env(EnvVars::UV_NO_VERIFY_HASHES, "1") .env(EnvVars::UV_NO_VERIFY_HASHES, "1")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -6198,7 +6198,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -6292,7 +6292,7 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path()) uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
@ -6300,7 +6300,7 @@ fn verify_hashes() -> anyhow::Result<()> {
.arg("requirements.in") .arg("requirements.in")
.arg("--verify-hashes") .arg("--verify-hashes")
.arg("--no-require-hashes") .arg("--no-require-hashes")
.arg("--show-settings"), @r#" .arg("--show-settings"), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -6339,7 +6339,7 @@ fn verify_hashes() -> anyhow::Result<()> {
constraints: [], constraints: [],
overrides: [], overrides: [],
build_constraints: [], build_constraints: [],
dry_run: false, dry_run: Disabled,
constraints_from_workspace: [], constraints_from_workspace: [],
overrides_from_workspace: [], overrides_from_workspace: [],
modifications: Sufficient, modifications: Sufficient,
@ -6435,7 +6435,7 @@ fn verify_hashes() -> anyhow::Result<()> {
} }
----- stderr ----- ----- stderr -----
"# "###
); );
Ok(()) Ok(())