mirror of https://github.com/astral-sh/uv
Use wire JSON schema for conflict items (#11196)
## Summary Closes https://github.com/astral-sh/uv/issues/11180.
This commit is contained in:
parent
1be8ba7df1
commit
efbc77bc37
|
|
@ -5,9 +5,7 @@ use uv_normalize::{ExtraName, GroupName, PackageName};
|
||||||
/// This is useful to force the resolver to fork according to extras that have
|
/// This is useful to force the resolver to fork according to extras that have
|
||||||
/// unavoidable conflicts with each other. (The alternative is that resolution
|
/// unavoidable conflicts with each other. (The alternative is that resolution
|
||||||
/// will fail.)
|
/// will fail.)
|
||||||
#[derive(
|
#[derive(Debug, Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||||
Debug, Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
|
|
||||||
)]
|
|
||||||
pub struct Conflicts(Vec<ConflictSet>);
|
pub struct Conflicts(Vec<ConflictSet>);
|
||||||
|
|
||||||
impl Conflicts {
|
impl Conflicts {
|
||||||
|
|
@ -60,7 +58,7 @@ impl Conflicts {
|
||||||
///
|
///
|
||||||
/// A `TryFrom<Vec<ConflictItem>>` impl may be used to build a set from a
|
/// A `TryFrom<Vec<ConflictItem>>` impl may be used to build a set from a
|
||||||
/// sequence. Note though that at least 2 items are required.
|
/// sequence. Note though that at least 2 items are required.
|
||||||
#[derive(Debug, Default, Clone, Eq, PartialEq, serde::Serialize, schemars::JsonSchema)]
|
#[derive(Debug, Default, Clone, Eq, PartialEq, serde::Serialize)]
|
||||||
pub struct ConflictSet(Vec<ConflictItem>);
|
pub struct ConflictSet(Vec<ConflictItem>);
|
||||||
|
|
||||||
impl ConflictSet {
|
impl ConflictSet {
|
||||||
|
|
@ -120,16 +118,7 @@ impl TryFrom<Vec<ConflictItem>> for ConflictSet {
|
||||||
/// Each item is a pair of a package and a corresponding extra name for that
|
/// Each item is a pair of a package and a corresponding extra name for that
|
||||||
/// package.
|
/// package.
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
|
||||||
Clone,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
PartialEq,
|
|
||||||
PartialOrd,
|
|
||||||
Ord,
|
|
||||||
serde::Deserialize,
|
|
||||||
serde::Serialize,
|
|
||||||
schemars::JsonSchema,
|
|
||||||
)]
|
)]
|
||||||
#[serde(
|
#[serde(
|
||||||
deny_unknown_fields,
|
deny_unknown_fields,
|
||||||
|
|
@ -252,7 +241,7 @@ impl hashbrown::Equivalent<ConflictItem> for ConflictItemRef<'_> {
|
||||||
/// The actual conflicting data for a package.
|
/// The actual conflicting data for a package.
|
||||||
///
|
///
|
||||||
/// That is, either an extra or a group name.
|
/// That is, either an extra or a group name.
|
||||||
#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, schemars::JsonSchema)]
|
#[derive(Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord)]
|
||||||
pub enum ConflictPackage {
|
pub enum ConflictPackage {
|
||||||
Extra(ExtraName),
|
Extra(ExtraName),
|
||||||
Group(GroupName),
|
Group(GroupName),
|
||||||
|
|
@ -426,7 +415,7 @@ impl SchemaConflicts {
|
||||||
/// schema format does not allow specifying the package name (or will make it
|
/// schema format does not allow specifying the package name (or will make it
|
||||||
/// optional in the future), where as the in-memory format needs the package
|
/// optional in the future), where as the in-memory format needs the package
|
||||||
/// name.
|
/// name.
|
||||||
#[derive(Debug, Default, Clone, Eq, PartialEq, serde::Serialize, schemars::JsonSchema)]
|
#[derive(Debug, Default, Clone, Eq, PartialEq, schemars::JsonSchema, serde::Serialize)]
|
||||||
pub struct SchemaConflictSet(Vec<SchemaConflictItem>);
|
pub struct SchemaConflictSet(Vec<SchemaConflictItem>);
|
||||||
|
|
||||||
/// Like [`ConflictItem`], but for deserialization in `pyproject.toml`.
|
/// Like [`ConflictItem`], but for deserialization in `pyproject.toml`.
|
||||||
|
|
@ -436,16 +425,7 @@ pub struct SchemaConflictSet(Vec<SchemaConflictItem>);
|
||||||
/// optional in the future), where as the in-memory format needs the package
|
/// optional in the future), where as the in-memory format needs the package
|
||||||
/// name.
|
/// name.
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
|
||||||
Clone,
|
|
||||||
Eq,
|
|
||||||
Hash,
|
|
||||||
PartialEq,
|
|
||||||
PartialOrd,
|
|
||||||
Ord,
|
|
||||||
serde::Deserialize,
|
|
||||||
serde::Serialize,
|
|
||||||
schemars::JsonSchema,
|
|
||||||
)]
|
)]
|
||||||
#[serde(
|
#[serde(
|
||||||
deny_unknown_fields,
|
deny_unknown_fields,
|
||||||
|
|
@ -457,6 +437,16 @@ pub struct SchemaConflictItem {
|
||||||
conflict: ConflictPackage,
|
conflict: ConflictPackage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl schemars::JsonSchema for SchemaConflictItem {
|
||||||
|
fn schema_name() -> String {
|
||||||
|
"SchemaConflictItem".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
||||||
|
<ConflictItemWire as schemars::JsonSchema>::json_schema(gen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'de> serde::Deserialize<'de> for SchemaConflictSet {
|
impl<'de> serde::Deserialize<'de> for SchemaConflictSet {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<SchemaConflictSet, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<SchemaConflictSet, D::Error>
|
||||||
where
|
where
|
||||||
|
|
@ -480,7 +470,11 @@ impl TryFrom<Vec<SchemaConflictItem>> for SchemaConflictSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
/// A single item in a conflicting set.
|
||||||
|
///
|
||||||
|
/// Each item is a pair of an (optional) package and a corresponding extra or group name for that
|
||||||
|
/// package.
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
|
||||||
struct ConflictItemWire {
|
struct ConflictItemWire {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
package: Option<PackageName>,
|
package: Option<PackageName>,
|
||||||
|
|
|
||||||
|
|
@ -623,35 +623,6 @@
|
||||||
"$ref": "#/definitions/ConfigSettingValue"
|
"$ref": "#/definitions/ConfigSettingValue"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ConflictPackage": {
|
|
||||||
"description": "The actual conflicting data for a package.\n\nThat is, either an extra or a group name.",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"Extra"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"Extra": {
|
|
||||||
"$ref": "#/definitions/ExtraName"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"Group"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"Group": {
|
|
||||||
"$ref": "#/definitions/GroupName"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"ExcludeNewer": {
|
"ExcludeNewer": {
|
||||||
"description": "Exclude distributions uploaded after the given timestamp.\n\nAccepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same format (e.g., `2006-12-02`).",
|
"description": "Exclude distributions uploaded after the given timestamp.\n\nAccepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same format (e.g., `2006-12-02`).",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
@ -1454,16 +1425,33 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"SchemaConflictItem": {
|
"SchemaConflictItem": {
|
||||||
"description": "Like [`ConflictItem`], but for deserialization in `pyproject.toml`.\n\nThe schema format is different from the in-memory format. Specifically, the schema format does not allow specifying the package name (or will make it optional in the future), where as the in-memory format needs the package name.",
|
"description": "A single item in a conflicting set.\n\nEach item is a pair of an (optional) package and a corresponding extra or group name for that package.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
|
||||||
"conflict"
|
|
||||||
],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"conflict": {
|
"extra": {
|
||||||
"$ref": "#/definitions/ConflictPackage"
|
"default": null,
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/ExtraName"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"default": null,
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/GroupName"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
|
"default": null,
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
"$ref": "#/definitions/PackageName"
|
"$ref": "#/definitions/PackageName"
|
||||||
|
|
@ -1473,8 +1461,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"additionalProperties": false
|
|
||||||
},
|
},
|
||||||
"SchemaConflictSet": {
|
"SchemaConflictSet": {
|
||||||
"description": "Like [`ConflictSet`], but for deserialization in `pyproject.toml`.\n\nThe schema format is different from the in-memory format. Specifically, the schema format does not allow specifying the package name (or will make it optional in the future), where as the in-memory format needs the package name.",
|
"description": "Like [`ConflictSet`], but for deserialization in `pyproject.toml`.\n\nThe schema format is different from the in-memory format. Specifically, the schema format does not allow specifying the package name (or will make it optional in the future), where as the in-memory format needs the package name.",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue