diff --git a/bin/generate_schema.py b/bin/generate_schema.py index e4f4507d2..b33cc092e 100755 --- a/bin/generate_schema.py +++ b/bin/generate_schema.py @@ -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 @@ -177,7 +182,7 @@ additionalProperties: false patternProperties: .+: - - type: string + type: string """ ) @@ -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"] @@ -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)) diff --git a/cibuildwheel/resources/cibuildwheel.schema.json b/cibuildwheel/resources/cibuildwheel.schema.json index 99b11117f..bc693ef60 100644 --- a/cibuildwheel/resources/cibuildwheel.schema.json +++ b/cibuildwheel/resources/cibuildwheel.schema.json @@ -218,11 +218,9 @@ "type": "object", "additionalProperties": false, "patternProperties": { - ".+": [ - { - "type": "string" - } - ] + ".+": { + "type": "string" + } } } ], diff --git a/noxfile.py b/noxfile.py index 397d6e722..8747b91dd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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)