mirror of https://github.com/astral-sh/uv
Implement settings conversion traits (#4489)
## Summary This does require cloning the settings, but I think it's fine. A better solution would be to have owned and unowned settings structs, so that we could convert `ResolverInstallerSettingsRef` to `InstallerSettingsRef` without cloning, but that requires maintaining owned and unowned variants. Closes https://github.com/astral-sh/uv/issues/4455.
This commit is contained in:
parent
ff72bb9bcc
commit
8afad69b03
|
|
@ -186,16 +186,7 @@ pub(crate) async fn add(
|
|||
let lock = project::lock::do_lock(
|
||||
project.workspace(),
|
||||
venv.interpreter(),
|
||||
&settings.upgrade,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
settings.resolution,
|
||||
settings.prerelease,
|
||||
&settings.config_setting,
|
||||
settings.exclude_newer,
|
||||
settings.link_mode,
|
||||
&settings.build_options,
|
||||
settings.clone().into(),
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
@ -218,14 +209,7 @@ pub(crate) async fn add(
|
|||
extras,
|
||||
dev,
|
||||
Modifications::Sufficient,
|
||||
&settings.reinstall,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
&settings.config_setting,
|
||||
settings.link_mode,
|
||||
settings.compile_bytecode,
|
||||
&settings.build_options,
|
||||
settings.into(),
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
|
|||
|
|
@ -2,23 +2,16 @@ use std::collections::Bound;
|
|||
|
||||
use anstream::eprint;
|
||||
|
||||
use distribution_types::{IndexLocations, UnresolvedRequirementSpecification};
|
||||
use install_wheel_rs::linker::LinkMode;
|
||||
use distribution_types::UnresolvedRequirementSpecification;
|
||||
use pep508_rs::RequirementOrigin;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||
use uv_configuration::{
|
||||
BuildOptions, Concurrency, ConfigSettings, ExtrasSpecification, IndexStrategy,
|
||||
KeyringProviderType, PreviewMode, Reinstall, SetupPyStrategy, Upgrade,
|
||||
};
|
||||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, Reinstall, SetupPyStrategy};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_distribution::{Workspace, DEV_DEPENDENCIES};
|
||||
use uv_git::GitResolver;
|
||||
use uv_requirements::upgrade::{read_lockfile, LockedRequirements};
|
||||
use uv_resolver::{
|
||||
ExcludeNewer, FlatIndex, InMemoryIndex, Lock, OptionsBuilder, PreReleaseMode, RequiresPython,
|
||||
ResolutionMode,
|
||||
};
|
||||
use uv_resolver::{FlatIndex, InMemoryIndex, Lock, OptionsBuilder, RequiresPython};
|
||||
use uv_toolchain::{Interpreter, ToolchainPreference, ToolchainRequest};
|
||||
use uv_types::{BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight};
|
||||
use uv_warnings::warn_user;
|
||||
|
|
@ -64,16 +57,7 @@ pub(crate) async fn lock(
|
|||
match do_lock(
|
||||
&workspace,
|
||||
&interpreter,
|
||||
&settings.upgrade,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
settings.resolution,
|
||||
settings.prerelease,
|
||||
&settings.config_setting,
|
||||
settings.exclude_newer,
|
||||
settings.link_mode,
|
||||
&settings.build_options,
|
||||
settings,
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
@ -101,16 +85,7 @@ pub(crate) async fn lock(
|
|||
pub(super) async fn do_lock(
|
||||
workspace: &Workspace,
|
||||
interpreter: &Interpreter,
|
||||
upgrade: &Upgrade,
|
||||
index_locations: &IndexLocations,
|
||||
index_strategy: IndexStrategy,
|
||||
keyring_provider: KeyringProviderType,
|
||||
resolution: ResolutionMode,
|
||||
prerelease: PreReleaseMode,
|
||||
config_setting: &ConfigSettings,
|
||||
exclude_newer: Option<ExcludeNewer>,
|
||||
link_mode: LinkMode,
|
||||
build_options: &BuildOptions,
|
||||
settings: ResolverSettings,
|
||||
preview: PreviewMode,
|
||||
connectivity: Connectivity,
|
||||
concurrency: Concurrency,
|
||||
|
|
@ -118,6 +93,20 @@ pub(super) async fn do_lock(
|
|||
cache: &Cache,
|
||||
printer: Printer,
|
||||
) -> Result<Lock, ProjectError> {
|
||||
// Extract the project settings.
|
||||
let ResolverSettings {
|
||||
index_locations,
|
||||
index_strategy,
|
||||
keyring_provider,
|
||||
resolution,
|
||||
prerelease,
|
||||
config_setting,
|
||||
exclude_newer,
|
||||
link_mode,
|
||||
upgrade,
|
||||
build_options,
|
||||
} = settings;
|
||||
|
||||
// When locking, include the project itself (as editable).
|
||||
let requirements = workspace
|
||||
.members_as_requirements()
|
||||
|
|
@ -204,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);
|
||||
|
|
@ -218,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,
|
||||
|
|
@ -247,7 +236,7 @@ pub(super) async fn do_lock(
|
|||
EmptyInstalledPackages,
|
||||
&hasher,
|
||||
&Reinstall::default(),
|
||||
upgrade,
|
||||
&upgrade,
|
||||
interpreter,
|
||||
None,
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -101,16 +101,7 @@ pub(crate) async fn remove(
|
|||
let lock = project::lock::do_lock(
|
||||
project.workspace(),
|
||||
venv.interpreter(),
|
||||
&settings.upgrade,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
settings.resolution,
|
||||
settings.prerelease,
|
||||
&settings.config_setting,
|
||||
settings.exclude_newer,
|
||||
settings.link_mode,
|
||||
&settings.build_options,
|
||||
settings,
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
@ -134,14 +125,7 @@ pub(crate) async fn remove(
|
|||
extras,
|
||||
dev,
|
||||
Modifications::Exact,
|
||||
&settings.reinstall,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
&settings.config_setting,
|
||||
settings.link_mode,
|
||||
settings.compile_bytecode,
|
||||
&settings.build_options,
|
||||
settings,
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
|
|||
|
|
@ -78,16 +78,7 @@ pub(crate) async fn run(
|
|||
let lock = project::lock::do_lock(
|
||||
project.workspace(),
|
||||
venv.interpreter(),
|
||||
&settings.upgrade,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
settings.resolution,
|
||||
settings.prerelease,
|
||||
&settings.config_setting,
|
||||
settings.exclude_newer,
|
||||
settings.link_mode,
|
||||
&settings.build_options,
|
||||
settings.clone().into(),
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
@ -104,14 +95,7 @@ pub(crate) async fn run(
|
|||
extras,
|
||||
dev,
|
||||
Modifications::Sufficient,
|
||||
&settings.reinstall,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
&settings.config_setting,
|
||||
settings.link_mode,
|
||||
settings.compile_bytecode,
|
||||
&settings.build_options,
|
||||
settings.clone().into(),
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
|
|||
|
|
@ -2,14 +2,9 @@ use std::path::Path;
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use distribution_types::IndexLocations;
|
||||
use install_wheel_rs::linker::LinkMode;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::{Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||
use uv_configuration::{
|
||||
BuildOptions, Concurrency, ConfigSettings, ExtrasSpecification, IndexStrategy,
|
||||
KeyringProviderType, PreviewMode, Reinstall, SetupPyStrategy,
|
||||
};
|
||||
use uv_configuration::{Concurrency, ExtrasSpecification, PreviewMode, SetupPyStrategy};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_distribution::{ProjectWorkspace, DEV_DEPENDENCIES};
|
||||
use uv_git::GitResolver;
|
||||
|
|
@ -77,14 +72,7 @@ pub(crate) async fn sync(
|
|||
extras,
|
||||
dev,
|
||||
modifications,
|
||||
&settings.reinstall,
|
||||
&settings.index_locations,
|
||||
settings.index_strategy,
|
||||
settings.keyring_provider,
|
||||
&settings.config_setting,
|
||||
settings.link_mode,
|
||||
settings.compile_bytecode,
|
||||
&settings.build_options,
|
||||
settings,
|
||||
preview,
|
||||
connectivity,
|
||||
concurrency,
|
||||
|
|
@ -107,14 +95,7 @@ pub(super) async fn do_sync(
|
|||
extras: ExtrasSpecification,
|
||||
dev: bool,
|
||||
modifications: Modifications,
|
||||
reinstall: &Reinstall,
|
||||
index_locations: &IndexLocations,
|
||||
index_strategy: IndexStrategy,
|
||||
keyring_provider: KeyringProviderType,
|
||||
config_setting: &ConfigSettings,
|
||||
link_mode: LinkMode,
|
||||
compile_bytecode: bool,
|
||||
build_options: &BuildOptions,
|
||||
settings: InstallerSettings,
|
||||
preview: PreviewMode,
|
||||
connectivity: Connectivity,
|
||||
concurrency: Concurrency,
|
||||
|
|
@ -122,6 +103,18 @@ pub(super) async fn do_sync(
|
|||
cache: &Cache,
|
||||
printer: Printer,
|
||||
) -> Result<(), ProjectError> {
|
||||
// Extract the project settings.
|
||||
let InstallerSettings {
|
||||
index_locations,
|
||||
index_strategy,
|
||||
keyring_provider,
|
||||
config_setting,
|
||||
link_mode,
|
||||
compile_bytecode,
|
||||
reinstall,
|
||||
build_options,
|
||||
} = settings;
|
||||
|
||||
// Validate that the Python version is supported by the lockfile.
|
||||
if let Some(requires_python) = lock.requires_python() {
|
||||
if !requires_python.contains(venv.interpreter().python_version()) {
|
||||
|
|
@ -174,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.
|
||||
|
|
@ -182,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,
|
||||
|
|
@ -205,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,
|
||||
|
|
|
|||
|
|
@ -1681,6 +1681,38 @@ impl PipSettings {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ResolverInstallerSettings> for ResolverSettings {
|
||||
fn from(settings: ResolverInstallerSettings) -> Self {
|
||||
Self {
|
||||
index_locations: settings.index_locations,
|
||||
index_strategy: settings.index_strategy,
|
||||
keyring_provider: settings.keyring_provider,
|
||||
resolution: settings.resolution,
|
||||
prerelease: settings.prerelease,
|
||||
config_setting: settings.config_setting,
|
||||
exclude_newer: settings.exclude_newer,
|
||||
link_mode: settings.link_mode,
|
||||
upgrade: settings.upgrade,
|
||||
build_options: settings.build_options,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResolverInstallerSettings> for InstallerSettings {
|
||||
fn from(settings: ResolverInstallerSettings) -> Self {
|
||||
Self {
|
||||
index_locations: settings.index_locations,
|
||||
index_strategy: settings.index_strategy,
|
||||
keyring_provider: settings.keyring_provider,
|
||||
config_setting: settings.config_setting,
|
||||
link_mode: settings.link_mode,
|
||||
compile_bytecode: settings.compile_bytecode,
|
||||
reinstall: settings.reinstall,
|
||||
build_options: settings.build_options,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Environment variables that are not exposed as CLI arguments.
|
||||
mod env {
|
||||
pub(super) const CONCURRENT_DOWNLOADS: (&str, &str) =
|
||||
|
|
|
|||
Loading…
Reference in New Issue