mirror of https://github.com/astral-sh/uv
Include build settings in cache key for registry source distribution lookups (#15225)
## Summary Like #15030, but for source distributions built from a registry.
This commit is contained in:
parent
76b4ae40c6
commit
40b894bb1d
|
|
@ -1,11 +1,15 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
|
||||||
use uv_cache::{Cache, CacheBucket, WheelCache};
|
use uv_cache::{Cache, CacheBucket, WheelCache};
|
||||||
use uv_cache_key::cache_digest;
|
use uv_cache_key::cache_digest;
|
||||||
use uv_configuration::ConfigSettings;
|
use uv_configuration::{ConfigSettings, PackageConfigSettings};
|
||||||
use uv_distribution_types::{CachedRegistryDist, Hashed, Index, IndexLocations, IndexUrl};
|
use uv_distribution_types::{
|
||||||
|
BuildVariables, CachedRegistryDist, ExtraBuildRequirement, ExtraBuildRequires,
|
||||||
|
ExtraBuildVariables, Hashed, Index, IndexLocations, IndexUrl,
|
||||||
|
};
|
||||||
use uv_fs::{directories, files};
|
use uv_fs::{directories, files};
|
||||||
use uv_normalize::PackageName;
|
use uv_normalize::PackageName;
|
||||||
use uv_platform_tags::Tags;
|
use uv_platform_tags::Tags;
|
||||||
|
|
@ -33,7 +37,10 @@ pub struct RegistryWheelIndex<'a> {
|
||||||
index_locations: &'a IndexLocations,
|
index_locations: &'a IndexLocations,
|
||||||
hasher: &'a HashStrategy,
|
hasher: &'a HashStrategy,
|
||||||
index: FxHashMap<&'a PackageName, Vec<IndexEntry<'a>>>,
|
index: FxHashMap<&'a PackageName, Vec<IndexEntry<'a>>>,
|
||||||
build_configuration: &'a ConfigSettings,
|
config_settings: &'a ConfigSettings,
|
||||||
|
config_settings_package: &'a PackageConfigSettings,
|
||||||
|
extra_build_requires: &'a ExtraBuildRequires,
|
||||||
|
extra_build_variables: &'a ExtraBuildVariables,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RegistryWheelIndex<'a> {
|
impl<'a> RegistryWheelIndex<'a> {
|
||||||
|
|
@ -43,14 +50,20 @@ impl<'a> RegistryWheelIndex<'a> {
|
||||||
tags: &'a Tags,
|
tags: &'a Tags,
|
||||||
index_locations: &'a IndexLocations,
|
index_locations: &'a IndexLocations,
|
||||||
hasher: &'a HashStrategy,
|
hasher: &'a HashStrategy,
|
||||||
build_configuration: &'a ConfigSettings,
|
config_settings: &'a ConfigSettings,
|
||||||
|
config_settings_package: &'a PackageConfigSettings,
|
||||||
|
extra_build_requires: &'a ExtraBuildRequires,
|
||||||
|
extra_build_variables: &'a ExtraBuildVariables,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
cache,
|
cache,
|
||||||
tags,
|
tags,
|
||||||
index_locations,
|
index_locations,
|
||||||
hasher,
|
hasher,
|
||||||
build_configuration,
|
config_settings,
|
||||||
|
config_settings_package,
|
||||||
|
extra_build_requires,
|
||||||
|
extra_build_variables,
|
||||||
index: FxHashMap::default(),
|
index: FxHashMap::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,7 +85,10 @@ impl<'a> RegistryWheelIndex<'a> {
|
||||||
self.tags,
|
self.tags,
|
||||||
self.index_locations,
|
self.index_locations,
|
||||||
self.hasher,
|
self.hasher,
|
||||||
self.build_configuration,
|
self.config_settings,
|
||||||
|
self.config_settings_package,
|
||||||
|
self.extra_build_requires,
|
||||||
|
self.extra_build_variables,
|
||||||
)),
|
)),
|
||||||
}) as _
|
}) as _
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +100,10 @@ impl<'a> RegistryWheelIndex<'a> {
|
||||||
tags: &Tags,
|
tags: &Tags,
|
||||||
index_locations: &'index IndexLocations,
|
index_locations: &'index IndexLocations,
|
||||||
hasher: &HashStrategy,
|
hasher: &HashStrategy,
|
||||||
build_configuration: &ConfigSettings,
|
config_settings: &ConfigSettings,
|
||||||
|
config_settings_package: &PackageConfigSettings,
|
||||||
|
extra_build_requires: &ExtraBuildRequires,
|
||||||
|
extra_build_variables: &ExtraBuildVariables,
|
||||||
) -> Vec<IndexEntry<'index>> {
|
) -> Vec<IndexEntry<'index>> {
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
|
|
||||||
|
|
@ -198,10 +217,26 @@ impl<'a> RegistryWheelIndex<'a> {
|
||||||
let cache_shard = cache_shard.shard(revision.id());
|
let cache_shard = cache_shard.shard(revision.id());
|
||||||
|
|
||||||
// If there are build settings, we need to scope to a cache shard.
|
// If there are build settings, we need to scope to a cache shard.
|
||||||
let cache_shard = if build_configuration.is_empty() {
|
let extra_build_deps =
|
||||||
|
Self::extra_build_requires_for(package, extra_build_requires);
|
||||||
|
let extra_build_vars =
|
||||||
|
Self::extra_build_variables_for(package, extra_build_variables);
|
||||||
|
let config_settings = Self::config_settings_for(
|
||||||
|
package,
|
||||||
|
config_settings,
|
||||||
|
config_settings_package,
|
||||||
|
);
|
||||||
|
let cache_shard = if config_settings.is_empty()
|
||||||
|
&& extra_build_deps.is_empty()
|
||||||
|
&& extra_build_vars.is_none()
|
||||||
|
{
|
||||||
cache_shard
|
cache_shard
|
||||||
} else {
|
} else {
|
||||||
cache_shard.shard(cache_digest(build_configuration))
|
cache_shard.shard(cache_digest(&(
|
||||||
|
&config_settings,
|
||||||
|
extra_build_deps,
|
||||||
|
extra_build_vars,
|
||||||
|
)))
|
||||||
};
|
};
|
||||||
|
|
||||||
for wheel_dir in uv_fs::entries(cache_shard).ok().into_iter().flatten() {
|
for wheel_dir in uv_fs::entries(cache_shard).ok().into_iter().flatten() {
|
||||||
|
|
@ -252,4 +287,36 @@ impl<'a> RegistryWheelIndex<'a> {
|
||||||
|
|
||||||
entries
|
entries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determine the [`ConfigSettings`] for the given package name.
|
||||||
|
fn config_settings_for<'settings>(
|
||||||
|
name: &PackageName,
|
||||||
|
config_settings: &'settings ConfigSettings,
|
||||||
|
config_settings_package: &PackageConfigSettings,
|
||||||
|
) -> Cow<'settings, ConfigSettings> {
|
||||||
|
if let Some(package_settings) = config_settings_package.get(name) {
|
||||||
|
Cow::Owned(package_settings.clone().merge(config_settings.clone()))
|
||||||
|
} else {
|
||||||
|
Cow::Borrowed(config_settings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine the extra build requirements for the given package name.
|
||||||
|
fn extra_build_requires_for<'settings>(
|
||||||
|
name: &PackageName,
|
||||||
|
extra_build_requires: &'settings ExtraBuildRequires,
|
||||||
|
) -> &'settings [ExtraBuildRequirement] {
|
||||||
|
extra_build_requires
|
||||||
|
.get(name)
|
||||||
|
.map(Vec::as_slice)
|
||||||
|
.unwrap_or(&[])
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determine the extra build variables for the given package name.
|
||||||
|
fn extra_build_variables_for<'settings>(
|
||||||
|
name: &PackageName,
|
||||||
|
extra_build_variables: &'settings ExtraBuildVariables,
|
||||||
|
) -> Option<&'settings BuildVariables> {
|
||||||
|
extra_build_variables.get(name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,16 @@ impl<'a> Planner<'a> {
|
||||||
tags: &Tags,
|
tags: &Tags,
|
||||||
) -> Result<Plan> {
|
) -> Result<Plan> {
|
||||||
// Index all the already-downloaded wheels in the cache.
|
// Index all the already-downloaded wheels in the cache.
|
||||||
let mut registry_index =
|
let mut registry_index = RegistryWheelIndex::new(
|
||||||
RegistryWheelIndex::new(cache, tags, index_locations, hasher, config_settings);
|
cache,
|
||||||
|
tags,
|
||||||
|
index_locations,
|
||||||
|
hasher,
|
||||||
|
config_settings,
|
||||||
|
config_settings_package,
|
||||||
|
extra_build_requires,
|
||||||
|
extra_build_variables,
|
||||||
|
);
|
||||||
let built_index = BuiltWheelIndex::new(
|
let built_index = BuiltWheelIndex::new(
|
||||||
cache,
|
cache,
|
||||||
tags,
|
tags,
|
||||||
|
|
|
||||||
|
|
@ -3927,7 +3927,6 @@ fn config_settings_registry() {
|
||||||
|
|
||||||
----- stderr -----
|
----- stderr -----
|
||||||
Resolved 1 package in [TIME]
|
Resolved 1 package in [TIME]
|
||||||
Prepared 1 package in [TIME]
|
|
||||||
Installed 1 package in [TIME]
|
Installed 1 package in [TIME]
|
||||||
+ iniconfig==2.0.0
|
+ iniconfig==2.0.0
|
||||||
"
|
"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue