Skip to content

Commit bb037ec

Browse files
committed
CI: enable free-threaded wheel builds [wheel build]
[skip cirrus] [skip azp] [skip circle]
1 parent 5ac5c15 commit bb037ec

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed
+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Workflow to build and test wheels for the free-threaded Python build.
2+
#
3+
# This should be merged back into wheels.yml when free-threaded wheel
4+
# builds can be uploaded to pypi along with the rest of numpy's release
5+
# artifacts.
6+
#
7+
# To work on the wheel building infrastructure on a fork, comment out:
8+
#
9+
# if: github.repository == 'numpy/numpy'
10+
#
11+
# in the get_commit_message job. Be sure to include [wheel build] in your commit
12+
# message to trigger the build. All files related to wheel building are located
13+
# at tools/wheels/
14+
# Alternatively, you can add labels to the pull request in order to trigger wheel
15+
# builds.
16+
# The labels that trigger builds are:
17+
# 36 - Build(for changes to the building process,
18+
# 14 - Release(ensure wheels build before release)
19+
name: Free-Threaded Wheel Builder
20+
21+
on:
22+
schedule:
23+
# ┌───────────── minute (0 - 59)
24+
# │ ┌───────────── hour (0 - 23)
25+
# │ │ ┌───────────── day of the month (1 - 31)
26+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
27+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
28+
# │ │ │ │ │
29+
- cron: "42 2 * * SUN,WED"
30+
pull_request:
31+
branches:
32+
- main
33+
- maintenance/**
34+
# we do not want to upload free-threaded wheels to pypi yet
35+
# so we've disabled builds on pushes
36+
workflow_dispatch:
37+
38+
concurrency:
39+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
40+
cancel-in-progress: true
41+
42+
permissions:
43+
contents: read # to fetch code (actions/checkout)
44+
45+
jobs:
46+
get_commit_message:
47+
name: Get commit message
48+
runs-on: ubuntu-latest
49+
# To enable this job and subsequent jobs on a fork, comment out:
50+
if: github.repository == 'numpy/numpy'
51+
outputs:
52+
message: ${{ steps.commit_message.outputs.message }}
53+
steps:
54+
- name: Checkout numpy
55+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
56+
# Gets the correct commit message for pull request
57+
with:
58+
ref: ${{ github.event.pull_request.head.sha }}
59+
- name: Get commit message
60+
id: commit_message
61+
run: |
62+
set -xe
63+
COMMIT_MSG=$(git log --no-merges -1 --oneline)
64+
echo "message=$COMMIT_MSG" >> $GITHUB_OUTPUT
65+
echo github.ref ${{ github.ref }}
66+
67+
build_wheels:
68+
name: Build wheel ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
69+
needs: get_commit_message
70+
if: >-
71+
contains(needs.get_commit_message.outputs.message, '[wheel build]') ||
72+
github.event_name == 'schedule' ||
73+
github.event_name == 'workflow_dispatch' ||
74+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && ( ! endsWith(github.ref, 'dev0')))
75+
runs-on: ${{ matrix.buildplat[0] }}
76+
strategy:
77+
# Ensure that a wheel builder finishes even if another fails
78+
fail-fast: false
79+
matrix:
80+
# Github Actions doesn't support pairing matrix values together, let's improvise
81+
# https://github.com/github/feedback/discussions/7835#discussioncomment-1769026
82+
buildplat:
83+
- [ubuntu-20.04, manylinux_x86_64, ""]
84+
- [ubuntu-20.04, musllinux_x86_64, ""]
85+
# cibuildwheel does not yet support Mac
86+
# windows is supported but numpy doesn't build on the image
87+
# TODO: build numpy and set up windows
88+
python: ["cp313t"]
89+
env:
90+
IS_32_BIT: ${{ matrix.buildplat[1] == 'win32' }}
91+
IS_SCHEDULE_DISPATCH: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
92+
steps:
93+
- name: Checkout numpy
94+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
95+
with:
96+
submodules: true
97+
98+
- name: Setup MSVC (32-bit)
99+
if: ${{ matrix.buildplat[1] == 'win32' }}
100+
uses: bus1/cabuild/action/msdevshell@e22aba57d6e74891d059d66501b6b5aed8123c4d # v1
101+
with:
102+
architecture: 'x86'
103+
104+
- name: pkg-config-for-win
105+
run: |
106+
choco install -y --no-progress --stoponfirstfailure --checksum 6004DF17818F5A6DBF19CB335CC92702 pkgconfiglite
107+
$CIBW = "${{ github.workspace }}/.openblas"
108+
# pkgconfig needs a complete path, and not just "./openblas since the
109+
# build is run in a tmp dir (?)
110+
# It seems somewhere in the env passing, `\` is not
111+
# passed through, so convert it to '/'
112+
$CIBW = $CIBW.replace("\","/")
113+
echo "CIBW_ENVIRONMENT_WINDOWS=PKG_CONFIG_PATH=$CIBW" >> $env:GITHUB_ENV
114+
if: runner.os == 'windows'
115+
116+
# Used to push the built wheels
117+
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
118+
with:
119+
python-version: "3.x"
120+
121+
- name: Setup macOS
122+
if: matrix.buildplat[0] == 'macos-13' || matrix.buildplat[0] == 'macos-14'
123+
run: |
124+
if [[ ${{ matrix.buildplat[2] }} == 'accelerate' ]]; then
125+
# macosx_arm64 and macosx_x86_64 with accelerate
126+
# only target Sonoma onwards
127+
CIBW="MACOSX_DEPLOYMENT_TARGET=14.0 INSTALL_OPENBLAS=false RUNNER_OS=macOS"
128+
echo "CIBW_ENVIRONMENT_MACOS=$CIBW" >> "$GITHUB_ENV"
129+
130+
# the macos-13 image that's used for building the x86_64 wheel can't test
131+
# a wheel with deployment target >= 14 without further work
132+
echo "CIBW_TEST_SKIP=*-macosx_x86_64" >> "$GITHUB_ENV"
133+
else
134+
# macosx_x86_64 with OpenBLAS
135+
# if INSTALL_OPENBLAS isn't specified then scipy-openblas is automatically installed
136+
CIBW="RUNNER_OS=macOS"
137+
PKG_CONFIG_PATH="$PWD/.openblas"
138+
DYLD="$DYLD_LIBRARY_PATH:/$PWD/.openblas/lib"
139+
echo "CIBW_ENVIRONMENT_MACOS=$CIBW PKG_CONFIG_PATH=$PKG_CONFIG_PATH DYLD_LIBRARY_PATH=$DYLD" >> "$GITHUB_ENV"
140+
fi
141+
142+
- name: Build wheels
143+
uses: pypa/cibuildwheel@ba8be0d98853f5744f24e7f902c8adef7ae2e7f3 # v2.18.1
144+
env:
145+
CIBW_PRERELEASE_PYTHONS: True
146+
CIBW_FREE_THREADED_SUPPORT: True
147+
CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }}
148+
# TODO: remove when a released cython can build numpy
149+
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
150+
151+
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
152+
with:
153+
name: ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }}
154+
path: ./wheelhouse/*.whl
155+
156+
- uses: mamba-org/setup-micromamba@422500192359a097648154e8db4e39bdb6c6eed7
157+
with:
158+
# for installation of anaconda-client, required for upload to
159+
# anaconda.org
160+
# Note that this step is *after* specific pythons have been used to
161+
# build and test the wheel
162+
# for installation of anaconda-client, for upload to anaconda.org
163+
# environment will be activated after creation, and in future bash steps
164+
init-shell: bash
165+
environment-name: upload-env
166+
create-args: >-
167+
anaconda-client
168+
169+
- name: Upload wheels
170+
if: success()
171+
shell: bash -el {0}
172+
# see https://github.com/marketplace/actions/setup-miniconda for why
173+
# `-el {0}` is required.
174+
env:
175+
NUMPY_NIGHTLY_UPLOAD_TOKEN: ${{ secrets.NUMPY_NIGHTLY_UPLOAD_TOKEN }}
176+
run: |
177+
source tools/wheels/upload_wheels.sh
178+
set_upload_vars
179+
# trigger an upload to
180+
# https://anaconda.org/scientific-python-nightly-wheels/numpy
181+
# for cron jobs or "Run workflow" (restricted to main branch).
182+
# The tokens were originally generated at anaconda.org
183+
upload_wheels

tools/wheels/cibw_before_build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ if [[ $RUNNER_OS == "Windows" ]]; then
5252
# delvewheel is the equivalent of delocate/auditwheel for windows.
5353
python -m pip install delvewheel wheel
5454
fi
55+
56+
# TODO: delete when numpy is buildable under free-threaded python with a released version of cython
57+
if [[ $(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))") == "True" ]]; then
58+
python -m pip install git+https://github.com/cython/cython meson-python ninja
59+
fi

tools/wheels/cibw_test_command.sh

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PROJECT_DIR="$1"
66

77
python -m pip install threadpoolctl
88
python -c "import numpy; numpy.show_config()"
9+
# TODO: delete when numpy is buildable under free-threaded python with a released version of cython
10+
if [[ $(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))") == "True" ]]; then
11+
python -m pip install git+https://github.com/cython/cython
12+
fi
913
if [[ $RUNNER_OS == "Windows" ]]; then
1014
# GH 20391
1115
PY_DIR=$(python -c "import sys; print(sys.prefix)")
@@ -26,6 +30,9 @@ fi
2630
# Set available memory value to avoid OOM problems on aarch64.
2731
# See gh-22418.
2832
export NPY_AVAILABLE_MEM="4 GB"
33+
if [[ $(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))") == "True" ]]; then
34+
export PYTHON_GIL=0
35+
fi
2936
# Run full tests with -n=auto. This makes pytest-xdist distribute tests across
3037
# the available N CPU cores: 2 by default for Linux instances and 4 for macOS arm64
3138
python -c "import sys; import numpy; sys.exit(not numpy.test(label='full', extra_argv=['-n=auto']))"

0 commit comments

Comments
 (0)