Skip to content

Build on Travis CI using manylinux #2

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

Merged
merged 2 commits into from
Jul 4, 2016
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
110 changes: 68 additions & 42 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,68 @@
sudo: required

language: python

python:
- "2.7"
- "3.5"

before_install:
- git clone -q --branch=master https://github.com/Itseez/opencv.git opencv
- python find_version.py > tmp
- opencv_version=$(cat tmp)
- rm tmp
- echo $opencv_version

install:
- sudo add-apt-repository ppa:kalakris/cmake -y
- sudo apt-get update -qq
- sudo apt-get install cmake
- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then sudo apt-get install python2.7-dev; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then sudo add-apt-repository ppa:fkrull/deadsnakes -y && sudo apt-get update -qq; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then sudo apt-get install libpython3.5-dev; fi
- python -m pip install --upgrade pip
- pip install -r requirements.txt
- cd opencv
- mkdir build
- whereis python
- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then cmake -H"." -B"build" -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python3=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON_EXECUTABLE=$(which python) -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -Wno-dev; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then cmake -H"." -B"build" -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE=$(which python) -DPYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -DPYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -Wno-dev; fi
- cd build
- cmake --build . --config Release
- cd ../..
- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then cp opencv/build/lib/*.so cv2; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then cp opencv/build/lib/python3/*.so cv2; fi
- python setup.py bdist_wheel --opencv-version "$opencv_version-$TRAVIS_BUILD_NUMBER"

before_script:
- pip install --no-index --find-links=dist/ opencv-python

script:
- cd tests
- python -m unittest test
notifications:
email: false

matrix:
include:
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
PYTHON_VERSION=26
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
PYTHON_VERSION=27
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
PYTHON_VERSION=33
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
PYTHON_VERSION=34
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
PYTHON_VERSION=35

- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PYTHON_VERSION=26
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PYTHON_VERSION=27
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PYTHON_VERSION=33
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PYTHON_VERSION=34
- sudo: required
services:
- docker
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
PRE_CMD=linux32
PYTHON_VERSION=35

install:
- docker pull $DOCKER_IMAGE

script:
- docker run --rm -v `pwd`:/io -e PYTHON_VERSION=$PYTHON_VERSION $DOCKER_IMAGE $PRE_CMD /io/travis/build-wheels.sh
- ls wheelhouse/
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ At the same time it allows anyone to build a custom version of OpenCV for any Py

## Why?

1. Installation of OpenCV for Python is pretty hideous:
1. Installation of OpenCV for Python is pretty hideous:
1. Download OpenCV
2. Find cv2.pyd from the package
- If it exists, copy it to the root of Python site-packages
Expand Down Expand Up @@ -42,6 +42,9 @@ Currently the ``setup.py`` file parses OpenCV version information from the OpenC

As described earlier, the ``.pyd`` file is normally copied to site-packages. I don't want to pollute the root folder, so the ``__init__.py`` file in cv2 folder handles the import logic correctly by importing the actual ``.pyd`` module and replacing the imported cv2 package in ``sys.modudes`` with the ``.pyd`` module.

## Many linux wheels
Linux wheels are built using [manylinux](https://github.com/pypa/python-manylinux-demo)

## Versioning

Currently the ``find_version.py`` script searches for the version information from OpenCV sources. The CI build number is then added after the actual OpenCV version to differentiate packages (this repo might have modifications but OpenCV version stays same).
Expand All @@ -50,4 +53,4 @@ Currently the ``find_version.py`` script searches for the version information fr

As Python's 2.x releases are slowly approaching legacy state, 2.7.x releases will be the only supported Python 2 versions. On Python 3 side, builds will be run only for the latest release which is at the moment 3.5.1.

There's also a build time limitation (AppVeyor open source builds may take max. 1 hour) which restricts the supported Python versions to two. However, if you wan't to get some other versions, just fork this repo and change the dependencies.
There's also a build time limitation (AppVeyor open source builds may take max. 1 hour) which restricts the supported Python versions to two. However, if you wan't to get some other versions, just fork this repo and change the dependencies.
80 changes: 36 additions & 44 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,73 @@
install:
- cmd: >-

git clone -q --branch=master https://github.com/Itseez/opencv.git "%APPVEYOR_BUILD_FOLDER%\opencv
git clone -q --branch=master https://github.com/c-martinez/opencv.git "%APPVEYOR_BUILD_FOLDER%\opencv

C:\Python35\python.exe find_version.py > tmp
C:\Python35\python.exe find_version.py

set /p opencv_version= < tmp

del tmp

echo %opencv_version%

appveyor UpdateBuild -Version "%opencv_version%-%APPVEYOR_BUILD_NUMBER%"

C:\Python27\python.exe -m pip install --upgrade pip

C:\Python27\python.exe -m pip install -r requirements.txt

C:\Python35\python.exe -m pip install --upgrade pip

C:\Python35\python.exe -m pip install -r requirements.txt

C:\Python27-x64\python.exe -m pip install --upgrade pip

C:\Python27-x64\python.exe -m pip install -r requirements.txt

C:\Python35-x64\python.exe -m pip install --upgrade pip

C:\Python35-x64\python.exe -m pip install -r requirements.txt

build_script:
- cmd: >-

if not exist "%APPVEYOR_BUILD_FOLDER%\opencv\build" mkdir "%APPVEYOR_BUILD_FOLDER%\opencv\build"

if not exist "%APPVEYOR_BUILD_FOLDER%\opencv\build64" mkdir "%APPVEYOR_BUILD_FOLDER%\opencv\build64"

cd opencv

cmake -G "Visual Studio 14" -H"." -B"build" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE=C:/Python35/python.exe -DPYTHON3_LIBRARY=C:/Python35/libs/python35.lib -DPYTHON3_INCLUDE_DIR=C:/Python35/include -Wno-dev

cd build

cmake --build . --config Release

cd ..

cmake -G "Visual Studio 14 Win64" -H"." -B"build64" -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE=C:/Python35-x64/python.exe -DPYTHON3_LIBRARY=C:/Python35-x64/libs/python35.lib -DPYTHON3_INCLUDE_DIR=C:/Python35-x64/include -Wno-dev

cd build64

cmake --build . --config Release

cd ..\..

xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build\lib\RELEASE\*.pyd" cv2
C:\Python27\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%

C:\Python27\python.exe setup.py bdist_wheel

del cv2\*.pyd

xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build64\lib\RELEASE\*.pyd" cv2
C:\Python27-x64\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%

C:\Python27-x64\python.exe setup.py bdist_wheel

del cv2\*.pyd

xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build\lib\python3\Release\*.pyd" cv2
C:\Python35\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%

C:\Python35\python.exe setup.py bdist_wheel

del cv2\*.pyd

xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build64\lib\python3\Release\*.pyd" cv2
C:\Python35-x64\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%

C:\Python35-x64\python.exe setup.py bdist_wheel

del cv2\*.pyd

before_test:
Expand All @@ -84,24 +76,24 @@ before_test:
cd ..

C:\Python27\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python

C:\Python27-x64\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python

C:\Python35\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python

C:\Python35-x64\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python

test_script:
- cmd: >-

cd %APPVEYOR_BUILD_FOLDER%\tests

C:\Python27\python.exe -m unittest test

C:\Python27-x64\python.exe -m unittest test

C:\Python35\python.exe -m unittest test

C:\Python35-x64\python.exe -m unittest test

artifacts:
Expand Down
3 changes: 2 additions & 1 deletion find_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
opencv_version += words[2]
break

sys.stdout.write(opencv_version)
with open('cv_version.py', 'w') as f:
f.write('opencv_version = "%s"'%opencv_version)
15 changes: 6 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
import os
import sys

opencv_version = ""

if "--opencv-version" in sys.argv:
index = sys.argv.index('--opencv-version')
sys.argv.pop(index)
opencv_version = sys.argv.pop(index)
else:
print("Error: no version info (--opencv-version missing), exiting.")
exit(1)
# cv_version.py should be generated by running find_version.py
from cv_version import opencv_version

numpy_version = ""

Expand All @@ -26,6 +19,9 @@ class BinaryDistribution(Distribution):
def has_ext_modules(asd):
return True

def is_pure(self):
return False

package_data = {}

if os.name == 'posix':
Expand All @@ -39,5 +35,6 @@ def has_ext_modules(asd):
distclass=BinaryDistribution,
packages=['cv2'],
package_data=package_data,
include_package_data=True,
install_requires="numpy==%s" % numpy_version,
)
52 changes: 52 additions & 0 deletions travis/build-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

/opt/_internal/cpython-3.5.1/bin/pip3.5 install --upgrade git+git://github.com/pypa/auditwheel

cd /io
git clone -q --branch=python-wheel https://github.com/c-martinez/opencv.git opencv

for PYBIN in /opt/python/cp$PYTHON_VERSION*/bin; do
$PYBIN/python find_version.py
$PYBIN/pip install -r requirements.txt

# Begin build
cd opencv
mkdir build
if [[ $PYTHON_VERSION == 2* ]]; then
cmake28 -H"." -B"build" -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python3=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON_EXECUTABLE=$PYBIN/python -DPYTHON_INCLUDE_DIR=$($PYBIN/python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$($PYBIN/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -Wno-dev;
fi

if [[ $PYTHON_VERSION == 3* ]]; then
cmake28 -H"." -B"build" -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python2=OFF -DBUILD_opencv_java=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DPYTHON3_EXECUTABLE=$PYBIN/python -DPYTHON_INCLUDE_DIR=$($PYBIN/python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_PACKAGES_PATH=$($PYBIN/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") -Wno-dev;
fi

# DO BUILD
cd build
cmake28 --build . --config Release
cd ../..

if [[ $PYTHON_VERSION == 2* ]]; then
cp opencv/build/lib/cv2.so cv2/
fi

if [[ $PYTHON_VERSION == 3* ]]; then
cp opencv/build/lib/python3/*.so cv2/
fi
rm -fr opencv/build

# Build wheel
$PYBIN/pip wheel . -w tmpwheels/
done

# Bundle external shared libraries into the wheels
for whl in tmpwheels/opencv*.whl; do
auditwheel repair $whl -w /io/wheelhouse/
done
rm -fr tmpwheels/

cd tests
# Install packages and test
for PYBIN in /opt/python/cp$PYTHON_VERSION*/bin/; do
$PYBIN/pip install opencv-python --no-index -f /io/wheelhouse
$PYBIN/python -m unittest test
done