Repository navigation
199 lines (171 loc) · 7.61 KB
/
Copy pathpython.yml
File metadata and controls
199 lines (171 loc) · 7.61 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: CI-python
# The Python module jinja2cpp (python/, docs/python.md, docs/tasks/0353): built in Debug with
# AddressSanitizer and UndefinedBehaviorSanitizer, its pytest suite run against the pinned Python
# Jinja2 with libasan preloaded into the (uninstrumented) interpreter, then `pip install .` as a
# user installs it. One job on the CPython floor (3.12, .python-version); the wheel matrix is
# docs/tasks/0356. The `installed` job builds python/ alone against an installed library, which
# proves that the module uses the public API only (docs/tasks/0357).
on:
push:
branches:
- master
- main
paths:
- 'python/**'
- 'src/**'
- 'include/**'
- 'pyproject.toml'
- 'CMakeLists.txt'
- 'thirdparty/**'
- 'cmake/**'
- '.github/workflows/python.yml'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- master
- main
paths:
- 'python/**'
- 'src/**'
- 'include/**'
- 'pyproject.toml'
- 'CMakeLists.txt'
- 'thirdparty/**'
- 'cmake/**'
- '.github/workflows/python.yml'
workflow_dispatch:
permissions:
contents: read
concurrency:
# The draft flag keeps the all-skipped run of a draft push from cancelling the full run that
# marking the PR ready just started
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.pull_request.draft }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
module:
name: Python ${{ matrix.python }} module, Debug address+undefined (${{ matrix.compiler }})
runs-on: ubuntu-24.04
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- { python: '3.12', compiler: gcc-14 }
# The lazy generate()'s CPython stack-protection path (docs/tasks/0457 D5)
- { python: '3.14', compiler: gcc-14 }
env:
# The interpreter's own allocations at exit are no leaks of the module: the refcount
# loop in python/tests/test_lifetime.py checks the module's references
ASAN_OPTIONS: detect_leaks=0:strict_string_checks=1:detect_stack_use_after_return=1
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- name: Install toolchain
uses: ./.github/actions/install-toolchain
with:
compiler: ${{ matrix.compiler }}
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python }}
# pytest and trio at the versions the upstream Jinja2 suite pins (python/tests/upstream), and
# the pinned transformers that python/tests/test_chat_templates.py checks patch() against
- name: Install the oracle and pytest
run: python -m pip install -r test/parity/requirements.txt -r python/tests/upstream/requirements.txt -r python/tests/requirements.txt -r test/chat_templates/requirements.txt
- uses: ./.github/actions/setup-ccache
with:
key: python-${{ matrix.compiler }}-${{ matrix.python }}-asan
- name: Configure
run: |
cmake -S . -B .build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DJINJA2CPP_DEPS_MODE=internal \
-DJINJA2CPP_BUILD_PYTHON=ON \
-DJINJA2CPP_BUILD_TESTS=OFF \
-DJINJA2CPP_WITH_BIGINT=boost \
-DJINJA2CPP_WITH_SANITIZERS=address+undefined \
-DJINJA2CPP_STRICT_WARNINGS=ON \
"-DPython_EXECUTABLE=$(command -v python)" \
"-DCMAKE_CXX_FLAGS=-Wno-error=maybe-uninitialized"
- name: Build
run: cmake --build .build --parallel
# From a directory outside python/, so that the package imported is the build's, which
# has the module next to its sources (python/CMakeLists.txt). The interpreter links no
# libstdc++: it is preloaded after libasan, or ASan's __cxa_throw finds no real one and the
# first C++ exception aborts
- name: Test under ASan
working-directory: .build/python
run: |
export LD_PRELOAD="$("$CC" -print-file-name=libasan.so) $("$CXX" -print-file-name=libstdc++.so)"
PYTHONPATH="$PWD" python -m pytest -p no:cacheprovider -ra "$GITHUB_WORKSPACE/python/tests"
# pallets/jinja 3.1.6 tests/ through the module with fallback="never" (docs/tasks/0355): prints
# the pass rate and fails on a failure python/tests/upstream/expected-failures.txt does not list
- name: Upstream Jinja2 suite under ASan
working-directory: .build/python
run: |
export LD_PRELOAD="$("$CC" -print-file-name=libasan.so) $("$CXX" -print-file-name=libstdc++.so)"
PYTHONPATH="$PWD" python "$GITHUB_WORKSPACE/python/tests/upstream/run.py"
- name: pip install .
run: |
python -m pip install -v .
cd "$RUNNER_TEMP"
python -m pytest -p no:cacheprovider -q "$GITHUB_WORKSPACE/python/tests"
installed:
name: Python ${{ matrix.python }} module against the installed library (${{ matrix.compiler }})
runs-on: ubuntu-24.04
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.draft }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- { python: '3.12', compiler: gcc-14 }
env:
PREFIX: ${{ github.workspace }}/.prefix
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- name: Install toolchain
uses: ./.github/actions/install-toolchain
with:
compiler: ${{ matrix.compiler }}
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python }}
# nanobind at the pin of pyproject.toml: python/ built alone takes it from the build's Python
- name: Install nanobind, the oracle and pytest
run: |
python -m pip install "$(grep -o 'nanobind==[0-9.]*' pyproject.toml)"
python -m pip install -r test/parity/requirements.txt -r python/tests/upstream/requirements.txt -r python/tests/requirements.txt -r test/chat_templates/requirements.txt
- uses: ./.github/actions/setup-ccache
with:
key: python-${{ matrix.compiler }}-${{ matrix.python }}-installed
# Static and position-independent, with the module's TLS model and big integers, as the wheel
# links it (docs/python.md, "Building against an installed library")
- name: Install the library
run: |
cmake -S . -B .build-lib -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DJINJA2CPP_DEPS_MODE=internal \
-DJINJA2CPP_BUILD_TESTS=OFF \
-DJINJA2CPP_PIC=ON \
-DJINJA2CPP_TLS_INITIAL_EXEC=ON \
-DJINJA2CPP_WITH_BIGINT=boost \
-DJINJA2CPP_STRICT_WARNINGS=ON \
"-DCMAKE_INSTALL_PREFIX=$PREFIX"
cmake --build .build-lib --parallel
cmake --install .build-lib
- name: Build the module alone
run: |
cmake -S python -B .build-module -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DJINJA2CPP_STRICT_WARNINGS=ON \
"-DCMAKE_PREFIX_PATH=$PREFIX" \
"-DPython_EXECUTABLE=$(command -v python)"
cmake --build .build-module --parallel
# Every header the module's objects were compiled from: the prefix, nanobind, Python or the
# system, never the checkout's include/ or src/
- name: Check the module's includes
run: python python/check_includes.py .build-module "$PREFIX"
- name: Test
working-directory: .build-module
run: PYTHONPATH="$PWD" python -m pytest -p no:cacheprovider -q -ra "$GITHUB_WORKSPACE/python/tests"