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

Build wheel using cibuildwheel #103

Merged
merged 7 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions .github/workflows/sdist.yml

This file was deleted.

152 changes: 104 additions & 48 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,135 @@
name: Wheel
name: PyPi wheel and sdist

on: [push]
on: [push, pull_request]

jobs:
build:
sdist:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python-version: 2.7
pep-425-tag: cp27-cp27mu
# we build for "wide-unicode" CPython 2.7, which is prevalent among
# most Linux distributions. See https://github.com/pypa/manylinux

- python-version: 3.5
pep-425-tag: cp35-cp35m

- python-version: 3.6
pep-425-tag: cp36-cp36m

- python-version: 3.7
pep-425-tag: cp37-cp37m

- python-version: 3.8
pep-425-tag: cp38-cp38

- python-version: 3.9
pep-425-tag: cp39-cp39

name: Python ${{ matrix.python-version }}
name: Python 3.9

steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
python-version: 3.9
architecture: x64

- name: Install test dependencies
run: pip install pytest twine
run: pip install wheel flake8 pytest

# Flake8 is already run in Source Distribution (sdist) workflow, so we don't run it here.
- name: Flake8
# stop the build if there are Python syntax errors or undefined names
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
run: |
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Build python-snappy manylinux wheels
uses: RalfG/python-wheels-manylinux-build@v0.3.3-manylinux2010_x86_64
with:
python-versions: ${{ matrix.pep-425-tag }}
system-packages: "snappy-devel"
- name: Install libsnappy-dev
run: sudo apt-get install libsnappy-dev

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

- name: Clean up sources
# this cleans up the sources to make sure `import snappy` uses the wheel
# an alternative would be to run pytest in a different working directory
run: rm -rf setup.py ./snappy
Comment on lines -58 to -61
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the reason of move to src.

- name: Install python-snappy sdist
run: pip install dist/python-snappy*.tar.gz

- name: Pytest
run: pytest --verbose test_snappy.py

- name: Archive wheels
if: startsWith(github.ref, 'refs/tags/0.')
- name: Archive sdist
uses: actions/upload-artifact@v2
with:
name: python_snappy-${{ matrix.pep-425-tag }}-manylinux
path: dist/python_snappy*-manylinux1*.whl
name: wheels
path: dist/python-snappy*.tar.gz

build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-10.15, windows-2019]
architecture: ['x64']
linux_archs: ["auto s390x"]
include:
- os: windows-2019
architecture: 'x86'
skip: "*2*win* *win_amd64"
environment_windows: INCLUDE="C:/Program Files (x86)/Snappy/include" LIB="C:/Program Files (x86)/Snappy/lib"
- os: windows-2019
architecture: 'x64'
skip: "*2*win* *win32"
environment_windows: INCLUDE="C:/Program Files/Snappy/include" LIB="C:/Program Files/Snappy/lib"
- os: ubuntu-20.04
architecture: 'x64'
linux_archs: aarch64 ppc64le

name: Python ${{ matrix.os }}
env:
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: "python -m pytest --verbose {project}/test_snappy.py"
CIBW_BEFORE_ALL_LINUX: yum install -y snappy-devel
MACOSX_DEPLOYMENT_TARGET: "10.9"
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}"
CIBW_BEFORE_ALL: "bash {project}/build_snappy.sh"
CIBW_SKIP: ${{ matrix.skip }}
CIBW_ENVIRONMENT_WINDOWS: ${{ matrix.environment_windows }}
CIBW_ARCHS_LINUX: ${{ matrix.linux_archs }}
CIBW_ARCHS_MACOS: x86_64 universal2
CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64"
steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
architecture: ${{ matrix.architecture }}

# - name: Install Visual C++ for Python 2.7
# if: runner.os == 'Windows'
# run: |
# choco install vcpython27 -f -y


- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Add msbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/setup-msbuild@v1.0.2

- name: delvewheel install
if: runner.os == 'Windows'
run: |
python -m pip install delvewheel==0.0.9

- name: Build wheels
uses: joerick/cibuildwheel@v1.9.0

- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
name: wheels

upload:
runs-on: ubuntu-latest
name: upload wheels
needs: ['sdist', 'build']
if: startsWith(github.ref, 'refs/tags/0.')
Copy link
Contributor Author

@Czaki Czaki Feb 4, 2021

Choose a reason for hiding this comment

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

here is the upload trigger

steps:
- name: Download test data
uses: actions/download-artifact@v1
with:
name: wheels
- name: Publish wheels to PyPI
if: startsWith(github.ref, 'refs/tags/0.')
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/python_snappy*-manylinux1*.whl
twine upload dist/*.whl
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include *.py AUTHORS README.rst snappy/*.h MANIFEST.in LICENSE
include *.py AUTHORS README.rst src/snappy/*.h MANIFEST.in LICENSE
25 changes: 25 additions & 0 deletions build_snappy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
git clone --depth 1 --branch 1.1.8 https://github.com/google/snappy snappy-src
cd snappy-src
git submodule update --init


case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*|MINGW*)
cmake -G "Visual Studio 16 2019" -A Win32 -S . -B "build32"
cmake -G "Visual Studio 16 2019" -A x64 -S . -B "build64"
cmake --build build32 --config Release --target install
cmake --build build64 --config Release --target install
;;

# Add here more strings to compare
# See correspondence table at the bottom of this answer

*)
cmake -S . -B "build" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build build --config Release --target install
;;
esac




18 changes: 15 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,26 @@
except ImportError:
from distutils.core import setup, Extension

import os

version = '0.6.0'
long_description = """
Python bindings for the snappy compression library from Google.

More details about Snappy library: http://google.github.io/snappy
"""

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


snappymodule = Extension('snappy._snappy',
libraries=['snappy'],
sources=['snappy/snappymodule.cc', 'snappy/crc32c.c'])
sources=['src/snappy/snappymodule.cc', 'src/snappy/crc32c.c'],
library_dirs=library_dirs,
include_dirs=include_dirs)

ext_modules = [snappymodule]
packages = ['snappy']
Expand All @@ -52,7 +61,7 @@
ext_modules = []
install_requires = ['cffi>=1.0.0']
setup_requires = ['cffi>=1.0.0']
cffi_modules = ['./snappy/snappy_cffi_builder.py:ffi']
cffi_modules = ['./src/snappy/snappy_cffi_builder.py:ffi']

setup(
name='python-snappy',
Expand Down Expand Up @@ -80,10 +89,13 @@
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9,'
],
ext_modules=ext_modules,
packages=packages,
install_requires=install_requires,
setup_requires=setup_requires,
cffi_modules=cffi_modules
cffi_modules=cffi_modules,
package_dir={'': 'src'},
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.