Skip to content

CI Use cibuildwheel action instead of custom script - #34215

Closed
lesteve wants to merge 17 commits into
scikit-learn:mainfrom
lesteve:use-cibuildwheel-action
Closed

lesteve wants to merge 17 commits into
scikit-learn:mainfrom
lesteve:use-cibuildwheel-action

Conversation

@lesteve

@lesteve lesteve commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

The advantage is that the cibuildwheel is pinned in the yaml, rather than from the latest version in PyPI.

The context is creating a scikit-learn-release repo similarly to https://github.com/numpy/numpy-release and https://github.com/numpy/scipy-release. This would remove one our custom quirk that I noticed.

@lesteve
lesteve force-pushed the use-cibuildwheel-action branch from ebc93cc to 3975104 Compare June 8, 2026 16:06
@agriyakhetarpal

agriyakhetarpal commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

@lesteve you might want to try out cibuildwheel v4 that came out recently: https://iscinumpy.dev/post/cibuildwheel-4-0-0/ while we're at it. Also, is there a chance the pre-cibuildwheel setup can be moved to cibuildwheel's before-build (and/or before-build-macos, etc.) step? That would make it easier to run cibuildwheel and produce wheels locally.

@lesteve

lesteve commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Thanks for your feedback @agriyakhetarpal, I tried to use cibuildwheel 4.0.0, let's see 🤞.

Also, is there a chance the pre-cibuildwheel setup can be moved to cibuildwheel's before-build (and/or before-build-macos, etc.) step?

I don't think so, because you need to set environment variables like MACOSX_DEPLOYMENT_TARGET and compiler variables like CFLAGS and I think you need to a separate step for this, you can not do it in before-build? At least numpy seems to have a similar approach with a GHA step before the cibuildwheel one:
https://github.com/numpy/numpy/blob/856ea449ad2d39fd41fe6c6dec5cc69e0fcab13d/.github/workflows/wheels.yml#L82-L102

@agriyakhetarpal

Copy link
Copy Markdown
Contributor

Thanks @lesteve, looks like this is working well! Minus the Windows Docker engine not being there and an unrelated test failure on macOS.

Also, is there a chance the pre-cibuildwheel setup can be moved to cibuildwheel's before-build (and/or before-build-macos, etc.) step?

I don't think so, because you need to set environment variables like MACOSX_DEPLOYMENT_TARGET and compiler variables like CFLAGS and I think you need to a separate step for this, you can not do it in before-build? At least numpy seems to have a similar approach with a GHA step before the cibuildwheel one: numpy/numpy@856ea44/.github/workflows/wheels.yml#L82-L102

Oh, I think it can be moved, as you should be able to define these variables within the build script and pass them along. The problem with the approach would have been the OpenMP download occurring multiple times, but that cannot really happen here as the job is parameterised across Python versions – unlike workflows elsewhere where cibuildwheel installs and manages its own Python and builds from the earliest to the latest supported Python version (and thus runs before-build multiple times, once per wheel). I think it's worth trying out. Something like:

- name: Build and test wheels
        uses: pypa/cibuildwheel@f03ac7617d6cff873ccf24cc0d567ef5ba5a9e6d # v4.0.0
        env:
          CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
          CIBW_ARCHS: all
          CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
          CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_image }}
          # Needed on Windows CI to compile with Visual Studio compiler
          # otherwise Meson detects a MINGW64 platform and use MINGW64
          # toolchain
          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_BUILD: bash {project}/build_tools/wheels/cibw_before_build.sh {project}
          CIBW_BEFORE_BUILD_MACOS: |
            set -e
            if [ "$(uname -m)" = "arm64" ]; then
              OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
            else
              OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
            fi
            "$HOME/miniconda3/bin/conda" create -y -n build "$OPENMP_URL"
            bash {project}/build_tools/wheels/cibw_before_build.sh {project}
          CIBW_ENVIRONMENT_MACOS: >-
            PREFIX="$HOME/miniconda3/envs/build"
            MACOSX_DEPLOYMENT_TARGET=$([ "$(uname -m)" = "arm64" ] && echo 12.0 || echo 10.9)
            CC=/usr/bin/clang
            CXX=/usr/bin/clang++
            CPPFLAGS="-Xpreprocessor -fopenmp"
            CFLAGS="-I$PREFIX/include"
            CXXFLAGS="-I$PREFIX/include"
            LDFLAGS="-Wl,-rpath,$PREFIX/lib -L$PREFIX/lib -lomp"
          CIBW_BEFORE_TEST_WINDOWS: bash build_tools/github/build_minimal_windows_image.sh ${{ matrix.python }} ${{matrix.platform_id}}
          CIBW_ENVIRONMENT_PASS_LINUX: RUNNER_OS
          # TODO Put back pandas when there is a pandas release with Python 3.14 wheels
          CIBW_TEST_REQUIRES: ${{ contains(matrix.python, '314') && 'pytest' || 'pytest pandas' }} scipy
          # On Windows, we use a custom Docker image and CIBW_TEST_REQUIRES_WINDOWS
          # does not make sense because it would install dependencies in the host
          # rather than inside the Docker image
          CIBW_TEST_REQUIRES_WINDOWS: ""
          CIBW_TEST_COMMAND: bash {project}/build_tools/wheels/test_wheels.sh {project}
          CIBW_TEST_COMMAND_WINDOWS: bash {project}/build_tools/github/test_windows_wheels.sh ${{ matrix.python }} {project} ${{matrix.platform_id}}
          CIBW_BUILD_VERBOSITY: 1

@lesteve

lesteve commented Jun 11, 2026 •

Copy link
Copy Markdown
Member Author

I see, but then there are also other environment variables CIBW_ENVIRONMENT that need to be defined on all platforms, like SKLEARN_SKIP_NETWORK_TESTS=1 1. I had a quick attempt with overrides and inheriting the common variables with append, but overall my feeling is that it was more complicated than a separate GHA step 😉 ...

Footnotes

  1. in this PR I moved the env variables to pyproject.toml, which I find a bit easier to manage. Also this is a small step towards making the local cibuildwheel run to the CI one. ↩

@lesteve
lesteve marked this pull request as ready for review June 11, 2026 15:55
@lesteve

lesteve commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

@thomasjpfan I think this is ready for review if you want to have a look.

The free-threaded wheel CI failures (Windows + macOS) are not related and seemed genuine ...

There may be more opportunities to move things from wheels.yml to pyproject.toml but they can be done in separate PRs.

@ogrisel

ogrisel commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

This switch was made in the WIP isolated release repo at: https://github.com/scikit-learn/scikit-learn-release.

I am not sure if it's worth improving the release workflow in the main dev repo or if we should directly implement those changes in the new repo.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change LGTM though.

@ogrisel

ogrisel commented Jun 19, 2026

Copy link
Copy Markdown
Member

I checked the diff of this PR and I think most of the improvements have been identically or very similarly implemented in https://github.com/scikit-learn/scikit-learn-repo.

@lesteve

lesteve commented Jul 28, 2026 •

Copy link
Copy Markdown
Member Author

Closing this one, since a similar thing has already been done in https://github.com/scikit-learn/scikit-learn-release.

@lesteve lesteve closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants