From 82908770421001e5b8c0e038bd567002da569c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Thu, 13 Jun 2024 15:04:36 +0200 Subject: [PATCH 1/4] Add CPython 3.13 free-threaded wheels --- .github/workflows/wheels.yml | 12 ++++++++++-- build_tools/wheels/build_wheels.sh | 7 +++++++ build_tools/wheels/cibw_before_test.sh | 15 +++++++++++++++ build_tools/wheels/test_wheels.sh | 8 ++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100755 build_tools/wheels/cibw_before_test.sh diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 9452ada189307..37e5d2cddfaca 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -86,6 +86,12 @@ jobs: python: 312 platform_id: manylinux_x86_64 manylinux_image: manylinux2014 + - os: ubuntu-latest + python: 313t + platform_id: manylinux_x86_64 + manylinux_image: manylinux2014 + prerelease_pythons: True + free_threaded_support: True # MacOS x86_64 - os: macos-12 @@ -154,7 +160,8 @@ jobs: - name: Build and test wheels env: - CIBW_PRERELEASE_PYTHONS: ${{ matrix.prerelease }} + CIBW_PRERELEASE_PYTHONS: ${{ matrix.prerelease_pythons }} + CIBW_FREE_THREADED_SUPPORT: ${{ matrix.free_threaded_support }} CIBW_ENVIRONMENT: SKLEARN_SKIP_NETWORK_TESTS=1 SKLEARN_BUILD_PARALLEL=3 CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }} @@ -167,7 +174,8 @@ jobs: CIBW_CONFIG_SETTINGS_WINDOWS: "setup-args=--vsenv" CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: bash build_tools/github/repair_windows_wheels.sh {wheel} {dest_dir} CIBW_BEFORE_TEST_WINDOWS: bash build_tools/github/build_minimal_windows_image.sh ${{ matrix.python }} - CIBW_TEST_REQUIRES: pytest pandas + CIBW_TEST_REQUIRES: pytest + CIBW_BEFORE_TEST: bash {project}/build_tools/wheels/cibw_before_test.sh CIBW_TEST_COMMAND: bash {project}/build_tools/wheels/test_wheels.sh CIBW_TEST_COMMAND_WINDOWS: bash {project}/build_tools/github/test_windows_wheels.sh ${{ matrix.python }} CIBW_BUILD_VERBOSITY: 1 diff --git a/build_tools/wheels/build_wheels.sh b/build_tools/wheels/build_wheels.sh index d2df4e3936829..7939596e720c0 100755 --- a/build_tools/wheels/build_wheels.sh +++ b/build_tools/wheels/build_wheels.sh @@ -59,6 +59,13 @@ if [[ "$GITHUB_EVENT_NAME" == "schedule" || "$CIRRUS_CRON" == "nightly" ]]; then export CIBW_BUILD_FRONTEND='pip; args: --pre --extra-index-url "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple"' fi +if [[ "$CIBW_FREE_THREADED_SUPPORT" =~ [tT]rue ]]; then + # Numpy, scipy, Cython only have free-threaded wheels on scientific-python-nightly-wheels + # TODO: remove this after CPython 3.13 is released (scheduled October 2024) + # and our dependencies have free-threaded wheels on PyPI + export CIBW_BUILD_FRONTEND='pip; args: --pre --extra-index-url "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple"' +fi + # The version of the built dependencies are specified # in the pyproject.toml file, while the tests are run # against the most recent version of the dependencies diff --git a/build_tools/wheels/cibw_before_test.sh b/build_tools/wheels/cibw_before_test.sh new file mode 100755 index 0000000000000..b2a0a82428702 --- /dev/null +++ b/build_tools/wheels/cibw_before_test.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e +set -x + +FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))")" +if [[ $FREE_THREADED_BUILD == "True" ]]; then + # TODO: remove when numpy and scipy have releases with free-threaded wheels + python -m pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy scipy +else + # There is no pandas free-threaded wheel at the time of writing, so we only + # install pandas in other builds + # TODO: adapt when there is a pandas free-threaded wheel + python -m pip install pandas +fi diff --git a/build_tools/wheels/test_wheels.sh b/build_tools/wheels/test_wheels.sh index e8cdf4b3ea8a2..da2c458c52903 100755 --- a/build_tools/wheels/test_wheels.sh +++ b/build_tools/wheels/test_wheels.sh @@ -6,6 +6,14 @@ set -x python -c "import joblib; print(f'Number of cores (physical): \ {joblib.cpu_count()} ({joblib.cpu_count(only_physical_cores=True)})')" +FREE_THREADED_BUILD="$(python -c"import sysconfig; print(bool(sysconfig.get_config_var('Py_GIL_DISABLED')))")" +if [[ $FREE_THREADED_BUILD == "True" ]]; then + # TODO: delete when importing numpy no longer enables the GIL + # setting to zero ensures the GIL is disabled while running the + # tests under free-threaded python + export PYTHON_GIL=0 +fi + # Test that there are no links to system libraries in the # threadpoolctl output section of the show_versions output: python -c "import sklearn; sklearn.show_versions()" From 4bd87c61fb095a858cd35042b3c4adedcf566241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Thu, 13 Jun 2024 16:57:22 +0200 Subject: [PATCH 2/4] [cd build gh] Trigger Github wheels From 24f5a0218e51f63fd9e517839caf7f483217975f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 14 Jun 2024 08:45:12 +0200 Subject: [PATCH 3/4] Add TODO --- .github/workflows/wheels.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 37e5d2cddfaca..71b3f7cd9a7db 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -90,6 +90,7 @@ jobs: python: 313t platform_id: manylinux_x86_64 manylinux_image: manylinux2014 + # TODO: remove next line when Python 3.13 is released prerelease_pythons: True free_threaded_support: True From cb5f85e0884c20a8c55b76128d12e2b5117fdcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 14 Jun 2024 08:45:22 +0200 Subject: [PATCH 4/4] [cd build gh] Trigger Github wheels