Skip to content

Commit

Permalink
manylinux and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
qchateau committed Sep 26, 2019
1 parent 5143a25 commit ae7d6b3
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ build/
tmp/
dist/
__pycache__/
wheelhouse/
compile_commands.json

*.so
*.egg-info/
*.pyc

clinic/_cbitstruct.c.h
MANIFEST
96 changes: 73 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
language: python
python: "3.7"

python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8-dev"

before_install:
- pip install cpp-coveralls

script:
- COVERAGE=1 python setup.py build -f
- python setup.py test
- cp build/temp.*/* .
- rm -rf build

- python setup.py build -f
- python setup.py test
- python setup.py sdist
- python setup.py bdist_wheel

after_success:
- coveralls --exclude clinic --gcov-options '\-lp'

env:
global:
- PYPI_REPOSITORY_URL=https://upload.pypi.org/legacy/
- PYPI_USERNAME=__token__
- secure: "jfAnPdxjTDw/mFbM2rmqjHaBtGpA+Rr+goCB5/Jp6RZ5N2M60nJliw8B5v7RwZDy//nSIdbTBU7cF/7WjEPwzrHUn5LQsS13ThzoS6KE7NUPa77TOxEpHXr4MJsyeSQMindEbAMeYP+lffI8/ISQ85evIbbSn6XzZSN/YBpQCTUGHWViqKIlpT70GYfRTeEJ0YvXxcJHKXoMuG7N80n8DW88FlfuI2age29cAe80pNn2yCZww2ZH0kG62HGQhzVv4v/uvxLLTaDP/JndYQyBnw6y5gesT2XCrgmCPgCTyVrtJsR96LjOukG2/T5etgpK0sgRwfgRk2DjKmlUqQOUm57lO+52ECaqqbaERFYe/Ub4JZ4DD05lKqm6wtQMD+fYl+TLKzGvCWayuLvxs7HqI+cz0BQQ7iynXuPUqX3xpkUDdAUzg9remmEJ1n8WG/NMHsv3Embh6zHS9RW7OUBXTELjrgJHVwjm8N0KtY063kMDArlSLNcf1gUPOx8MTOXBQWcauxmLfXMyaWrjHQ++1dWRFWjNVkUWfv+l17/ZHJHHnaJ6VpzhrZ5uku4LfEH8hgOCL6EYbO1PVXuEvFXDQX6wIFdbXaXSkx78ZgfiJf3xDqxcU1jl7+ipoCe2xkXaRkka0wg1gwCsfF53suXGIEIMRBWqrGJI9vETu5mVQDY="


deploy:
provider: script
skip_cleanup: true
script: bash travis/deploy.sh
on:
tags: true
condition: $DEPLOY = 1


jobs:
include:
- stage: build
name: "Manylinux x86_64"
env: DOCKER_IMAGE=quay.io/pypa/manylinux2010_x86_64
PLAT=manylinux2010_x86_64
DEPLOY=1
services:
- docker
install:
- docker pull $DOCKER_IMAGE
script:
- docker run --rm -e PLAT=$PLAT -v `pwd`:/io $DOCKER_IMAGE $PRE_CMD /io/travis/build-wheels.sh
- ls wheelhouse/

- stage: build
name: "Manylinux i686"
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PLAT=manylinux1_i686
DEPLOY=1
install:
- docker pull $DOCKER_IMAGE
script:
- docker run --rm -e PLAT=$PLAT -v `pwd`:/io $DOCKER_IMAGE $PRE_CMD /io/travis/build-wheels.sh
- ls wheelhouse/

- stage: build
name: Coverage
env: COVERAGE=1
install:
- pip install cpp-coveralls bitstruct
script:
- python setup.py install
- nosetests cbitstruct
- coveralls --exclude clinic --gcov-options '\-lp'

- stage: build
name: Performance
install:
- pip install bitstruct
script:
- python setup.py install
- python cbitstruct/tests/test_perf.py

- stage: build
name: "Forward support"
python: "3.8-dev"
install:
- pip install bitstruct
script:
- python setup.py install
- nosetests cbitstruct
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.
50 changes: 23 additions & 27 deletions tests/test_perf.py → cbitstruct/tests/test_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import timeit
import unittest

setup = """
SETUP_SCRIPT = """
import string
import random
import cbitstruct
Expand Down Expand Up @@ -32,9 +32,9 @@


class PerfTest(unittest.TestCase):
def generic_test(self, name, bitstruct, cbitstruct):
bstime = timeit.timeit(bitstruct, setup=setup, number=NBS) / NBS
cbstime = timeit.timeit(cbitstruct, setup=setup, number=NCBS) / NCBS
def generic(self, name, bitstruct, cbitstruct):
bstime = timeit.timeit(bitstruct, setup=SETUP_SCRIPT, number=NBS) / NBS
cbstime = timeit.timeit(cbitstruct, setup=SETUP_SCRIPT, number=NCBS) / NCBS
improvement = bstime / cbstime

print(
Expand All @@ -43,115 +43,111 @@ def generic_test(self, name, bitstruct, cbitstruct):
)

def test_unpack(self):
self.generic_test(
self.generic(
"unpack", "bitstruct.unpack(fmt, data)", "cbitstruct.unpack(fmt, data)"
)

def test_unpack_from(self):
self.generic_test(
self.generic(
"unpack_from",
"bitstruct.unpack_from(fmt, data, 3)",
"cbitstruct.unpack_from(fmt, data, 3)",
)

def test_unpack_dict(self):
self.generic_test(
self.generic(
"unpack_dict",
"bitstruct.unpack_dict(fmt, names, data)",
"cbitstruct.unpack_dict(fmt, names, data)",
)

def test_unpack_from_dict(self):
self.generic_test(
self.generic(
"unpack_from_dict",
"bitstruct.unpack_from_dict(fmt, names, data, 3)",
"cbitstruct.unpack_from_dict(fmt, names, data, 3)",
)

def test_compiled_unpack(self):
self.generic_test("compiled unpack", "bs.unpack(data)", "cbs.unpack(data)")
self.generic("compiled unpack", "bs.unpack(data)", "cbs.unpack(data)")

def test_compiled_unpack_from(self):
self.generic_test(
self.generic(
"compiled unpack_from",
"bs.unpack_from(data, 3)",
"cbs.unpack_from(data, 3)",
)

def test_compiled_unpack_dict(self):
self.generic_test(
"compiled unpack_dict", "dbs.unpack(data)", "cdbs.unpack(data)"
)
self.generic("compiled unpack_dict", "dbs.unpack(data)", "cdbs.unpack(data)")

def test_compiled_unpack_from_dict(self):
self.generic_test(
self.generic(
"compiled unpack_from_dict",
"dbs.unpack_from(data, 3)",
"cdbs.unpack_from(data, 3)",
)

def test_pack(self):
self.generic_test(
self.generic(
"pack", "bitstruct.pack(fmt, *values)", "cbitstruct.pack(fmt, *values)"
)

def test_pack_into(self):
self.generic_test(
self.generic(
"pack_into",
"bitstruct.pack_into(fmt, dst, 3, *values)",
"cbitstruct.pack_into(fmt, dst, 3, *values)",
)

def test_pack_dict(self):
self.generic_test(
self.generic(
"pack_dict",
"bitstruct.pack_dict(fmt, names, values_dict)",
"cbitstruct.pack_dict(fmt, names, values_dict)",
)

def test_pack_into_dict(self):
self.generic_test(
self.generic(
"pack_into_dict",
"bitstruct.pack_into_dict(fmt, names, dst, 3, values_dict)",
"cbitstruct.pack_into_dict(fmt, names, dst, 3, values_dict)",
)

def test_compiled_pack(self):
self.generic_test("compiled pack", "bs.pack(*values)", "cbs.pack(*values)")
self.generic("compiled pack", "bs.pack(*values)", "cbs.pack(*values)")

def test_compiled_pack_into(self):
self.generic_test(
self.generic(
"compiled pack_into",
"bs.pack_into(dst, 3, *values)",
"cbs.pack_into(dst, 3, *values)",
)

def test_compiled_pack_dict(self):
self.generic_test(
self.generic(
"compiled pack_dict", "dbs.pack(values_dict)", "cdbs.pack(values_dict)"
)

def test_compiled_pack_into_dict(self):
self.generic_test(
self.generic(
"compiled pack_into_dict",
"dbs.pack_into(dst, 3, values_dict)",
"cdbs.pack_into(dst, 3, values_dict)",
)

def test_calcsize(self):
self.generic_test(
"calcsize", "bitstruct.calcsize(fmt)", "cbitstruct.calcsize(fmt)"
)
self.generic("calcsize", "bitstruct.calcsize(fmt)", "cbitstruct.calcsize(fmt)")

def test_byteswap_str(self):
self.generic_test(
self.generic(
"byteswap str",
"bitstruct.byteswap('123456789', data, 0)",
"cbitstruct.byteswap('123456789', data, 0)",
)

def test_byteswap_integer(self):
self.generic_test(
self.generic(
"byteswap list of int",
"bitstruct.byteswap([1,2,3,4,5,6,7,8,9], data, 0)",
"cbitstruct.byteswap([1,2,3,4,5,6,7,8,9], data, 0)",
Expand Down
7 changes: 0 additions & 7 deletions compile_commands.json

This file was deleted.

2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nose
bitstruct
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import os
from setuptools import setup, Extension
from distutils.core import setup, Extension


extra_compile_args = []
extra_compile_args = ["-std=c11"]
extra_link_args = []

if os.environ.get("COVERAGE"):
Expand All @@ -14,6 +14,7 @@
with open("README.md", "r") as fh:
long_description = fh.read()


setup(
name="cbitstruct",
version="0.0.1",
Expand Down Expand Up @@ -47,10 +48,8 @@
"_cbitstruct",
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
sources=["_cbitstruct.c"],
sources=["cbitstruct/_cbitstruct.c"],
)
],
py_modules=["cbitstruct"],
test_suite="tests",
tests_require=["bitstruct"],
packages=["cbitstruct", "cbitstruct.tests"],
)
22 changes: 22 additions & 0 deletions travis/build-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -e -x

# Show gcc version
gcc --version

# Compile wheels
for PYBIN in /opt/python/cp3*/bin; do
"${PYBIN}/pip" install -r /io/dev-requirements.txt
"${PYBIN}/pip" wheel /io/ -w wheelhouse/
done

# Bundle external shared libraries into the wheels
for whl in wheelhouse/*.whl; do
auditwheel repair "$whl" --plat $PLAT -w /io/wheelhouse/
done

# Install packages and test
for PYBIN in /opt/python/cp3*/bin/; do
"${PYBIN}/pip" install cbitstruct --no-index -f /io/wheelhouse
(cd "$HOME"; "${PYBIN}/nosetests" cbitstruct)
done
4 changes: 4 additions & 0 deletions travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pip install pip --upgrade
pip install twine

twine upload --repository-url "$PYPI_REPOSITORY_URL" -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" wheelhouse/*

0 comments on commit ae7d6b3

Please sign in to comment.