Repository navigation
241 lines (233 loc) · 8.96 KB
/
Copy pathpython-test.yaml
File metadata and controls
241 lines (233 loc) · 8.96 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
# Derived from `maturin generate-ci github`, but hand-maintained since:
# the wheel jobs gained a Python-version dimension and the `test` job carries
# comments explaining why it builds in place. Re-running the generator would
# drop both, so edit this file directly and keep it in sync with maturin's shape.
name: python-test
on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "python/**"
# The consistency runner reads this shared manifest, so a golden-only
# change must re-run this workflow.
- "tests/consistency/**"
# tests/ast_contract_test.py decodes the captured parser output as its
# fixture, so regenerating the golden file must re-run this workflow.
- "testdata/ast/**"
- ".github/workflows/python-test.yaml"
workflow_dispatch:
permissions:
contents: read
jobs:
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
working-directory: "python"
command: sdist
args: -o dist
- name: Upload sdist
uses: actions/upload-artifact@v7
with:
name: sdist-${{ github.run_id }}
path: python/dist
# These jobs build a wheel for *every* interpreter available to maturin,
# not one -- `--find-interpreter` means "find them all", and it picks up
# whatever the image ships plus anything on PATH. That is where the
# cp310..cp315 / pp311 spread comes from; there is no version matrix here
# and adding one would only duplicate wheels the default build already
# produces. Interpreters below `requires-python` are skipped outright --
# maturin never probes them -- so the 3.9 in the Linux images is not built.
#
# Linux x86_64 runs in the native manylinux image, which ships 3.9 through
# 3.15 (plus free-threaded 3.14t/3.15t and PyPy 3.11), so its cp315 comes
# for free. The macOS runner image also carries 3.15. The Windows image
# stops at 3.14, so that job installs 3.15 explicitly below -- setup-python
# adds to what maturin discovers rather than replacing it. Linux aarch64
# needs its own steps for the same reason, but for a different one; see
# below.
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [ x86_64, aarch64 ]
steps:
- uses: actions/checkout@v7
- uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
target: ${{ matrix.target }}
manylinux: auto
working-directory: "python"
command: build
args: --release -o dist --find-interpreter
env:
# Workaround ring 0.17 build issue
CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"
# aarch64 is a cross build, so maturin-action runs it in
# ghcr.io/rust-cross/manylinux2014-cross:aarch64 rather than the native
# quay.io/pypa/manylinux2014_x86_64 image the x86_64 leg uses. That
# cross image does have 3.15 and 3.15t, but --find-interpreter never
# offers them -- it reports 3.10 through 3.14, 3.14t and PyPy 3.11 and
# stops. Naming them explicitly resolves, so the two steps below build
# them by hand. Without them aarch64 Linux ships no 3.15 wheel at all,
# which is the gap #404 is about.
- name: Build the aarch64 CPython 3.15 wheel
if: matrix.target == 'aarch64'
uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
target: aarch64
manylinux: auto
working-directory: "python"
command: build
args: --release -o dist -i python3.15
env:
# Workaround ring 0.17 build issue
CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"
# Free-threaded 3.15 on aarch64. The x86_64 leg gets cp315t from the
# native image; this asks the cross image the same question.
- name: Build the aarch64 free-threaded 3.15 wheel
if: matrix.target == 'aarch64'
uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
target: aarch64
manylinux: auto
working-directory: "python"
command: build
args: --release -o dist -i python3.15t
env:
# Workaround ring 0.17 build issue
CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"
- name: Upload wheels-linux-${{ matrix.target }}-${{ github.run_id }}
uses: actions/upload-artifact@v7
with:
name: wheels-linux-${{ matrix.target }}-${{ github.run_id }}
path: python/dist
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
# The Windows image tops out at 3.14. Without this the cp315 wheel
# never gets built; with it maturin finds 3.10-3.14 from the image
# plus 3.15 here.
- name: Set up Python 3.15
uses: actions/setup-python@v7
with:
python-version: "3.15"
- uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
working-directory: "python"
command: build
args: --release -o dist --find-interpreter
- name: Upload wheels-windows-${{ github.run_id }}
uses: actions/upload-artifact@v7
with:
name: wheels-windows-${{ github.run_id }}
path: python/dist
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v7
- uses: PyO3/maturin-action@v1
with:
maturin-version: v1.15.0
working-directory: "python"
command: build
target: universal2-apple-darwin
args: --release -o dist --find-interpreter
- name: Upload wheels-macos-${{ github.run_id }}
uses: actions/upload-artifact@v7
with:
name: wheels-macos-${{ github.run_id }}
path: python/dist
test:
name: Test on ${{ matrix.os }} / ${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# "3.x" is the runner default; 3.15 is the newest CPython the wheels
# ship, and the newest is the one most likely to break.
python: [ "3.x", "3.15" ]
steps:
- uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
# Build the extension in-place via maturin develop so that the compiled
# `_kcl_lib.<abi>.so` is placed inside `python/kcl_lib/` alongside its
# Python source. This matters because the tests run with `working-directory:
# python`, and `python/kcl_lib/__init__.py` (which does `from ._kcl_lib
# import *`) would otherwise shadow the wheel's site-packages copy and
# fail with `ModuleNotFoundError: No module named 'kcl_lib._kcl_lib'`.
- name: Create virtualenv and install maturin + pytest
working-directory: "python"
shell: bash
run: |
python -m venv .venv
if [ "$RUNNER_OS" = "Windows" ]; then
.venv/Scripts/pip install maturin==1.15.0 pytest
else
.venv/bin/pip install maturin==1.15.0 pytest
fi
- name: Build extension in-place with maturin
working-directory: "python"
shell: bash
run: |
if [ "$RUNNER_OS" = "Windows" ]; then
.venv/Scripts/maturin develop --release
else
.venv/bin/maturin develop --release
fi
- name: Run pytest
working-directory: "python"
shell: bash
run: |
if [ "$RUNNER_OS" = "Windows" ]; then
.venv/Scripts/python -m pytest -v
else
.venv/bin/python -m pytest -v
fi
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'"
permissions:
contents: read
id-token: write
needs: [ macos, linux, windows ]
steps:
# Collect every wheel leg in one step. The explicit per-name list this
# replaces had to be hand-edited for every new target, platform, or
# Python version; the pattern picks all of them up. `merge-multiple`
# keeps them flat in python/dist rather than nesting a directory per
# artifact. `wheels-` deliberately excludes the sdist artifact, which is
# published separately and not wanted here.
- uses: actions/download-artifact@v8
with:
pattern: wheels-*-${{ github.run_id }}
path: python/dist
merge-multiple: true
- name: Publish to PyPI
# The issue https://github.com/pypa/gh-action-pypi-publish/issues/310 has not tagged a release yet
# Use the commit hash to get the temporary fix
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
packages-dir: python/dist