Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 5 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ rust-netrc = { version = "0.1.2" }
rustc-hash = { version = "2.0.0" }
rustix = { version = "1.0.0", default-features = false, features = ["fs", "std"] }
same-file = { version = "1.0.6" }
schemars = { version = "0.8.21", features = ["url"] }
schemars = { version = "1.0.0-rc.1", features = ["url2"] }
seahash = { version = "4.1.0" }
self-replace = { version = "1.5.0" }
serde = { version = "1.0.210", features = ["derive", "rc"] }
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-build-backend/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
use std::fmt::Display;
use std::path::PathBuf;
use uv_macros::OptionsMetadata;

Expand Down
30 changes: 9 additions & 21 deletions crates/uv-configuration/src/name_specifiers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::str::FromStr;
use std::{borrow::Cow, str::FromStr};

use uv_pep508::PackageName;

Expand Down Expand Up @@ -63,28 +63,16 @@ impl<'de> serde::Deserialize<'de> for PackageNameSpecifier {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for PackageNameSpecifier {
fn schema_name() -> String {
"PackageNameSpecifier".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("PackageNameSpecifier")
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
string: Some(Box::new(schemars::schema::StringValidation {
// See: https://packaging.python.org/en/latest/specifications/name-normalization/#name-format
pattern: Some(
r"^(:none:|:all:|([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]))$"
.to_string(),
),
..schemars::schema::StringValidation::default()
})),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some("The name of a package, or `:all:` or `:none:` to select or omit all packages, respectively.".to_string()),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn json_schema(_gen: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"pattern": r"^(:none:|:all:|([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]))$",
"description": "The name of a package, or `:all:` or `:none:` to select or omit all packages, respectively.",
})
}
}

Expand Down
21 changes: 8 additions & 13 deletions crates/uv-configuration/src/required_version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::Formatter;
use std::str::FromStr;
use std::{borrow::Cow, fmt::Formatter};

use uv_pep440::{Version, VersionSpecifier, VersionSpecifiers, VersionSpecifiersParseError};

Expand Down Expand Up @@ -36,20 +36,15 @@ impl FromStr for RequiredVersion {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for RequiredVersion {
fn schema_name() -> String {
String::from("RequiredVersion")
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("RequiredVersion")
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some("A version specifier, e.g. `>=0.5.0` or `==0.5.0`.".to_string()),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "A version specifier, e.g. `>=0.5.0` or `==0.5.0`."
})
}
}

Expand Down
21 changes: 8 additions & 13 deletions crates/uv-configuration/src/trusted_host.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Deserializer};
use std::str::FromStr;
use std::{borrow::Cow, str::FromStr};
use url::Url;

/// A host specification (wildcard, or host, with optional scheme and/or port) for which
Expand Down Expand Up @@ -143,20 +143,15 @@ impl std::fmt::Display for TrustedHost {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for TrustedHost {
fn schema_name() -> String {
"TrustedHost".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("TrustedHost")
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some("A host or host-port pair.".to_string()),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "A host or host-port pair."
})
}
}

Expand Down
7 changes: 5 additions & 2 deletions crates/uv-dev/src/generate_json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;
use anstream::println;
use anyhow::{Result, bail};
use pretty_assertions::StrComparison;
use schemars::{JsonSchema, schema_for};
use schemars::JsonSchema;
use serde::Deserialize;

use uv_settings::Options as SettingsOptions;
Expand Down Expand Up @@ -91,7 +91,10 @@ const REPLACEMENTS: &[(&str, &str)] = &[

/// Generate the JSON schema for the combined options as a string.
fn generate() -> String {
let schema = schema_for!(CombinedOptions);
let settings = schemars::generate::SchemaSettings::draft07();
let generator = schemars::SchemaGenerator::new(settings);
let schema = generator.into_root_schema_for::<CombinedOptions>();

let mut output = serde_json::to_string_pretty(&schema).unwrap();

for (value, replacement) in REPLACEMENTS {
Expand Down
23 changes: 9 additions & 14 deletions crates/uv-distribution-types/src/index_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,15 @@ impl IndexUrl {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for IndexUrl {
fn schema_name() -> String {
"IndexUrl".to_string()
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some("The URL of an index to use for fetching packages (e.g., `https://pypi.org/simple`), or a local path.".to_string()),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("IndexUrl")
}

fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "The URL of an index to use for fetching packages (e.g., `https://pypi.org/simple`), or a local path."
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/uv-distribution-types/src/pip_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! flags set.

use serde::{Deserialize, Deserializer, Serialize};
use std::path::Path;
use std::{borrow::Cow, path::Path};

use crate::{Index, IndexUrl};

Expand Down Expand Up @@ -50,14 +50,14 @@ macro_rules! impl_index {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for $name {
fn schema_name() -> String {
fn schema_name() -> Cow<'static, str> {
IndexUrl::schema_name()
}

fn json_schema(
r#gen: &mut schemars::r#gen::SchemaGenerator,
) -> schemars::schema::Schema {
IndexUrl::json_schema(r#gen)
generator: &mut schemars::generate::SchemaGenerator,
) -> schemars::Schema {
IndexUrl::json_schema(generator)
}
}
};
Expand Down
20 changes: 10 additions & 10 deletions crates/uv-distribution-types/src/status_code_strategy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::Deref;
use std::{borrow::Cow, ops::Deref};

use http::StatusCode;
use rustc_hash::FxHashSet;
Expand Down Expand Up @@ -136,17 +136,17 @@ impl<'de> Deserialize<'de> for SerializableStatusCode {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for SerializableStatusCode {
fn schema_name() -> String {
"StatusCode".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("StatusCode")
}

fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
let mut schema = r#gen.subschema_for::<u16>().into_object();
schema.metadata().description = Some("HTTP status code (100-599)".to_string());
schema.number().minimum = Some(100.0);
schema.number().maximum = Some(599.0);

schema.into()
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "number",
"minimum": 100,
"maximum": 599,
"description": "HTTP status code (100-599)"
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ pub struct PortablePathBuf(Box<Path>);

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for PortablePathBuf {
fn schema_name() -> String {
PathBuf::schema_name()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("PortablePathBuf")
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
PathBuf::json_schema(_gen)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-pep508/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ version-ranges = { workspace = true }

[dev-dependencies]
insta = { version = "1.40.0" }
serde_json = { version = "1.0.128" }
serde_json = { workspace = true }
tracing-test = { version = "0.2.5" }

[features]
Expand Down
26 changes: 10 additions & 16 deletions crates/uv-pep508/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#![warn(missing_docs)]

use std::borrow::Cow;
use std::error::Error;
use std::fmt::{Debug, Display, Formatter};
use std::path::Path;
Expand Down Expand Up @@ -334,22 +335,15 @@ impl Reporter for TracingReporter {

#[cfg(feature = "schemars")]
impl<T: Pep508Url> schemars::JsonSchema for Requirement<T> {
fn schema_name() -> String {
"Requirement".to_string()
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(
"A PEP 508 dependency specifier, e.g., `ruff >= 0.6.0`".to_string(),
),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("Requirement")
}

fn json_schema(_gen: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "A PEP 508 dependency specifier, e.g., `ruff >= 0.6.0`"
})
}
}

Expand Down
24 changes: 8 additions & 16 deletions crates/uv-pep508/src/marker/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,23 +1707,15 @@ impl Display for MarkerTreeContents {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for MarkerTree {
fn schema_name() -> String {
"MarkerTree".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("MarkerTree")
}

fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::String.into()),
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(
"A PEP 508-compliant marker expression, e.g., `sys_platform == 'Darwin'`"
.to_string(),
),
..schemars::schema::Metadata::default()
})),
..schemars::schema::SchemaObject::default()
}
.into()
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "A PEP 508-compliant marker expression, e.g., `sys_platform == 'Darwin'`"
})
}
}

Expand Down Expand Up @@ -2515,7 +2507,7 @@ mod test {
#[test]
fn test_simplification_extra_versus_other() {
// Here, the `extra != 'foo'` cannot be simplified out, because
// `extra == 'foo'` can be true even when `extra == 'bar`' is true.
// `extra == 'foo'` can be true even when `extra == 'bar'`' is true.
assert_simplifies(
r#"extra != "foo" and (extra == "bar" or extra == "baz")"#,
"(extra == 'bar' and extra != 'foo') or (extra == 'baz' and extra != 'foo')",
Expand Down
10 changes: 5 additions & 5 deletions crates/uv-pypi-types/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use petgraph::{
graph::{DiGraph, NodeIndex},
};
use rustc_hash::{FxHashMap, FxHashSet};
use std::{collections::BTreeSet, hash::Hash, rc::Rc};
use std::{borrow::Cow, collections::BTreeSet, hash::Hash, rc::Rc};
use uv_normalize::{ExtraName, GroupName, PackageName};

use crate::dependency_groups::{DependencyGroupSpecifier, DependencyGroups};
Expand Down Expand Up @@ -638,12 +638,12 @@ pub struct SchemaConflictItem {

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for SchemaConflictItem {
fn schema_name() -> String {
"SchemaConflictItem".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("SchemaConflictItem")
}

fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
<ConflictItemWire as schemars::JsonSchema>::json_schema(r#gen)
fn json_schema(generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
<ConflictItemWire as schemars::JsonSchema>::json_schema(generator)
}
}

Expand Down
Loading
Loading