Skip to content

Commit

Permalink
Package C extension to wheel (#225)
Browse files Browse the repository at this point in the history
* Run auditwheel to check manylinux compatibility

* Package inside_polygon_ext binary extension to wheel

* Switch to cibuildwheel

* skip test publish from fork PRs

* only publish when test publishing worked

* Update poetry.lock

* v6.5.1

* Create poetry.lock

* add acknowledgement

---------

Co-authored-by: Jannik Kissinger <github@michelfe.it>
  • Loading branch information
theirix and jannikmi authored Jun 14, 2024
1 parent 7a6ba7b commit 208f663
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 301 deletions.
110 changes: 93 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,85 @@ jobs:
- name: Run tox
run: tox

deploy:
runs-on: ubuntu-latest
needs: test
if: endsWith(github.ref, '/master')
permissions:
id-token: write
contents: write
make-wheels:
name: Make ${{ matrix.os }} ${{ matrix.cibw_arch }} wheels
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
cibw_arch: ["native"]
cibw_build: ["cp38-* cp39-* cp310-* cp311-* cp312-*"]
fail-fast: false

steps:
- uses: actions/checkout@v4
- name: "Checkout repo"
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- name: Install poetry
run: pip install poetry

- name: "Build wheels"
uses: pypa/cibuildwheel@v2.19.1
with:
python-version: 3.8
output-dir: dist
env:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_SKIP: "*musllinux*"
CIBW_ARCHS: ${{ matrix.cibw_arch }}
CIBW_BUILD_FRONTEND: pip
CIBW_BEFORE_ALL_LINUX: yum install -y libffi-devel clang make
CIBW_BUILD_VERBOSITY: 1

- name: Install build dependencies
run: |
pip install poetry
- name: "Upload wheel as artifact"
uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.os }}-${{ matrix.cibw_arch }}-wheel
path: "./**/dist/*.whl"

make-sdist:
name: Make source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install poetry
run: pip install poetry

- run: poetry build -f sdist

- uses: actions/upload-artifact@v4
with:
name: artifact-source-dist
path: "./**/dist/*.tar.gz"


test-publish:
name: Test PyPI Publishing
runs-on: ubuntu-latest
needs: [test, make-wheels, make-sdist]
# only run jobs if the feature branch is the base repo (not in a fork)
# TODO fails PRs from forks due to: "missing or insufficient OIDC token permissions,
# the ACTIONS_ID_TOKEN_REQUEST_TOKEN environment variable was unset"
if: github.event.pull_request.head.repo.full_name == github.repository
permissions:
id-token: write
contents: write
steps:
- name: Fetch version
id: fetch_version
run: echo "version_nr=$(poetry version -s)" >> $GITHUB_OUTPUT

- name: Build a binary wheel and a source tarball
# Note: poetry build required to support CLI script entrypoint in pyproject.toml?!
- name: Download all artifacts
uses: actions/download-artifact@v4

- name: Copy artifacts to dist/ folder
run: |
poetry build --no-interaction
find . -name 'artifact-*' -exec unzip '{}' \;
mkdir -p dist/
find . -name '*.tar.gz' -exec mv '{}' dist/ \;
find . -name '*.whl' -exec mv '{}' dist/ \;
ls -lR dist/
- name: Test PyPI Publishing
uses: pypa/gh-action-pypi-publish@release/v1
Expand All @@ -80,6 +132,30 @@ jobs:
repository-url: https://test.pypi.org/legacy/
skip-existing: true

publish:
runs-on: ubuntu-latest
# Note: only runs, when test publishing worked
needs: [test, make-wheels, make-sdist, test-publish]
if: endsWith(github.ref, '/master')
permissions:
id-token: write
contents: write
steps:
- name: Fetch version
id: fetch_version
run: echo "version_nr=$(poetry version -s)" >> $GITHUB_OUTPUT

- name: Download all artifacts
uses: actions/download-artifact@v4

- name: Copy artifacts to dist/ folder
run: |
find . -name 'artifact-*' -exec unzip '{}' \;
mkdir -p dist/
find . -name '*.tar.gz' -exec mv '{}' dist/ \;
find . -name '*.whl' -exec mv '{}' dist/ \;
ls -lR dist/
- name: Create GitHub Release
id: create_gh_release
uses: ncipollo/release-action@v1
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========


6.5.1 (2024-06-14)
------------------

* added support for cibuildwheel: publish wheels including the native C extension. GHA CI/CD pipeline creates sdist (no binaries inside) and a bunch of binary wheels with a prebuilt clang-pip extension for each python version. Thanks to @theirix



6.5.0 (2024-03-14)
------------------

Expand Down
1 change: 1 addition & 0 deletions docs/3_about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Thanks to:

- `Adam <https://github.com/adamchainz>`__ for adding organisational features to the project and for helping me with publishing and testing routines.
- `ringsaturn <https://github.com/ringsaturn>`__ for valuable feedback, sponsoring this project, creating the ``tzfpy`` package and adding the ``pytz`` compatibility extra
- `theirix <https://github.com/theirix>`__ for adding support for cibuildwheel
- `snowman2 <https://github.com/snowman2>`__ for creating the conda-forge recipe.
- `synapticarbors <https://github.com/synapticarbors>`__ for fixing Numba import with py27.
- `zedrdave <https://github.com/zedrdave>`__ for valuable feedback.
Expand Down
Loading

0 comments on commit 208f663

Please sign in to comment.