Skip to content

Commit 85bb4a3

Browse files
committed
update README, minor fixes, update issue template
1 parent d434c01 commit 85bb4a3

File tree

5 files changed

+97
-42
lines changed

5 files changed

+97
-42
lines changed

.github/issue_template.md

+27
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,30 @@ Write here what went wrong.
1313
- architecture (e.g. x86)
1414
- opencv-python version
1515

16+
##### Issue submission checklist
17+
18+
- [ ] This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
19+
<!--
20+
21+
Use Q&A forums such as https://answers.opencv.org/questions/ and https://stackoverflow.com/ and other communities
22+
to discuss problems. Tickets without real issue statements related to this build toolchain will be closed.
23+
24+
-->
25+
- [ ] 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)
26+
<!--
27+
28+
If you have some OpenCV bug report which needs to fixed in the C++ code,
29+
please report issue to the OpenCV repository:
30+
31+
https://github.com/opencv/opencv/issues
32+
33+
See also:
34+
35+
* OpenCV documentation: https://docs.opencv.org
36+
* OpenCV FAQ page: https://github.com/opencv/opencv/wiki/FAQ
37+
* OpenCV forum: https://answers.opencv.org
38+
* Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
39+
40+
-->
41+
- [ ] 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")
42+
- [ ] I'm using the latest version of ``opencv-python``

README.md

+38-24
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ A: It's easier for users to understand ``opencv-python`` than ``cv2`` and it mak
7373
## Documentation for opencv-python
7474

7575
[![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)
76-
[![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)
76+
[![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)
7777

7878
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.
7979

80-
### Build process
80+
### CI build process
8181

8282
The project is structured like a normal Python package with a standard ``setup.py`` file.
8383
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
9191
- Contrib modules are also included as a submodule
9292

9393
2. Find OpenCV version from the sources
94-
3. Install Python dependencies
9594

96-
- ``setup.py`` installs the dependencies itself, so you need to run it in an environment
97-
where you have the rights to install modules with Pip for the running Python
98-
99-
4. Build OpenCV
95+
3. Build OpenCV
10096

10197
- tests are disabled, otherwise build time increases too much
10298
- there are 4 build matrix entries for each build combination: with and without contrib modules, with and without GUI (headless)
10399
- Linux builds run in manylinux Docker containers (CentOS 5)
100+
- source distributions are separate entries in the build matrix
104101

105-
5. Rearrange OpenCV's build result, add our custom files and generate wheel
102+
4. Rearrange OpenCV's build result, add our custom files and generate wheel
106103

107-
6. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
104+
5. Linux and macOS wheels are transformed with auditwheel and delocate, correspondingly
108105

109-
7. Install the generated wheel
110-
8. Test that Python can import the library and run some sanity checks
111-
9. Use twine to upload the generated wheel to PyPI (only in release builds)
106+
6. Install the generated wheel
107+
7. Test that Python can import the library and run some sanity checks
108+
8. Use twine to upload the generated wheel to PyPI (only in release builds)
112109

113-
Steps 1--5 are handled by ``setup.py bdist_wheel``.
110+
Steps 1--4 are handled by ``pip wheel``.
114111

115-
The build can be customized with environment variables.
116-
In addition to any variables that OpenCV's build accepts, we recognize:
112+
The build can be customized with environment variables. In addition to any variables that OpenCV's build accepts, we recognize:
117113

114+
- ``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.
118115
- ``ENABLE_CONTRIB`` and ``ENABLE_HEADLESS``. Set to ``1`` to build the contrib and/or headless version
119-
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
116+
- ``CMAKE_ARGS``. Additional arguments for OpenCV's CMake invocation. You can use this to make a custom build.
117+
118+
See the next section for more info about manual builds outside the CI environment.
120119

121120
### Manual builds
122121

123-
If some dependency is not enabled in the pre-built wheels, you can also run the `setup.py` locally to create a custom wheel.
122+
If some dependency is not enabled in the pre-built wheels, you can also run the build locally to create a custom wheel.
124123

125124
1. Clone this repository: `git clone --recursive https://github.com/skvark/opencv-python.git`
126-
2. Go to the root of the repository
127-
3. Add custom Cmake flags if needed, for example: `export CMAKE_FLAGS="-DSOME_FLAG=ON -DSOME_OTHER_FLAG=OFF"`
128-
4. Run ``python setup.py bdist_wheel``
129-
- Optionally use the `manylinux` images as a build hosts if maximum portability is needed (and run `auditwheel` for the wheel after build)
130-
5. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
125+
2. ``cd opencv-python``
126+
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)
127+
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`
128+
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``.
129+
- Optional: on Linux use the `manylinux` images as a build hosts if maximum portability is needed and run `auditwheel` for the wheel after build
130+
- Optional: on macOS use ``delocate`` (same as ``auditwheel`` but for macOS)
131+
6. You'll have the wheel file in the `dist` folder and you can do with that whatever you wish
132+
133+
#### Source distributions
134+
135+
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.
136+
137+
You can also force ``pip`` to build the wheels from the source distribution for example with:
138+
139+
``pip install --no-binary opencv-python opencv-python``
140+
``pip install --no-binary :all: opencv-python``
141+
142+
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.
143+
144+
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.
131145

132146
### Licensing
133147

@@ -147,7 +161,7 @@ The packages include also other binaries. Full list of licenses can be found fro
147161

148162
### Versioning
149163

150-
``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.
164+
``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.
151165

152166
### Releases
153167

@@ -177,7 +191,7 @@ Python 3.x releases are provided for officially supported versions (not in EOL).
177191

178192
Currently, builds for following Python versions are provided:
179193

180-
- 3.5
194+
- 3.5 (EOL in 2020-09-13, builds for 3.5 will not be provided after this)
181195
- 3.6
182196
- 3.7
183197
- 3.8

cv2/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
# this makes them available
1010
globals().update(importlib.import_module('cv2.cv2').__dict__)
1111

12-
if sys.platform == 'darwin':
12+
is_ci_build = False
13+
14+
try:
15+
from .version import ci_build
16+
is_ci_build = ci_build
17+
except:
18+
pass
19+
20+
# the Qt plugin is included currently only in the pre-built wheels
21+
if sys.platform == 'darwin' and is_ci_build:
1322
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
1423
os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
1524
)

find_version.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
if __name__ == "__main__":
66
contrib = sys.argv[1]
77
headless = sys.argv[2]
8+
ci_build = sys.argv[2]
89

910
opencv_version = ""
1011
# dig out the version from OpenCV sources
@@ -51,4 +52,5 @@
5152
with open('cv2/version.py', 'w') as f:
5253
f.write("opencv_version = \"{}\"\n".format(opencv_version))
5354
f.write("contrib = {}\n".format(contrib))
54-
f.write("headless = {}".format(headless))
55+
f.write("headless = {}\n".format(headless))
56+
f.write("ci_build = {}".format(ci_build))

setup.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def main():
5252
["submodule", "update", "--init", "--recursive", "opencv_contrib"]
5353
)
5454

55-
package_version, build_contrib, build_headless = get_opencv_version(
56-
build_contrib, build_headless
55+
package_version, build_contrib, build_headless = get_and_set_info(
56+
build_contrib, build_headless, is_CI_build
5757
)
5858

5959
# https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
@@ -153,31 +153,33 @@ def main():
153153
"-DWITH_MSMF=OFF"
154154
) # see: https://github.com/skvark/opencv-python/issues/263
155155

156+
if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
157+
subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
158+
156159
# OS-specific components during CI builds
157160
if is_CI_build:
158161
if sys.platform.startswith("linux") and not build_headless:
159162
cmake_args.append("-DWITH_QT=4")
160163

161164
if sys.platform == "darwin" and not build_headless:
162-
cmake_args.append("-DWITH_QT=5")
165+
if "bdist_wheel" in sys.argv:
166+
cmake_args.append("-DWITH_QT=5")
167+
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
168+
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
169+
]
170+
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
163171

164172
if sys.platform.startswith("linux"):
165173
cmake_args.append("-DWITH_V4L=ON")
166174
cmake_args.append("-DWITH_LAPACK=ON")
167175
cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
168176

169-
if sys.platform.startswith("linux") and not x64 and "bdist_wheel" in sys.argv:
170-
subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
177+
# https://github.com/scikit-build/scikit-build/issues/479
178+
if "CMAKE_ARGS" in os.environ:
179+
import shlex
171180

172-
if (
173-
sys.platform == "darwin"
174-
and "bdist_wheel" in sys.argv
175-
and ("WITH_QT=5" in sys.argv or "WITH_QT=5" in cmake_args)
176-
):
177-
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
178-
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
179-
]
180-
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
181+
cmake_args.extend(shlex.split(os.environ["CMAKE_ARGS"]))
182+
del shlex
181183

182184
# works via side effect
183185
RearrangeCMakeOutput(
@@ -377,16 +379,17 @@ def _classify_installed_files_override(
377379
)
378380

379381

380-
def get_opencv_version(contrib, headless):
382+
def get_and_set_info(contrib, headless, ci_build):
381383
# cv2/version.py should be generated by running find_version.py
382384
version = {}
383385
here = os.path.abspath(os.path.dirname(__file__))
384386
version_file = os.path.join(here, "cv2", "version.py")
385387

386388
# generate a fresh version.py always when Git repository exists
389+
# (in sdists the version.py file already exists)
387390
if os.path.exists(".git"):
388391
old_args = sys.argv.copy()
389-
sys.argv = ["", str(contrib), str(headless)]
392+
sys.argv = ["", str(contrib), str(headless), str(ci_build)]
390393
runpy.run_path("find_version.py", run_name="__main__")
391394
sys.argv = old_args
392395

0 commit comments

Comments
 (0)