Add variants json definitions

This commit is contained in:
konstin 2025-07-03 22:01:47 +02:00
parent e4ea748074
commit 5c0d9651a6
4 changed files with 65 additions and 0 deletions

2
Cargo.lock generated
View file

@ -6013,8 +6013,10 @@ dependencies = [
"itertools 0.14.0",
"rkyv",
"serde",
"serde_json",
"sha3",
"thiserror 2.0.12",
"uv-pep508",
]
[[package]]

View file

@ -10,6 +10,8 @@ authors.workspace = true
license.workspace = true
[dependencies]
uv-pep508 = { workspace = true }
hex = { workspace = true }
itertools = { workspace = true }
rkyv = { workspace = true }
@ -17,5 +19,8 @@ serde = { workspace = true }
sha3 = { workspace = true }
thiserror = { workspace = true }
[dev-dependencies]
serde_json = { workspace = true }
[lints]
workspace = true

View file

@ -1,3 +1,5 @@
pub mod variants_json;
use std::cmp;
use std::collections::HashMap;
use std::num::NonZeroU32;

View file

@ -0,0 +1,56 @@
use std::collections::HashMap;
use serde::Deserialize;
use uv_pep508::{MarkerTree, Requirement};
/// Mapping of namespaces in a variant
pub type Variant = HashMap<String, VariantNamespace>;
/// Mapping of features to their possible values in a namespace
pub type VariantNamespace = HashMap<String, Vec<String>>;
// TODO(konsti): Validate the string contents
pub type Namespace = String;
pub type Feature = String;
pub type Property = String;
/// Combined index metadata for wheel variants.
///
/// See <https://wheelnext.dev/variants.json>
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct VariantsJsonContent {
/// Default provider priorities
pub default_priorities: DefaultPriorities,
/// Mapping of namespaces to provider information
pub providers: HashMap<String, Provider>,
/// Mapping of variant labels to properties
pub variants: HashMap<String, Variant>,
}
/// Default provider priorities
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DefaultPriorities {
/// Default namespace priorities
pub namespace: Vec<String>,
/// Default feature priorities
#[serde(default)]
pub feature: HashMap<Namespace, Vec<Feature>>,
/// Default property priorities
#[serde(default)]
pub property: HashMap<Namespace, HashMap<Feature, Vec<Property>>>,
}
/// Provider information
#[derive(Debug, PartialEq, Eq, 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
pub enable_if: Option<MarkerTree>,
/// Dependency specifiers for how to install the plugin
pub requires: Vec<Requirement>,
}