Skip to content

Commit

Permalink
fix(schema): small bug + prepare for SchemaStore
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Oct 6, 2023
1 parent fff9ec3 commit 34538a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
42 changes: 39 additions & 3 deletions bin/generate_schema.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env python

import argparse
import copy
import json
from typing import Any

import yaml

parser = argparse.ArgumentParser()
parser.add_argument("--schemastore", action="store_true", help="Generate schema_store version")
args = parser.parse_args()

starter = """
$id: https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/resources/cibuildwheel.schema.json
$schema: http://json-schema.org/draft-07/schema
Expand Down Expand Up @@ -177,7 +182,7 @@
additionalProperties: false
patternProperties:
.+:
- type: string
type: string
"""
)

Expand Down Expand Up @@ -210,7 +215,13 @@
for key, value in schema["properties"].items():
value["title"] = f'CIBW_{key.replace("-", "_").upper()}'

non_global_options = {k: {"$ref": f"#/properties/{k}"} for k in schema["properties"]}
if args.schemastore:
non_global_options = {
k: {"$ref": f"#/properties/tool/properties/cibuildwheel/properties/{k}"}
for k in schema["properties"]
}
else:
non_global_options = {k: {"$ref": f"#/properties/{k}"} for k in schema["properties"]}
del non_global_options["build"]
del non_global_options["skip"]
del non_global_options["container-engine"]
Expand Down Expand Up @@ -257,4 +268,29 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
schema["properties"]["overrides"] = overrides
schema["properties"] |= oses

print(json.dumps(schema, indent=2))
if not args.schemastore:
print(json.dumps(schema, indent=2))
raise SystemExit(0)

schema_store_txt = """
$id: https://json.schemastore.org/cibuildwheel.json
$schema: http://json-schema.org/draft-07/schema#
additionalProperties: false
description: cibuildwheel's toml file, generated with ./bin/generate_schema.py --schemastore from cibuildwheel.
type: object
properties:
tool:
type: object
additionalProperties: false
properties:
cibuildwheel:
type: object
additionalProperties: false
"""
schema_store = yaml.safe_load(schema_store_txt)

schema_store["properties"]["tool"]["properties"]["cibuildwheel"]["properties"] = schema[
"properties"
]

print(json.dumps(schema_store, indent=2))
8 changes: 3 additions & 5 deletions cibuildwheel/resources/cibuildwheel.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,9 @@
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
"type": "string"
}
]
".+": {
"type": "string"
}
}
}
],
Expand Down
3 changes: 3 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def update_proj(session: nox.Session) -> None:

@nox.session(reuse_venv=True)
def generate_schema(session: nox.Session) -> None:
"""
Generate the cibuildwheel.schema.json file.
"""
session.install("pyyaml")
output = session.run("python", "bin/generate_schema.py", silent=True)
assert isinstance(output, str)
Expand Down

0 comments on commit 34538a9

Please sign in to comment.