Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build wheels for linux, windows, mac using cibuildwheel #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

leocov-dev
Copy link

@leocov-dev leocov-dev commented May 24, 2024

I'd like to be able to easily use this library on macOS and windows but without published wheels it is difficult.
To that end I've added a github actions workflow that uses cibuildwheel to create wheels for a variety of platforms/architectures.
cibuildwheels is a well established project for building wheels used by many large projects (see links).
https://github.com/pypa/cibuildwheel
https://cibuildwheel.pypa.io/en/stable/working-examples/
In addition to building wheels it runs the test suite on all the wheels it creates.
example of workflow running (can inspect generated artifacts):
https://github.com/leocov-dev/blurhash-python/actions/workflows/ci.yml

changes:

  • cibuildwheels action workflow
  • publish workflow for PyPi
  • convert setup.py to pyproject.toml
  • update tests to work in CI

Comment on lines +63 to +69
Local Build
-----------

Build source distribution and wheels into `dist/` directory.
```
$ python -m build
```
Copy link
Author

Choose a reason for hiding this comment

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

i removed the container build scripts since they seemed aimed at producing wheels for manual upload to PyPi and the python -m build command is suitable for testing the build locally. Other platform wheels could be downloaded from github CI artifacts during a PR review for additional testing if desired.

setup_requires=[
'cffi',
'setuptools-scm',
],
cffi_modules=['src/build_blurhash.py:ffibuilder'],
Copy link
Author

Choose a reason for hiding this comment

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

this has no equivalent that I am aware of in the new pyproject.toml spec - alternatives all seemed to need custom build scripts.

import pytest

from PIL import Image
from blurhash import encode

_test_dir = os.path.dirname(__file__)
Copy link
Author

Choose a reason for hiding this comment

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

cibuildwheel will fail to find relative paths when running tests against each wheel so resolving the paths in a different way was required.

Comment on lines +49 to +67
upload_pypi:
name: Publish to PyPi
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

# trusted publishing workflow:
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
- uses: pypa/gh-action-pypi-publish@release/v1.8
Copy link
Author

Choose a reason for hiding this comment

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

there are many options for publishing the wheels, i included this as an example.

this would:

  • wait for a release that is published
  • run the build again and generate artifacts (zip files containing wheels and sdist)
  • unpack all artifacts
  • push wheels and sdist to pypi

but it is certainly possible to do something else or do it manually.

@leocov-dev leocov-dev marked this pull request as ready for review May 24, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant