Skip to content

Commit

Permalink
fix: add test of examples in docs and fix
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Sep 21, 2023
1 parent 7b88dd3 commit a5db7f8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 7 deletions.
11 changes: 8 additions & 3 deletions bin/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
string_table_array = yaml.safe_load(
"""
- type: string
- patternProperties:
- type: object
additionalProperties: false
patternProperties:
.+:
oneOf:
- type: string
Expand All @@ -170,7 +172,9 @@
string_table = yaml.safe_load(
"""
- type: string
- patternProperties:
- type: object
additionalProperties: false
patternProperties:
.+:
- type: string
"""
Expand Down Expand Up @@ -207,11 +211,12 @@
del non_global_options["skip"]
del non_global_options["container-engine"]
del non_global_options["test-skip"]
del non_global_options["archs"]

overrides["items"]["properties"]["select"]["oneOf"] = string_array
overrides["items"]["properties"] |= non_global_options.copy()

del overrides["items"]["properties"]["archs"]

not_linux = non_global_options.copy()

del not_linux["environment-pass"]
Expand Down
65 changes: 65 additions & 0 deletions cibuildwheel/resources/cibuildwheel.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": {
"oneOf": [
Expand Down Expand Up @@ -214,6 +216,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
Expand Down Expand Up @@ -522,6 +526,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": {
"oneOf": [
Expand Down Expand Up @@ -554,6 +560,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
Expand Down Expand Up @@ -712,6 +720,21 @@
"type": "object",
"additionalProperties": false,
"properties": {
"archs": {
"description": "Change the architectures built on your machine by default.",
"title": "CIBW_ARCHS",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"before-all": {
"description": "Execute a shell command on the build system before any wheels are built.",
"title": "CIBW_BEFORE_ALL",
Expand Down Expand Up @@ -816,6 +839,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": {
"oneOf": [
Expand All @@ -842,6 +867,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
Expand Down Expand Up @@ -999,6 +1026,21 @@
"type": "object",
"additionalProperties": false,
"properties": {
"archs": {
"description": "Change the architectures built on your machine by default.",
"title": "CIBW_ARCHS",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"before-all": {
"description": "Execute a shell command on the build system before any wheels are built.",
"title": "CIBW_BEFORE_ALL",
Expand Down Expand Up @@ -1103,6 +1145,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": {
"oneOf": [
Expand Down Expand Up @@ -1135,6 +1179,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
Expand Down Expand Up @@ -1212,6 +1258,21 @@
"type": "object",
"additionalProperties": false,
"properties": {
"archs": {
"description": "Change the architectures built on your machine by default.",
"title": "CIBW_ARCHS",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"before-all": {
"description": "Execute a shell command on the build system before any wheels are built.",
"title": "CIBW_BEFORE_ALL",
Expand Down Expand Up @@ -1316,6 +1377,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": {
"oneOf": [
Expand Down Expand Up @@ -1348,6 +1411,8 @@
"type": "string"
},
{
"type": "object",
"additionalProperties": false,
"patternProperties": {
".+": [
{
Expand Down
4 changes: 0 additions & 4 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,9 +898,7 @@ Platform-specific environment variables are also available:<br/>
CIBW_REPAIR_WHEEL_COMMAND: >
python scripts/repair_wheel.py -w {dest_dir} {wheel} &&
python scripts/check_repaired_wheel.py -w {dest_dir} {wheel}
```

```yaml
# Use abi3audit to catch issues with Limited API wheels
CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
auditwheel repair -w {dest_dir} {wheel} &&
Expand Down Expand Up @@ -934,9 +932,7 @@ Platform-specific environment variables are also available:<br/>
'python scripts/repair_wheel.py -w {dest_dir} {wheel}',
'python scripts/check_repaired_wheel.py -w {dest_dir} {wheel}',
]
```

```toml
# Use abi3audit to catch issues with Limited API wheels
[tool.cibuildwheel.linux]
repair-wheel-command = [
Expand Down
47 changes: 47 additions & 0 deletions unit_test/validate_schema_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations

import re
from pathlib import Path

import pytest
Expand Down Expand Up @@ -54,3 +57,47 @@ def test_overrides_no_select():
validator = validate_pyproject.api.Validator()
with pytest.raises(validate_pyproject.error_reporting.ValidationError):
validator(example)


def test_docs_examples():
"""
Parse out all the configuration examples, build valid TOML out of them, and
make sure they pass.
"""

expr = re.compile(
r"""
!!! tab examples "pyproject.toml"
\s*
\s*```toml
(.*?)```""",
re.MULTILINE | re.DOTALL,
)

txt = DIR.parent.joinpath("docs/options.md").read_text()

blocks: list[str] = []
for match in expr.finditer(txt):
lines = (line.strip() for line in match.group(1).strip().splitlines() if line.strip())
block: list[str] = []
header = ""
for line in lines:
if line.startswith(("[tool.cibuildwheel", "[[tool.cibuildwheel")):
header = line
elif line.startswith("#"):
if block:
blocks.append("\n".join([header, *block]))
block = []
elif " = " in line and any(x.startswith(line.partition(" = ")[0]) for x in block):
blocks.append("\n".join([header, *block]))
block = [line]
else:
block.append(line)
blocks.append("\n".join([header, *block]))

for example_txt in blocks:
print(example_txt)
print()
example = tomllib.loads(example_txt)
validator = validate_pyproject.api.Validator()
assert validator(example) is not None

0 comments on commit a5db7f8

Please sign in to comment.