提交 fbbd6096 编写于 作者: O Olli-Pekka Heinisuo

fix conflicts

......@@ -13,3 +13,30 @@ Write here what went wrong.
- architecture (e.g. x86)
- opencv-python version
##### Issue submission checklist
- [ ] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
<!--
Use Q&A forums such as https://answers.opencv.org/questions/ and https://stackoverflow.com/ and other communities
to discuss problems. Tickets without real issue statements related to this build toolchain will be closed.
-->
- [ ] I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
<!--
If you have some OpenCV bug report which needs to fixed in the C++ code,
please report issue to the OpenCV repository:
https://github.com/opencv/opencv/issues
See also:
* OpenCV documentation: https://docs.opencv.org
* OpenCV FAQ page: https://github.com/opencv/opencv/wiki/FAQ
* OpenCV forum: https://answers.opencv.org
* Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
-->
- [ ] The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
- [ ] I'm using the latest version of ``opencv-python``
......@@ -4,10 +4,10 @@ env:
# pip dependencies to _test_ your project
- TEST_DEPENDS="numpy==1.11.1"
# params to bdist_wheel. used to set osx build target.
- BDIST_PARAMS=""
- CONFIG_PATH="travis_config.sh"
- USE_CCACHE=1
- UNICODE_WIDTH=32
- SDIST=0
# Save some time, we and setup check them out on demand instead
# https://docs.travis-ci.com/user/customizing-the-build/#Git-Clone-Depth
......@@ -28,6 +28,7 @@ stages:
jobs:
fast_finish: true
# Travis exclude is buggy, this seems to be the only way to disable default build
exclude:
- language: ruby
include:
......@@ -57,6 +58,48 @@ jobs:
# used in OSX custom build script dealing with local bottle caching
- $HOME/local_bottle_metadata
# source distributions
- os: linux
stage: s1
script: skip
env:
- SDIST=1
- ENABLE_CONTRIB=0
- ENABLE_HEADLESS=0
python: "3.8"
language: python
dist: xenial
- os: linux
stage: s1
script: skip
env:
- SDIST=1
- ENABLE_CONTRIB=0
- ENABLE_HEADLESS=1
python: "3.8"
language: python
dist: xenial
- os: linux
stage: s1
script: skip
env:
- SDIST=1
- ENABLE_CONTRIB=1
- ENABLE_HEADLESS=0
python: "3.8"
language: python
dist: xenial
- os: linux
stage: s1
script: skip
env:
- SDIST=1
- ENABLE_CONTRIB=1
- ENABLE_HEADLESS=1
python: "3.8"
language: python
dist: xenial
# default builds for MacOS
#further jobs in the list will use the same stage until the next assignment
- stage: final
......@@ -606,25 +649,28 @@ jobs:
# The first line is printed in the folding header in Travis output
before_install: |
# Check out and prepare the source
set -e
# Multibuild doesn't have releases, so --depth would break eventually (see
# https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
git submodule update --init multibuild
echo "Source multibuild/common_utils.sh"
source multibuild/common_utils.sh
# https://github.com/matthew-brett/multibuild/issues/116
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
echo "Source multibuild/travis_steps.sh"
source multibuild/travis_steps.sh
# This sets -x
echo "Source travis_multibuild_customize.sh"
source travis_multibuild_customize.sh
echo $ENABLE_CONTRIB > contrib.enabled
echo $ENABLE_HEADLESS > headless.enabled
if [ -n "$IS_OSX" ]; then
echo "homebrew"
if [[ $SDIST == 0 ]]; then
# Check out and prepare the source
# Multibuild doesn't have releases, so --depth would break eventually (see
# https://superuser.com/questions/1240216/server-does-not-allow-request-for-unadvertised)
git submodule update --init multibuild
source multibuild/common_utils.sh
# https://github.com/matthew-brett/multibuild/issues/116
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export ARCH_FLAGS=" "; fi
source multibuild/travis_steps.sh
# This sets -x
source travis_multibuild_customize.sh
echo $ENABLE_CONTRIB > contrib.enabled
echo $ENABLE_HEADLESS > headless.enabled
if [ -n "$IS_OSX" ]; then
export PATH="/usr/local/sbin:$PATH"
TAPS="$(brew --repository)/Library/Taps"
if [ -e "$TAPS/caskroom/homebrew-cask" -a -e "$TAPS/homebrew/homebrew-cask" ]; then
rm -rf "$TAPS/caskroom/homebrew-cask"
......@@ -635,29 +681,42 @@ before_install: |
git clean -fxd || echo "status: $?"
sleep 1 || echo "status: $?"
git status || echo "status: $?"' \; || echo "status: $?"
brew_cache_cleanup
fi
echo "end"
# Not interested in travis internal scripts' output
fi
echo "end"
# Not interested in travis internal scripts' output
set +x
install: |
# Build and package
set -x
build_wheel $REPO_DIR $PLAT
if [[ $SDIST == 1 ]]; then
python -m pip install --upgrade pip
python -m pip install scikit-build
python setup.py sdist
else
build_wheel $REPO_DIR $PLAT
fi
set +x
script: |
# Install and run tests
set -x
install_run $PLAT && rc=$? || rc=$?
if [[ $SDIST == 1 ]]; then
echo "skipping tests because of sdist"
else
install_run $PLAT && rc=$? || rc=$?
fi
set +x
#otherwise, Travis logic terminates prematurely
#https://travis-ci.community/t/shell-session-update-command-not-found-in-build-log-causes-build-to-fail-if-trap-err-is-set/817
trap ERR
test "$rc" -eq 0
before_cache: |
......@@ -665,58 +724,81 @@ before_cache: |
set -e; set -x
if [ -n "$IS_OSX" ]; then
# When Taps is cached, this dir causes "Error: file exists" on `brew update`
if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
fi
# When Taps is cached, this dir causes "Error: file exists" on `brew update`
if [ -e "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask" ]; then
rm -rf "$(brew --repository)/Library/Taps/homebrew/homebrew-cask/homebrew-cask"
fi
brew_cache_cleanup
brew_cache_cleanup
fi
set +x; set +e
after_success: |
# Upload wheels to pypi if tag is set, otherwise save to Azure Storage
# Upload wheels to pypi if tag is set
set -x
if [ -n "$TRAVIS_TAG" ]; then
set -x
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
pip install --user twine
pip install --user --upgrade six
if [[ $ENABLE_CONTRIB == 0 ]]; then
if [[ $ENABLE_HEADLESS == 0 ]]; then
echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
else
echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
fi
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
pip install twine
pip install --upgrade pyOpenSSL
else
if [[ $ENABLE_HEADLESS == 0 ]]; then
echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
else
echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
fi
fi
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
pip install --user twine
pip install --user --upgrade six
if [[ $ENABLE_CONTRIB == 0 ]]; then
if [[ $ENABLE_HEADLESS == 0 ]]; then
echo "This is default build. Deployment will be done to to PyPI entry opencv-python."
else
echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-python-headless."
fi
if [[ $SDIST == 1 ]]; then
twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
else
if [[ $ENABLE_HEADLESS == 0 ]]; then
echo "This is contrib build. Deployment will be done to to PyPI entry opencv-contrib-python."
else
echo "This is headless contrib build. Deployment will be done to to PyPI entry opencv-contrib-python-headless."
fi
twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
fi
twine upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
set +x
else
set -x
fi
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
# macpython 3.5 doesn't support recent TLS protocols which causes twine
# upload to fail, so we use the system Python to run twine
/usr/bin/python -m ensurepip --user
/usr/bin/python -m pip install --user -U pip
/usr/bin/python -m pip install --user -U -I twine
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
if [[ $SDIST == 1 ]]; then
/usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/dist
else
brew install azure-cli
/usr/bin/python -m upload -u ${USER} -p ${PASS} --skip-existing ${TRAVIS_BUILD_DIR}/wheelhouse/opencv*
fi
az storage container create -n ${TRAVIS_COMMIT} --public-access blob
az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern *.whl
fi
set -x
fi
# Save to Azure storage always
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
else
brew install azure-cli
fi
az storage container create -n ${TRAVIS_COMMIT} --public-access blob
if [[ $SDIST == 1 ]]; then
az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/dist --pattern *.gz
else
az storage blob upload-batch -d ${TRAVIS_COMMIT} -s ${TRAVIS_BUILD_DIR}/wheelhouse --pattern opencv*.whl
fi
set +x
include LICENSE-3RD-PARTY.txt
include LICENSE.txt
include README.md
include find_version.py
include setup.py
include pyproject.toml
recursive-include cv2 *
recursive-include docker *
recursive-include opencv *
recursive-include opencv_contrib *
recursive-include patches *
......@@ -73,11 +73,11 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
## Documentation for opencv-python
[![AppVeyor CI test status (Windows)](https://img.shields.io/appveyor/ci/skvark/opencv-python.svg?maxAge=3600&label=Windows)](https://ci.appveyor.com/project/skvark/opencv-python)
[![Travis CI test status (Linux and OS X)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
[![Travis CI test status (Linux and macOS)](https://img.shields.io/travis/skvark/opencv-python.svg?maxAge=3600&label=Linux+macOS)](https://travis-ci.org/skvark/opencv-python)
The aim of this repository is to provide means to package each new [OpenCV release](https://github.com/opencv/opencv/releases) for the most used Python versions and platforms.
### Build process
### CI build process
The project is structured like a normal Python package with a standard ``setup.py`` file.
The build process for a single entry in the build matrices is as follows (see for example ``appveyor.yml`` file):
......@@ -91,43 +91,57 @@ The build process for a single entry in the build matrices is as follows (see fo
- Contrib modules are also included as a submodule
2. Find OpenCV version from the sources
3. Install Python dependencies
- ``setup.py`` installs the dependencies itself, so you need to run it in an environment
where you have the rights to install modules with Pip for the running Python
4. Build OpenCV
3. Build OpenCV
- tests are disabled, otherwise build time increases too much
- there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless)
- Linux builds run in manylinux Docker containers (CentOS 5)
- source distributions are separate entries in the build matrix
5. Rearrange OpenCV's build result, add our custom files and generate wheel
4. Rearrange OpenCV's build result, add our custom files and generate wheel
6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
5. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
7. Install the generated wheel
8. Test that Python can import the library and run some sanity checks
9. Use twine to upload the generated wheel to PyPI (only in release builds)
6. Install the generated wheel
7. Test that Python can import the library and run some sanity checks
8. Use twine to upload the generated wheel to PyPI (only in release builds)
Steps 1--5 are handled by ``setup.py bdist_wheel``.
Steps 1--4 are handled by ``pip wheel``.
The build can be customized with environment variables.
In addition to any variables that OpenCV's build accepts, we recognize:
The build can be customized with environment variables. In addition to any variables that OpenCV's build accepts, we recognize:
- ``CI_BUILD``. Set to ``1`` to emulate the CI environment build behaviour. Used only in CI builds to force certain build flags on in ``setup.py``. Do not use this unless you know what you are doing.
- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
See the next section for more info about manual builds outside the CI environment.
### Manual builds
If some dependency is not enabled in the pre-built wheels, you can also run the `setup.py` locally to create a custom wheel.
If some dependency is not enabled in the pre-built wheels, you can also run the build locally to create a custom wheel.
1. Clone this repository: `git clone --recursive https://github.com/skvark/opencv-python.git`
2. Go to the root of the repository
3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"`
4. Run ``python setup.py bdist_wheel``
- Optionally use the `manylinux` images as a build hosts if maximum portability is needed (and run `auditwheel` for the wheel after build)
5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
2. ``cd opencv-python``
3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"` (in Windows you need to set environment variables differently depending on Command Line or PowerShell)
4. Select the version which you wish to build with `ENABLE_CONTRIB` and `ENABLE_HEADLESS`: i.e. `export ENABLE_CONTRIB=1` if you wish to build `opencv-contrib-python`
5. Run ``pip wheel . --verbose``. NOTE: make sure you have the latest ``pip``, the ``pip wheel`` command replaces the old ``python setup.py bdist_wheel`` command which does not support ``pyproject.toml``.
- Optional: on Linux use the `manylinux` images as a build hosts if maximum portability is needed and run `auditwheel` for the wheel after build
- Optional: on macOS use ``delocate`` (same as ``auditwheel`` but for macOS)
6. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
#### Source distributions
Since OpenCV version 4.3.0, also source distributions are provided in PyPI. This means that if your system is not compatible with any of the wheels in PyPI, ``pip`` will attempt to build OpenCV from sources.
You can also force ``pip`` to build the wheels from the source distribution for example with:
``pip install --no-binary opencv-python opencv-python``
``pip install --no-binary :all: opencv-python``
If you need contrib modules or headless version, just change the package name (step 4 in the previous section is not needed). However, any additional CMake flags can be provided via environment variables as described in step 3 of the manual build section. If none are provided, OpenCV's CMake scripts will attempt to find and enable any suitable dependencies and enable them. Headless distributions have hard coded CMake flags which disable all possible GUI dependencies.
Please note that build tools and ``numpy`` are required for the build to succeed. On slow systems such as Raspberry Pi the full build may take several hours. On a 8-core Ryzen 7 3700X the build takes about 6 minutes.
### Licensing
......@@ -147,7 +161,7 @@ The packages include also other binaries. Full list of licenses can be found fro
### Versioning
``find_version.py`` script searches for the version information from OpenCV sources and appends also a revision number specific to this repository to the version string.
``find_version.py`` script searches for the version information from OpenCV sources and appends also a revision number specific to this repository to the version string. It saves the version information to ``version.py`` file under ``cv2`` in addition to some other flags.
### Releases
......@@ -177,7 +191,7 @@ Python 3.x releases are provided for officially supported versions (not in EOL).
Currently, builds for following Python versions are provided:
- 3.5
- 3.5 (EOL in 2020-09-13, builds for 3.5 will not be provided after this)
- 3.6
- 3.7
- 3.8
......
......@@ -141,14 +141,14 @@ build_script:
- cmd: |
"%PYTHON%/python.exe" -m pip install --upgrade pip
"%PYTHON%/python.exe" -m pip install --upgrade setuptools
"%PYTHON%/python.exe" setup.py bdist_wheel
set "CI_BUILD=True" && "%PYTHON%/python.exe" -m pip wheel --wheel-dir=%cd%\dist . --verbose
before_test:
- ps: |
cd ${Env:APPVEYOR_BUILD_FOLDER}\tests
$env:PYTHONWARNINGS = "ignore:::pip._internal.cli.base_command"
&"${Env:PYTHON}/python.exe" -m pip install --user (ls "../dist/opencv_*.whl")
&"${Env:PYTHON}/python.exe" -m pip install --user --no-warn-script-location (ls "../dist/opencv_*.whl")
if ($LastExitCode -ne 0) {throw $LastExitCode}
test_script:
......@@ -158,7 +158,7 @@ test_script:
"%PYTHON%/python.exe" -m unittest test
artifacts:
- path: dist\*.whl
- path: dist\opencv*.whl
name: wheels
deploy_script:
......
......@@ -9,7 +9,16 @@ from .data import *
# this makes them available
globals().update(importlib.import_module('cv2.cv2').__dict__)
if sys.platform == 'darwin':
is_ci_build = False
try:
from .version import ci_build
is_ci_build = ci_build
except:
pass
# the Qt plugin is included currently only in the pre-built wheels
if sys.platform == 'darwin' and is_ci_build:
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
)
......@@ -2,49 +2,55 @@ import sys
import os
import subprocess
opencv_version = ""
# dig out the version from OpenCV sources
version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
with open(version_file_path, 'r') as f:
for line in f:
words = line.split()
if "CV_VERSION_MAJOR" in words:
opencv_version += words[2]
opencv_version += "."
if "CV_VERSION_MINOR" in words:
opencv_version += words[2]
opencv_version += "."
if "CV_VERSION_REVISION" in words:
opencv_version += words[2]
break
# used in local dev releases
git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
try:
tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
except subprocess.CalledProcessError as e:
# no tags reachable (e.g. on a topic branch in a fork), see
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
tag=[]
else:
print(e.output); raise
if len(tag) == 1:
# tag identifies the build and should be a sequential revision number
version = tag[0]
opencv_version += ".{}".format(version)
else:
# local version identifier, not to be published on PyPI
version = git_hash
opencv_version += "+{}".format(version)
print("Version: ", opencv_version)
with open('cv_version.py', 'w') as f:
f.write('opencv_version = "{}"'.format(opencv_version))
if __name__ == "__main__":
contrib = sys.argv[1]
headless = sys.argv[2]
ci_build = sys.argv[2]
opencv_version = ""
# dig out the version from OpenCV sources
version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
with open(version_file_path, 'r') as f:
for line in f:
words = line.split()
if "CV_VERSION_MAJOR" in words:
opencv_version += words[2]
opencv_version += "."
if "CV_VERSION_MINOR" in words:
opencv_version += words[2]
opencv_version += "."
if "CV_VERSION_REVISION" in words:
opencv_version += words[2]
break
# used in local dev releases
git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode()
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
try:
tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-')
except subprocess.CalledProcessError as e:
# no tags reachable (e.g. on a topic branch in a fork), see
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
tag=[]
else:
print(e.output); raise
if len(tag) == 1:
# tag identifies the build and should be a sequential revision number
version = tag[0]
opencv_version += ".{}".format(version)
else:
# local version identifier, not to be published on PyPI
version = git_hash
opencv_version += "+{}".format(version)
with open('cv2/version.py', 'w') as f:
f.write("opencv_version = \"{}\"\n".format(opencv_version))
f.write("contrib = {}\n".format(contrib))
f.write("headless = {}\n".format(headless))
f.write("ci_build = {}".format(ci_build))
[build-system]
requires = [
"setuptools", "wheel", "scikit-build", "cmake", "pip",
"numpy==1.11.3; python_version=='3.5'",
"numpy==1.13.3; python_version=='3.6'",
"numpy==1.14.5; python_version=='3.7'",
"numpy==1.17.3; python_version>='3.8'"
]
\ No newline at end of file
# No 3rd-party modules here, see "3rd-party" note below
import io
import os
import os.path
......@@ -7,43 +6,38 @@ import runpy
import subprocess
import re
import sysconfig
import skbuild
from skbuild import cmaker
def main():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# These are neede for source fetching
CI_BUILD = os.environ.get("CI_BUILD", "False")
is_CI_build = True if CI_BUILD == "True" else False
cmake_source_dir = "opencv"
minimum_supported_numpy = "1.13.1"
build_contrib = get_build_env_var_by_name("contrib")
# headless flag to skip GUI deps if needed
build_headless = get_build_env_var_by_name("headless")
# Only import 3rd-party modules after having installed all the build dependencies:
# any of them, or their dependencies, can be updated during that process,
# leading to version conflicts
minimum_supported_numpy = "1.11.1"
if sys.version_info[:2] >= (3, 6):
minimum_supported_numpy = "1.11.3"
minimum_supported_numpy = "1.13.3"
if sys.version_info[:2] >= (3, 7):
minimum_supported_numpy = "1.14.5"
if sys.version_info[:2] >= (3, 8):
minimum_supported_numpy = "1.17.3"
numpy_version = get_or_install("numpy", minimum_supported_numpy)
get_or_install("scikit-build")
get_or_install("cmake")
import skbuild
from skbuild import cmaker
numpy_version = "numpy>=%s" % minimum_supported_numpy
python_version = cmaker.CMaker.get_python_version()
python_lib_path = cmaker.CMaker.get_python_library(python_version).replace('\\', '/')
python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace('\\', '/')
python_lib_path = cmaker.CMaker.get_python_library(python_version).replace(
"\\", "/"
)
python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace(
"\\", "/"
)
if os.path.exists(".git"):
import pip._internal.vcs.git as git
g = git.Git() # NOTE: pip API's are internal, this has to be refactored
......@@ -58,6 +52,10 @@ def main():
["submodule", "update", "--init", "--recursive", "opencv_contrib"]
)
package_version, build_contrib, build_headless = get_and_set_info(
build_contrib, build_headless, is_CI_build
)
# https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
x64 = sys.maxsize > 2 ** 32
......@@ -73,12 +71,11 @@ def main():
package_name = "opencv-python-headless"
long_description = io.open("README.md", encoding="utf-8").read()
package_version = get_opencv_version()
packages = ["cv2", "cv2.data"]
package_data = {
"cv2": ["*%s" % sysconfig.get_config_vars().get("SO")]
"cv2": ["*%s" % sysconfig.get_config_vars().get("SO"), "version.py"]
+ (["*.dll"] if os.name == "nt" else [])
+ ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
"cv2.data": ["*.xml"],
......@@ -87,29 +84,36 @@ def main():
# Files from CMake output to copy to package.
# Path regexes with forward slashes relative to CMake install dir.
rearrange_cmake_output_data = {
'cv2': ([r'bin/opencv_ffmpeg\d{3,4}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else []) +
"cv2": (
[r"bin/opencv_ffmpeg\d{3,4}%s\.dll" % ("_64" if x64 else "")]
if os.name == "nt"
else []
)
+
# In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
# Naming conventions vary so widely between versions and OSes
# had to give up on checking them.
['python/cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
'cv2.data': [ # OPENCV_OTHER_INSTALL_PATH
('etc' if os.name == 'nt' else 'share/OpenCV') +
r'/haarcascades/.*\.xml'
]
[
"python/cv2[^/]*%(ext)s"
% {"ext": re.escape(sysconfig.get_config_var("EXT_SUFFIX"))}
],
"cv2.data": [ # OPENCV_OTHER_INSTALL_PATH
("etc" if os.name == "nt" else "share/OpenCV") + r"/haarcascades/.*\.xml"
],
}
# Files in sourcetree outside package dir that should be copied to package.
# Raw paths relative to sourcetree root.
files_outside_package_dir = {"cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]}
ci_cmake_generator = (
["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
if os.name == "nt"
else ["-G", "Unix Makefiles"]
)
cmake_args = (
(
["-G", "Visual Studio 14" + (" Win64" if x64 else "")]
if os.name == "nt"
else ["-G", "Unix Makefiles"] # don't make CMake try (and fail) Ninja first
)
(ci_cmake_generator if is_CI_build else [])
+ [
# skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
"-DPYTHON3_EXECUTABLE=%s" % sys.executable,
......@@ -139,41 +143,41 @@ def main():
)
)
# OS-specific components
if sys.platform.startswith('linux') and not build_headless:
cmake_args.append("-DWITH_QT=4")
if sys.platform == 'darwin' and not build_headless:
cmake_args.append("-DWITH_QT=5")
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
]
if build_headless:
# it seems that cocoa cannot be disabled so on macOS the package is not truly headless
cmake_args.append("-DWITH_WIN32UI=OFF")
cmake_args.append("-DWITH_QT=OFF")
cmake_args.append(
"-DWITH_MSMF=OFF"
) # see: https://github.com/skvark/opencv-python/issues/263
if sys.platform.startswith("linux"):
cmake_args.append("-DWITH_V4L=ON")
cmake_args.append("-DWITH_LAPACK=ON")
cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
cmake_args.append("-DWITH_GTK=OFF")
if is_CI_build:
cmake_args.append(
"-DWITH_MSMF=OFF"
) # see: https://github.com/skvark/opencv-python/issues/263
if sys.platform.startswith("linux") and not x64:
if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
if sys.platform == "darwin":
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
# Fixes for macOS builds
if sys.platform == "darwin":
cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
# OS-specific components during CI builds
if is_CI_build:
if sys.platform.startswith("linux") and not build_headless:
cmake_args.append("-DWITH_QT=4")
if sys.platform == "darwin" and not build_headless:
if "bdist_wheel" in sys.argv:
cmake_args.append("-DWITH_QT=5")
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
]
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
if sys.platform.startswith("linux"):
cmake_args.append("-DWITH_V4L=ON")
cmake_args.append("-DWITH_LAPACK=ON")
cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
# https://github.com/scikit-build/scikit-build/issues/479
if "CMAKE_ARGS" in os.environ:
import shlex
cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
del shlex
......@@ -193,9 +197,8 @@ def main():
packages=packages,
package_data=package_data,
maintainer="Olli-Pekka Heinisuo",
include_package_data=True,
ext_modules=EmptyListWithLength(),
install_requires="numpy>=%s" % numpy_version,
install_requires=numpy_version,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
......@@ -376,17 +379,24 @@ class RearrangeCMakeOutput(object):
)
def install_packages(*requirements):
# No more convenient way until PEP 518 is implemented; setuptools only handles eggs
subprocess.check_call([sys.executable, "-m", "pip", "install"] + list(requirements))
def get_and_set_info(contrib, headless, ci_build):
# cv2/version.py should be generated by running find_version.py
version = {}
here = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(here, "cv2", "version.py")
# generate a fresh version.py always when Git repository exists
# (in sdists the version.py file already exists)
if os.path.exists(".git"):
old_args = sys.argv.copy()
sys.argv = ["", str(contrib), str(headless), str(ci_build)]
runpy.run_path("find_version.py", run_name="__main__")
sys.argv = old_args
def get_opencv_version():
# cv_version.py should be generated by running find_version.py
runpy.run_path("find_version.py")
from cv_version import opencv_version
with open(version_file) as fp:
exec(fp.read(), version)
return opencv_version
return version["opencv_version"], version["contrib"], version["headless"]
def get_build_env_var_by_name(flag_name):
......@@ -406,25 +416,6 @@ def get_build_env_var_by_name(flag_name):
return flag_set
def get_or_install(name, version=None):
""" If a package is already installed, build against it. If not, install """
# Do not import 3rd-party modules into the current process
import json
js_packages = json.loads(
subprocess.check_output(
[sys.executable, "-m", "pip", "list", "--format", "json"]
).decode("ascii")
) # valid names & versions are ASCII as per PEP 440
try:
[package] = (package for package in js_packages if package["name"] == name)
except ValueError:
install_packages("%s==%s" % (name, version) if version else name)
return version
else:
return package["version"]
# This creates a list which is empty but returns a length of 1.
# Should make the wheel a binary distribution and platlib compliant.
class EmptyListWithLength(list):
......
......@@ -14,7 +14,7 @@ function bdist_wheel_cmd {
# copied from multibuild's common_utils.sh
# add osx deployment target so it doesnt default to 10.6
local abs_wheelhouse=$1
python setup.py bdist_wheel $BDIST_PARAMS
CI_BUILD=1 pip wheel --wheel-dir="$PWD/dist" . --verbose $BDIST_PARAMS
cp dist/*.whl $abs_wheelhouse
if [ -n "$USE_CCACHE" -a -z "$BREW_BOOTSTRAP_MODE" ]; then ccache -s; fi
}
......@@ -88,7 +88,7 @@ function pre_build {
echo "Running for OSX"
local CACHE_STAGE; (echo "$TRAVIS_BUILD_STAGE_NAME" | grep -qiF "final") || CACHE_STAGE=1
export USER=travis
#after the cache stage, all bottles and Homebrew metadata should be already cached locally
if [ -n "$CACHE_STAGE" ]; then
brew update
......@@ -110,7 +110,7 @@ function pre_build {
brew_install_and_cache_within_time_limit ffmpeg_opencv || { [ $? -gt 1 ] && return 2 || return 0; }
else
brew unlink python@2
brew install ffmpeg_opencv
brew install -vd ffmpeg_opencv
fi
if [ -n "$CACHE_STAGE" ]; then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册