Skip to content

Commit

Permalink
Automatically deploy linux wheels to pypi via TravisCI (#20)
Browse files Browse the repository at this point in the history
Add pypi deployment to TravisCI
  • Loading branch information
mdimura authored Sep 27, 2020
1 parent d0d3115 commit 5ab0c64
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 60 deletions.
86 changes: 49 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
sudo: false
language: cpp
dist: xenial
compiler:
- clang
- gcc
os:
- osx
- linux
env:
- PYTHON=2.7
- PYTHON=3.7
matrix:
exclude:
- os: linux
os: linux
dist: focal

jobs:
include:
- name: Ubuntu-python2-make
stage: make
services: docker
script: docker run --rm -v ${TRAVIS_BUILD_DIR}:/io:rw -w="/io" quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh 2
workspaces:
create:
name: wheels2
paths:
- wheelhouse
- name: Ubuntu-python3-make
stage: make
services: docker
script: docker run --rm -v ${TRAVIS_BUILD_DIR}:/io:rw -w="/io" quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh 3
workspaces:
create:
name: wheels3
paths:
- wheelhouse
- dist
- name: macOS-python2-make
stage: make
os: osx
env: PYTHON=2.7
compiler: clang
- os: osx
compiler: gcc
addons:
apt:
packages:
- csh
- python-numpy
- libboost-dev
- libeigen3-dev
- g++
- clang
homebrew:
packages:
- md5sha1sum
update: true
install: pyenv install -s 3.7-dev
script: ./make_osx.sh
- name: macOS-python3
stage: make
os: osx
env: PYTHON=3.7
compiler: clang
install: pyenv install -s 3.7-dev
script: ./make_osx.sh
- name: deploy pypi
stage: deploy
services: docker
workspaces:
use:
- wheels3
- wheels2
script: docker run --rm -e PYPI_USER -e PYPI_PASS -v ${TRAVIS_BUILD_DIR}:/io:rw -w="/io" quay.io/pypa/manylinux1_x86_64 /io/pypi-upload.sh

addons:
install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pyenv install -s 3.7-dev; fi
script:
- pyenv global `pyenv versions | grep "^ *$PYTHON" | head -n1`
- mkdir build && cd build
- cmake -DPYTHON_EXECUTABLE:FILEPATH=`pyenv which python$PYTHON` ..
- make
stages:
- make
- name: deploy
if: tag IS present
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.0.2)
project("LabelLib")

set(CMAKE_CXX_STANDARD 11)
if(MSVC)
Expand Down
38 changes: 15 additions & 23 deletions build-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,27 @@

#Usage:
#git clone --recursive https://github.com/Fluorescence-Tools/LabelLib.git
#docker run -e PYPI_USER=***** -e PYPI_PASS=***** --rm -v `pwd`/LabelLib:/io:rw quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh
#docker run --rm -v `pwd`/LabelLib:/io:rw -w="/io" quay.io/pypa/manylinux1_x86_64 /io/build-wheels.sh [2|3]

PYBIN=/opt/python/cp37-cp37m/bin
"${PYBIN}/pip" install cmake
set -e

VERSION_PREFIX=$1 # Could be `2` for python 2.*, `3` for python 3.x, `35` for python 3.5, etc; leave empy for all versions

DEFAULT_BIN=/opt/python/cp37-cp37m/bin
"${DEFAULT_BIN}/pip" install cmake
ln -s /opt/_internal/*/bin/cmake /usr/bin/cmake
"${PYBIN}/pip" install twine

#create the source package
git submodule update --init
${DEFAULT_BIN}/python3 setup.py sdist

# Compile wheels
for PYBIN in /opt/python/*/bin; do
for PYBIN in /opt/python/cp${VERSION_PREFIX}*/bin; do
"${PYBIN}/pip" install numpy
"${PYBIN}/pip" wheel /io/ -w wheelhouse/
"${PYBIN}/pip" wheel ./ -w wheelhouse_tmp/
done

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

if [ -n "$PYPI_USER" ]; then
cat << EOF > ~/.pypirc
[distutils]
index-servers =
pypi
[pypi]
repository: https://upload.pypi.org/legacy/
username: $PYPI_USER
password: $PYPI_PASS
EOF
( cd /io; git submodule update --init; ${PYBIN}/python3 setup.py sdist)
/opt/_internal/*/bin/twine upload /io/wheelhouse/* /io/dist/*.tar.gz
fi
7 changes: 7 additions & 0 deletions make_osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e

pyenv global `pyenv versions | grep "^ *$PYTHON" | head -n1`
mkdir build && cd build
cmake -DPYTHON_EXECUTABLE:FILEPATH=`pyenv which python$PYTHON` ..
make
29 changes: 29 additions & 0 deletions pypi-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# This script builds python/manylinux wheels

#Usage:
#git clone --recursive https://github.com/Fluorescence-Tools/LabelLib.git
#docker run -e PYPI_USER=***** -e PYPI_PASS=***** --rm -v `pwd`/LabelLib:/io:rw -w="/io" quay.io/pypa/manylinux1_x86_64 /io/pypi-upload.sh

set -e
DEFAULT_BIN=/opt/python/cp37-cp37m/bin

if [ -z "${PYPI_USER}" ] || [ -z "${PYPI_PASS}" ]; then
echo "ERROR PYPI credintials are not set!"
exit 1
fi

cat << EOF > ~/.pypirc
[distutils]
index-servers =
pypi
[pypi]
repository: https://upload.pypi.org/legacy/
username = $PYPI_USER
password = $PYPI_PASS
EOF

"${DEFAULT_BIN}/pip" install twine
"${DEFAULT_BIN}/twine" upload ./wheelhouse/LabelLib-*.whl ./dist/LabelLib-*.tar.gz

0 comments on commit 5ab0c64

Please sign in to comment.