Skip to content

Commit 40d36e4

Browse files
c-martinezskvark
authored andcommitted
Build on Travis CI using manylinux (#2)
* Build on Travis CI using manylinux * Fix appveyor (maybe)
1 parent a4934f7 commit 40d36e4

File tree

6 files changed

+169
-98
lines changed

6 files changed

+169
-98
lines changed

.travis.yml

+68-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,68 @@
1-
sudo: required
2-
3-
language: python
4-
5-
python:
6-
- "2.7"
7-
- "3.5"
8-
9-
before_install:
10-
- git clone -q --branch=master https://github.com/Itseez/opencv.git opencv
11-
- python find_version.py > tmp
12-
- opencv_version=$(cat tmp)
13-
- rm tmp
14-
- echo $opencv_version
15-
16-
install:
17-
- sudo add-apt-repository ppa:kalakris/cmake -y
18-
- sudo apt-get update -qq
19-
- sudo apt-get install cmake
20-
- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then sudo apt-get install python2.7-dev; fi
21-
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then sudo add-apt-repository ppa:fkrull/deadsnakes -y && sudo apt-get update -qq; fi
22-
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then sudo apt-get install libpython3.5-dev; fi
23-
- python -m pip install --upgrade pip
24-
- pip install -r requirements.txt
25-
- cd opencv
26-
- mkdir build
27-
- whereis python
28-
- 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
29-
- 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
30-
- cd build
31-
- cmake --build . --config Release
32-
- cd ../..
33-
- if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then cp opencv/build/lib/*.so cv2; fi
34-
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then cp opencv/build/lib/python3/*.so cv2; fi
35-
- python setup.py bdist_wheel --opencv-version "$opencv_version-$TRAVIS_BUILD_NUMBER"
36-
37-
before_script:
38-
- pip install --no-index --find-links=dist/ opencv-python
39-
40-
script:
41-
- cd tests
42-
- python -m unittest test
1+
notifications:
2+
email: false
3+
4+
matrix:
5+
include:
6+
- sudo: required
7+
services:
8+
- docker
9+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
10+
PYTHON_VERSION=26
11+
- sudo: required
12+
services:
13+
- docker
14+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
15+
PYTHON_VERSION=27
16+
- sudo: required
17+
services:
18+
- docker
19+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
20+
PYTHON_VERSION=33
21+
- sudo: required
22+
services:
23+
- docker
24+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
25+
PYTHON_VERSION=34
26+
- sudo: required
27+
services:
28+
- docker
29+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_x86_64
30+
PYTHON_VERSION=35
31+
32+
- sudo: required
33+
services:
34+
- docker
35+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
36+
PRE_CMD=linux32
37+
PYTHON_VERSION=26
38+
- sudo: required
39+
services:
40+
- docker
41+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
42+
PRE_CMD=linux32
43+
PYTHON_VERSION=27
44+
- sudo: required
45+
services:
46+
- docker
47+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
48+
PRE_CMD=linux32
49+
PYTHON_VERSION=33
50+
- sudo: required
51+
services:
52+
- docker
53+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
54+
PRE_CMD=linux32
55+
PYTHON_VERSION=34
56+
- sudo: required
57+
services:
58+
- docker
59+
env: DOCKER_IMAGE=quay.io/pypa/manylinux1_i686
60+
PRE_CMD=linux32
61+
PYTHON_VERSION=35
62+
63+
install:
64+
- docker pull $DOCKER_IMAGE
65+
66+
script:
67+
- docker run --rm -v `pwd`:/io -e PYTHON_VERSION=$PYTHON_VERSION $DOCKER_IMAGE $PRE_CMD /io/travis/build-wheels.sh
68+
- ls wheelhouse/

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ At the same time it allows anyone to build a custom version of OpenCV for any Py
1313

1414
## Why?
1515

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

4343
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.
4444

45+
## Many linux wheels
46+
Linux wheels are built using [manylinux](https://github.com/pypa/python-manylinux-demo)
47+
4548
## Versioning
4649

4750
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).
@@ -50,4 +53,4 @@ Currently the ``find_version.py`` script searches for the version information fr
5053

5154
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.
5255

53-
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.
56+
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.

appveyor.yml

+36-44
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,73 @@
11
install:
22
- cmd: >-
33
4-
git clone -q --branch=master https://github.com/Itseez/opencv.git "%APPVEYOR_BUILD_FOLDER%\opencv
4+
git clone -q --branch=master https://github.com/c-martinez/opencv.git "%APPVEYOR_BUILD_FOLDER%\opencv
55
6-
C:\Python35\python.exe find_version.py > tmp
6+
C:\Python35\python.exe find_version.py
77
8-
set /p opencv_version= < tmp
9-
10-
del tmp
11-
12-
echo %opencv_version%
13-
14-
appveyor UpdateBuild -Version "%opencv_version%-%APPVEYOR_BUILD_NUMBER%"
15-
168
C:\Python27\python.exe -m pip install --upgrade pip
17-
9+
1810
C:\Python27\python.exe -m pip install -r requirements.txt
1911
2012
C:\Python35\python.exe -m pip install --upgrade pip
21-
13+
2214
C:\Python35\python.exe -m pip install -r requirements.txt
2315
2416
C:\Python27-x64\python.exe -m pip install --upgrade pip
25-
17+
2618
C:\Python27-x64\python.exe -m pip install -r requirements.txt
2719
2820
C:\Python35-x64\python.exe -m pip install --upgrade pip
29-
21+
3022
C:\Python35-x64\python.exe -m pip install -r requirements.txt
31-
23+
3224
build_script:
3325
- cmd: >-
3426
3527
if not exist "%APPVEYOR_BUILD_FOLDER%\opencv\build" mkdir "%APPVEYOR_BUILD_FOLDER%\opencv\build"
36-
28+
3729
if not exist "%APPVEYOR_BUILD_FOLDER%\opencv\build64" mkdir "%APPVEYOR_BUILD_FOLDER%\opencv\build64"
38-
30+
3931
cd opencv
40-
32+
4133
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
42-
34+
4335
cd build
44-
36+
4537
cmake --build . --config Release
46-
38+
4739
cd ..
4840
4941
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
50-
42+
5143
cd build64
52-
44+
5345
cmake --build . --config Release
54-
46+
5547
cd ..\..
5648
5749
xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build\lib\RELEASE\*.pyd" cv2
58-
59-
C:\Python27\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%
60-
50+
51+
C:\Python27\python.exe setup.py bdist_wheel
52+
6153
del cv2\*.pyd
6254
6355
xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build64\lib\RELEASE\*.pyd" cv2
64-
65-
C:\Python27-x64\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%
66-
56+
57+
C:\Python27-x64\python.exe setup.py bdist_wheel
58+
6759
del cv2\*.pyd
6860
6961
xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build\lib\python3\Release\*.pyd" cv2
70-
71-
C:\Python35\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%
72-
62+
63+
C:\Python35\python.exe setup.py bdist_wheel
64+
7365
del cv2\*.pyd
7466
7567
xcopy "%APPVEYOR_BUILD_FOLDER%\opencv\build64\lib\python3\Release\*.pyd" cv2
76-
77-
C:\Python35-x64\python.exe setup.py bdist_wheel --opencv-version %APPVEYOR_BUILD_VERSION%
78-
68+
69+
C:\Python35-x64\python.exe setup.py bdist_wheel
70+
7971
del cv2\*.pyd
8072
8173
before_test:
@@ -84,24 +76,24 @@ before_test:
8476
cd ..
8577
8678
C:\Python27\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python
87-
79+
8880
C:\Python27-x64\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python
89-
81+
9082
C:\Python35\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python
91-
83+
9284
C:\Python35-x64\python.exe -m pip install --no-index --find-links=%APPVEYOR_BUILD_FOLDER%\dist\ opencv-python
93-
85+
9486
test_script:
9587
- cmd: >-
96-
88+
9789
cd %APPVEYOR_BUILD_FOLDER%\tests
9890
9991
C:\Python27\python.exe -m unittest test
100-
92+
10193
C:\Python27-x64\python.exe -m unittest test
102-
94+
10395
C:\Python35\python.exe -m unittest test
104-
96+
10597
C:\Python35-x64\python.exe -m unittest test
10698
10799
artifacts:

find_version.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@
2020
opencv_version += words[2]
2121
break
2222

23-
sys.stdout.write(opencv_version)
23+
with open('cv_version.py', 'w') as f:
24+
f.write('opencv_version = "%s"'%opencv_version)

setup.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
import os
55
import sys
66

7-
opencv_version = ""
8-
9-
if "--opencv-version" in sys.argv:
10-
index = sys.argv.index('--opencv-version')
11-
sys.argv.pop(index)
12-
opencv_version = sys.argv.pop(index)
13-
else:
14-
print("Error: no version info (--opencv-version missing), exiting.")
15-
exit(1)
7+
# cv_version.py should be generated by running find_version.py
8+
from cv_version import opencv_version
169

1710
numpy_version = ""
1811

@@ -26,6 +19,9 @@ class BinaryDistribution(Distribution):
2619
def has_ext_modules(asd):
2720
return True
2821

22+
def is_pure(self):
23+
return False
24+
2925
package_data = {}
3026

3127
if os.name == 'posix':
@@ -39,5 +35,6 @@ def has_ext_modules(asd):
3935
distclass=BinaryDistribution,
4036
packages=['cv2'],
4137
package_data=package_data,
38+
include_package_data=True,
4239
install_requires="numpy==%s" % numpy_version,
4340
)

travis/build-wheels.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
/opt/_internal/cpython-3.5.1/bin/pip3.5 install --upgrade git+git://github.com/pypa/auditwheel
4+
5+
cd /io
6+
git clone -q --branch=python-wheel https://github.com/c-martinez/opencv.git opencv
7+
8+
for PYBIN in /opt/python/cp$PYTHON_VERSION*/bin; do
9+
$PYBIN/python find_version.py
10+
$PYBIN/pip install -r requirements.txt
11+
12+
# Begin build
13+
cd opencv
14+
mkdir build
15+
if [[ $PYTHON_VERSION == 2* ]]; then
16+
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;
17+
fi
18+
19+
if [[ $PYTHON_VERSION == 3* ]]; then
20+
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;
21+
fi
22+
23+
# DO BUILD
24+
cd build
25+
cmake28 --build . --config Release
26+
cd ../..
27+
28+
if [[ $PYTHON_VERSION == 2* ]]; then
29+
cp opencv/build/lib/cv2.so cv2/
30+
fi
31+
32+
if [[ $PYTHON_VERSION == 3* ]]; then
33+
cp opencv/build/lib/python3/*.so cv2/
34+
fi
35+
rm -fr opencv/build
36+
37+
# Build wheel
38+
$PYBIN/pip wheel . -w tmpwheels/
39+
done
40+
41+
# Bundle external shared libraries into the wheels
42+
for whl in tmpwheels/opencv*.whl; do
43+
auditwheel repair $whl -w /io/wheelhouse/
44+
done
45+
rm -fr tmpwheels/
46+
47+
cd tests
48+
# Install packages and test
49+
for PYBIN in /opt/python/cp$PYTHON_VERSION*/bin/; do
50+
$PYBIN/pip install opencv-python --no-index -f /io/wheelhouse
51+
$PYBIN/python -m unittest test
52+
done

0 commit comments

Comments
 (0)