Add unowned settings variants (#4490)

## Summary

This PR adds unowned settings variants so that we can convert from
`ResolverInstallerSettings` to `ResolverSettings` without allocating.
This commit is contained in:
Charlie Marsh 2024-06-24 23:18:16 +03:00 committed by GitHub
parent 8afad69b03
commit 849478fa91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 118 additions and 31 deletions

View File

@ -186,7 +186,7 @@ pub(crate) async fn add(
let lock = project::lock::do_lock( let lock = project::lock::do_lock(
project.workspace(), project.workspace(),
venv.interpreter(), venv.interpreter(),
settings.clone().into(), settings.as_ref().into(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,
@ -209,7 +209,7 @@ pub(crate) async fn add(
extras, extras,
dev, dev,
Modifications::Sufficient, Modifications::Sufficient,
settings.into(), settings.as_ref().into(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,

View File

@ -19,7 +19,7 @@ use uv_warnings::warn_user;
use crate::commands::project::{find_requires_python, ProjectError}; use crate::commands::project::{find_requires_python, ProjectError};
use crate::commands::{pip, project, ExitStatus}; use crate::commands::{pip, project, ExitStatus};
use crate::printer::Printer; use crate::printer::Printer;
use crate::settings::ResolverSettings; use crate::settings::{ResolverSettings, ResolverSettingsRef};
/// Resolve the project requirements into a lockfile. /// Resolve the project requirements into a lockfile.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -57,7 +57,7 @@ pub(crate) async fn lock(
match do_lock( match do_lock(
&workspace, &workspace,
&interpreter, &interpreter,
settings, settings.as_ref(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,
@ -85,7 +85,7 @@ pub(crate) async fn lock(
pub(super) async fn do_lock( pub(super) async fn do_lock(
workspace: &Workspace, workspace: &Workspace,
interpreter: &Interpreter, interpreter: &Interpreter,
settings: ResolverSettings, settings: ResolverSettingsRef<'_>,
preview: PreviewMode, preview: PreviewMode,
connectivity: Connectivity, connectivity: Connectivity,
concurrency: Concurrency, concurrency: Concurrency,
@ -94,7 +94,7 @@ pub(super) async fn do_lock(
printer: Printer, printer: Printer,
) -> Result<Lock, ProjectError> { ) -> Result<Lock, ProjectError> {
// Extract the project settings. // Extract the project settings.
let ResolverSettings { let ResolverSettingsRef {
index_locations, index_locations,
index_strategy, index_strategy,
keyring_provider, keyring_provider,
@ -193,11 +193,11 @@ pub(super) async fn do_lock(
let flat_index = { let flat_index = {
let client = FlatIndexClient::new(&client, cache); let client = FlatIndexClient::new(&client, cache);
let entries = client.fetch(index_locations.flat_index()).await?; let entries = client.fetch(index_locations.flat_index()).await?;
FlatIndex::from_entries(entries, None, &hasher, &build_options) FlatIndex::from_entries(entries, None, &hasher, build_options)
}; };
// If an existing lockfile exists, build up a set of preferences. // If an existing lockfile exists, build up a set of preferences.
let LockedRequirements { preferences, git } = read_lockfile(workspace, &upgrade).await?; let LockedRequirements { preferences, git } = read_lockfile(workspace, upgrade).await?;
// Create the Git resolver. // Create the Git resolver.
let git = GitResolver::from_refs(git); let git = GitResolver::from_refs(git);
@ -207,17 +207,17 @@ pub(super) async fn do_lock(
&client, &client,
cache, cache,
interpreter, interpreter,
&index_locations, index_locations,
&flat_index, &flat_index,
&index, &index,
&git, &git,
&in_flight, &in_flight,
index_strategy, index_strategy,
setup_py, setup_py,
&config_setting, config_setting,
build_isolation, build_isolation,
link_mode, link_mode,
&build_options, build_options,
exclude_newer, exclude_newer,
concurrency, concurrency,
preview, preview,
@ -236,7 +236,7 @@ pub(super) async fn do_lock(
EmptyInstalledPackages, EmptyInstalledPackages,
&hasher, &hasher,
&Reinstall::default(), &Reinstall::default(),
&upgrade, upgrade,
interpreter, interpreter,
None, None,
None, None,

View File

@ -101,7 +101,7 @@ pub(crate) async fn remove(
let lock = project::lock::do_lock( let lock = project::lock::do_lock(
project.workspace(), project.workspace(),
venv.interpreter(), venv.interpreter(),
settings, settings.as_ref(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,
@ -125,7 +125,7 @@ pub(crate) async fn remove(
extras, extras,
dev, dev,
Modifications::Exact, Modifications::Exact,
settings, settings.as_ref(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,

View File

@ -78,7 +78,7 @@ pub(crate) async fn run(
let lock = project::lock::do_lock( let lock = project::lock::do_lock(
project.workspace(), project.workspace(),
venv.interpreter(), venv.interpreter(),
settings.clone().into(), settings.as_ref().into(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,
@ -95,7 +95,7 @@ pub(crate) async fn run(
extras, extras,
dev, dev,
Modifications::Sufficient, Modifications::Sufficient,
settings.clone().into(), settings.as_ref().into(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,

View File

@ -19,7 +19,7 @@ use crate::commands::pip::operations::Modifications;
use crate::commands::project::ProjectError; use crate::commands::project::ProjectError;
use crate::commands::{pip, project, ExitStatus}; use crate::commands::{pip, project, ExitStatus};
use crate::printer::Printer; use crate::printer::Printer;
use crate::settings::InstallerSettings; use crate::settings::{InstallerSettings, InstallerSettingsRef};
/// Sync the project environment. /// Sync the project environment.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -72,7 +72,7 @@ pub(crate) async fn sync(
extras, extras,
dev, dev,
modifications, modifications,
settings, settings.as_ref(),
preview, preview,
connectivity, connectivity,
concurrency, concurrency,
@ -95,7 +95,7 @@ pub(super) async fn do_sync(
extras: ExtrasSpecification, extras: ExtrasSpecification,
dev: bool, dev: bool,
modifications: Modifications, modifications: Modifications,
settings: InstallerSettings, settings: InstallerSettingsRef<'_>,
preview: PreviewMode, preview: PreviewMode,
connectivity: Connectivity, connectivity: Connectivity,
concurrency: Concurrency, concurrency: Concurrency,
@ -104,7 +104,7 @@ pub(super) async fn do_sync(
printer: Printer, printer: Printer,
) -> Result<(), ProjectError> { ) -> Result<(), ProjectError> {
// Extract the project settings. // Extract the project settings.
let InstallerSettings { let InstallerSettingsRef {
index_locations, index_locations,
index_strategy, index_strategy,
keyring_provider, keyring_provider,
@ -167,7 +167,7 @@ pub(super) async fn do_sync(
let flat_index = { let flat_index = {
let client = FlatIndexClient::new(&client, cache); let client = FlatIndexClient::new(&client, cache);
let entries = client.fetch(index_locations.flat_index()).await?; let entries = client.fetch(index_locations.flat_index()).await?;
FlatIndex::from_entries(entries, Some(tags), &hasher, &build_options) FlatIndex::from_entries(entries, Some(tags), &hasher, build_options)
}; };
// Create a build dispatch. // Create a build dispatch.
@ -175,17 +175,17 @@ pub(super) async fn do_sync(
&client, &client,
cache, cache,
venv.interpreter(), venv.interpreter(),
&index_locations, index_locations,
&flat_index, &flat_index,
&index, &index,
&git, &git,
&in_flight, &in_flight,
index_strategy, index_strategy,
setup_py, setup_py,
&config_setting, config_setting,
build_isolation, build_isolation,
link_mode, link_mode,
&build_options, build_options,
exclude_newer, exclude_newer,
concurrency, concurrency,
preview, preview,
@ -198,11 +198,11 @@ pub(super) async fn do_sync(
&resolution, &resolution,
site_packages, site_packages,
modifications, modifications,
&reinstall, reinstall,
&build_options, build_options,
link_mode, link_mode,
compile_bytecode, compile_bytecode,
&index_locations, index_locations,
&hasher, &hasher,
tags, tags,
&client, &client,

View File

@ -1087,6 +1087,18 @@ pub(crate) struct InstallerSettings {
pub(crate) build_options: BuildOptions, pub(crate) build_options: BuildOptions,
} }
#[derive(Debug, Clone)]
pub(crate) struct InstallerSettingsRef<'a> {
pub(crate) index_locations: &'a IndexLocations,
pub(crate) index_strategy: IndexStrategy,
pub(crate) keyring_provider: KeyringProviderType,
pub(crate) config_setting: &'a ConfigSettings,
pub(crate) link_mode: LinkMode,
pub(crate) compile_bytecode: bool,
pub(crate) reinstall: &'a Reinstall,
pub(crate) build_options: &'a BuildOptions,
}
impl InstallerSettings { impl InstallerSettings {
/// Resolve the [`InstallerSettings`] from the CLI and filesystem configuration. /// Resolve the [`InstallerSettings`] from the CLI and filesystem configuration.
pub(crate) fn combine(args: InstallerOptions, filesystem: Option<FilesystemOptions>) -> Self { pub(crate) fn combine(args: InstallerOptions, filesystem: Option<FilesystemOptions>) -> Self {
@ -1164,6 +1176,19 @@ impl InstallerSettings {
), ),
} }
} }
pub(crate) fn as_ref(&self) -> InstallerSettingsRef {
InstallerSettingsRef {
index_locations: &self.index_locations,
index_strategy: self.index_strategy,
keyring_provider: self.keyring_provider,
config_setting: &self.config_setting,
link_mode: self.link_mode,
compile_bytecode: self.compile_bytecode,
reinstall: &self.reinstall,
build_options: &self.build_options,
}
}
} }
/// The resolved settings to use for an invocation of the `uv` CLI when resolving dependencies. /// The resolved settings to use for an invocation of the `uv` CLI when resolving dependencies.
@ -1185,6 +1210,20 @@ pub(crate) struct ResolverSettings {
pub(crate) build_options: BuildOptions, pub(crate) build_options: BuildOptions,
} }
#[derive(Debug, Clone)]
pub(crate) struct ResolverSettingsRef<'a> {
pub(crate) index_locations: &'a IndexLocations,
pub(crate) index_strategy: IndexStrategy,
pub(crate) keyring_provider: KeyringProviderType,
pub(crate) resolution: ResolutionMode,
pub(crate) prerelease: PreReleaseMode,
pub(crate) config_setting: &'a ConfigSettings,
pub(crate) exclude_newer: Option<ExcludeNewer>,
pub(crate) link_mode: LinkMode,
pub(crate) upgrade: &'a Upgrade,
pub(crate) build_options: &'a BuildOptions,
}
impl ResolverSettings { impl ResolverSettings {
/// Resolve the [`ResolverSettings`] from the CLI and filesystem configuration. /// Resolve the [`ResolverSettings`] from the CLI and filesystem configuration.
pub(crate) fn combine(args: ResolverOptions, filesystem: Option<FilesystemOptions>) -> Self { pub(crate) fn combine(args: ResolverOptions, filesystem: Option<FilesystemOptions>) -> Self {
@ -1261,6 +1300,21 @@ impl ResolverSettings {
), ),
} }
} }
pub(crate) fn as_ref(&self) -> ResolverSettingsRef {
ResolverSettingsRef {
index_locations: &self.index_locations,
index_strategy: self.index_strategy,
keyring_provider: self.keyring_provider,
resolution: self.resolution,
prerelease: self.prerelease,
config_setting: &self.config_setting,
exclude_newer: self.exclude_newer,
link_mode: self.link_mode,
upgrade: &self.upgrade,
build_options: &self.build_options,
}
}
} }
/// The resolved settings to use for an invocation of the `uv` CLI with both resolver and installer /// The resolved settings to use for an invocation of the `uv` CLI with both resolver and installer
@ -1285,6 +1339,22 @@ pub(crate) struct ResolverInstallerSettings {
pub(crate) build_options: BuildOptions, pub(crate) build_options: BuildOptions,
} }
#[derive(Debug, Clone)]
pub(crate) struct ResolverInstallerSettingsRef<'a> {
pub(crate) index_locations: &'a IndexLocations,
pub(crate) index_strategy: IndexStrategy,
pub(crate) keyring_provider: KeyringProviderType,
pub(crate) resolution: ResolutionMode,
pub(crate) prerelease: PreReleaseMode,
pub(crate) config_setting: &'a ConfigSettings,
pub(crate) exclude_newer: Option<ExcludeNewer>,
pub(crate) link_mode: LinkMode,
pub(crate) compile_bytecode: bool,
pub(crate) upgrade: &'a Upgrade,
pub(crate) reinstall: &'a Reinstall,
pub(crate) build_options: &'a BuildOptions,
}
impl ResolverInstallerSettings { impl ResolverInstallerSettings {
/// Resolve the [`ResolverInstallerSettings`] from the CLI and filesystem configuration. /// Resolve the [`ResolverInstallerSettings`] from the CLI and filesystem configuration.
pub(crate) fn combine( pub(crate) fn combine(
@ -1374,6 +1444,23 @@ impl ResolverInstallerSettings {
), ),
} }
} }
pub(crate) fn as_ref(&self) -> ResolverInstallerSettingsRef {
ResolverInstallerSettingsRef {
index_locations: &self.index_locations,
index_strategy: self.index_strategy,
keyring_provider: self.keyring_provider,
resolution: self.resolution,
prerelease: self.prerelease,
config_setting: &self.config_setting,
exclude_newer: self.exclude_newer,
link_mode: self.link_mode,
compile_bytecode: self.compile_bytecode,
upgrade: &self.upgrade,
reinstall: &self.reinstall,
build_options: &self.build_options,
}
}
} }
/// The resolved settings to use for an invocation of the `pip` CLI. /// The resolved settings to use for an invocation of the `pip` CLI.
@ -1681,8 +1768,8 @@ impl PipSettings {
} }
} }
impl From<ResolverInstallerSettings> for ResolverSettings { impl<'a> From<ResolverInstallerSettingsRef<'a>> for ResolverSettingsRef<'a> {
fn from(settings: ResolverInstallerSettings) -> Self { fn from(settings: ResolverInstallerSettingsRef<'a>) -> Self {
Self { Self {
index_locations: settings.index_locations, index_locations: settings.index_locations,
index_strategy: settings.index_strategy, index_strategy: settings.index_strategy,
@ -1698,8 +1785,8 @@ impl From<ResolverInstallerSettings> for ResolverSettings {
} }
} }
impl From<ResolverInstallerSettings> for InstallerSettings { impl<'a> From<ResolverInstallerSettingsRef<'a>> for InstallerSettingsRef<'a> {
fn from(settings: ResolverInstallerSettings) -> Self { fn from(settings: ResolverInstallerSettingsRef<'a>) -> Self {
Self { Self {
index_locations: settings.index_locations, index_locations: settings.index_locations,
index_strategy: settings.index_strategy, index_strategy: settings.index_strategy,