Skip to content

Commit

Permalink
feat: add inherit to override (#1730)
Browse files Browse the repository at this point in the history
* feat: add inherit to override

Signed-off-by: Henry Schreiner <[email protected]>

* refactor: use dict and support prepend

Signed-off-by: Henry Schreiner <[email protected]>

* Refactor: simplifying by splitting the responsibilities of _dig_first

* Refactor to allow merging of string settings, and preserve table cascades

* docs: add some docs for inherit

Signed-off-by: Henry Schreiner <[email protected]>

* Apply suggestions from code review

Co-authored-by: Joe Rickerby <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
Co-authored-by: Joe Rickerby <[email protected]>
  • Loading branch information
henryiii and joerick authored Mar 2, 2024
1 parent ae2451a commit 8f58f71
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 144 deletions.
64 changes: 31 additions & 33 deletions bin/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
additionalProperties: false
description: cibuildwheel's settings.
type: object
defines:
inherit:
enum:
- none
- prepend
- append
default: none
description: How to inherit the parent's value.
properties:
archs:
description: Change the architectures built on your machine by default.
Expand Down Expand Up @@ -153,9 +161,6 @@

schema = yaml.safe_load(starter)

if args.schemastore:
schema["$id"] += "#"

string_array = yaml.safe_load(
"""
- type: string
Expand Down Expand Up @@ -214,19 +219,28 @@
additionalProperties: false
properties:
select: {}
inherit:
type: object
additionalProperties: false
properties:
before-all: {"$ref": "#/defines/inherit"}
before-build: {"$ref": "#/defines/inherit"}
before-test: {"$ref": "#/defines/inherit"}
config-settings: {"$ref": "#/defines/inherit"}
container-engine: {"$ref": "#/defines/inherit"}
environment: {"$ref": "#/defines/inherit"}
environment-pass: {"$ref": "#/defines/inherit"}
repair-wheel-command: {"$ref": "#/defines/inherit"}
test-command: {"$ref": "#/defines/inherit"}
test-extras: {"$ref": "#/defines/inherit"}
test-requires: {"$ref": "#/defines/inherit"}
"""
)

for key, value in schema["properties"].items():
value["title"] = f'CIBW_{key.replace("-", "_").upper()}'

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"]}
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 @@ -273,27 +287,11 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
schema["properties"]["overrides"] = overrides
schema["properties"] |= oses

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"
]
if args.schemastore:
schema["$id"] = "https://json.schemastore.org/partial-cibuildwheel.json"
schema["$schema"] = "http://json-schema.org/draft-07/schema#"
schema[
"description"
] = "cibuildwheel's toml file, generated with ./bin/generate_schema.py --schemastore from cibuildwheel."

print(json.dumps(schema_store, indent=2))
print(json.dumps(schema, indent=2))
Loading

0 comments on commit 8f58f71

Please sign in to comment.