-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create binary wheels with mypyc (#242)
Co-authored-by: Ofek Lev <[email protected]>
- Loading branch information
Showing
11 changed files
with
219 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ on: | |
pull_request: | ||
branches: [ master ] | ||
|
||
env: | ||
CIBW_TEST_COMMAND: python -m unittest discover --start-directory {project} | ||
CIBW_SKIP: pp* | ||
CIBW_ENVIRONMENT_PASS_LINUX: TOMLI_USE_MYPYC | ||
|
||
jobs: | ||
|
||
linters: | ||
|
@@ -74,12 +79,102 @@ jobs: | |
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
binary-wheels-standard: | ||
name: Binary wheels for ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Switch build backend to setuptools | ||
run: | | ||
pip install -r scripts/requirements.txt | ||
python scripts/use_setuptools.py | ||
- name: Build wheels | ||
uses: pypa/[email protected] | ||
env: | ||
CIBW_ARCHS_MACOS: x86_64 arm64 | ||
TOMLI_USE_MYPYC: '1' | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: artifact-standard-${{ matrix.os }} | ||
path: wheelhouse/*.whl | ||
if-no-files-found: error | ||
|
||
pure-python-wheel-and-sdist: | ||
name: Build a pure Python wheel and source distribution | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install build dependencies | ||
run: pip install build | ||
|
||
- name: Build | ||
run: python -m build | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: artifact-pure-python | ||
path: dist/* | ||
if-no-files-found: error | ||
|
||
binary-wheels-arm: | ||
name: Build Linux wheels for ARM | ||
runs-on: ubuntu-latest | ||
# Very slow (~ 1 hour), no need to run on PRs | ||
if: > | ||
github.event_name == 'push' | ||
&& | ||
(github.ref == 'refs/heads/master' || startsWith(github.event.ref, 'refs/tags')) | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Switch build backend to setuptools | ||
run: | | ||
pip install -r scripts/requirements.txt | ||
python scripts/use_setuptools.py | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: arm64 | ||
|
||
- name: Build wheels | ||
uses: pypa/[email protected] | ||
env: | ||
CIBW_ARCHS_LINUX: aarch64 | ||
TOMLI_USE_MYPYC: '1' | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: artifact-arm-linux | ||
path: wheelhouse/*.whl | ||
if-no-files-found: error | ||
|
||
allgood: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- tests | ||
- coverage | ||
- linters | ||
- binary-wheels-standard | ||
- pure-python-wheel-and-sdist | ||
- binary-wheels-arm | ||
steps: | ||
- run: echo "Great success!" | ||
|
||
|
@@ -89,19 +184,20 @@ jobs: | |
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
path: dist | ||
pattern: artifact-* | ||
merge-multiple: true | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
- name: Install build and publish tools | ||
- name: Install twine | ||
run: | | ||
pip install build twine | ||
- name: Build and check | ||
pip install twine | ||
- name: Check and publish | ||
run: | | ||
rm -rf dist/ && python -m build | ||
twine check --strict dist/* | ||
- name: Publish | ||
run: | | ||
twine upload dist/* | ||
env: | ||
TWINE_USERNAME: __token__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# Changelog | ||
|
||
## 2.2.0 | ||
|
||
- Added | ||
- mypyc generated binary wheels for common platforms | ||
|
||
## 2.1.0 | ||
|
||
- Deprecated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
prune tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tomli-w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pathlib import Path | ||
import tomllib | ||
|
||
import tomli_w # type: ignore[import-not-found] | ||
|
||
pyproject_path = Path(__file__).parent.parent / "pyproject.toml" | ||
data = tomllib.loads(pyproject_path.read_bytes().decode()) | ||
data["build-system"] = { | ||
"requires": ["setuptools>=69", "mypy[mypyc]>=1.13"], | ||
"build-backend": "setuptools.build_meta", | ||
} | ||
pyproject_path.write_bytes(tomli_w.dumps(data).encode()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
|
||
from setuptools import setup # type: ignore[import-untyped] | ||
|
||
if os.environ.get("TOMLI_USE_MYPYC") == "1": | ||
import glob | ||
|
||
from mypyc.build import mypycify # type: ignore[import-untyped] | ||
|
||
files = glob.glob("src/**/*.py", recursive=True) | ||
ext_modules = mypycify(files) | ||
else: | ||
ext_modules = [] | ||
|
||
setup(ext_modules=ext_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.