Rename some internal settings structs (#4288)

## Summary

In preparation for future refactors.
This commit is contained in:
Charlie Marsh 2024-06-12 13:35:41 -07:00 committed by GitHub
parent d8f1de6134
commit cf830288f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 123 additions and 176 deletions

View File

@ -189,7 +189,7 @@ async fn run() -> Result<ExitStatus> {
// Resolve the settings from the command-line arguments and workspace configuration. // Resolve the settings from the command-line arguments and workspace configuration.
let args = PipCompileSettings::resolve(args, workspace); let args = PipCompileSettings::resolve(args, workspace);
rayon::ThreadPoolBuilder::new() rayon::ThreadPoolBuilder::new()
.num_threads(args.shared.concurrency.installs) .num_threads(args.pip.concurrency.installs)
.build_global() .build_global()
.expect("failed to initialize global rayon pool"); .expect("failed to initialize global rayon pool");
@ -217,38 +217,38 @@ async fn run() -> Result<ExitStatus> {
&constraints, &constraints,
&overrides, &overrides,
args.overrides_from_workspace, args.overrides_from_workspace,
args.shared.extras, args.pip.extras,
args.shared.output_file.as_deref(), args.pip.output_file.as_deref(),
args.shared.resolution, args.pip.resolution,
args.shared.prerelease, args.pip.prerelease,
args.shared.dependency_mode, args.pip.dependency_mode,
args.upgrade, args.upgrade,
args.shared.generate_hashes, args.pip.generate_hashes,
args.shared.no_emit_package, args.pip.no_emit_package,
args.shared.no_strip_extras, args.pip.no_strip_extras,
!args.shared.no_annotate, !args.pip.no_annotate,
!args.shared.no_header, !args.pip.no_header,
args.shared.custom_compile_command, args.pip.custom_compile_command,
args.shared.emit_index_url, args.pip.emit_index_url,
args.shared.emit_find_links, args.pip.emit_find_links,
args.shared.emit_marker_expression, args.pip.emit_marker_expression,
args.shared.emit_index_annotation, args.pip.emit_index_annotation,
args.shared.index_locations, args.pip.index_locations,
args.shared.index_strategy, args.pip.index_strategy,
args.shared.keyring_provider, args.pip.keyring_provider,
args.shared.setup_py, args.pip.setup_py,
args.shared.config_setting, args.pip.config_setting,
globals.connectivity, globals.connectivity,
args.shared.no_build_isolation, args.pip.no_build_isolation,
args.shared.no_build, args.pip.no_build,
args.shared.python_version, args.pip.python_version,
args.shared.python_platform, args.pip.python_platform,
args.shared.exclude_newer, args.pip.exclude_newer,
args.shared.annotation_style, args.pip.annotation_style,
args.shared.link_mode, args.pip.link_mode,
args.shared.python, args.pip.python,
args.shared.system, args.pip.system,
args.shared.concurrency, args.pip.concurrency,
globals.native_tls, globals.native_tls,
globals.quiet, globals.quiet,
globals.preview, globals.preview,
@ -265,7 +265,7 @@ async fn run() -> Result<ExitStatus> {
// Resolve the settings from the command-line arguments and workspace configuration. // Resolve the settings from the command-line arguments and workspace configuration.
let args = PipSyncSettings::resolve(args, workspace); let args = PipSyncSettings::resolve(args, workspace);
rayon::ThreadPoolBuilder::new() rayon::ThreadPoolBuilder::new()
.num_threads(args.shared.concurrency.installs) .num_threads(args.pip.concurrency.installs)
.build_global() .build_global()
.expect("failed to initialize global rayon pool"); .expect("failed to initialize global rayon pool");
@ -287,28 +287,28 @@ async fn run() -> Result<ExitStatus> {
&requirements, &requirements,
&constraints, &constraints,
&args.reinstall, &args.reinstall,
args.shared.link_mode, args.pip.link_mode,
args.shared.compile_bytecode, args.pip.compile_bytecode,
args.shared.require_hashes, args.pip.require_hashes,
args.shared.index_locations, args.pip.index_locations,
args.shared.index_strategy, args.pip.index_strategy,
args.shared.keyring_provider, args.pip.keyring_provider,
args.shared.setup_py, args.pip.setup_py,
globals.connectivity, globals.connectivity,
&args.shared.config_setting, &args.pip.config_setting,
args.shared.no_build_isolation, args.pip.no_build_isolation,
args.shared.no_build, args.pip.no_build,
args.shared.no_binary, args.pip.no_binary,
args.shared.python_version, args.pip.python_version,
args.shared.python_platform, args.pip.python_platform,
args.shared.strict, args.pip.strict,
args.shared.exclude_newer, args.pip.exclude_newer,
args.shared.python, args.pip.python,
args.shared.system, args.pip.system,
args.shared.break_system_packages, args.pip.break_system_packages,
args.shared.target, args.pip.target,
args.shared.prefix, args.pip.prefix,
args.shared.concurrency, args.pip.concurrency,
globals.native_tls, globals.native_tls,
globals.preview, globals.preview,
cache, cache,
@ -325,7 +325,7 @@ async fn run() -> Result<ExitStatus> {
// Resolve the settings from the command-line arguments and workspace configuration. // Resolve the settings from the command-line arguments and workspace configuration.
let args = PipInstallSettings::resolve(args, workspace); let args = PipInstallSettings::resolve(args, workspace);
rayon::ThreadPoolBuilder::new() rayon::ThreadPoolBuilder::new()
.num_threads(args.shared.concurrency.installs) .num_threads(args.pip.concurrency.installs)
.build_global() .build_global()
.expect("failed to initialize global rayon pool"); .expect("failed to initialize global rayon pool");
@ -358,34 +358,34 @@ async fn run() -> Result<ExitStatus> {
&constraints, &constraints,
&overrides, &overrides,
args.overrides_from_workspace, args.overrides_from_workspace,
&args.shared.extras, &args.pip.extras,
args.shared.resolution, args.pip.resolution,
args.shared.prerelease, args.pip.prerelease,
args.shared.dependency_mode, args.pip.dependency_mode,
args.upgrade, args.upgrade,
args.shared.index_locations, args.pip.index_locations,
args.shared.index_strategy, args.pip.index_strategy,
args.shared.keyring_provider, args.pip.keyring_provider,
args.reinstall, args.reinstall,
args.shared.link_mode, args.pip.link_mode,
args.shared.compile_bytecode, args.pip.compile_bytecode,
args.shared.require_hashes, args.pip.require_hashes,
args.shared.setup_py, args.pip.setup_py,
globals.connectivity, globals.connectivity,
&args.shared.config_setting, &args.pip.config_setting,
args.shared.no_build_isolation, args.pip.no_build_isolation,
args.shared.no_build, args.pip.no_build,
args.shared.no_binary, args.pip.no_binary,
args.shared.python_version, args.pip.python_version,
args.shared.python_platform, args.pip.python_platform,
args.shared.strict, args.pip.strict,
args.shared.exclude_newer, args.pip.exclude_newer,
args.shared.python, args.pip.python,
args.shared.system, args.pip.system,
args.shared.break_system_packages, args.pip.break_system_packages,
args.shared.target, args.pip.target,
args.shared.prefix, args.pip.prefix,
args.shared.concurrency, args.pip.concurrency,
globals.native_tls, globals.native_tls,
globals.preview, globals.preview,
cache, cache,
@ -415,16 +415,16 @@ async fn run() -> Result<ExitStatus> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
commands::pip_uninstall( commands::pip_uninstall(
&sources, &sources,
args.shared.python, args.pip.python,
args.shared.system, args.pip.system,
args.shared.break_system_packages, args.pip.break_system_packages,
args.shared.target, args.pip.target,
args.shared.prefix, args.pip.prefix,
cache, cache,
globals.connectivity, globals.connectivity,
globals.native_tls, globals.native_tls,
globals.preview, globals.preview,
args.shared.keyring_provider, args.pip.keyring_provider,
printer, printer,
) )
.await .await
@ -440,9 +440,9 @@ async fn run() -> Result<ExitStatus> {
commands::pip_freeze( commands::pip_freeze(
args.exclude_editable, args.exclude_editable,
args.shared.strict, args.pip.strict,
args.shared.python.as_deref(), args.pip.python.as_deref(),
args.shared.system, args.pip.system,
globals.preview, globals.preview,
&cache, &cache,
printer, printer,
@ -464,9 +464,9 @@ async fn run() -> Result<ExitStatus> {
args.exclude_editable, args.exclude_editable,
&args.exclude, &args.exclude,
&args.format, &args.format,
args.shared.strict, args.pip.strict,
args.shared.python.as_deref(), args.pip.python.as_deref(),
args.shared.system, args.pip.system,
globals.preview, globals.preview,
&cache, &cache,
printer, printer,
@ -483,9 +483,9 @@ async fn run() -> Result<ExitStatus> {
commands::pip_show( commands::pip_show(
args.package, args.package,
args.shared.strict, args.pip.strict,
args.shared.python.as_deref(), args.pip.python.as_deref(),
args.shared.system, args.pip.system,
globals.preview, globals.preview,
&cache, &cache,
printer, printer,
@ -541,17 +541,17 @@ async fn run() -> Result<ExitStatus> {
commands::venv( commands::venv(
&args.name, &args.name,
args.shared.python.as_deref(), args.pip.python.as_deref(),
args.shared.link_mode, args.pip.link_mode,
&args.shared.index_locations, &args.pip.index_locations,
args.shared.index_strategy, args.pip.index_strategy,
args.shared.keyring_provider, args.pip.keyring_provider,
uv_virtualenv::Prompt::from_args(prompt), uv_virtualenv::Prompt::from_args(prompt),
args.system_site_packages, args.system_site_packages,
globals.connectivity, globals.connectivity,
args.seed, args.seed,
args.allow_existing, args.allow_existing,
args.shared.exclude_newer, args.pip.exclude_newer,
globals.native_tls, globals.native_tls,
globals.preview, globals.preview,
&cache, &cache,

View File

@ -387,16 +387,12 @@ impl RemoveSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipCompileSettings { pub(crate) struct PipCompileSettings {
// CLI-only settings.
pub(crate) src_file: Vec<PathBuf>, pub(crate) src_file: Vec<PathBuf>,
pub(crate) constraint: Vec<PathBuf>, pub(crate) constraint: Vec<PathBuf>,
pub(crate) r#override: Vec<PathBuf>, pub(crate) r#override: Vec<PathBuf>,
pub(crate) refresh: Refresh, pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade, pub(crate) upgrade: Upgrade,
pub(crate) pip: PipSettings,
// Shared settings.
pub(crate) shared: PipSharedSettings,
// Override dependencies from workspace.
pub(crate) overrides_from_workspace: Vec<Requirement>, pub(crate) overrides_from_workspace: Vec<Requirement>,
} }
@ -462,7 +458,7 @@ impl PipCompileSettings {
compat_args: _, compat_args: _,
} = args; } = args;
let overrides_from_workspace: Vec<Requirement> = if let Some(workspace) = &workspace { let overrides_from_workspace = if let Some(workspace) = &workspace {
workspace workspace
.options .options
.override_dependencies .override_dependencies
@ -478,7 +474,6 @@ impl PipCompileSettings {
}; };
Self { Self {
// CLI-only settings.
src_file, src_file,
constraint: constraint constraint: constraint
.into_iter() .into_iter()
@ -488,9 +483,7 @@ impl PipCompileSettings {
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package), upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
overrides_from_workspace, overrides_from_workspace,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -552,15 +545,12 @@ impl PipCompileSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipSyncSettings { pub(crate) struct PipSyncSettings {
// CLI-only settings.
pub(crate) src_file: Vec<PathBuf>, pub(crate) src_file: Vec<PathBuf>,
pub(crate) constraint: Vec<PathBuf>, pub(crate) constraint: Vec<PathBuf>,
pub(crate) reinstall: Reinstall, pub(crate) reinstall: Reinstall,
pub(crate) refresh: Refresh, pub(crate) refresh: Refresh,
pub(crate) dry_run: bool, pub(crate) dry_run: bool,
pub(crate) pip: PipSettings,
// Shared settings.
pub(crate) shared: PipSharedSettings,
} }
impl PipSyncSettings { impl PipSyncSettings {
@ -609,7 +599,6 @@ impl PipSyncSettings {
} = args; } = args;
Self { Self {
// CLI-only settings.
src_file, src_file,
constraint: constraint constraint: constraint
.into_iter() .into_iter()
@ -618,9 +607,7 @@ impl PipSyncSettings {
reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package), reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package),
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
dry_run, dry_run,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -668,7 +655,6 @@ impl PipSyncSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipInstallSettings { pub(crate) struct PipInstallSettings {
// CLI-only settings.
pub(crate) package: Vec<String>, pub(crate) package: Vec<String>,
pub(crate) requirement: Vec<PathBuf>, pub(crate) requirement: Vec<PathBuf>,
pub(crate) editable: Vec<String>, pub(crate) editable: Vec<String>,
@ -679,9 +665,7 @@ pub(crate) struct PipInstallSettings {
pub(crate) refresh: Refresh, pub(crate) refresh: Refresh,
pub(crate) dry_run: bool, pub(crate) dry_run: bool,
pub(crate) overrides_from_workspace: Vec<Requirement>, pub(crate) overrides_from_workspace: Vec<Requirement>,
pub(crate) pip: PipSettings,
// Shared settings.
pub(crate) shared: PipSharedSettings,
} }
impl PipInstallSettings { impl PipInstallSettings {
@ -743,7 +727,7 @@ impl PipInstallSettings {
compat_args: _, compat_args: _,
} = args; } = args;
let overrides_from_workspace: Vec<Requirement> = if let Some(workspace) = &workspace { let overrides_from_workspace = if let Some(workspace) = &workspace {
workspace workspace
.options .options
.override_dependencies .override_dependencies
@ -759,7 +743,6 @@ impl PipInstallSettings {
}; };
Self { Self {
// CLI-only settings.
package, package,
requirement, requirement,
editable, editable,
@ -773,9 +756,7 @@ impl PipInstallSettings {
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package), refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
dry_run, dry_run,
overrides_from_workspace, overrides_from_workspace,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -832,11 +813,9 @@ impl PipInstallSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipUninstallSettings { pub(crate) struct PipUninstallSettings {
// CLI-only settings.
pub(crate) package: Vec<String>, pub(crate) package: Vec<String>,
pub(crate) requirement: Vec<PathBuf>, pub(crate) requirement: Vec<PathBuf>,
// Shared settings. pub(crate) pip: PipSettings,
pub(crate) shared: PipSharedSettings,
} }
impl PipUninstallSettings { impl PipUninstallSettings {
@ -856,12 +835,9 @@ impl PipUninstallSettings {
} = args; } = args;
Self { Self {
// CLI-only settings.
package, package,
requirement, requirement,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -881,10 +857,8 @@ impl PipUninstallSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipFreezeSettings { pub(crate) struct PipFreezeSettings {
// CLI-only settings.
pub(crate) exclude_editable: bool, pub(crate) exclude_editable: bool,
// Shared settings. pub(crate) pip: PipSettings,
pub(crate) shared: PipSharedSettings,
} }
impl PipFreezeSettings { impl PipFreezeSettings {
@ -900,11 +874,8 @@ impl PipFreezeSettings {
} = args; } = args;
Self { Self {
// CLI-only settings.
exclude_editable, exclude_editable,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -921,14 +892,11 @@ impl PipFreezeSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipListSettings { pub(crate) struct PipListSettings {
// CLI-only settings.
pub(crate) editable: bool, pub(crate) editable: bool,
pub(crate) exclude_editable: bool, pub(crate) exclude_editable: bool,
pub(crate) exclude: Vec<PackageName>, pub(crate) exclude: Vec<PackageName>,
pub(crate) format: ListFormat, pub(crate) format: ListFormat,
pub(crate) pip: PipSettings,
// CLI-only settings.
pub(crate) shared: PipSharedSettings,
} }
impl PipListSettings { impl PipListSettings {
@ -948,14 +916,11 @@ impl PipListSettings {
} = args; } = args;
Self { Self {
// CLI-only settings.
editable, editable,
exclude_editable, exclude_editable,
exclude, exclude,
format, format,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -972,11 +937,8 @@ impl PipListSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipShowSettings { pub(crate) struct PipShowSettings {
// CLI-only settings.
pub(crate) package: Vec<PackageName>, pub(crate) package: Vec<PackageName>,
pub(crate) pip: PipSettings,
// CLI-only settings.
pub(crate) shared: PipSharedSettings,
} }
impl PipShowSettings { impl PipShowSettings {
@ -992,11 +954,8 @@ impl PipShowSettings {
} = args; } = args;
Self { Self {
// CLI-only settings.
package, package,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -1013,10 +972,7 @@ impl PipShowSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipCheckSettings { pub(crate) struct PipCheckSettings {
// CLI-only settings. pub(crate) shared: PipSettings,
// Shared settings.
pub(crate) shared: PipSharedSettings,
} }
impl PipCheckSettings { impl PipCheckSettings {
@ -1029,8 +985,7 @@ impl PipCheckSettings {
} = args; } = args;
Self { Self {
// Shared settings. shared: PipSettings::combine(
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -1046,15 +1001,12 @@ impl PipCheckSettings {
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct VenvSettings { pub(crate) struct VenvSettings {
// CLI-only settings.
pub(crate) seed: bool, pub(crate) seed: bool,
pub(crate) allow_existing: bool, pub(crate) allow_existing: bool,
pub(crate) name: PathBuf, pub(crate) name: PathBuf,
pub(crate) prompt: Option<String>, pub(crate) prompt: Option<String>,
pub(crate) system_site_packages: bool, pub(crate) system_site_packages: bool,
pub(crate) pip: PipSettings,
// CLI-only settings.
pub(crate) shared: PipSharedSettings,
} }
impl VenvSettings { impl VenvSettings {
@ -1075,21 +1027,17 @@ impl VenvSettings {
no_index, no_index,
index_strategy, index_strategy,
keyring_provider, keyring_provider,
exclude_newer, exclude_newer,
compat_args: _, compat_args: _,
} = args; } = args;
Self { Self {
// CLI-only settings.
seed, seed,
allow_existing, allow_existing,
name, name,
prompt, prompt,
system_site_packages, system_site_packages,
pip: PipSettings::combine(
// Shared settings.
shared: PipSharedSettings::combine(
PipOptions { PipOptions {
python, python,
system: flag(system, no_system), system: flag(system, no_system),
@ -1118,7 +1066,7 @@ impl VenvSettings {
/// Represents the shared settings that are used across all `pip` commands. /// Represents the shared settings that are used across all `pip` commands.
#[allow(clippy::struct_excessive_bools)] #[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipSharedSettings { pub(crate) struct PipSettings {
pub(crate) index_locations: IndexLocations, pub(crate) index_locations: IndexLocations,
pub(crate) python: Option<String>, pub(crate) python: Option<String>,
pub(crate) system: bool, pub(crate) system: bool,
@ -1158,8 +1106,8 @@ pub(crate) struct PipSharedSettings {
pub(crate) concurrency: Concurrency, pub(crate) concurrency: Concurrency,
} }
impl PipSharedSettings { impl PipSettings {
/// Resolve the [`PipSharedSettings`] from the CLI and workspace configuration. /// Resolve the [`PipSettings`] from the CLI and workspace configuration.
pub(crate) fn combine(args: PipOptions, workspace: Option<Workspace>) -> Self { pub(crate) fn combine(args: PipOptions, workspace: Option<Workspace>) -> Self {
let PipOptions { let PipOptions {
python, python,
@ -1363,7 +1311,6 @@ where
Err(VarError::NotPresent) => return None, Err(VarError::NotPresent) => return None,
Err(VarError::NotUnicode(_)) => parse_failure(name, expected), Err(VarError::NotUnicode(_)) => parse_failure(name, expected),
}; };
Some( Some(
val.parse() val.parse()
.unwrap_or_else(|_| parse_failure(name, expected)), .unwrap_or_else(|_| parse_failure(name, expected)),