Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions crates/uv-pypi-types/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use uv_normalize::{ExtraName, GroupName, PackageName};
/// This is useful to force the resolver to fork according to extras that have
/// unavoidable conflicts with each other. (The alternative is that resolution
/// will fail.)
#[derive(
Debug, Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
)]
#[derive(Debug, Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Conflicts(Vec<ConflictSet>);

impl Conflicts {
Expand Down Expand Up @@ -60,7 +58,7 @@ impl Conflicts {
///
/// A `TryFrom<Vec<ConflictItem>>` impl may be used to build a set from a
/// 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>);

impl ConflictSet {
Expand Down Expand Up @@ -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
/// package.
#[derive(
Debug,
Clone,
Eq,
Hash,
PartialEq,
PartialOrd,
Ord,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
)]
#[serde(
deny_unknown_fields,
Expand Down Expand Up @@ -252,7 +241,7 @@ impl hashbrown::Equivalent<ConflictItem> for ConflictItemRef<'_> {
/// The actual conflicting data for a package.
///
/// 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 {
Extra(ExtraName),
Group(GroupName),
Expand Down Expand Up @@ -426,7 +415,7 @@ impl SchemaConflicts {
/// 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.
#[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>);

/// Like [`ConflictItem`], but for deserialization in `pyproject.toml`.
Expand All @@ -436,16 +425,7 @@ pub struct SchemaConflictSet(Vec<SchemaConflictItem>);
/// optional in the future), where as the in-memory format needs the package
/// name.
#[derive(
Debug,
Clone,
Eq,
Hash,
PartialEq,
PartialOrd,
Ord,
serde::Deserialize,
serde::Serialize,
schemars::JsonSchema,
Debug, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, serde::Deserialize, serde::Serialize,
)]
#[serde(
deny_unknown_fields,
Expand All @@ -457,6 +437,16 @@ pub struct SchemaConflictItem {
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 {
fn deserialize<D>(deserializer: D) -> Result<SchemaConflictSet, D::Error>
where
Expand All @@ -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 {
#[serde(default)]
package: Option<PackageName>,
Expand Down
61 changes: 24 additions & 37 deletions uv.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.