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(
project.workspace(),
venv.interpreter(),
settings.clone().into(),
settings.as_ref().into(),
preview,
connectivity,
concurrency,
@ -209,7 +209,7 @@ pub(crate) async fn add(
extras,
dev,
Modifications::Sufficient,
settings.into(),
settings.as_ref().into(),
preview,
connectivity,
concurrency,

View file

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

View file

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

View file

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

View file

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

View file

@ -1087,6 +1087,18 @@ pub(crate) struct InstallerSettings {
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 {
/// Resolve the [`InstallerSettings`] from the CLI and filesystem configuration.
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.
@ -1185,6 +1210,20 @@ pub(crate) struct ResolverSettings {
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 {
/// Resolve the [`ResolverSettings`] from the CLI and filesystem configuration.
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
@ -1285,6 +1339,22 @@ pub(crate) struct ResolverInstallerSettings {
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 {
/// Resolve the [`ResolverInstallerSettings`] from the CLI and filesystem configuration.
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.
@ -1681,8 +1768,8 @@ impl PipSettings {
}
}
impl From<ResolverInstallerSettings> for ResolverSettings {
fn from(settings: ResolverInstallerSettings) -> Self {
impl<'a> From<ResolverInstallerSettingsRef<'a>> for ResolverSettingsRef<'a> {
fn from(settings: ResolverInstallerSettingsRef<'a>) -> Self {
Self {
index_locations: settings.index_locations,
index_strategy: settings.index_strategy,
@ -1698,8 +1785,8 @@ impl From<ResolverInstallerSettings> for ResolverSettings {
}
}
impl From<ResolverInstallerSettings> for InstallerSettings {
fn from(settings: ResolverInstallerSettings) -> Self {
impl<'a> From<ResolverInstallerSettingsRef<'a>> for InstallerSettingsRef<'a> {
fn from(settings: ResolverInstallerSettingsRef<'a>) -> Self {
Self {
index_locations: settings.index_locations,
index_strategy: settings.index_strategy,