Skip to content

Commit 2bbcd61

Browse files
authored
Merge pull request #103 from Czaki/wheel_build
Build wheel using cibuildwheel
2 parents a374380 + 3c446f5 commit 2bbcd61

15 files changed

Lines changed: 145 additions & 112 deletions

.github/workflows/sdist.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

.github/workflows/wheel.yml

Lines changed: 104 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,135 @@
1-
name: Wheel
1+
name: PyPi wheel and sdist
22

3-
on: [push]
3+
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
sdist:
77
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
include:
11-
- python-version: 2.7
12-
pep-425-tag: cp27-cp27mu
13-
# we build for "wide-unicode" CPython 2.7, which is prevalent among
14-
# most Linux distributions. See https://github.com/pypa/manylinux
15-
16-
- python-version: 3.5
17-
pep-425-tag: cp35-cp35m
18-
19-
- python-version: 3.6
20-
pep-425-tag: cp36-cp36m
21-
22-
- python-version: 3.7
23-
pep-425-tag: cp37-cp37m
24-
25-
- python-version: 3.8
26-
pep-425-tag: cp38-cp38
27-
28-
- python-version: 3.9
29-
pep-425-tag: cp39-cp39
308

31-
name: Python ${{ matrix.python-version }}
9+
name: Python 3.9
3210

3311
steps:
3412
- uses: actions/checkout@v2
3513

3614
- name: Setup Python
3715
uses: actions/setup-python@v2
3816
with:
39-
python-version: ${{ matrix.python-version }}
17+
python-version: 3.9
4018
architecture: x64
4119

4220
- name: Install test dependencies
43-
run: pip install pytest twine
21+
run: pip install wheel flake8 pytest
4422

45-
# Flake8 is already run in Source Distribution (sdist) workflow, so we don't run it here.
23+
- name: Flake8
24+
# stop the build if there are Python syntax errors or undefined names
25+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
26+
run: |
27+
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
28+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4629
47-
- name: Build python-snappy manylinux wheels
48-
uses: RalfG/python-wheels-manylinux-build@v0.3.3-manylinux2010_x86_64
49-
with:
50-
python-versions: ${{ matrix.pep-425-tag }}
51-
system-packages: "snappy-devel"
30+
- name: Install libsnappy-dev
31+
run: sudo apt-get install libsnappy-dev
5232

53-
- name: Install python-snappy wheel
54-
# manylinux1 offers broader compatibility than manylinux2010 or manylinux2014
55-
run: |
56-
pip install dist/python_snappy*-manylinux1*.whl
33+
- name: Generate source distribution
34+
run: python setup.py sdist
5735

58-
- name: Clean up sources
59-
# this cleans up the sources to make sure `import snappy` uses the wheel
60-
# an alternative would be to run pytest in a different working directory
61-
run: rm -rf setup.py ./snappy
36+
- name: Install python-snappy sdist
37+
run: pip install dist/python-snappy*.tar.gz
6238

6339
- name: Pytest
6440
run: pytest --verbose test_snappy.py
6541

66-
- name: Archive wheels
67-
if: startsWith(github.ref, 'refs/tags/0.')
42+
- name: Archive sdist
6843
uses: actions/upload-artifact@v2
6944
with:
70-
name: python_snappy-${{ matrix.pep-425-tag }}-manylinux
71-
path: dist/python_snappy*-manylinux1*.whl
45+
name: wheels
46+
path: dist/python-snappy*.tar.gz
47+
48+
build:
49+
runs-on: ${{ matrix.os }}
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
os: [ubuntu-20.04, macos-10.15, windows-2019]
54+
architecture: ['x64']
55+
linux_archs: ["auto s390x"]
56+
include:
57+
- os: windows-2019
58+
architecture: 'x86'
59+
skip: "*2*win* *win_amd64"
60+
environment_windows: INCLUDE="C:/Program Files (x86)/Snappy/include" LIB="C:/Program Files (x86)/Snappy/lib"
61+
- os: windows-2019
62+
architecture: 'x64'
63+
skip: "*2*win* *win32"
64+
environment_windows: INCLUDE="C:/Program Files/Snappy/include" LIB="C:/Program Files/Snappy/lib"
65+
- os: ubuntu-20.04
66+
architecture: 'x64'
67+
linux_archs: aarch64 ppc64le
68+
69+
name: Python ${{ matrix.os }}
70+
env:
71+
CIBW_TEST_REQUIRES: pytest
72+
CIBW_TEST_COMMAND: "python -m pytest --verbose {project}/test_snappy.py"
73+
CIBW_BEFORE_ALL_LINUX: yum install -y snappy-devel
74+
MACOSX_DEPLOYMENT_TARGET: "10.9"
75+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}"
76+
CIBW_BEFORE_ALL: "bash {project}/build_snappy.sh"
77+
CIBW_SKIP: ${{ matrix.skip }}
78+
CIBW_ENVIRONMENT_WINDOWS: ${{ matrix.environment_windows }}
79+
CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }}
80+
CIBW_ARCHS_MACOS: x86_64 universal2
81+
CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64"
82+
steps:
83+
- uses: actions/checkout@v2
84+
85+
- name: Setup Python
86+
uses: actions/setup-python@v2
87+
with:
88+
python-version: "3.8"
89+
architecture: ${{ matrix.architecture }}
90+
91+
# - name: Install Visual C++ for Python 2.7
92+
# if: runner.os == 'Windows'
93+
# run: |
94+
# choco install vcpython27 -f -y
7295

96+
97+
- name: Set up QEMU
98+
if: runner.os == 'Linux'
99+
uses: docker/setup-qemu-action@v1
100+
with:
101+
platforms: all
102+
103+
- name: Add msbuild to PATH
104+
if: runner.os == 'Windows'
105+
uses: microsoft/setup-msbuild@v1.0.2
106+
107+
- name: delvewheel install
108+
if: runner.os == 'Windows'
109+
run: |
110+
python -m pip install delvewheel==0.0.9
111+
112+
- name: Build wheels
113+
uses: joerick/cibuildwheel@v1.9.0
114+
115+
- uses: actions/upload-artifact@v2
116+
with:
117+
path: ./wheelhouse/*.whl
118+
name: wheels
119+
120+
upload:
121+
runs-on: ubuntu-latest
122+
name: upload wheels
123+
needs: ['sdist', 'build']
124+
if: startsWith(github.ref, 'refs/tags/0.')
125+
steps:
126+
- name: Download test data
127+
uses: actions/download-artifact@v1
128+
with:
129+
name: wheels
73130
- name: Publish wheels to PyPI
74-
if: startsWith(github.ref, 'refs/tags/0.')
75131
env:
76132
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
77133
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
78134
run: |
79-
twine upload dist/python_snappy*-manylinux1*.whl
135+
twine upload dist/*.whl

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include *.py AUTHORS README.rst snappy/*.h MANIFEST.in LICENSE
1+
include *.py AUTHORS README.rst src/snappy/*.h MANIFEST.in LICENSE

build_snappy.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
git clone --depth 1 --branch 1.1.8 https://github.com/google/snappy snappy-src
2+
cd snappy-src
3+
git submodule update --init
4+
5+
6+
case "$(uname -s)" in
7+
CYGWIN*|MINGW32*|MSYS*|MINGW*)
8+
cmake -G "Visual Studio 16 2019" -A Win32 -S . -B "build32"
9+
cmake -G "Visual Studio 16 2019" -A x64 -S . -B "build64"
10+
cmake --build build32 --config Release --target install
11+
cmake --build build64 --config Release --target install
12+
;;
13+
14+
# Add here more strings to compare
15+
# See correspondence table at the bottom of this answer
16+
17+
*)
18+
cmake -S . -B "build" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
19+
cmake --build build --config Release --target install
20+
;;
21+
esac
22+
23+
24+
25+

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,26 @@
2929
except ImportError:
3030
from distutils.core import setup, Extension
3131

32+
import os
33+
3234
version = '0.6.0'
3335
long_description = """
3436
Python bindings for the snappy compression library from Google.
3537
3638
More details about Snappy library: http://google.github.io/snappy
3739
"""
3840

41+
library_dirs, include_dirs = [], []
42+
if os.environ.get("CIBUILDWHEEL", False) and sys.version_info[:2] == (3, 9) and sys.platform =="darwin":
43+
library_dirs = ["/usr/local/lib/"]
44+
include_dirs = ["/usr/local/include/"]
45+
3946

4047
snappymodule = Extension('snappy._snappy',
4148
libraries=['snappy'],
42-
sources=['snappy/snappymodule.cc', 'snappy/crc32c.c'])
49+
sources=['src/snappy/snappymodule.cc', 'src/snappy/crc32c.c'],
50+
library_dirs=library_dirs,
51+
include_dirs=include_dirs)
4352

4453
ext_modules = [snappymodule]
4554
packages = ['snappy']
@@ -52,7 +61,7 @@
5261
ext_modules = []
5362
install_requires = ['cffi>=1.0.0']
5463
setup_requires = ['cffi>=1.0.0']
55-
cffi_modules = ['./snappy/snappy_cffi_builder.py:ffi']
64+
cffi_modules = ['./src/snappy/snappy_cffi_builder.py:ffi']
5665

5766
setup(
5867
name='python-snappy',
@@ -80,10 +89,13 @@
8089
'Programming Language :: Python :: 3.5',
8190
'Programming Language :: Python :: 3.6',
8291
'Programming Language :: Python :: 3.7',
92+
'Programming Language :: Python :: 3.8',
93+
'Programming Language :: Python :: 3.9,'
8394
],
8495
ext_modules=ext_modules,
8596
packages=packages,
8697
install_requires=install_requires,
8798
setup_requires=setup_requires,
88-
cffi_modules=cffi_modules
99+
cffi_modules=cffi_modules,
100+
package_dir={'': 'src'},
89101
)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)