Skip to content

Commit

Permalink
Support PyPy builds - not Windows (#28)
Browse files Browse the repository at this point in the history
Needs to run pypy_patch.py after builds until PyO3/maturin#312 is closed
Cannot support Windows PyPy until PyO3/maturin#115 is closed
  • Loading branch information
milesgranger authored Feb 18, 2021
1 parent a7c41df commit e94b30f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 41 deletions.
46 changes: 34 additions & 12 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,64 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9, pypy-3.6]
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v1
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
architecture: x64

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true

- name: Python Dev Install
- name: Python Maturin Install
run: |
pip install --upgrade pip
pip install -r dev-requirements.txt
pip install maturin
- name: Build Wheels - Linux
if: startsWith(matrix.os, 'ubuntu')
- name: Build Wheels - Linux - CPython
if: ${{ startsWith(matrix.os, 'ubuntu') && !startsWith(matrix.python-version, 'pypy') }}
run: |
docker run --rm -v $(pwd):/io konstin2/maturin build --release --out wheels
ls -l wheels
- name: Build Wheels - Non-Linux
if: startsWith(matrix.os, 'windows') || startsWith(matrix.os, 'macos')
- name: Build Wheels - Windows and OSX - CPython
if: ${{ !startsWith(matrix.os, 'ubuntu') && !startsWith(matrix.python-version, 'pypy') }}
run: |
pip install maturin
maturin build --release --out wheels
maturin sdist --out wheels
ls -l wheels
- name: Build Wheels - Linux and OSX - PyPy
if: ${{ !startsWith(matrix.os, 'windows') && startsWith(matrix.python-version, 'pypy') }}
run: |
make pypy-build
ls -l wheels
# TODO: Windows PyPy not supported - ref: https://github.com/PyO3/maturin/issues/115
#- name: Build Wheels - Windows - PyPy
# if: ${{ startsWith(matrix.os, 'windows') && startsWith(matrix.python-version, 'pypy') }}
# run: |
# maturin build -i $(where pypy3) --release --out wheels --no-sdist
# ls wheels

- name: Install wheel
run: pip install cramjam --no-index --find-links wheels
if: ${{ !(startsWith(matrix.os, 'windows') && startsWith(matrix.python-version, 'pypy')) }}
run: pip install cramjam --no-index --find-links wheels/

- name: Test - CPython
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
run: |
pip install --upgrade pip
pip install -r dev-requirements.txt
make test
- name: Test
run: make test
- name: Test - PyPy
if: ${{ startsWith(matrix.python-version, 'pypy') && !startsWith(matrix.os, 'windows') }}
run: pypy -c "import cramjam"
68 changes: 40 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: ReleaseCI

on:
release:
types:
- published
- prereleased
push:
tags:
- "*"
Expand All @@ -12,37 +15,46 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ 3.6, 3.7, 3.8, 3.9, pypy-3.6 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true

- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'

- name: Install Dev requirements
run: |
pip install --upgrade pip
pip install -r dev-requirements.txt
- uses: actions/checkout@v2

- name: Build Wheels - Linux
if: startsWith(matrix.os, 'ubuntu')
run: |
docker run --rm -v $(pwd):/io konstin2/maturin build --release --out wheels
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Build Wheels - Non-Linux
if: startsWith(matrix.os, 'windows') || startsWith(matrix.os, 'macos')
run: |
pip install maturin
maturin build --release --out wheels
maturin sdist --out wheels
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true

- name: Python Maturin Install
run: |
pip install --upgrade pip
pip install maturin
- name: Build Wheels - Linux - CPython
if: ${{ startsWith(matrix.os, 'ubuntu') && !startsWith(matrix.python-version, 'pypy') }}
run: |
docker run --rm -v $(pwd):/io konstin2/maturin build --release --out wheels
ls -l wheels
- name: Build Wheels - Windows and OSX - CPython
if: ${{ !startsWith(matrix.os, 'ubuntu') && !startsWith(matrix.python-version, 'pypy') }}
run: |
pip install maturin
maturin build --release --out wheels
maturin sdist --out wheels
ls -l wheels
- name: Build Wheels - Linux and OSX - PyPy
if: ${{ !startsWith(matrix.os, 'windows') && startsWith(matrix.python-version, 'pypy') }}
run: |
make pypy-build
ls -l wheels
- name: Publish
env:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ dev-install:
maturin build --release --out wheels --interpreter $(shell which python)
pip uninstall cramjam -y
rm wheels/*.tar.gz
pip install --no-index wheels/*
pip install cramjam --no-index --find-links wheels/

pypy-build:
maturin build -i $(shell which pypy) --release --out wheels
pypy ./pypy_patch.py
26 changes: 26 additions & 0 deletions pypy_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sysconfig
import pathlib
import re
import sys

"""
Hacky hack, not very good support with maturin for PyPy
1. Doesn't work on Windows
2. The naming is wrong in resulting wheels in Linux & OSX
This script patches the last issue; ran after normal maturin build for these
systems on PyPy builds.
"""

abi = sysconfig.get_config_var("SOABI").replace("-", "_")
major, minor = sys.version_info.major, sys.version_info.minor

regex = re.compile(r"(?P<name>pp3[py0-9_]+-pypy[3_p0-9]+)")

for file in pathlib.Path("./wheels").iterdir():
if file.name.endswith(".whl"):
new_name = regex.sub(f"pp{major}{minor}-{abi}", file.name)
new_name = new_name.replace("linux", "manylinux2010")
print(f"Renaming {file.name} -> {new_name}")
file.rename(file.parent.joinpath(new_name))

0 comments on commit e94b30f

Please sign in to comment.