Repository navigation
131 lines (125 loc) · 5.2 KB
/
Copy pathpython_bindings.yml
File metadata and controls
131 lines (125 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Python bindings are generated
# Generated files, never edited by hand:
# - lib/python_bindings/pybind_espp.cpp, by lib/autogenerate_bindings.py (litgen,
# pinned in lib/requirements.txt) from the headers;
# - the .pyi type stubs under lib/python_bindings/espp/, by lib/generate_stubs.py
# (pybind11-stubgen, pinned in lib/stubs-requirements.txt) from the BUILT module.
# This regenerates both and fails if either differs from what is committed; the
# stubs must also pass mypy and mypy's stubtest against the module.
#
# To fix a failure: regenerate (see lib/README.md, "Generating python bindings"
# and "Type stubs") and commit the result; if the generated code is wrong, fix
# the header or the generator, not the generated files.
# Minimal token scope: never writes.
permissions:
contents: read
on:
pull_request:
paths:
- "components/*/include/**"
- "lib/autogenerate_bindings.py"
- "lib/requirements.txt"
- "lib/generate_stubs.py"
- "lib/stubs-requirements.txt"
- "lib/stubtest_allowlist.txt"
- "lib/CMakeLists.txt"
- "lib/espp.cmake"
- "lib/python_bindings/**"
- ".pre-commit-config.yaml"
- ".github/workflows/python_bindings.yml"
push:
branches: [main]
paths:
- "components/*/include/**"
- "lib/autogenerate_bindings.py"
- "lib/requirements.txt"
- "lib/generate_stubs.py"
- "lib/stubs-requirements.txt"
- "lib/stubtest_allowlist.txt"
- "lib/CMakeLists.txt"
- "lib/espp.cmake"
- "lib/python_bindings/**"
- ".pre-commit-config.yaml"
- ".github/workflows/python_bindings.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
regenerate:
name: Regenerate and compare
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
with:
python-version: "3.14"
- name: Install the pinned generator
run: pip install -r lib/requirements.txt
- name: Regenerate the bindings
working-directory: lib
run: python autogenerate_bindings.py
- name: The committed files match the generated ones
run: |
if ! git diff --exit-code --stat -- lib/python_bindings; then
echo "::error::lib/python_bindings differs from what autogenerate_bindings.py generates."
echo "Regenerate (see lib/README.md) and commit the result; never edit the generated files by hand."
git diff -- lib/python_bindings | head -200
exit 1
fi
stubs:
name: Type stubs match the built module
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- uses: actions/checkout@v7
with:
submodules: "recursive" # the module builds against external/ (fmt, cli, ...)
- uses: actions/setup-python@v6
with:
# the committed stubs were generated with this python
python-version: "3.13"
- name: Install the pinned stub tools
run: pip install -r lib/stubs-requirements.txt
- name: Build the python module
run: |
cmake -S lib -B build-stubs -DCMAKE_BUILD_TYPE=Release \
-DESPP_BUILD_PYTHON=ON -DESPP_INSTALL=ON -DPYBIND11_FINDPYTHON=ON \
-DPython_EXECUTABLE="$(which python)" \
-Dpybind11_DIR="$(python -m pybind11 --cmakedir)"
cmake --build build-stubs --parallel 4
cmake --install build-stubs --prefix "$RUNNER_TEMP/espp-prefix"
- name: The committed stubs match the generated ones
env:
PYTHONPATH: ${{ runner.temp }}/espp-prefix
run: python lib/generate_stubs.py --check
- name: The stubs pass mypy
working-directory: ${{ runner.temp }}
env:
MYPYPATH: ${{ runner.temp }}/espp-prefix
# silent: report the espp package only, not the packages it imports
run: python -m mypy -p espp --follow-imports=silent
- name: The stubs match the module (stubtest)
working-directory: ${{ runner.temp }}
env:
PYTHONPATH: ${{ runner.temp }}/espp-prefix
MYPYPATH: ${{ runner.temp }}/espp-prefix
run: |
# every pybind11 class is reported as "metaclass differs" (the
# pybind11_type metaclass has no stub): drop that message only.
# stubtest exits 1 when it reports anything; any other status (a crash,
# a signal), or 1 with nothing reported, is a failure in itself.
status=0
python -m mypy.stubtest espp._espp --concise \
--allowlist "$GITHUB_WORKSPACE/lib/stubtest_allowlist.txt" > stubtest.txt 2>&1 || status=$?
if [ "$status" -gt 1 ] || { [ "$status" -ne 0 ] && ! grep -q . stubtest.txt; }; then
cat stubtest.txt
echo "::error::stubtest exited with status $status."
exit 1
fi
if grep -v "metaclass differs" stubtest.txt | grep .; then
echo "::error::stubtest found differences between the stubs and the module (above)."
exit 1
fi
echo "stubtest: $(grep -c . stubtest.txt) metaclass notes, nothing else"