Skip to content

Commit 8a0d481

Browse files
joerickampagenthenryiii
authored
Add the ability to set 'inherit' at all levels of the options cascade (#2928)
* Add the ability to set 'inherit' at all levels of the options cascade * add tests * Clarify util name/docs * Document option inheritance across configuration layers Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 Co-authored-by: Joe Rickerby <[email protected]> * update schema * Validate inherit option names Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Validate overrides eagerly Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Harden inherit rule parsing Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Report unsupported option inheritance Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Handle null list values during inheritance Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Add inheritance to the configuration schema Amp-Thread-ID: https://ampcode.com/threads/T-019fefe0-6bbb-736e-b01c-d7f15d2db320 * Fix unsupported options merging empty values - prefer to fail fast * stylistic changes * Apply suggestion from @henryiii Co-authored-by: Henry Schreiner <[email protected]> --------- Co-authored-by: Amp <[email protected]> Co-authored-by: Henry Schreiner <[email protected]>
1 parent 8bc038b commit 8a0d481

10 files changed

Lines changed: 1258 additions & 193 deletions

File tree

‎bin/generate_schema.py‎

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@
4040
description: cibuildwheel's settings.
4141
type: object
4242
properties:
43+
inherit:
44+
type: object
45+
additionalProperties: false
46+
properties:
47+
audit-command: {"$ref": "#/$defs/inherit"}
48+
audit-requires: {"$ref": "#/$defs/inherit"}
49+
before-all: {"$ref": "#/$defs/inherit"}
50+
before-build: {"$ref": "#/$defs/inherit"}
51+
xbuild-tools: {"$ref": "#/$defs/inherit"}
52+
xbuild-files: {"$ref": "#/$defs/inherit"}
53+
before-test: {"$ref": "#/$defs/inherit"}
54+
config-settings: {"$ref": "#/$defs/inherit"}
55+
container-engine: {"$ref": "#/$defs/inherit"}
56+
environment: {"$ref": "#/$defs/inherit"}
57+
environment-pass: {"$ref": "#/$defs/inherit"}
58+
repair-wheel-command: {"$ref": "#/$defs/inherit"}
59+
test-command: {"$ref": "#/$defs/inherit"}
60+
test-extras: {"$ref": "#/$defs/inherit"}
61+
test-sources: {"$ref": "#/$defs/inherit"}
62+
test-requires: {"$ref": "#/$defs/inherit"}
63+
test-environment: {"$ref": "#/$defs/inherit"}
64+
test-runtime: {"$ref": "#/$defs/inherit"}
4365
audit-command:
4466
description: Execute a shell command to audit each wheel after it is repaired. Use {wheel} for each wheel path, or {abi3_wheel} to only audit abi3 wheels.
4567
type: string_array
@@ -332,31 +354,30 @@ def build_frontend_schema(
332354
additionalProperties: false
333355
properties:
334356
select: {}
335-
inherit:
336-
type: object
337-
additionalProperties: false
338-
properties:
339-
audit-command: {"$ref": "#/$defs/inherit"}
340-
audit-requires: {"$ref": "#/$defs/inherit"}
341-
before-all: {"$ref": "#/$defs/inherit"}
342-
before-build: {"$ref": "#/$defs/inherit"}
343-
xbuild-tools: {"$ref": "#/$defs/inherit"}
344-
xbuild-files: {"$ref": "#/$defs/inherit"}
345-
before-test: {"$ref": "#/$defs/inherit"}
346-
config-settings: {"$ref": "#/$defs/inherit"}
347-
container-engine: {"$ref": "#/$defs/inherit"}
348-
environment: {"$ref": "#/$defs/inherit"}
349-
environment-pass: {"$ref": "#/$defs/inherit"}
350-
repair-wheel-command: {"$ref": "#/$defs/inherit"}
351-
test-command: {"$ref": "#/$defs/inherit"}
352-
test-extras: {"$ref": "#/$defs/inherit"}
353-
test-sources: {"$ref": "#/$defs/inherit"}
354-
test-requires: {"$ref": "#/$defs/inherit"}
355-
test-environment: {"$ref": "#/$defs/inherit"}
356-
test-runtime: {"$ref": "#/$defs/inherit"}
357357
"""
358358
)
359359

360+
INHERITABLE_OPTIONS = frozenset(
361+
{
362+
"audit-command",
363+
"audit-requires",
364+
"before-all",
365+
"before-build",
366+
"before-test",
367+
"config-settings",
368+
"environment",
369+
"environment-pass",
370+
"repair-wheel-command",
371+
"test-command",
372+
"test-environment",
373+
"test-extras",
374+
"test-groups",
375+
"test-requires",
376+
"test-sources",
377+
"xbuild-tools",
378+
}
379+
)
380+
360381
for key, value in schema["properties"].items():
361382
value["title"] = f"CIBW_{key.replace('-', '_').upper()}"
362383

@@ -388,6 +409,19 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
388409
}
389410

390411

412+
def inherit_schema(options: dict[str, Any]) -> dict[str, Any]:
413+
properties = {
414+
name: {"$ref": "#/$defs/inherit"} for name in options if name in INHERITABLE_OPTIONS
415+
}
416+
return {
417+
"description": "How options at this configuration level inherit previous values.",
418+
"oneOf": [
419+
{"type": "string"},
420+
as_object(properties),
421+
],
422+
}
423+
424+
391425
oses = {
392426
"linux": as_object(non_global_options),
393427
"windows": as_object(not_linux),
@@ -410,6 +444,13 @@ def as_object(d: dict[str, Any]) -> dict[str, Any]:
410444

411445
del oses["linux"]["properties"]["dependency-versions"]
412446

447+
schema["properties"]["inherit"] = {
448+
**inherit_schema(schema["properties"]),
449+
"title": "CIBW_INHERIT",
450+
}
451+
overrides["items"]["properties"]["inherit"] = inherit_schema(overrides["items"]["properties"])
452+
for os_schema in oses.values():
453+
os_schema["properties"]["inherit"] = inherit_schema(os_schema["properties"])
413454

414455
schema["$defs"]["build-frontend-no-pyodide"] = build_frontend_schema(
415456
FRONTENDS,

0 commit comments

Comments
 (0)