From 3259d52cb6b5f91cba5ea3ac58232c1567de39a2 Mon Sep 17 00:00:00 2001 From: Peter Lithammer Date: Wed, 26 May 2021 09:36:40 +0200 Subject: [PATCH] ci: replace custom workflow with cibuildwheel --- .github/workflows/publish.yml | 153 ---------------------------------- .github/workflows/python.yml | 88 +++++++++++++++---- pyproject.toml | 10 +++ setup.py | 8 +- 4 files changed, 88 insertions(+), 171 deletions(-) delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index d5e7517..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,153 +0,0 @@ -name: Publish - -on: - release: - types: [published] - -jobs: - build_sdist: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.8'] - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2.2.2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: python -m pip install --upgrade setuptools - - - name: Create packages - run: python setup.py sdist - - - uses: actions/upload-artifact@v2.2.4 - with: - name: python_packages - path: dist - - build_wheel_linux: - runs-on: ubuntu-latest - strategy: - matrix: - image: - - quay.io/pypa/manylinux1_i686 - - quay.io/pypa/manylinux1_x86_64 - - quay.io/pypa/manylinux2010_x86_64 - # - quay.io/pypa/manylinux2014_x86_64 - steps: - - uses: actions/checkout@v2 - - - name: Pull Docker images - run: docker pull ${{ matrix.image }} - - - name: Build ${{ matrix.image }} wheel - run: | - cat <<'EOF' | docker run --rm -i -v $PWD:/app ${{ matrix.image }} - for pybin in /opt/python/*/bin; do - "$pybin/python" -m pip wheel /app/ -w /app/dist - done - - for whl in /app/dist/*.whl; do - auditwheel repair "$whl" -w /app/dist/wheelhouse - done - EOF - - - uses: actions/upload-artifact@v2.2.4 - with: - name: python_packages - path: dist/wheelhouse - - build_wheel_macos: - runs-on: macos-latest - strategy: - matrix: - python-version: ['3.6', '3.7', '3.8', '3.9'] - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2.2.2 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: python -m pip install --upgrade pip setuptools wheel - - - name: Build wheel - run: python setup.py bdist_wheel - - # - name: Delocate for macOS wheels - # run: | - # python -m pip install --upgrade delocate - # delocate-addplat --rm-orig \ - # -p macosx_10_15_x86_64 \ - # -p macosx_10_14_x86_64 \ - # -p macosx_10_13_x86_64 \ - # -p macosx_10_12_x86_64 \ - # -p macosx_10_11_x86_64 \ - # -p macosx_10_10_x86_64 \ - # dist/*.whl - - - uses: actions/upload-artifact@v2.2.4 - with: - name: python_packages - path: dist - - build_wheel_windows: - runs-on: windows-latest - strategy: - matrix: - python-version: ['3.6', '3.7', '3.8', '3.9'] - arch: ['x86', 'x64'] - steps: - - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} (${{ matrix.arch }}) - uses: actions/setup-python@v2.2.2 - with: - python-version: ${{ matrix.python-version }} - arch: ${{ matrix.arch }} - - - name: Install dependencies - run: python -m pip install --upgrade pip setuptools wheel - - - name: Build wheel - run: python setup.py bdist_wheel - - - uses: actions/upload-artifact@v2.2.4 - with: - name: python_packages - path: dist - - publish: - needs: - - build_sdist - - build_wheel_linux - - build_wheel_macos - - build_wheel_windows - runs-on: ubuntu-latest - steps: - - uses: actions/download-artifact@v2.0.10 - with: - name: python_packages - path: dist - - - name: Show result - run: ls -l dist - - - name: Publish packages to TestPyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.TEST_PYPI_TOKEN }} - repository_url: https://test.pypi.org/legacy/ - - - name: Publish packages to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 4a24985..b194743 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -7,33 +7,87 @@ on: pull_request: branches: - master + release: + types: + - published jobs: - tox: + build_wheels: + name: Build wheels on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest - python-version: - - '3.6' - - '3.7' - - '3.8' - - '3.9' + os: [ubuntu-20.04, windows-2019, macos-10.15] + + steps: + - uses: actions/checkout@v2 + + # Needed to build non-native architectures. + # https://cibuildwheel.readthedocs.io/en/stable/faq/#emulation + - name: Setup QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v1 + with: + platforms: all + + - name: Build wheels + uses: pypa/cibuildwheel@v2.2.2 + env: + # While arm64 wheels can be built on x86_64, they cannot be tested. + # The ability to test the arm64 wheels will be added in a future + # release of cibuildwheel, once Apple Silicon CI runners are widely + # available. + CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64" + + - uses: actions/upload-artifact@v2 + with: + name: python_packages + path: ./wheelhouse/*.whl + + build_sdist: + name: Build source distribution + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Python uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: '3.8' - - name: Install Tox - run: pip install tox tox-gh-actions - env: - PIP_CONSTRAINT: requirements.txt + - name: Install build + run: pip install build + + - name: Build sdist + run: python -m build -s + + - uses: actions/upload-artifact@v2 + with: + name: python_packages + path: dist/*.tar.gz + + publish: + needs: + - build_wheels + - build_sdist + runs-on: ubuntu-latest + # if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v') + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: actions/download-artifact@v2 + with: + name: python_packages + path: dist - - name: Test - run: tox + - name: Publish packages to TestPyPI + uses: pypa/gh-action-pypi-publish@v1 + with: + user: __token__ + password: ${{ secrets.TEST_PYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + + - name: Publish packages to PyPI + uses: pypa/gh-action-pypi-publish@v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index f98b3fd..3a80b71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,16 @@ requires = ["setuptools>=40.8.0", "wheel"] build-backend = "setuptools.build_meta" +[tool.cibuildwheel] +test-command = "pytest {package}/tests" +test-requires = "pytest" + +[tool.cibuildwheel.macos] +archs = ["x86_64", "universal2", "arm64"] + +[tool.cibuildwheel.linux] +archs = ["auto", "aarch64"] + [tool.black] line-length = 79 target-version = ["py36"] diff --git a/setup.py b/setup.py index ae689d5..56e83ab 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,13 @@ +import os + from setuptools import Extension, setup setup( ext_modules=[ - Extension("_jump", sources=["src/jump/jump.c"], optional=True) + Extension( + "_jump", + sources=["src/jump/jump.c"], + optional=os.environ.get("CIBUILDWHEEL", "0") != "1", + ) ] )