Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
name: Python

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request]

jobs:
check_format:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format job wasn't working correctly anymore – the default Python version in Azure Pipelines no longer works with our version of black – so it needed maintenance. I moved it to GitHub Actions so all the Python CI would be in one place.

If you'd like to remove Azure Pipelines entirely, I could move the one remaining job to GitHub Actions in a follow-on PR.

name: Check Python code format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Set up Python and install dependencies
working-directory: python/tests
run: uv sync --project . --python 3.13

- name: Check code format
working-directory: python/tests
run: uv run --project . black --check ..

build_wheels_quick:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the Python tests depend on cibuildwheel, I broke out a separate build task with just the wheels needed for testing, so that the Python tests don't take quite so long to start. (As is, the builds we need for testing take 2 minutes, which makes for slow iteration times.)

name: Build wheels for quick testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true # Optional, use if you use setuptools_scm

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS_LINUX: "x86_64"
# We do not need to support Python 3.6–3.8, and we only need
# manylinux for testing. PyPy isn't useful as this is a binary
# extension.
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-musllinux_*

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-quick
path: ./wheelhouse/*.whl

test_wheels:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new test task

name: Test wheels with Python ${{ matrix.python-version }} and NumPy ${{ matrix.numpy-version }}
needs: [build_wheels_quick]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.9"
numpy-version: "1.25.2"
- python-version: "3.10"
numpy-version: "1.26.4"
- python-version: "3.11"
numpy-version: "1.26.4"
- python-version: "3.12"
numpy-version: "1.26.4"
- python-version: "3.11"
numpy-version: "2.4.2"
- python-version: "3.12"
numpy-version: "2.4.2"

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"

- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
pattern: cibw-wheels-quick
path: dist
merge-multiple: true

- name: Set up Python ${{ matrix.python-version }} and install dependencies
working-directory: python/tests
run: uv sync --project . --python ${{ matrix.python-version }}

- name: Install NumPy ${{ matrix.numpy-version }}
working-directory: python/tests
run: |
uv pip install --project . --only-binary :all: numpy==${{ matrix.numpy-version }}

- name: Install manylinux wheel built for Python ${{ matrix.python-version }}
working-directory: python/tests
run: uv pip install --project . ../../dist/*cp$(echo ${{ matrix.python-version }} | tr -d .)*.whl

- name: Run tests
working-directory: python/tests
run: uv run --project . pytest

build_wheels_main:
name: Build remaining wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true # Optional, use if you use setuptools_scm

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
CIBW_ARCHS_WINDOWS: "AMD64 x86"
# disable aarm64 build since its too slow to build(docker + qemu)
CIBW_ARCHS_LINUX: "x86_64 i686"
# We do not need to support Python 3.6–3.8, and the quick build
# has already taken care of manylinux. PyPy isn't useful as this is
# a binary extension.
CIBW_SKIP: pp* cp36-* cp37-* cp38-* *-manylinux_x86_64

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-main-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

# It looks cibuildwheels did not clean build folder(CMake), and it results to Windows arm64 build failure(trying to reuse x86 build of .obj)
# So supply separated build job for Windows ARM64 build
# TODO: clean build folder using CIBW_BEFORE_ALL?
build_wheels_win_arm64:
name: Build ARM64 wheels on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true # Optional, use if you use setuptools_scm

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.5
env:
CIBW_ARCHS_WINDOWS: "ARM64"
CIBW_SKIP: pp*

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

make_sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Optional, use if you use setuptools_scm
fetch-tags: true # Optional, use if you use setuptools_scm

- name: Build SDist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_all:
needs: [build_wheels_quick, build_wheels_main, build_wheels_win_arm64, make_sdist]
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
# upload to PyPI on every tag starting with 'v'
# NOTE: Without github.event_name & githug.ref check, `upload_all` task is still triggered on 'main' branch push.
# (then get 'Branch "main" is not allowed to deploy to release due to environment protection rules.' error)
# So still do event_name and github.ref check.
# TODO: Make it work only using Github `environment` feature.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
# if: github.event_name == 'push' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
# Use Trusted Publisher feature:
# https://docs.pypi.org/trusted-publishers/
# so no use of PYPI_API_TOKEN
#password: ${{ secrets.PYPI_API_TOKEN }}
#
# Avoid race condition when using multiple CIs
skip-existing: true
verbose: true
115 changes: 0 additions & 115 deletions .github/workflows/wheels.yml

This file was deleted.

Loading
Loading