Implement 0.0.3

This commit is contained in:
konstin 2025-12-01 17:22:44 +01:00
parent 3e9ff9447a
commit dc6757b270
10 changed files with 70 additions and 42 deletions

View File

@ -628,7 +628,8 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
let mut disabled_namespaces = FxHashSet::default();
let mut resolved_namespaces: FxHashMap<VariantNamespace, Arc<VariantProviderOutput>> =
futures::stream::iter(variants_json.providers.iter().filter(|(_, provider)| {
provider.plugin_use.unwrap_or_default().run_on_install()
provider.install_time.unwrap_or(true)
&& !provider.optional
&& provider
.enable_if
.evaluate(marker_env, &MarkerVariantsUniversal, &[])
@ -641,22 +642,27 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
.try_collect()
.await?;
// "Query" the non-install time providers, whose properties are all in the priorities
// "Query" the static providers
for (namespace, provider) in &variants_json.providers {
// Track disabled namespaces for consistency checks.
if !provider
.enable_if
.evaluate(marker_env, &MarkerVariantsUniversal, &[])
|| provider.optional
{
disabled_namespaces.insert(namespace.clone());
continue;
}
if provider.plugin_use.unwrap_or_default().run_on_install() {
if provider.install_time.unwrap_or(true) {
continue;
}
let Some(features) = variants_json.default_priorities.property.get(namespace) else {
let Some(features) = variants_json
.static_properties
.as_ref()
.and_then(|static_properties| static_properties.get(namespace))
else {
warn!(
"Missing namespace {namespace} in default properties for {}=={}",
debug_filename.name, debug_filename.version

View File

@ -1,3 +1,4 @@
use std::collections::BTreeMap;
use std::ops::Deref;
use rustc_hash::FxHashMap;
@ -13,7 +14,7 @@ use uv_pypi_types::VerbatimParsedUrl;
/// Mapping of namespaces in a variant
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct Variant(FxHashMap<VariantNamespace, FxHashMap<VariantFeature, Vec<VariantValue>>>);
pub struct Variant(BTreeMap<VariantNamespace, BTreeMap<VariantFeature, Vec<VariantValue>>>);
impl MarkerVariantsEnvironment for Variant {
fn contains_namespace(&self, namespace: &VariantNamespace) -> bool {
@ -74,7 +75,7 @@ impl MarkerVariantsEnvironment for Variant {
}
impl Deref for Variant {
type Target = FxHashMap<VariantNamespace, FxHashMap<VariantFeature, Vec<VariantValue>>>;
type Target = BTreeMap<VariantNamespace, BTreeMap<VariantFeature, Vec<VariantValue>>>;
fn deref(&self) -> &Self::Target {
&self.0
@ -87,11 +88,13 @@ impl Deref for Variant {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct VariantsJsonContent {
/// Default provider priorities
/// Default provider priorities.
pub default_priorities: DefaultPriorities,
/// Mapping of namespaces to provider information
/// Mapping of namespaces to provider information.
pub providers: FxHashMap<VariantNamespace, Provider>,
/// Mapping of variant labels to properties
/// The supported, ordered properties for `AoT` providers.
pub static_properties: Option<Variant>,
/// Mapping of variant labels to properties.
pub variants: FxHashMap<VariantLabel, Variant>,
}
@ -123,10 +126,10 @@ pub struct DefaultPriorities {
pub namespace: Vec<VariantNamespace>,
/// Default feature priorities
#[serde(default)]
pub feature: FxHashMap<VariantNamespace, Vec<VariantFeature>>,
pub feature: BTreeMap<VariantNamespace, Vec<VariantFeature>>,
/// Default property priorities
#[serde(default)]
pub property: FxHashMap<VariantNamespace, FxHashMap<VariantFeature, Vec<VariantValue>>>,
pub property: BTreeMap<VariantNamespace, BTreeMap<VariantFeature, Vec<VariantValue>>>,
}
/// A `namespace :: feature :: property` entry.
@ -138,47 +141,30 @@ pub struct VariantPropertyType {
pub value: VariantValue,
}
/// The stages at which a plugin is run.
///
/// Specifically captures whether it needs to be run at install time.
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum PluginUse {
/// The plugin is never run, it is only static.
None,
/// The plugin is run at build time, the install time evaluation is static.
Build,
/// The plugin is run both at build time and at install time.
#[default]
All,
}
impl PluginUse {
/// Whether to run this plugin on installation, `false` for plugins evaluated from
/// default priorities.
pub fn run_on_install(self) -> bool {
match self {
Self::All => true,
Self::None | Self::Build => false,
}
}
}
/// Provider information
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Provider {
/// Object reference to plugin class
pub plugin_api: Option<String>,
/// Environment marker specifying when to enable the plugin
/// Environment marker specifying when to enable the plugin.
#[serde(
skip_serializing_if = "uv_pep508::marker::ser::is_empty",
serialize_with = "uv_pep508::marker::ser::serialize",
default
)]
pub enable_if: MarkerTree,
/// Whether this is an install-time provider. `false` means that it is an `AoT` provider instead.
///
/// Defaults to `true`
pub install_time: Option<bool>,
/// Whether this is an optional provider.
///
/// If it is `true`, the provider is not used unless the user opts in to it.
///
/// Defaults to `false`
#[serde(default)]
pub optional: bool,
/// Object reference to plugin class
pub plugin_api: Option<String>,
/// Dependency specifiers for how to install the plugin
pub requires: Option<Vec<Requirement<VerbatimParsedUrl>>>,
/// Whether this plugin is run at install time.
pub plugin_use: Option<PluginUse>,
}

View File

@ -19,6 +19,13 @@
}
}
},
"static-properties": {
"mathlib": {
"kind": [
"very_fast_lib"
]
}
},
"providers": {
"cpu_level": {
"enable-if": "platform_machine == 'x86_64' or platform_machine == 'AMD64'",
@ -26,6 +33,9 @@
"requires": [
"cpu_level_provider >= 0.1, <0.2"
]
},
"mathlib": {
"install-time": false
}
},
"variants": {
@ -34,6 +44,11 @@
"x86_64_level": [
"v1"
]
},
"mathlib": {
"kind": [
"very_fast_lib"
]
}
},
"cpu2": {
@ -41,6 +56,11 @@
"x86_64_level": [
"v2"
]
},
"mathlib": {
"kind": [
"very_fast_lib"
]
}
},
"cpu3": {
@ -48,6 +68,11 @@
"x86_64_level": [
"v3"
]
},
"mathlib": {
"kind": [
"very_fast_lib"
]
}
},
"cpu4": {
@ -55,6 +80,11 @@
"x86_64_level": [
"v4"
]
},
"mathlib": {
"kind": [
"very_fast_lib"
]
}
}
}

Binary file not shown.

View File

@ -30,6 +30,12 @@ namespace = ["cpu_level"]
requires = ["cpu_level_provider >= 0.1, <0.2"]
enable-if = "platform_machine == 'x86_64' or platform_machine == 'AMD64'"
[variant.providers.mathlib]
install-time = false
[variant.static-properties]
mathlib = { "kind" = ["very_fast_lib"] }
[build-system]
requires = ["uv_build>=0.8.0,<0.10.0"]
build-backend = "uv_build"