Skip to content

Commit afdd3fa

Browse files
authored
Test Python + NumPy in CI (#405)
Add test tasks to GitHub Actions which test the generated wheels using different Python and NumPy versions. I've added four tests for issues #400 and they are all failing in the way I expect – surfacing disparities between `num_face_vertices` and `numpy_num_face_vertices()`. I've also added tests for issue #401 which is passing, and #402 is also covered in the #400 tests so those will need further investigation at a later time. Closes #403
1 parent 8a3f8b9 commit afdd3fa

File tree

12 files changed

+766
-282
lines changed

12 files changed

+766
-282
lines changed

.github/workflows/python.yml

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
name: Python
2+
3+
# Build on every branch push, tag push, and pull request change:
4+
on: [push, pull_request]
5+
6+
jobs:
7+
check_format:
8+
name: Check Python code format
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install uv
14+
uses: astral-sh/setup-uv@v4
15+
with:
16+
version: "latest"
17+
18+
- name: Set up Python and install dependencies
19+
working-directory: tests/python
20+
run: uv sync --project . --python 3.13
21+
22+
- name: Check code format
23+
working-directory: tests/python
24+
run: uv run --project . black --check ../..
25+
26+
build_wheels_quick:
27+
name: Build wheels for quick testing
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
fetch-tags: true # Optional, use if you use setuptools_scm
34+
35+
- name: Build wheels
36+
uses: pypa/cibuildwheel@v2.16.5
37+
env:
38+
CIBW_ARCHS_LINUX: "x86_64"
39+
# We do not need to support Python 3.6–3.8, and we only need
40+
# manylinux for testing. PyPy isn't useful as this is a binary
41+
# extension.
42+
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-musllinux_*
43+
44+
- uses: actions/upload-artifact@v4
45+
with:
46+
name: cibw-wheels-quick
47+
path: ./wheelhouse/*.whl
48+
49+
test_wheels:
50+
name: Test wheels with Python ${{ matrix.python-version }} and NumPy ${{ matrix.numpy-version }}
51+
needs: [build_wheels_quick]
52+
runs-on: ubuntu-latest
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
include:
57+
- python-version: "3.9"
58+
numpy-version: "1.25.2"
59+
- python-version: "3.10"
60+
numpy-version: "1.26.4"
61+
- python-version: "3.11"
62+
numpy-version: "1.26.4"
63+
- python-version: "3.12"
64+
numpy-version: "1.26.4"
65+
- python-version: "3.11"
66+
numpy-version: "2.4.2"
67+
- python-version: "3.12"
68+
numpy-version: "2.4.2"
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Install uv
74+
uses: astral-sh/setup-uv@v4
75+
with:
76+
version: "latest"
77+
78+
- name: Download wheel artifacts
79+
uses: actions/download-artifact@v4
80+
with:
81+
pattern: cibw-wheels-quick
82+
path: dist
83+
merge-multiple: true
84+
85+
- name: Set up Python ${{ matrix.python-version }} and install dependencies
86+
working-directory: tests/python
87+
run: uv sync --project . --python ${{ matrix.python-version }}
88+
89+
- name: Install NumPy ${{ matrix.numpy-version }}
90+
working-directory: tests/python
91+
run: |
92+
uv pip install --project . --only-binary :all: numpy==${{ matrix.numpy-version }}
93+
94+
- name: Install manylinux wheel built for Python ${{ matrix.python-version }}
95+
working-directory: tests/python
96+
run: uv pip install --project . ../../dist/*cp$(echo ${{ matrix.python-version }} | tr -d .)*.whl
97+
98+
- name: Run tests
99+
working-directory: tests/python
100+
run: uv run --project . pytest
101+
102+
build_wheels_main:
103+
name: Build remaining wheels on ${{ matrix.os }}
104+
runs-on: ${{ matrix.os }}
105+
strategy:
106+
matrix:
107+
os: [ubuntu-latest, windows-latest, macos-latest]
108+
109+
steps:
110+
- uses: actions/checkout@v4
111+
with:
112+
fetch-depth: 0
113+
fetch-tags: true # Optional, use if you use setuptools_scm
114+
115+
- name: Build wheels
116+
uses: pypa/cibuildwheel@v2.16.5
117+
env:
118+
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
119+
CIBW_ARCHS_WINDOWS: "AMD64 x86"
120+
# disable aarm64 build since its too slow to build(docker + qemu)
121+
CIBW_ARCHS_LINUX: "x86_64 i686"
122+
# We do not need to support Python 3.6–3.8, and the quick build
123+
# has already taken care of manylinux. PyPy isn't useful as this is
124+
# a binary extension.
125+
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-manylinux_x86_64
126+
127+
- uses: actions/upload-artifact@v4
128+
with:
129+
name: cibw-wheels-main-${{ matrix.os }}-${{ strategy.job-index }}
130+
path: ./wheelhouse/*.whl
131+
132+
# It looks cibuildwheels did not clean build folder(CMake), and it results to Windows arm64 build failure(trying to reuse x86 build of .obj)
133+
# So supply separated build job for Windows ARM64 build
134+
# TODO: clean build folder using CIBW_BEFORE_ALL?
135+
build_wheels_win_arm64:
136+
name: Build ARM64 wheels on Windows
137+
runs-on: windows-latest
138+
steps:
139+
- uses: actions/checkout@v4
140+
with:
141+
fetch-depth: 0
142+
fetch-tags: true # Optional, use if you use setuptools_scm
143+
144+
- name: Build wheels
145+
uses: pypa/cibuildwheel@v2.16.5
146+
env:
147+
CIBW_ARCHS_WINDOWS: "ARM64"
148+
CIBW_SKIP: pp*
149+
150+
- uses: actions/upload-artifact@v4
151+
with:
152+
name: cibw-wheels-win-arm64
153+
path: ./wheelhouse/*.whl
154+
155+
make_sdist:
156+
name: Make SDist
157+
runs-on: ubuntu-latest
158+
steps:
159+
- uses: actions/checkout@v4
160+
with:
161+
fetch-depth: 0 # Optional, use if you use setuptools_scm
162+
fetch-tags: true # Optional, use if you use setuptools_scm
163+
164+
- name: Build SDist
165+
run: pipx run build --sdist
166+
167+
- uses: actions/upload-artifact@v4
168+
with:
169+
name: cibw-sdist
170+
path: dist/*.tar.gz
171+
172+
upload_all:
173+
needs: [build_wheels_quick, build_wheels_main, build_wheels_win_arm64, make_sdist]
174+
runs-on: ubuntu-latest
175+
environment: release
176+
permissions:
177+
# IMPORTANT: this permission is mandatory for trusted publishing
178+
id-token: write
179+
# upload to PyPI on every tag starting with 'v'
180+
# NOTE: Without github.event_name & githug.ref check, `upload_all` task is still triggered on 'main' branch push.
181+
# (then get 'Branch "main" is not allowed to deploy to release due to environment protection rules.' error)
182+
# So still do event_name and github.ref check.
183+
# TODO: Make it work only using Github `environment` feature.
184+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
185+
# alternatively, to publish when a GitHub Release is created, use the following rule:
186+
# if: github.event_name == 'push' && github.event.action == 'published'
187+
steps:
188+
- uses: actions/download-artifact@v4
189+
with:
190+
pattern: cibw-*
191+
path: dist
192+
merge-multiple: true
193+
194+
- uses: pypa/gh-action-pypi-publish@release/v1
195+
with:
196+
# Use Trusted Publisher feature:
197+
# https://docs.pypi.org/trusted-publishers/
198+
# so no use of PYPI_API_TOKEN
199+
#password: ${{ secrets.PYPI_API_TOKEN }}
200+
#
201+
# Avoid race condition when using multiple CIs
202+
skip-existing: true
203+
verbose: true

.github/workflows/wheels.yml

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)