-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Conversation
Local Build | ||
----------- | ||
|
||
Build source distribution and wheels into `dist/` directory. | ||
``` | ||
$ python -m build | ||
``` |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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__) |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
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: