From cf830288f3c75d2471ec7fa8abadbafaabbcfee0 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 12 Jun 2024 13:35:41 -0700 Subject: [PATCH] Rename some internal settings structs (#4288) ## Summary In preparation for future refactors. --- crates/uv/src/main.rs | 200 +++++++++++++++++++------------------- crates/uv/src/settings.rs | 99 +++++-------------- 2 files changed, 123 insertions(+), 176 deletions(-) diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 0fc946654..fbfefa0b9 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -189,7 +189,7 @@ async fn run() -> Result { // Resolve the settings from the command-line arguments and workspace configuration. let args = PipCompileSettings::resolve(args, workspace); rayon::ThreadPoolBuilder::new() - .num_threads(args.shared.concurrency.installs) + .num_threads(args.pip.concurrency.installs) .build_global() .expect("failed to initialize global rayon pool"); @@ -217,38 +217,38 @@ async fn run() -> Result { &constraints, &overrides, args.overrides_from_workspace, - args.shared.extras, - args.shared.output_file.as_deref(), - args.shared.resolution, - args.shared.prerelease, - args.shared.dependency_mode, + args.pip.extras, + args.pip.output_file.as_deref(), + args.pip.resolution, + args.pip.prerelease, + args.pip.dependency_mode, args.upgrade, - args.shared.generate_hashes, - args.shared.no_emit_package, - args.shared.no_strip_extras, - !args.shared.no_annotate, - !args.shared.no_header, - args.shared.custom_compile_command, - args.shared.emit_index_url, - args.shared.emit_find_links, - args.shared.emit_marker_expression, - args.shared.emit_index_annotation, - args.shared.index_locations, - args.shared.index_strategy, - args.shared.keyring_provider, - args.shared.setup_py, - args.shared.config_setting, + args.pip.generate_hashes, + args.pip.no_emit_package, + args.pip.no_strip_extras, + !args.pip.no_annotate, + !args.pip.no_header, + args.pip.custom_compile_command, + args.pip.emit_index_url, + args.pip.emit_find_links, + args.pip.emit_marker_expression, + args.pip.emit_index_annotation, + args.pip.index_locations, + args.pip.index_strategy, + args.pip.keyring_provider, + args.pip.setup_py, + args.pip.config_setting, globals.connectivity, - args.shared.no_build_isolation, - args.shared.no_build, - args.shared.python_version, - args.shared.python_platform, - args.shared.exclude_newer, - args.shared.annotation_style, - args.shared.link_mode, - args.shared.python, - args.shared.system, - args.shared.concurrency, + args.pip.no_build_isolation, + args.pip.no_build, + args.pip.python_version, + args.pip.python_platform, + args.pip.exclude_newer, + args.pip.annotation_style, + args.pip.link_mode, + args.pip.python, + args.pip.system, + args.pip.concurrency, globals.native_tls, globals.quiet, globals.preview, @@ -265,7 +265,7 @@ async fn run() -> Result { // Resolve the settings from the command-line arguments and workspace configuration. let args = PipSyncSettings::resolve(args, workspace); rayon::ThreadPoolBuilder::new() - .num_threads(args.shared.concurrency.installs) + .num_threads(args.pip.concurrency.installs) .build_global() .expect("failed to initialize global rayon pool"); @@ -287,28 +287,28 @@ async fn run() -> Result { &requirements, &constraints, &args.reinstall, - args.shared.link_mode, - args.shared.compile_bytecode, - args.shared.require_hashes, - args.shared.index_locations, - args.shared.index_strategy, - args.shared.keyring_provider, - args.shared.setup_py, + args.pip.link_mode, + args.pip.compile_bytecode, + args.pip.require_hashes, + args.pip.index_locations, + args.pip.index_strategy, + args.pip.keyring_provider, + args.pip.setup_py, globals.connectivity, - &args.shared.config_setting, - args.shared.no_build_isolation, - args.shared.no_build, - args.shared.no_binary, - args.shared.python_version, - args.shared.python_platform, - args.shared.strict, - args.shared.exclude_newer, - args.shared.python, - args.shared.system, - args.shared.break_system_packages, - args.shared.target, - args.shared.prefix, - args.shared.concurrency, + &args.pip.config_setting, + args.pip.no_build_isolation, + args.pip.no_build, + args.pip.no_binary, + args.pip.python_version, + args.pip.python_platform, + args.pip.strict, + args.pip.exclude_newer, + args.pip.python, + args.pip.system, + args.pip.break_system_packages, + args.pip.target, + args.pip.prefix, + args.pip.concurrency, globals.native_tls, globals.preview, cache, @@ -325,7 +325,7 @@ async fn run() -> Result { // Resolve the settings from the command-line arguments and workspace configuration. let args = PipInstallSettings::resolve(args, workspace); rayon::ThreadPoolBuilder::new() - .num_threads(args.shared.concurrency.installs) + .num_threads(args.pip.concurrency.installs) .build_global() .expect("failed to initialize global rayon pool"); @@ -358,34 +358,34 @@ async fn run() -> Result { &constraints, &overrides, args.overrides_from_workspace, - &args.shared.extras, - args.shared.resolution, - args.shared.prerelease, - args.shared.dependency_mode, + &args.pip.extras, + args.pip.resolution, + args.pip.prerelease, + args.pip.dependency_mode, args.upgrade, - args.shared.index_locations, - args.shared.index_strategy, - args.shared.keyring_provider, + args.pip.index_locations, + args.pip.index_strategy, + args.pip.keyring_provider, args.reinstall, - args.shared.link_mode, - args.shared.compile_bytecode, - args.shared.require_hashes, - args.shared.setup_py, + args.pip.link_mode, + args.pip.compile_bytecode, + args.pip.require_hashes, + args.pip.setup_py, globals.connectivity, - &args.shared.config_setting, - args.shared.no_build_isolation, - args.shared.no_build, - args.shared.no_binary, - args.shared.python_version, - args.shared.python_platform, - args.shared.strict, - args.shared.exclude_newer, - args.shared.python, - args.shared.system, - args.shared.break_system_packages, - args.shared.target, - args.shared.prefix, - args.shared.concurrency, + &args.pip.config_setting, + args.pip.no_build_isolation, + args.pip.no_build, + args.pip.no_binary, + args.pip.python_version, + args.pip.python_platform, + args.pip.strict, + args.pip.exclude_newer, + args.pip.python, + args.pip.system, + args.pip.break_system_packages, + args.pip.target, + args.pip.prefix, + args.pip.concurrency, globals.native_tls, globals.preview, cache, @@ -415,16 +415,16 @@ async fn run() -> Result { .collect::>(); commands::pip_uninstall( &sources, - args.shared.python, - args.shared.system, - args.shared.break_system_packages, - args.shared.target, - args.shared.prefix, + args.pip.python, + args.pip.system, + args.pip.break_system_packages, + args.pip.target, + args.pip.prefix, cache, globals.connectivity, globals.native_tls, globals.preview, - args.shared.keyring_provider, + args.pip.keyring_provider, printer, ) .await @@ -440,9 +440,9 @@ async fn run() -> Result { commands::pip_freeze( args.exclude_editable, - args.shared.strict, - args.shared.python.as_deref(), - args.shared.system, + args.pip.strict, + args.pip.python.as_deref(), + args.pip.system, globals.preview, &cache, printer, @@ -464,9 +464,9 @@ async fn run() -> Result { args.exclude_editable, &args.exclude, &args.format, - args.shared.strict, - args.shared.python.as_deref(), - args.shared.system, + args.pip.strict, + args.pip.python.as_deref(), + args.pip.system, globals.preview, &cache, printer, @@ -483,9 +483,9 @@ async fn run() -> Result { commands::pip_show( args.package, - args.shared.strict, - args.shared.python.as_deref(), - args.shared.system, + args.pip.strict, + args.pip.python.as_deref(), + args.pip.system, globals.preview, &cache, printer, @@ -541,17 +541,17 @@ async fn run() -> Result { commands::venv( &args.name, - args.shared.python.as_deref(), - args.shared.link_mode, - &args.shared.index_locations, - args.shared.index_strategy, - args.shared.keyring_provider, + args.pip.python.as_deref(), + args.pip.link_mode, + &args.pip.index_locations, + args.pip.index_strategy, + args.pip.keyring_provider, uv_virtualenv::Prompt::from_args(prompt), args.system_site_packages, globals.connectivity, args.seed, args.allow_existing, - args.shared.exclude_newer, + args.pip.exclude_newer, globals.native_tls, globals.preview, &cache, diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 7449d5088..01c542e1b 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -387,16 +387,12 @@ impl RemoveSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipCompileSettings { - // CLI-only settings. pub(crate) src_file: Vec, pub(crate) constraint: Vec, pub(crate) r#override: Vec, pub(crate) refresh: Refresh, pub(crate) upgrade: Upgrade, - - // Shared settings. - pub(crate) shared: PipSharedSettings, - // Override dependencies from workspace. + pub(crate) pip: PipSettings, pub(crate) overrides_from_workspace: Vec, } @@ -462,7 +458,7 @@ impl PipCompileSettings { compat_args: _, } = args; - let overrides_from_workspace: Vec = if let Some(workspace) = &workspace { + let overrides_from_workspace = if let Some(workspace) = &workspace { workspace .options .override_dependencies @@ -478,7 +474,6 @@ impl PipCompileSettings { }; Self { - // CLI-only settings. src_file, constraint: constraint .into_iter() @@ -488,9 +483,7 @@ impl PipCompileSettings { refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package), overrides_from_workspace, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -552,15 +545,12 @@ impl PipCompileSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipSyncSettings { - // CLI-only settings. pub(crate) src_file: Vec, pub(crate) constraint: Vec, pub(crate) reinstall: Reinstall, pub(crate) refresh: Refresh, pub(crate) dry_run: bool, - - // Shared settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipSyncSettings { @@ -609,7 +599,6 @@ impl PipSyncSettings { } = args; Self { - // CLI-only settings. src_file, constraint: constraint .into_iter() @@ -618,9 +607,7 @@ impl PipSyncSettings { reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package), refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), dry_run, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -668,7 +655,6 @@ impl PipSyncSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipInstallSettings { - // CLI-only settings. pub(crate) package: Vec, pub(crate) requirement: Vec, pub(crate) editable: Vec, @@ -679,9 +665,7 @@ pub(crate) struct PipInstallSettings { pub(crate) refresh: Refresh, pub(crate) dry_run: bool, pub(crate) overrides_from_workspace: Vec, - - // Shared settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipInstallSettings { @@ -743,7 +727,7 @@ impl PipInstallSettings { compat_args: _, } = args; - let overrides_from_workspace: Vec = if let Some(workspace) = &workspace { + let overrides_from_workspace = if let Some(workspace) = &workspace { workspace .options .override_dependencies @@ -759,7 +743,6 @@ impl PipInstallSettings { }; Self { - // CLI-only settings. package, requirement, editable, @@ -773,9 +756,7 @@ impl PipInstallSettings { refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), dry_run, overrides_from_workspace, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -832,11 +813,9 @@ impl PipInstallSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipUninstallSettings { - // CLI-only settings. pub(crate) package: Vec, pub(crate) requirement: Vec, - // Shared settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipUninstallSettings { @@ -856,12 +835,9 @@ impl PipUninstallSettings { } = args; Self { - // CLI-only settings. package, requirement, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -881,10 +857,8 @@ impl PipUninstallSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipFreezeSettings { - // CLI-only settings. pub(crate) exclude_editable: bool, - // Shared settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipFreezeSettings { @@ -900,11 +874,8 @@ impl PipFreezeSettings { } = args; Self { - // CLI-only settings. exclude_editable, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -921,14 +892,11 @@ impl PipFreezeSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipListSettings { - // CLI-only settings. pub(crate) editable: bool, pub(crate) exclude_editable: bool, pub(crate) exclude: Vec, pub(crate) format: ListFormat, - - // CLI-only settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipListSettings { @@ -948,14 +916,11 @@ impl PipListSettings { } = args; Self { - // CLI-only settings. editable, exclude_editable, exclude, format, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -972,11 +937,8 @@ impl PipListSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipShowSettings { - // CLI-only settings. pub(crate) package: Vec, - - // CLI-only settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl PipShowSettings { @@ -992,11 +954,8 @@ impl PipShowSettings { } = args; Self { - // CLI-only settings. package, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -1013,10 +972,7 @@ impl PipShowSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct PipCheckSettings { - // CLI-only settings. - - // Shared settings. - pub(crate) shared: PipSharedSettings, + pub(crate) shared: PipSettings, } impl PipCheckSettings { @@ -1029,8 +985,7 @@ impl PipCheckSettings { } = args; Self { - // Shared settings. - shared: PipSharedSettings::combine( + shared: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -1046,15 +1001,12 @@ impl PipCheckSettings { #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] pub(crate) struct VenvSettings { - // CLI-only settings. pub(crate) seed: bool, pub(crate) allow_existing: bool, pub(crate) name: PathBuf, pub(crate) prompt: Option, pub(crate) system_site_packages: bool, - - // CLI-only settings. - pub(crate) shared: PipSharedSettings, + pub(crate) pip: PipSettings, } impl VenvSettings { @@ -1075,21 +1027,17 @@ impl VenvSettings { no_index, index_strategy, keyring_provider, - exclude_newer, compat_args: _, } = args; Self { - // CLI-only settings. seed, allow_existing, name, prompt, system_site_packages, - - // Shared settings. - shared: PipSharedSettings::combine( + pip: PipSettings::combine( PipOptions { python, system: flag(system, no_system), @@ -1118,7 +1066,7 @@ impl VenvSettings { /// Represents the shared settings that are used across all `pip` commands. #[allow(clippy::struct_excessive_bools)] #[derive(Debug, Clone)] -pub(crate) struct PipSharedSettings { +pub(crate) struct PipSettings { pub(crate) index_locations: IndexLocations, pub(crate) python: Option, pub(crate) system: bool, @@ -1158,8 +1106,8 @@ pub(crate) struct PipSharedSettings { pub(crate) concurrency: Concurrency, } -impl PipSharedSettings { - /// Resolve the [`PipSharedSettings`] from the CLI and workspace configuration. +impl PipSettings { + /// Resolve the [`PipSettings`] from the CLI and workspace configuration. pub(crate) fn combine(args: PipOptions, workspace: Option) -> Self { let PipOptions { python, @@ -1363,7 +1311,6 @@ where Err(VarError::NotPresent) => return None, Err(VarError::NotUnicode(_)) => parse_failure(name, expected), }; - Some( val.parse() .unwrap_or_else(|_| parse_failure(name, expected)),