Skip to content

Commit 36e4080

Browse files
authored
fix(schema): small bug + prepare for SchemaStore (#1638)
* fix(schema): small bug + prepare for SchemaStore Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * fix(schema): schema kw is supposed to have a number sign * fix(schema): differing conventions Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent fff9ec3 commit 36e4080

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

bin/generate_schema.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
#!/usr/bin/env python
22

3+
import argparse
34
import copy
45
import json
56
from typing import Any
67

78
import yaml
89

10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("--schemastore", action="store_true", help="Generate schema_store version")
12+
args = parser.parse_args()
13+
914
starter = """
1015
$id: https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/resources/cibuildwheel.schema.json
1116
$schema: http://json-schema.org/draft-07/schema
@@ -146,6 +151,9 @@
146151

147152
schema = yaml.safe_load(starter)
148153

154+
if args.schemastore:
155+
schema["$id"] += "#"
156+
149157
string_array = yaml.safe_load(
150158
"""
151159
- type: string
@@ -177,7 +185,7 @@
177185
additionalProperties: false
178186
patternProperties:
179187
.+:
180-
- type: string
188+
type: string
181189
"""
182190
)
183191

@@ -210,7 +218,13 @@
210218
for key, value in schema["properties"].items():
211219
value["title"] = f'CIBW_{key.replace("-", "_").upper()}'
212220

213-
non_global_options = {k: {"$ref": f"#/properties/{k}"} for k in schema["properties"]}
221+
if args.schemastore:
222+
non_global_options = {
223+
k: {"$ref": f"#/properties/tool/properties/cibuildwheel/properties/{k}"}
224+
for k in schema["properties"]
225+
}
226+
else:
227+
non_global_options = {k: {"$ref": f"#/properties/{k}"} for k in schema["properties"]}
214228
del non_global_options["build"]
215229
del non_global_options["skip"]
216230
del non_global_options["container-engine"]
@@ -257,4 +271,27 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
257271
schema["properties"]["overrides"] = overrides
258272
schema["properties"] |= oses
259273

260-
print(json.dumps(schema, indent=2))
274+
if not args.schemastore:
275+
print(json.dumps(schema, indent=2))
276+
raise SystemExit(0)
277+
278+
schema_store_txt = """
279+
$id: https://json.schemastore.org/cibuildwheel.json
280+
$schema: http://json-schema.org/draft-07/schema#
281+
additionalProperties: false
282+
description: cibuildwheel's toml file, generated with ./bin/generate_schema.py --schemastore from cibuildwheel.
283+
type: object
284+
properties:
285+
tool:
286+
type: object
287+
properties:
288+
cibuildwheel:
289+
type: object
290+
"""
291+
schema_store = yaml.safe_load(schema_store_txt)
292+
293+
schema_store["properties"]["tool"]["properties"]["cibuildwheel"]["properties"] = schema[
294+
"properties"
295+
]
296+
297+
print(json.dumps(schema_store, indent=2))

cibuildwheel/resources/cibuildwheel.schema.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,9 @@
218218
"type": "object",
219219
"additionalProperties": false,
220220
"patternProperties": {
221-
".+": [
222-
{
223-
"type": "string"
224-
}
225-
]
221+
".+": {
222+
"type": "string"
223+
}
226224
}
227225
}
228226
],

noxfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def update_proj(session: nox.Session) -> None:
115115

116116
@nox.session(reuse_venv=True)
117117
def generate_schema(session: nox.Session) -> None:
118+
"""
119+
Generate the cibuildwheel.schema.json file.
120+
"""
118121
session.install("pyyaml")
119122
output = session.run("python", "bin/generate_schema.py", silent=True)
120123
assert isinstance(output, str)

0 commit comments

Comments
 (0)