From 7de5b94452c9202928809cc1fd8e55aed3ce55d3 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 16 May 2024 15:16:04 -0700 Subject: [PATCH] WIP Windows to CIBW, in-tree backend --- .github/workflows/ci.yaml | 595 +++++++++++++++++++------------------- packaging/pep517.py | 51 ++++ pyproject.toml | 3 +- setup.py | 34 +++ 4 files changed, 388 insertions(+), 295 deletions(-) create mode 100644 packaging/pep517.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 33e2bcab..22b6197f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,7 +2,7 @@ name: PyYAML CI on: -# push: + push: # pull_request: # types: [opened, synchronize, reopened] workflow_dispatch: @@ -33,7 +33,7 @@ jobs: # uses: actions/checkout@v4 # # - name: Install a python -# uses: actions/setup-python@v4 +# uses: actions/setup-python@v5 # with: # python-version: 3.x # @@ -74,150 +74,150 @@ jobs: # with: # name: dist # path: dist/*.tar.gz - - - linux_libyaml: - name: libyaml ${{matrix.cfg.arch}} ${{matrix.cfg.platform}} - runs-on: ubuntu-22.04 - strategy: - # FIXME: dynamic matrix away the slow ones - matrix: - cfg: - - { platform: manylinux1, arch: x86_64 } - - { platform: manylinux2014, arch: x86_64 } - - { platform: manylinux2014, arch: aarch64 } - - { platform: manylinux2014, arch: s390x } - - { platform: musllinux_1_1, arch: x86_64 } - - { platform: musllinux_1_1, arch: aarch64 } - env: - DOCKER_IMAGE: quay.io/pypa/${{matrix.cfg.platform}}_${{matrix.cfg.arch}} - steps: - - name: Check cached libyaml state - id: cached_libyaml - uses: actions/cache@v4 - with: - path: libyaml - key: libyaml_${{matrix.cfg.platform}}_${{matrix.cfg.arch}}_${{env.LIBYAML_REF}} - - - name: configure docker foreign arch support - uses: docker/setup-qemu-action@v2 - if: matrix.cfg.arch != 'x86_64' && steps.cached_libyaml.outputs.cache-hit != 'true' - - - name: Checkout pyyaml - uses: actions/checkout@v4 - if: steps.cached_libyaml.outputs.cache-hit != 'true' - - - name: Build libyaml - run: > - docker run --rm - --volume "$(pwd):/io" - --env LIBYAML_REF - --env LIBYAML_REPO - --workdir /io - "$DOCKER_IMAGE" - /io/packaging/build/libyaml.sh - if: steps.cached_libyaml.outputs.cache-hit != 'true' - - - name: ensure output is world readable (or cache fill fails with Permission Denied) - run: > - sudo chmod -R a+r ./libyaml/ - if: steps.cached_libyaml.outputs.cache-hit != 'true' - - make_linux_pyyaml_matrix: - runs-on: ubuntu-22.04 - outputs: - matrix_json: ${{ steps.make_matrix.outputs.matrix_json }} - steps: - - uses: actions/checkout@v4 - - name: make a matrix - id: make_matrix - uses: ./.github/actions/dynamatrix - with: - matrix_yaml: | - include: - - { platform: manylinux1, arch: x86_64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: manylinux1, arch: x86_64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: manylinux2014, arch: x86_64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: manylinux2014, arch: x86_64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: manylinux2014, arch: x86_64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: manylinux2014, arch: x86_64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip" } - - { platform: manylinux2014, arch: aarch64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: aarch64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: aarch64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: aarch64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: aarch64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: aarch64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: manylinux2014, arch: s390x, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs }} } - - { platform: musllinux_1_1, arch: x86_64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: aarch64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: aarch64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: aarch64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: aarch64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } - - { platform: musllinux_1_1, arch: aarch64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_slow_jobs }} } - - - linux_pyyaml: - needs: [linux_libyaml, make_linux_pyyaml_matrix] - name: pyyaml ${{matrix.arch}} ${{matrix.platform}} ${{matrix.spec}} - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.make_linux_pyyaml_matrix.outputs.matrix_json) }} - - steps: - - name: Checkout PyYAML - uses: actions/checkout@v4 - - - name: Fetch cached libyaml - id: cached_libyaml - uses: actions/cache/restore@v4 - with: - path: libyaml - key: libyaml_${{matrix.platform}}_${{matrix.arch}}_${{env.LIBYAML_REF}} - fail-on-cache-miss: true - - - name: configure docker foreign arch support - uses: docker/setup-qemu-action@v2 - if: matrix.arch != 'x86_64' - - - name: Build/Test/Package - env: - CIBW_ARCHS: all - # HACK: ick, maybe deconstruct the matrix a bit or query cibuildwheel for its default target *linux spec first? - CIBW_BUILD: ${{matrix.spec}}-${{ contains(matrix.platform, 'musllinux') && 'musllinux' || 'manylinux' }}_${{matrix.arch}} - CIBW_BUILD_VERBOSITY: 1 - # containerized Linux builds require explicit CIBW_ENVIRONMENT - CIBW_ENVIRONMENT: > - C_INCLUDE_PATH=libyaml/include - LIBRARY_PATH=libyaml/src/.libs - LD_LIBRARY_PATH=libyaml/src/.libs - PYYAML_FORCE_CYTHON=1 - PYYAML_FORCE_LIBYAML=1 - CIBW_TEST_COMMAND: cd {project}; pytest - CIBW_TEST_REQUIRES: pytest - run: | - set -eux - python3 -V - python3 -m pip install -U --user ${{ matrix.cibw_version || 'cibuildwheel' }} - python3 -m cibuildwheel --platform auto --output-dir dist . - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: dist - path: dist/*.whl - if-no-files-found: error - if: ${{ ! env.skip_artifact_upload }} +# +# +# linux_libyaml: +# name: libyaml ${{matrix.cfg.arch}} ${{matrix.cfg.platform}} +# runs-on: ubuntu-22.04 +# strategy: +# # FIXME: dynamic matrix away the slow ones +# matrix: +# cfg: +# - { platform: manylinux1, arch: x86_64 } +# - { platform: manylinux2014, arch: x86_64 } +# - { platform: manylinux2014, arch: aarch64 } +# - { platform: manylinux2014, arch: s390x } +# - { platform: musllinux_1_1, arch: x86_64 } +# - { platform: musllinux_1_1, arch: aarch64 } +# env: +# DOCKER_IMAGE: quay.io/pypa/${{matrix.cfg.platform}}_${{matrix.cfg.arch}} +# steps: +# - name: Check cached libyaml state +# id: cached_libyaml +# uses: actions/cache@v4 +# with: +# path: libyaml +# key: libyaml_${{matrix.cfg.platform}}_${{matrix.cfg.arch}}_${{env.LIBYAML_REF}} +# +# - name: configure docker foreign arch support +# uses: docker/setup-qemu-action@v3 +# if: matrix.cfg.arch != 'x86_64' && steps.cached_libyaml.outputs.cache-hit != 'true' +# +# - name: Checkout pyyaml +# uses: actions/checkout@v4 +# if: steps.cached_libyaml.outputs.cache-hit != 'true' +# +# - name: Build libyaml +# run: > +# docker run --rm +# --volume "$(pwd):/io" +# --env LIBYAML_REF +# --env LIBYAML_REPO +# --workdir /io +# "$DOCKER_IMAGE" +# /io/packaging/build/libyaml.sh +# if: steps.cached_libyaml.outputs.cache-hit != 'true' +# +# - name: ensure output is world readable (or cache fill fails with Permission Denied) +# run: > +# sudo chmod -R a+r ./libyaml/ +# if: steps.cached_libyaml.outputs.cache-hit != 'true' +# +# make_linux_pyyaml_matrix: +# runs-on: ubuntu-22.04 +# outputs: +# matrix_json: ${{ steps.make_matrix.outputs.matrix_json }} +# steps: +# - uses: actions/checkout@v4 +# - name: make a matrix +# id: make_matrix +# uses: ./.github/actions/dynamatrix +# with: +# matrix_yaml: | +# include: +# - { platform: manylinux1, arch: x86_64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: manylinux1, arch: x86_64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: manylinux2014, arch: x86_64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: manylinux2014, arch: x86_64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: manylinux2014, arch: x86_64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: manylinux2014, arch: x86_64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip" } +# - { platform: manylinux2014, arch: aarch64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: aarch64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: aarch64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: aarch64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: aarch64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: aarch64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: manylinux2014, arch: s390x, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp38, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs }} } +# - { platform: musllinux_1_1, arch: x86_64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: aarch64, spec: cp39, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: aarch64, spec: cp310, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: aarch64, spec: cp311, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: aarch64, spec: cp312, omit: ${{ env.skip_ci_redundant_jobs || env.skip_slow_jobs }} } +# - { platform: musllinux_1_1, arch: aarch64, spec: cp313, cibw_version: "https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip", omit: ${{ env.skip_slow_jobs }} } +# +# +# linux_pyyaml: +# needs: [linux_libyaml, make_linux_pyyaml_matrix] +# name: pyyaml ${{matrix.arch}} ${{matrix.platform}} ${{matrix.spec}} +# runs-on: ubuntu-22.04 +# strategy: +# fail-fast: false +# matrix: ${{ fromJSON(needs.make_linux_pyyaml_matrix.outputs.matrix_json) }} +# +# steps: +# - name: Checkout PyYAML +# uses: actions/checkout@v4 +# +# - name: Fetch cached libyaml +# id: cached_libyaml +# uses: actions/cache/restore@v4 +# with: +# path: libyaml +# key: libyaml_${{matrix.platform}}_${{matrix.arch}}_${{env.LIBYAML_REF}} +# fail-on-cache-miss: true +# +# - name: configure docker foreign arch support +# uses: docker/setup-qemu-action@v3 +# if: matrix.arch != 'x86_64' +# +# - name: Build/Test/Package +# env: +# CIBW_ARCHS: all +# # HACK: ick, maybe deconstruct the matrix a bit or query cibuildwheel for its default target *linux spec first? +# CIBW_BUILD: ${{matrix.spec}}-${{ contains(matrix.platform, 'musllinux') && 'musllinux' || 'manylinux' }}_${{matrix.arch}} +# CIBW_BUILD_VERBOSITY: 1 +# # containerized Linux builds require explicit CIBW_ENVIRONMENT +# CIBW_ENVIRONMENT: > +# C_INCLUDE_PATH=libyaml/include +# LIBRARY_PATH=libyaml/src/.libs +# LD_LIBRARY_PATH=libyaml/src/.libs +# PYYAML_FORCE_CYTHON=1 +# PYYAML_FORCE_LIBYAML=1 +# CIBW_TEST_COMMAND: cd {project}; pytest +# CIBW_TEST_REQUIRES: pytest +# run: | +# set -eux +# python3 -V +# python3 -m pip install -U --user ${{ matrix.cibw_version || 'cibuildwheel' }} +# python3 -m cibuildwheel --platform auto --output-dir dist . +# +# - name: Upload artifacts +# uses: actions/upload-artifact@v3 +# with: +# name: dist +# path: dist/*.whl +# if-no-files-found: error +# if: ${{ ! env.skip_artifact_upload }} # # macos_libyaml: # name: libyaml macos ${{matrix.arch}} @@ -344,154 +344,161 @@ jobs: # name: dist # path: dist/*.whl # if-no-files-found: error -# -# windows_libyaml: -# name: libyaml ${{matrix.platform}} ${{matrix.arch}} -# runs-on: ${{matrix.platform}} -# strategy: -# matrix: -# include: -# - platform: windows-2022 -# arch: x64 -# - platform: windows-2022 -# arch: win32 -# steps: -# - name: Get cached libyaml state -# id: cached_libyaml -# uses: actions/cache@v4 -# with: -# path: libyaml -# key: libyaml_${{matrix.platform}}_${{matrix.arch}}_${{env.LIBYAML_REF}} -# -# - name: Build libyaml -# shell: bash -# if: steps.cached_libyaml.outputs.cache-hit != 'true' -# run: | -# # git spews all over stderr unless we tell it not to -# export GIT_REDIRECT_STDERR="2>&1" -# -# if [[ ! -d ./libyaml ]]; then -# git clone -b ${{ env.LIBYAML_REF }} ${{ env.LIBYAML_REPO }} 2>&1 -# fi -# -# pushd libyaml -# git clean -fdx -# popd -# -# mkdir libyaml/build -# -# pushd libyaml/build -# cmake.exe -G "Visual Studio 16 2019" -A ${{ matrix.arch }} -DYAML_STATIC_LIB_NAME=yaml .. -# cmake.exe --build . --config Release -# popd -# -# -# windows_pyyaml: -# needs: windows_libyaml -# name: pyyaml ${{ matrix.platform }} ${{matrix.python_arch}} ${{matrix.spec}} -# runs-on: ${{matrix.platform}} -# strategy: -# matrix: -# include: -# - platform: windows-2022 -# build_arch: x64 -# python_arch: x64 -# spec: 3.8 -## - platform: windows-2022 -## build_arch: x64 -## python_arch: x64 -## spec: 3.9 -## - platform: windows-2022 -## build_arch: x64 -## python_arch: x64 -## spec: '3.10' -## - platform: windows-2022 -## build_arch: x64 -## python_arch: x64 -## spec: '3.11' -## - platform: windows-2022 -## build_arch: x64 -## python_arch: x64 -## spec: '3.12' -# - platform: windows-2022 -# build_arch: x64 -# python_arch: x64 -# spec: '3.13' -# - platform: windows-2022 -# build_arch: win32 -# python_arch: x86 -# spec: 3.8 -## - platform: windows-2022 -## build_arch: win32 -## python_arch: x86 -## spec: 3.9 -## - platform: windows-2022 -## build_arch: win32 -## python_arch: x86 -## spec: '3.10' -## - platform: windows-2022 -## build_arch: win32 -## python_arch: x86 -## spec: '3.11' -## - platform: windows-2022 -## build_arch: win32 -## python_arch: x86 -## spec: '3.12' -# - platform: windows-2022 -# build_arch: win32 -# python_arch: x86 -# spec: '3.13' -# steps: -# # autocrlf screws up tests under Windows -# - name: Set git to use LF -# run: | -# git config --global core.autocrlf false -# git config --global core.eol lf -# -# - name: Checkout pyyaml -# uses: actions/checkout@v4 -# -# - name: Get cached libyaml state -# id: cached_libyaml -# uses: actions/cache/restore@v4 -# with: -# path: libyaml -# key: libyaml_${{matrix.platform}}_${{matrix.build_arch}}_${{env.LIBYAML_REF}} -# fail-on-cache-miss: true -# -# - name: Install python ${{ matrix.spec }} -# uses: actions/setup-python@v4 -# with: -# architecture: ${{ matrix.python_arch }} -# python-version: ${{ matrix.spec }} -# -# - name: Build/Test/Package -# env: -# PYYAML_FORCE_CYTHON: 1 -# PYYAML_FORCE_LIBYAML: 1 -# shell: bash -# run: | -# set -eux -# python -V -# python -m pip install "Cython<3.0" setuptools wheel -# -# python setup.py \ -# --with-libyaml build_ext \ -# -I libyaml/include \ -# -L libyaml/build/Release \ -# -D YAML_DECLARE_STATIC \ -# build bdist_wheel -# -# # run tests on built wheel -# python -m pip install dist/*.whl pytest -# python -I -m pytest -# -# - name: Upload artifacts -# uses: actions/upload-artifact@v3 -# with: -# name: dist -# path: dist/*.whl -# if-no-files-found: error + + windows_libyaml: + name: libyaml ${{matrix.platform}} ${{matrix.arch}} + runs-on: ${{matrix.platform}} + strategy: + matrix: + include: + - platform: windows-2022 + arch: x64 + - platform: windows-2022 + arch: win32 + steps: + - name: Get cached libyaml state + id: cached_libyaml + uses: actions/cache@v4 + with: + path: libyaml + key: libyaml_${{'windows'}}_${{matrix.arch}}_${{env.LIBYAML_REF}} + + - name: Build libyaml + shell: bash + if: steps.cached_libyaml.outputs.cache-hit != 'true' + run: | + # git spews all over stderr unless we tell it not to + export GIT_REDIRECT_STDERR="2>&1" + + if [[ ! -d ./libyaml ]]; then + git clone -b ${{ env.LIBYAML_REF }} ${{ env.LIBYAML_REPO }} 2>&1 + fi + + pushd libyaml + git clean -fdx + popd + + mkdir libyaml/build + + pushd libyaml/build + cmake.exe -G "Visual Studio 17 2022" -A ${{ matrix.arch }} -DYAML_STATIC_LIB_NAME=yaml .. + cmake.exe --build . --config Release + popd + + make_windows_pyyaml_matrix: + runs-on: ubuntu-22.04 + outputs: + matrix_json: ${{ steps.make_matrix.outputs.matrix_json }} + steps: + - uses: actions/checkout@v4 + - name: make a matrix + id: make_matrix + uses: ./.github/actions/dynamatrix + with: + matrix_yaml: | + include: + - spec: cp38-win_amd64 + build_arch: x64 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp39-win_amd64 + build_arch: x64 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp310-win_amd64 + build_arch: x64 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp311-win_amd64 + build_arch: x64 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp312-win_amd64 + build_arch: x64 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp313-win_amd64 + cibw_version: https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip + build_arch: x64 + + - spec: cp38-win32 + build_arch: win32 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp39-win32 + build_arch: win32 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp310-win32 + build_arch: win32 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp311-win32 + build_arch: win32 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp312-win32 + build_arch: win32 + omit: ${{ env.skip_ci_redundant_jobs }} + + - spec: cp313-win32 + build_arch: win32 + cibw_version: https://github.com/nitzmahone/cibuildwheel/archive/refs/heads/py313_support.zip + omit: ${{ env.skip_ci_redundant_jobs }} + + windows_pyyaml: + needs: [windows_libyaml, make_windows_pyyaml_matrix] + name: pyyaml ${{matrix.spec}} + runs-on: ${{ matrix.runs-on || 'windows-2022' }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.make_windows_pyyaml_matrix.outputs.matrix_json) }} + steps: + # autocrlf screws up tests under Windows + - name: Set git to use LF + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout pyyaml + uses: actions/checkout@v4 + + - name: Get cached libyaml state + id: cached_libyaml + uses: actions/cache/restore@v4 + with: + path: libyaml + key: libyaml_${{'windows'}}_${{ contains(matrix.spec, 'win_amd64') && 'x64' || 'win32' }}_${{env.LIBYAML_REF}} + fail-on-cache-miss: true + + - name: Install python ${{ matrix.spec }} + uses: actions/setup-python@v5 + with: + architecture: ${{ contains(matrix.spec, 'win_amd64') && 'x64' || 'x86' }} + python-version: '3.11' + + - name: Build/Test/Package + shell: bash + env: + CIBW_BUILD: ${{matrix.spec}} + CIBW_BUILD_VERBOSITY: 1 + CIBW_TEST_COMMAND: cd {project}; pytest + CIBW_TEST_REQUIRES: pytest + CIBW_CONFIG_SETTINGS: | + pyyaml_build_config='{"include_dirs": ["libyaml/include"], "library_dirs": ["libyaml/build/Release"], "define": [["YAML_DECLARE_STATIC", 1]], "force": 1}' + run: | + set -eux + python -V + python -m pip install -U --user ${{ matrix.cibw_version || 'cibuildwheel' }} + python -m cibuildwheel --output-dir dist . + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/*.whl + if-no-files-found: error + # check: # if: always() # needs: diff --git a/packaging/pep517.py b/packaging/pep517.py new file mode 100644 index 00000000..5f390266 --- /dev/null +++ b/packaging/pep517.py @@ -0,0 +1,51 @@ +import inspect + + +def _bridge_build_meta(): + import functools + import sys + + from setuptools import build_meta + + self_module = sys.modules[__name__] + + for attr_name in build_meta.__all__: + attr_value = getattr(build_meta, attr_name) + if callable(attr_value): + setattr(self_module, attr_name, functools.partial(_expose_config_settings, attr_value)) + + +class ActiveConfigSettings: + _current = {} + + def __init__(self, config_settings): + self._config = config_settings + + def __enter__(self): + type(self)._current = self._config + + def __exit__(self, exc_type, exc_val, exc_tb): + type(self)._current = {} + + @classmethod + def current(cls): + return cls._current + + +def _expose_config_settings(real_method, *args, **kwargs): + from contextlib import nullcontext + import inspect + + sig = inspect.signature(real_method) + boundargs = sig.bind(*args, **kwargs) + + config = boundargs.arguments.get('config_settings') + + ctx = ActiveConfigSettings(config) if config else nullcontext() + + with ctx: + return real_method(*args, **kwargs) + + +_bridge_build_meta() + diff --git a/pyproject.toml b/pyproject.toml index 6231323d..a497adf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,4 +5,5 @@ requires = [ "Cython; python_version < '3.13'", "Cython>=3.0; python_version >= '3.13'" ] -build-backend = "setuptools.build_meta" +backend-path = ["packaging"] +build-backend = "pep517" diff --git a/setup.py b/setup.py index 7cd40e05..3fffc1cd 100644 --- a/setup.py +++ b/setup.py @@ -101,6 +101,14 @@ bdist_wheel = None +try: + from pep517 import ActiveConfigSettings +except ImportError: + class ActiveConfigSettings: + @staticmethod + def current(): + return {} + # on Windows, disable wheel generation warning noise windows_ignore_warnings = [ "Unknown distribution option: 'python_requires'", @@ -180,6 +188,31 @@ def __init__(self, name, sources, feature_name, feature_description, class build_ext(_build_ext): + def finalize_options(self): + super().finalize_options() + pep517_config = ActiveConfigSettings.current() + + build_config = pep517_config.get('pyyaml_build_config') + + if build_config: + import json + build_config = json.loads(build_config) + print(f"`pyyaml_build_config`: {build_config}") + else: + build_config = {} + print("No `pyyaml_build_config` setting found.") + + for key, value in build_config.items(): + existing_value = getattr(self, key, ...) + if existing_value is ...: + print(f"ignoring unknown config key {key!r}") + continue + + if existing_value: + print(f"combining {key!r} {existing_value!r} and {value!r}") + value = existing_value + value # FIXME: handle type diff + + setattr(self, key, value) def run(self): optional = True @@ -237,6 +270,7 @@ def build_extensions(self): if with_ext is not None and not with_ext: continue if with_cython: + print(f"BUILDING CYTHON EXT; {self.include_dirs=} {self.library_dirs=} {self.define=}") ext.sources = self.cython_sources(ext.sources, ext) try: self.build_extension(ext)