Repository navigation
530 lines (511 loc) · 22.5 KB
/
Copy pathpython.yml
File metadata and controls
530 lines (511 loc) · 22.5 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
name: Python SDK
# Heavy lane. The wheel matrix and its smoke / stub / nogil gates build
# across every supported OS and Python, so they run post-merge on main,
# on the nightly schedule, on release tags, in the merge queue, and on a
# PR only when the Python SDK, FFI, or core sources changed or the
# `full-ci` label is set. Never on draft PRs. The fast PR merge gate
# lives in ci.yml.
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
merge_group:
schedule:
- cron: "23 6 * * *"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: python-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
changes:
name: Detect changed paths
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/paths.yml
# Matrix planner. On a PR the wheel matrix is the ubuntu/3.12 abi3 leg
# plus the ubuntu/3.14t free-threaded (GIL-release) leg — the two that
# carry the real per-PR risk; the macOS/Windows and other wheels are
# proven post-merge on main, on the nightly schedule, on tags, and in
# the merge queue. The ABI3 `compatibility` smoke runs its single
# ubuntu/3.14 leg (the newest ABI, the real compat risk) on a PR and
# the full os×py grid otherwise.
setup:
name: Plan matrices
needs: changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
build_matrix: ${{ steps.plan.outputs.build_matrix }}
compat_matrix: ${{ steps.plan.outputs.compat_matrix }}
steps:
- name: Choose matrix breadth
id: plan
shell: bash
env:
IS_PR: ${{ github.event_name == 'pull_request' }}
run: |
set -euo pipefail
ubuntu312='{"os":"ubuntu-latest","python":"3.12","label":"ubuntu py3.12"}'
ubuntu314t='{"os":"ubuntu-latest","python":"3.14t","label":"ubuntu py3.14t (nogil)"}'
if [ "${IS_PR}" = "true" ]; then
build="[${ubuntu312},${ubuntu314t}]"
compat='[{"os":"ubuntu-latest","python":"3.14"}]'
else
macos312='{"os":"macos-latest","python":"3.12","label":"macos py3.12"}'
windows312='{"os":"windows-latest","python":"3.12","label":"windows py3.12"}'
build="[${ubuntu312},${macos312},${windows312},${ubuntu314t}]"
# 3.12 legs dropped: the `build` job already import-smokes the
# 3.12 abi3 wheel on all three OSes, so a 3.12 compat re-import is
# redundant. The 3.14 legs are the real forward-ABI signal.
compat='[{"os":"ubuntu-latest","python":"3.14"},{"os":"macos-latest","python":"3.14"},{"os":"windows-latest","python":"3.14"}]'
fi
{
echo "build_matrix={\"include\":${build}}"
echo "compat_matrix={\"include\":${compat}}"
} >> "$GITHUB_OUTPUT"
# Single guard reused by every heavy job below. On any non-PR event
# (push to main, schedule, tag, merge_group) the matrix runs in full.
# On a PR it runs only for a non-draft whose changes touched the
# Python SDK / FFI / core, or that carries the `full-ci` label. The
# PEP 703 free-threaded build emits a per-version wheel
# (`cp314-cp314t-*`) rather than an `abi3` wheel because the
# free-threaded ABI is not stable-ABI compatible; the `gil_used =
# false` attribute on the `#[pymodule]` keeps the GIL disabled after
# import. The free-threaded floor is CPython 3.14 (PyO3 does not
# support free-threaded builds below 3.14). The OS/interpreter set is
# chosen by the `setup` planner.
build:
name: Build wheel (${{ matrix.label }})
needs: [changes, setup]
# full-ci and force_full each force the heavy lane on their own: a
# full-ci PR runs even when the diff is docs-render-only, and a rename
# that moved real source into the doc tree runs even though the
# rename-blind dorny `python` flag is false. Absent both, the original
# selective behavior holds.
if: >-
github.event_name != 'pull_request' ||
(github.event.pull_request.draft == false &&
(contains(github.event.pull_request.labels.*.name, 'full-ci') ||
needs.changes.outputs.force_full == 'true' ||
(needs.changes.outputs.docs_render_only != 'true' &&
needs.changes.outputs.python == 'true')))
runs-on: ${{ matrix.os }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup.outputs.build_matrix) }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-rust-deps
with:
components: clippy
# The Linux wheels build in two manylinux images (glibc 2.17 and
# 2.28). One shared cache hands the older image build scripts
# linked against the newer glibc, so each interpreter keeps its own.
cache-key: py${{ matrix.python }}
- uses: actions/setup-python@v7
with:
# The free-threaded interpreter (`3.14t`) is a PEP 703 build.
# `actions/setup-python@v6` honours the `t` suffix and
# provisions the `python3.14t` binary the matching wheel needs.
python-version: ${{ matrix.python }}
- name: Clippy (Python SDK)
shell: bash
run: cargo clippy -p thetadatadx-py --all-targets --locked -- -D warnings
- shell: bash
run: python -m pip install --upgrade pip "maturin>=1.9.4,<2.0"
# Linux wheels are built in a manylinux Docker image so the published
# wheel is installable on every supported platform: Ubuntu 22.04 /
# RHEL 8 / Google Colab / Databricks / CentOS 7 all pin glibc at or
# below 2.34. Building on `ubuntu-latest` directly ties the wheel to
# the runner's much newer glibc, which silently breaks every older
# runtime. The abi3 wheel uses manylinux2014 (glibc 2.17); the PEP 703
# free-threaded wheel uses manylinux_2_28 (glibc 2.28), whose image
# ships the `python3.14t` interpreter it is built for.
- name: Build wheel (Linux, manylinux)
if: matrix.os == 'ubuntu-latest'
uses: PyO3/maturin-action@v1
with:
# `--interpreter python3.12` targets the abi3 floor declared in
# `thetadatadx-py/Cargo.toml` (pyo3/abi3-py312), and
# `--interpreter python3.14t` makes maturin emit a
# `cp314-cp314t-*` wheel rather than the abi3 one. The default
# `python` binary inside the manylinux2014 Docker image is
# Python 2.7, which lacks `sys.implementation` and breaks
# maturin's interpreter probe; the versioned names resolve
# cleanly inside both images.
command: build
args: --release -m thetadatadx-py/Cargo.toml -o dist/ --interpreter python${{ matrix.python }}
manylinux: ${{ endsWith(matrix.python, 't') && '2_28' || '2014' }}
target: x86_64
- name: Build wheel (macOS / Windows)
if: matrix.os != 'ubuntu-latest'
shell: bash
run: python -m maturin build --release -m thetadatadx-py/Cargo.toml -o dist/ --interpreter python
- name: Install wheel
shell: bash
run: python -m pip install --force-reinstall dist/*.whl
- name: Import smoke
shell: bash
run: |
python - <<'PY'
import thetadatadx
from thetadatadx import Contract
option = Contract.option("SPY", expiration="20260620", strike="550", right="C")
print(thetadatadx.__file__)
print(option.symbol, thetadatadx.__version__)
PY
# Run the Python pytest suite against the freshly-installed wheel. The
# `THETADATADX_TEST_CREDS`-gated tests skip cleanly without secrets so this
# step exercises the install path AND the public-API surface contracts
# that don't need a live FPSS handshake. Kept as a separate step from
# the import smoke above so a pytest regression points at the suite,
# not at the smoke output.
- name: Pytest suite (skipped tests stay skipped)
shell: bash
run: |
python -m pip install pytest
python -m pytest thetadatadx-py/tests/ -v
- name: Inspect wheel contents
shell: bash
run: python3 scripts/dev/inspect_artifacts.py dist/*.whl
- uses: actions/upload-artifact@v7
with:
name: wheel-${{ runner.os }}-${{ matrix.python }}
path: dist/*.whl
# ───────────────────────────────────────────────────────────────
# The stubtest, doctest, and nogil throughput gates are lifted to
# standalone jobs with their own `runs-on` so a matrix label rename
# (`ubuntu-latest` → anything else) does NOT silently skip them.
# A prior in-matrix `if: matrix.os == 'ubuntu-latest'` form depended
# on the literal matrix value; lifting them out decouples the gate
# execution from the build-matrix label shape. Each depends on the
# `build` job, so when `build` is skipped on a path-irrelevant PR
# these skip with it; on main / schedule / tag they always run.
# ───────────────────────────────────────────────────────────────
stubtest:
# mypy stubtest verifies `__init__.pyi` matches
# the runtime byte-for-byte. The allowlist documents the small
# set of structural pyo3 false positives (`__init__` vs `__new__`
# for pyclass constructors, etc.) plus the explicit "deliberately
# unstubbed" generator-emitted surface.
name: Stubtest (.pyi vs runtime)
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- uses: actions/download-artifact@v8
with:
name: wheel-Linux-3.12
path: dist/
- shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install mypy
python -m pip install --force-reinstall dist/*.whl
- name: Stubtest (.pyi vs runtime)
shell: bash
run: |
python -m mypy.stubtest thetadatadx \
--allowlist thetadatadx-py/stubtest_allowlist.txt \
--ignore-missing-stub \
--ignore-disjoint-bases \
--ignore-positional-only
fresh-install-smoke:
# Fresh-venv smoke test. Simulates a first-time
# user typing `pip install thetadatadx-py` then importing every
# documented top-level export. Runs in a brand-new venv so a
# pollution-by-development-deps regression cannot mask a real
# missing export.
name: Fresh-install smoke
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- uses: actions/download-artifact@v8
with:
name: wheel-Linux-3.12
path: dist/
- shell: bash
run: |
python -m venv /tmp/thetadatadx-smoke
/tmp/thetadatadx-smoke/bin/pip install --upgrade pip
/tmp/thetadatadx-smoke/bin/pip install pytest
/tmp/thetadatadx-smoke/bin/pip install dist/*.whl
/tmp/thetadatadx-smoke/bin/python -m pytest thetadatadx-py/tests/test_fresh_install_smoke.py -v
/tmp/thetadatadx-smoke/bin/python -m pytest thetadatadx-py/tests/test_module_exports.py -v
compatibility:
name: ABI3 smoke (${{ matrix.os }} py${{ matrix.python }})
runs-on: ${{ matrix.os }}
needs: [setup, build]
timeout-minutes: 15
# PR: the single ubuntu/3.14 leg (newest ABI = the real compat risk);
# full os×py grid on main/tag/nightly. Set by the `setup` planner.
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.setup.outputs.compat_matrix) }}
steps:
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- uses: actions/download-artifact@v8
with:
# The abi3 wheel is the one tagged with the host Python the
# build job ran on (`3.12`). The freethreaded wheel carries
# its own matrix entry (`3.14t`) and is not part of the abi3
# compatibility surface.
name: wheel-${{ runner.os }}-3.12
path: dist/
- shell: bash
run: python -m pip install --force-reinstall dist/*.whl
- shell: bash
run: python -c "import thetadatadx; print(thetadatadx.__file__)"
# Standalone smoke job for the PEP 703 free-threaded wheels. Confirms
# the matching nogil wheel installs on its target interpreter AND that
# importing the module does NOT auto-re-enable the GIL (a missing
# `gil_used = false` on the `#[pymodule]` would flip the GIL back on
# at import time — this job catches that regression).
freethreaded:
name: Free-threaded smoke (py${{ matrix.python }})
runs-on: ubuntu-latest
needs: build
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python: ["3.14t"]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- uses: actions/download-artifact@v8
with:
name: wheel-Linux-${{ matrix.python }}
path: dist/
- shell: bash
run: python -m pip install --force-reinstall dist/*.whl
- name: GIL stays disabled after import
shell: bash
run: |
python - <<'PY'
import sys
assert not sys._is_gil_enabled(), "interpreter started with GIL enabled — unexpected for a freethreaded build"
import thetadatadx
assert not sys._is_gil_enabled(), (
"importing thetadatadx re-enabled the GIL — the #[pymodule] "
"attribute `gil_used = false` is missing or the wheel was "
"built without it"
)
print(f"thetadatadx imported on {sys.version.split()[0]}, GIL stayed disabled")
PY
# Parallel-throughput gate — meaningful only on the free-threaded
# interpreter, where the contended/baseline ratio reveals whether
# the GIL is truly released on the dispatcher hot path. Asserts the
# nogil interpreter sees < 1.8x overhead under CPU contention; a
# regression that re-acquires the GIL pushes the ratio toward the
# held-GIL band (~2x observed on stock 3.13). Folded into this job
# because it downloads the same 3.14t wheel and asserts on the same
# interpreter as the GIL-stays-disabled check above. The threshold
# is kept in lockstep at 1.8x with
# `thetadatadx-py/tests/test_no_gil.py::test_parallel_throughput_bench_runs`.
- name: Parallel throughput (nogil gate)
shell: bash
run: |
python thetadatadx-py/benches/bench_parallel_throughput.py | tee bench.json
python - <<'PY'
import json, pathlib, sys
payload = json.loads(pathlib.Path("bench.json").read_text().strip().splitlines()[-1])
ratio = payload["overhead_ratio"]
gil = payload["gil_enabled"]
print(f"interpreter={payload['python']} gil={gil} overhead={ratio:.3f}x")
# Free-threaded build must keep overhead under 1.8x. A held
# GIL pushes the ratio to ~2x (observed on stock 3.13: 2.06x).
if gil:
sys.exit("nogil gate triggered on a GIL-enabled interpreter")
if ratio >= 1.8:
sys.exit(f"nogil overhead ratio {ratio:.3f}x ≥ 1.8x — GIL may be held on hot path")
PY
# The full pytest suite already runs on the 3.14t wheel in the `build`
# job; this job's unique value is the GIL-stays-disabled assert and the
# nogil overhead ratio above, so it does not re-run the suite.
sdist:
name: Build source distribution
needs: changes
# full-ci and force_full each force the heavy lane on their own (see
# the build note); otherwise the original selective behavior.
if: >-
github.event_name != 'pull_request' ||
(github.event.pull_request.draft == false &&
(contains(github.event.pull_request.labels.*.name, 'full-ci') ||
needs.changes.outputs.force_full == 'true' ||
(needs.changes.outputs.docs_render_only != 'true' &&
needs.changes.outputs.python == 'true')))
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-rust-deps
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- shell: bash
run: python -m pip install --upgrade pip "maturin>=1.9.4,<2.0"
- shell: bash
run: python -m maturin sdist -m thetadatadx-py/Cargo.toml -o dist/
- name: Inspect sdist contents
shell: bash
run: python3 scripts/dev/inspect_artifacts.py dist/*.tar.gz
- shell: bash
run: python -m pip install --force-reinstall dist/*.tar.gz
- shell: bash
run: python -c "import thetadatadx"
- if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v7
with:
name: sdist
path: dist/*.tar.gz
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build, stubtest, fresh-install-smoke, compatibility, freethreaded, sdist]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
timeout-minutes: 130
permissions:
contents: read
actions: read
steps:
- uses: actions/checkout@v7
- name: Require CI green for this tag
# A tag push starts every workflow at once and none of them can see
# another's jobs. #1352 put crates.io and the GitHub Release behind
# ci.yml's `verified` aggregate, but that job lives in ci.yml, so this
# publisher kept uploading on its own file's jobs alone -- none of which
# are fmt, clippy, the core tests, wire-schema drift, the surface gates
# or semver. A red core gate would have split the
# release across registries, with the parts that did upload unyankable.
uses: ./.github/actions/require-ci-green
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Preflight - tag matches package version
shell: bash
run: |
set -euo pipefail
version=$(python3 -c 'import pathlib, tomllib; print(tomllib.loads(pathlib.Path("Cargo.toml").read_text())["workspace"]["package"]["version"])')
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
echo "::error::tag ${GITHUB_REF_NAME} does not match Python package version ${version} (expected v${version})"
exit 1
fi
- uses: actions/download-artifact@v8
with:
path: dist/
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
# ═══════════════════════════════════════════════════════════════
# AGGREGATOR GATE. A single roll-up status summarizing every job in
# this workflow, mirroring `ci.yml`'s `ci-gate`. It runs with
# `if: always()`, depends on every other job, and fails unless every
# dependency finished `success` or `skipped`. A heavy job that
# legitimately skips on a path-irrelevant PR (the whole matrix skips
# when `build` skips) counts as a pass; a real `failure` or
# `cancelled` fails the gate. This is the one Python-lane check branch
# protection should require — requiring it (instead of a hand-kept
# list of per-job names) keeps a conditionally-skipped required check
# from leaving the merge gate permanently unsatisfiable, and a newly
# added job is covered the moment it appears in `needs` below.
# ═══════════════════════════════════════════════════════════════
# Everything in this workflow that VERIFIES, named once and excluding
# the publish job. The publishers in the other workflows wait on this
# across files, and the workflow's own merge gate below depends on it
# rather than restating the list. It must never come to include
# `publish`: that job waits on the sibling workflows' aggregates, so a
# gate that contained it would wait on itself.
verified:
name: Python verified
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
needs:
- changes
- setup
- build
- stubtest
- fresh-install-smoke
- compatibility
- freethreaded
- sdist
steps:
- name: Fail unless every verification job succeeded or was skipped
shell: bash
env:
NEEDS_JSON: ${{ toJSON(needs) }}
run: |
set -euo pipefail
python3 - <<'PY'
import json
import os
import sys
needs = json.loads(os.environ["NEEDS_JSON"])
bad = sorted(
name
for name, data in needs.items()
if data.get("result") not in ("success", "skipped")
)
for name in sorted(needs):
print(f"{name}: {needs[name].get('result')}")
if bad:
joined = ", ".join(bad)
sys.exit(f"not verified: {joined} did not succeed or skip")
print("verified: every verification job succeeded or was skipped")
PY
python-gate:
name: Python gate
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
needs:
- verified
- publish
steps:
- name: Fail unless every dependency succeeded or was skipped
shell: bash
env:
NEEDS_JSON: ${{ toJSON(needs) }}
run: |
set -euo pipefail
python3 - <<'PY'
import json
import os
import sys
needs = json.loads(os.environ["NEEDS_JSON"])
bad = sorted(
name
for name, data in needs.items()
if data.get("result") not in ("success", "skipped")
)
for name in sorted(needs):
print(f"{name}: {needs[name].get('result')}")
if bad:
joined = ", ".join(bad)
sys.exit(f"Python gate failed: {joined} did not succeed or skip")
print("Python gate passed: every dependency succeeded or was skipped")
PY