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>
This commit is contained in:
+40
-3
@@ -1,11 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--schemastore", action="store_true", help="Generate schema_store version")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
starter = """
|
starter = """
|
||||||
$id: https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/resources/cibuildwheel.schema.json
|
$id: https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/resources/cibuildwheel.schema.json
|
||||||
$schema: http://json-schema.org/draft-07/schema
|
$schema: http://json-schema.org/draft-07/schema
|
||||||
@@ -146,6 +151,9 @@ properties:
|
|||||||
|
|
||||||
schema = yaml.safe_load(starter)
|
schema = yaml.safe_load(starter)
|
||||||
|
|
||||||
|
if args.schemastore:
|
||||||
|
schema["$id"] += "#"
|
||||||
|
|
||||||
string_array = yaml.safe_load(
|
string_array = yaml.safe_load(
|
||||||
"""
|
"""
|
||||||
- type: string
|
- type: string
|
||||||
@@ -177,7 +185,7 @@ string_table = yaml.safe_load(
|
|||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
patternProperties:
|
patternProperties:
|
||||||
.+:
|
.+:
|
||||||
- type: string
|
type: string
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -210,7 +218,13 @@ items:
|
|||||||
for key, value in schema["properties"].items():
|
for key, value in schema["properties"].items():
|
||||||
value["title"] = f'CIBW_{key.replace("-", "_").upper()}'
|
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["build"]
|
||||||
del non_global_options["skip"]
|
del non_global_options["skip"]
|
||||||
del non_global_options["container-engine"]
|
del non_global_options["container-engine"]
|
||||||
@@ -257,4 +271,27 @@ del oses["linux"]["properties"]["dependency-versions"]
|
|||||||
schema["properties"]["overrides"] = overrides
|
schema["properties"]["overrides"] = overrides
|
||||||
schema["properties"] |= oses
|
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
|
||||||
|
properties:
|
||||||
|
cibuildwheel:
|
||||||
|
type: object
|
||||||
|
"""
|
||||||
|
schema_store = yaml.safe_load(schema_store_txt)
|
||||||
|
|
||||||
|
schema_store["properties"]["tool"]["properties"]["cibuildwheel"]["properties"] = schema[
|
||||||
|
"properties"
|
||||||
|
]
|
||||||
|
|
||||||
|
print(json.dumps(schema_store, indent=2))
|
||||||
|
|||||||
@@ -218,11 +218,9 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
".+": [
|
".+": {
|
||||||
{
|
"type": "string"
|
||||||
"type": "string"
|
}
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ def update_proj(session: nox.Session) -> None:
|
|||||||
|
|
||||||
@nox.session(reuse_venv=True)
|
@nox.session(reuse_venv=True)
|
||||||
def generate_schema(session: nox.Session) -> None:
|
def generate_schema(session: nox.Session) -> None:
|
||||||
|
"""
|
||||||
|
Generate the cibuildwheel.schema.json file.
|
||||||
|
"""
|
||||||
session.install("pyyaml")
|
session.install("pyyaml")
|
||||||
output = session.run("python", "bin/generate_schema.py", silent=True)
|
output = session.run("python", "bin/generate_schema.py", silent=True)
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
|
|||||||
Reference in New Issue
Block a user