|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
| 3 | +import argparse |
3 | 4 | import copy
|
4 | 5 | import json
|
5 | 6 | from typing import Any
|
6 | 7 |
|
7 | 8 | import yaml
|
8 | 9 |
|
| 10 | +parser = argparse.ArgumentParser() |
| 11 | +parser.add_argument("--schemastore", action="store_true", help="Generate schema_store version") |
| 12 | +args = parser.parse_args() |
| 13 | + |
9 | 14 | starter = """
|
10 | 15 | $id: https://github.com/pypa/cibuildwheel/blob/main/cibuildwheel/resources/cibuildwheel.schema.json
|
11 | 16 | $schema: http://json-schema.org/draft-07/schema
|
|
146 | 151 |
|
147 | 152 | schema = yaml.safe_load(starter)
|
148 | 153 |
|
| 154 | +if args.schemastore: |
| 155 | + schema["$id"] += "#" |
| 156 | + |
149 | 157 | string_array = yaml.safe_load(
|
150 | 158 | """
|
151 | 159 | - type: string
|
|
177 | 185 | additionalProperties: false
|
178 | 186 | patternProperties:
|
179 | 187 | .+:
|
180 |
| - - type: string |
| 188 | + type: string |
181 | 189 | """
|
182 | 190 | )
|
183 | 191 |
|
|
210 | 218 | for key, value in schema["properties"].items():
|
211 | 219 | value["title"] = f'CIBW_{key.replace("-", "_").upper()}'
|
212 | 220 |
|
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"]} |
214 | 228 | del non_global_options["build"]
|
215 | 229 | del non_global_options["skip"]
|
216 | 230 | del non_global_options["container-engine"]
|
@@ -257,4 +271,27 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
|
257 | 271 | schema["properties"]["overrides"] = overrides
|
258 | 272 | schema["properties"] |= oses
|
259 | 273 |
|
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)) |
0 commit comments