From d5d7fbfb5100d38520216e092426c9d4f2c3642e Mon Sep 17 00:00:00 2001 From: Nycholas de Oliveira e Oliveira Date: Sun, 11 Feb 2024 11:55:53 -0300 Subject: [PATCH] Build Python wheels for all the platforms --- .github/workflows/pre_release.yml | 49 ++++++++++++++++--- .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++-- pyproject.toml | 16 +++++- requirements/cbuild.txt | 4 ++ 4 files changed, 137 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pre_release.yml b/.github/workflows/pre_release.yml index fcfdee04..aeef7247 100644 --- a/.github/workflows/pre_release.yml +++ b/.github/workflows/pre_release.yml @@ -101,7 +101,7 @@ jobs: allow-empty: true build: - name: Build source + name: Build source on ${{ matrix.platform }} needs: [run-tox, coverage] runs-on: ${{ matrix.platform }} strategy: @@ -109,9 +109,7 @@ jobs: matrix: platform: - ubuntu-latest - - macos-latest - - windows-latest - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.12"] steps: - name: Checkout source at ${{ matrix.platform }} uses: actions/checkout@v4 @@ -124,7 +122,6 @@ jobs: python -m pip install -r requirements/build.txt python -m build --outdir dist-${{ matrix.platform }}-${{ matrix.python-version }} - name: Compiles Python modules to C extensions with Mypyc - if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python-version == '3.12' }} env: MYPYC_ENABLE: 1 run: | @@ -135,15 +132,46 @@ jobs: - name: Tar build and wheel distributions files run: | tar -cvf dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar dist-${{ matrix.platform }}-${{ matrix.python-version }} + tar -cvf mypyc-dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar mypyc-dist-${{ matrix.platform }}-${{ matrix.python-version }} - name: Upload build and wheel distributions files uses: actions/upload-artifact@v4 with: name: pre-release-build-${{ matrix.platform }}-${{ matrix.python-version }} - path: dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + path: | + dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + mypyc-dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + + build-wheels: + name: Build wheels on ${{ matrix.platform }} + needs: [run-tox, coverage] + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: + - ubuntu-latest + - macos-latest + - windows-latest + python-version: ["3.12"] + steps: + - name: Checkout source at ${{ matrix.platform }} + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install cbuild dependencies + run: python -m pip install -r requirements/cbuild.txt + - name: Build wheels + run: python -m cibuildwheel --output-dir wheelhouse + - uses: actions/upload-artifact@v4 + with: + name: pre-release-cibw-wheels-${{ matrix.platform }}-${{ matrix.python-version }} + path: ./wheelhouse/*.whl publish-testpypi: name: Publish to TestPyPI - needs: build + needs: [build, build-wheels] runs-on: ${{ matrix.platform }} permissions: contents: write @@ -164,10 +192,17 @@ jobs: uses: actions/download-artifact@v4 with: name: pre-release-build-${{ matrix.platform }}-${{ matrix.python-version }} + - name: Download cibw wheels distributions files + uses: actions/download-artifact@v4 + with: + path: pre-release-cibw-wheels + pattern: pre-release-cibw-wheels-* + merge-multiple: true - name: Build source and wheel distributions to version ${{ github.ref_name }} run: | python -m pip install -r requirements/build.txt tar -xvf dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + mv pre-release-cibw-wheels/* dist-${{ matrix.platform }}-${{ matrix.python-version }}/ twine check --strict dist-${{ matrix.platform }}-${{ matrix.python-version }}/* - name: Publish distribution to TestPyPI uses: pypa/gh-action-pypi-publish@v1.8.11 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a41a2596..8a6a17a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,67 @@ permissions: contents: write jobs: - build-n-publish: - name: Build and publish to PyPI + build: + name: Build source on ${{ matrix.platform }} + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: + - ubuntu-latest + python-version: ["3.12"] + steps: + - name: Checkout source at ${{ matrix.platform }} + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Build source and wheel distributions + run: | + python -m pip install -r requirements/build.txt + python -m build --outdir dist-${{ matrix.platform }}-${{ matrix.python-version }} + - name: Tar build and wheel distributions files + run: | + tar -cvf dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar dist-${{ matrix.platform }}-${{ matrix.python-version }} + - name: Upload build and wheel distributions files + uses: actions/upload-artifact@v4 + with: + name: release-build-${{ matrix.platform }}-${{ matrix.python-version }} + path: | + dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + + build-wheels: + name: Build wheels on ${{ matrix.platform }} + needs: [run-tox, coverage] + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: + - ubuntu-latest + - macos-latest + - windows-latest + python-version: ["3.12"] + steps: + - name: Checkout source at ${{ matrix.platform }} + uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install cbuild dependencies + run: python -m pip install -r requirements/cbuild.txt + - name: Build wheels + run: python -m cibuildwheel --output-dir wheelhouse + - uses: actions/upload-artifact@v4 + with: + name: release-cibw-wheels-${{ matrix.platform }}-${{ matrix.python-version }} + path: ./wheelhouse/*.whl + + publish-n-release: + name: Publish to PyPI and generate GitHub release ${{ github.ref_name }} + needs: [build, build-wheels] runs-on: ${{ matrix.platform }} permissions: contents: write @@ -27,16 +86,28 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + - name: Download build and wheel distributions files + uses: actions/download-artifact@v4 + with: + name: release-build-${{ matrix.platform }}-${{ matrix.python-version }} + - name: Download cibw wheels distributions files + uses: actions/download-artifact@v4 + with: + path: release-cibw-wheels + pattern: release-cibw-wheels-* + merge-multiple: true - name: Build source and wheel distributions to version ${{ github.ref_name }} run: | python -m pip install -r requirements/build.txt - python -m build - twine check --strict dist/* + tar -xvf dist-${{ matrix.platform }}-${{ matrix.python-version }}.tar + mv release-cibw-wheels/* dist-${{ matrix.platform }}-${{ matrix.python-version }}/ + twine check --strict dist-${{ matrix.platform }}-${{ matrix.python-version }}/* - name: Publish distribution to PyPI uses: pypa/gh-action-pypi-publish@v1.8.11 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} + packages-dir: dist-${{ matrix.platform }}-${{ matrix.python-version }}/ - name: Create GitHub Release id: create_release uses: softprops/action-gh-release@v1 @@ -49,4 +120,4 @@ jobs: LICENSE AUTHORS README.md - dist/* + dist-${{ matrix.platform }}-${{ matrix.python-version }}/* diff --git a/pyproject.toml b/pyproject.toml index fe5e29ad..caf6d59d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ backend-path = ["src/buildtools"] [project] name = "Flask-JSONRPC" -version = "3.0.1a0" +version = "3.0.1a1" description = "Adds JSONRPC support to Flask." readme = {file = "README.md", content-type = "text/markdown"} license = {file = "LICENSE"} @@ -59,6 +59,20 @@ namespaces = false [tool.distutils.bdist_wheel] universal = true +[tool.cibuildwheel] +before-all = "uname -a" +build-verbosity = 1 +skip = [ + "cp3{8,9,10}-*", + "*-manylinux_i686", + "*-musllinux_i686", + "*-win32", + "pp*", +] + +[tool.cibuildwheel.environment] +MYPYC_ENABLE = "1" + [tool.ruff] src = ["src"] fix = true diff --git a/requirements/cbuild.txt b/requirements/cbuild.txt index 507ebe30..8fc77cee 100644 --- a/requirements/cbuild.txt +++ b/requirements/cbuild.txt @@ -1,5 +1,9 @@ -r build.txt +# Tools +# ------------------------------------------------------------------------------ +cibuildwheel==2.16.5 + # Mypyc # ------------------------------------------------------------------------------ mypy[mypyc]==1.8.0 # https://github.com/python/mypy