forked from opencv/opencv-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·628 lines (542 loc) · 24.3 KB
/
setup.py
File metadata and controls
executable file
·628 lines (542 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
from datetime import date
import glob
import io
import os
import os.path
import sys
import subprocess
import re
import sysconfig
import platform
from skbuild import cmaker, setup
def main():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
CI_BUILD = os.environ.get("CI_BUILD", "False")
is_CI_build = True if CI_BUILD == "1" else False
cmake_source_dir = "opencv"
build_contrib = get_build_env_var_by_name("contrib")
build_headless = get_build_env_var_by_name("headless")
build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
build_rolling = get_build_env_var_by_name("rolling")
# CUDA architecture configuration - can be overridden via environment variables
# CUDA 12.x supports: 5.0+ (Maxwell through Hopper)
# CUDA 13.x supports: 7.5+ (Turing through Hopper)
# Reference architectures:
# maxwell=5.0;5.2, pascal=6.0;6.1, volta=7.0, turing=7.5,
# ampere=8.0;8.6, lovelace=8.9, hopper=9.0
cuda_arch_bin = os.environ.get("CUDA_ARCH_BIN", "7.5;8.0;8.6;8.9;9.0")
cuda_arch_ptx = os.environ.get("CUDA_ARCH_PTX", "9.0")
# NOTE: since 2.3.0 numpy upgraded from manylinux2014 to manylinux_2_28
# see https://numpy.org/doc/stable/release/2.3.0-notes.html#numpy-2-3-0-release-notes
install_requires = [
'numpy<2.0; python_version<"3.9"',
'numpy(>=2, <2.3.0); python_version>="3.9"',
]
python_version = cmaker.CMaker.get_python_version()
python_lib_path = cmaker.CMaker.get_python_library(python_version) or ""
# HACK: For Scikit-build 0.17.3 and newer that returns None or empty sptring for PYTHON_LIBRARY in manylinux2014
# A small release related to PYTHON_LIBRARY handling changes in 0.17.2; scikit-build 0.17.3 returns an empty string from get_python_library if no Python library is present (like on manylinux), where 0.17.2 returned None, and previous versions returned a non-existent path. Note that adding REQUIRED to find_package(PythonLibs will fail, but it is incorrect (you must not link to libPython.so) and was really just injecting a non-existent path before.
# TODO: Remove the hack when the issue is handled correctly in main OpenCV CMake.
if python_lib_path == "":
python_lib_path = "libpython%sm.a" % python_version
python_lib_path = python_lib_path.replace("\\", "/")
python_include_dir = cmaker.CMaker.get_python_include_dir(python_version).replace(
"\\", "/"
)
if not bool(os.environ.get('OPENCV_PYTHON_SKIP_GIT_COMMANDS', False)) and 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
g.run_command(["submodule", "sync"])
if build_rolling:
g.run_command(
["submodule", "update", "--init", "--recursive", "--remote", cmake_source_dir]
)
if build_contrib:
g.run_command(
["submodule", "update", "--init", "--recursive", "--remote", "opencv_contrib"]
)
else:
g.run_command(
["submodule", "update", "--init", "--recursive", cmake_source_dir]
)
if build_contrib:
g.run_command(
["submodule", "update", "--init", "--recursive", "opencv_contrib"]
)
package_version, build_contrib, build_headless, build_rolling = generate_version_file(
build_contrib, build_headless, build_rolling, cuda_arch_bin, cuda_arch_ptx
)
print(f"package_version={package_version} build_contrib={build_contrib}, build_headless={build_headless}, build_rolling={build_rolling}, cuda_arch_bin={cuda_arch_bin}, cuda_arch_ptx={cuda_arch_ptx}")
# https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
is64 = sys.maxsize > 2 ** 32
package_name = "opencv-python-cuda"
long_description = io.open("README.md", encoding="utf-8").read()
packages = ["cv2", "cv2.data"]
package_data = {
"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"],
}
# 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_videoio_ffmpeg\d{4}%s\.dll" % ("_64" if is64 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.
# If not specifying PY_LIMITED_API, the Python sources go under python/cv2/python-3.MINOR_VERSION/ instead of python/cv2/python-3/
[
r"python/cv2/python-%s*/cv2.*"
% (sys.version_info[0]) if 'CMAKE_ARGS' in os.environ and "-DPYTHON3_LIMITED_API=ON" in os.environ['CMAKE_ARGS']
else r"python/cv2/python-%s.*/cv2.*"
% (sys.version_info[0])
]
+
[
r"python/cv2/__init__.py"
]
+
[
r"python/cv2/.*config.*.py"
]
+
[ r"python/cv2/py.typed" ] if sys.version_info >= (3, 6) else []
,
"cv2.data": [ # OPENCV_OTHER_INSTALL_PATH
("etc" if os.name == "nt" else "share/opencv4") + r"/haarcascades/.*\.xml"
],
"cv2.gapi": [
"python/cv2" + r"/gapi/.*\.py"
],
"cv2.mat_wrapper": [
"python/cv2" + r"/mat_wrapper/.*\.py"
],
"cv2.misc": [
"python/cv2" + r"/misc/.*\.py"
],
"cv2.utils": [
"python/cv2" + r"/utils/.*\.py"
],
}
if sys.version_info >= (3, 6):
rearrange_cmake_output_data["cv2.typing"] = ["python/cv2" + r"/typing/.*\.py"]
# 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","*.dll"]}
ci_cmake_generator = (
["-G", "Visual Studio 17 2022", "-T", "v143"]
if os.name == "nt"
else ["-G", "Unix Makefiles"]
)
cudnn_library = os.environ["CUDNN_LIBRARY"]
cudnn_include_dir = os.environ["CUDNN_INCLUDE_DIR"]
# Video Codec SDK paths for NVCUVID/NVCUVENC (optional, enables hardware video decode/encode)
nvcuvid_library = os.environ.get("CUDA_nvcuvid_LIBRARY", "")
nvencodeapi_library = os.environ.get("CUDA_nvencodeapi_LIBRARY", "")
nvcuvid_include_dir = os.environ.get("NVCUVID_INCLUDE_DIR", "")
cmake_args = (
(ci_cmake_generator if is_CI_build else [])
+ [
# skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
f"-DPYTHON3_EXECUTABLE={sys.executable}",
f"-DPYTHON_DEFAULT_EXECUTABLE={sys.executable}",
f"-DPYTHON3_INCLUDE_DIR={python_include_dir}",
f"-DPYTHON3_LIBRARY={python_lib_path}",
"-DBUILD_opencv_python3=ON",
"-DBUILD_opencv_python2=OFF",
# Disable the Java build by default as it is not needed
f"-DBUILD_opencv_java={build_java}",
# Relative dir to install the built module to in the build tree.
# The default is generated from sysconfig, we'd rather have a constant for simplicity
"-DOPENCV_PYTHON3_INSTALL_PATH=python",
# Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
# and skbuild bails out on seeing that
"-DINSTALL_CREATE_DISTRIB=ON",
# See opencv/CMakeLists.txt for options and defaults
"-DBUILD_opencv_apps=OFF",
"-DBUILD_opencv_freetype=OFF",
"-DBUILD_SHARED_LIBS=OFF",
"-DBUILD_TESTS=OFF",
"-DBUILD_PERF_TESTS=OFF",
"-DBUILD_DOCS=OFF",
"-DOPENCV_ENABLE_NONFREE=OFF",
"-DPYTHON3_LIMITED_API=ON",
"-DBUILD_OPENEXR=ON",
"-DWITH_CUDA=ON",
"-DWITH_NVCUVID=ON",
"-DWITH_NVCUVENC=ON",
f"-DCUDA_ARCH_BIN={cuda_arch_bin}",
f"-DCUDA_ARCH_PTX={cuda_arch_ptx}",
f"-DCUDNN_LIBRARY={cudnn_library}",
f"-DCUDNN_INCLUDE_DIR={cudnn_include_dir}",
]
+ (
# Video Codec SDK paths for hardware video decode/encode support
[
f"-DCUDA_nvcuvid_LIBRARY={nvcuvid_library}",
f"-DCUDA_nvencodeapi_LIBRARY={nvencodeapi_library}",
f"-DCMAKE_INCLUDE_PATH={nvcuvid_include_dir}",
]
if nvcuvid_library and nvcuvid_include_dir
else []
)
+ (
# CUDA 12.9+ requires MSVC's conformant preprocessor for CCCL headers.
# -Xcompiler passes the flag from nvcc to the host compiler (MSVC).
# See: https://github.com/NVIDIA/cccl/issues/5166
["-DCUDA_NVCC_FLAGS=-Xcompiler /Zc:preprocessor"]
if sys.platform == "win32"
else []
)
+ (
# CMake flags for windows/arm64 build
["-DCMAKE_GENERATOR_PLATFORM=ARM64",
# Emulated cmake requires following flags to correctly detect
# target architecture for windows/arm64 build
"-DOPENCV_WORKAROUND_CMAKE_20989=ON",
"-DCMAKE_SYSTEM_PROCESSOR=ARM64"]
if platform.machine() == "ARM64" and sys.platform == "win32"
# If it is not defined 'linker flags: /machine:X86' on Windows x64
else ["-DCMAKE_GENERATOR_PLATFORM=x64"] if is64 and sys.platform == "win32"
else []
)
+ (
["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")]
if build_contrib
else []
)
)
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_GTK=OFF")
# see: https://github.com/skvark/opencv-python/issues/263
# see: https://github.com/opencv/opencv-python/issues/771
cmake_args.append("-DWITH_MSMF=OFF")
cmake_args.append("-DWITH_OBSENSOR=OFF") # Orbbec cameras backend uses MSMF API
if sys.platform.startswith("linux") and not is64 and "bdist_wheel" in sys.argv:
subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
# OS-specific components during CI builds
if is_CI_build:
if (
not build_headless
and "bdist_wheel" in sys.argv
and sys.platform.startswith("linux")
):
cmake_args.append("-DWITH_QT=5")
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
if sys.platform.startswith("linux"):
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
(r"lib/qt/plugins/platforms/libqxcb\.so")
]
# add fonts for Qt5
fonts = []
for file in os.listdir("/usr/share/fonts/dejavu"):
if file.endswith(".ttf"):
fonts.append(
(r"lib/qt/fonts/dejavu/%s\.ttf" % file.split(".")[0])
)
rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
if sys.platform == "darwin":
rearrange_cmake_output_data["cv2.qt.plugins.platforms"] = [
(r"lib/qt/plugins/platforms/libqcocoa\.dylib")
]
if sys.platform.startswith("linux"):
cmake_args.append("-DWITH_V4L=ON")
cmake_args.append("-DWITH_LAPACK=ON")
cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
# works via side effect
RearrangeCMakeOutput(
rearrange_cmake_output_data, files_outside_package_dir, package_data.keys()
)
setup(
name=package_name,
version=package_version,
url="https://github.com/Breakthrough/opencv-python-cuda",
license="Apache 2.0",
description="[Unofficial] OpenCV Python bindings with CUDA support.",
long_description=long_description,
long_description_content_type="text/markdown",
packages=packages,
package_data=package_data,
maintainer="Breakthrough",
ext_modules=EmptyListWithLength(),
install_requires=install_requires,
python_requires=">=3.7",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: C++",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Image Recognition",
"Topic :: Software Development",
],
cmake_args=cmake_args,
cmake_source_dir=cmake_source_dir,
)
class RearrangeCMakeOutput:
"""
Patch SKBuild logic to only take files related to the Python package
and construct a file hierarchy that SKBuild expects (see below)
"""
_setuptools_wrap = None
# Have to wrap a function reference, or it's converted
# into an instance method on attr assignment
import argparse
wraps = argparse.Namespace(_classify_installed_files=None)
del argparse
package_paths_re = None
packages = None
files_outside_package = None
def __init__(self, package_paths_re, files_outside_package, packages):
cls = self.__class__
assert not cls.wraps._classify_installed_files, "Singleton object"
import skbuild.setuptools_wrap
cls._setuptools_wrap = skbuild.setuptools_wrap
cls.wraps._classify_installed_files = (
cls._setuptools_wrap._classify_installed_files
)
cls._setuptools_wrap._classify_installed_files = (
self._classify_installed_files_override
)
cls.package_paths_re = package_paths_re
cls.files_outside_package = files_outside_package
cls.packages = packages
def __del__(self):
cls = self.__class__
cls._setuptools_wrap._classify_installed_files = (
cls.wraps._classify_installed_files
)
cls.wraps._classify_installed_files = None
cls._setuptools_wrap = None
def _classify_installed_files_override(
self,
install_paths,
package_data,
package_prefixes,
py_modules,
new_py_modules,
scripts,
new_scripts,
data_files,
cmake_source_dir,
cmake_install_reldir,
):
"""
From all CMake output, we're only interested in a few files
and must place them into CMake install dir according
to Python conventions for SKBuild to find them:
package\
file
subpackage\
etc.
"""
cls = self.__class__
# 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
# 'path'/'dir' = relative to sourcetree root
cmake_install_dir = os.path.join(
cls._setuptools_wrap.CMAKE_INSTALL_DIR(), cmake_install_reldir
)
install_relpaths = [
os.path.relpath(p, cmake_install_dir) for p in install_paths
]
fslash_install_relpaths = [
p.replace(os.path.sep, "/") for p in install_relpaths
]
relpaths_zip = list(zip(fslash_install_relpaths, install_relpaths))
final_install_relpaths = []
print("Copying files from CMake output")
# add lines from the old __init__.py file to the config file
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts', '__init__.py'), 'r') as custom_init:
custom_init_data = custom_init.read()
# OpenCV generates config with different name for case with PYTHON3_LIMITED_API=ON
config_py = os.path.join(cmake_install_dir, 'python', 'cv2', 'config-%s.%s.py'
% (sys.version_info[0], sys.version_info[1]))
if not os.path.exists(config_py):
config_py = os.path.join(cmake_install_dir, 'python', 'cv2', 'config-%s.py' % sys.version_info[0])
with open(config_py, 'w') as opencv_init_config:
opencv_init_config.write(custom_init_data)
if sys.version_info >= (3, 6):
for p in install_relpaths:
if p.endswith(".pyi"):
target_rel_path = os.path.relpath(p, "python/cv2")
cls._setuptools_wrap._copy_file(
os.path.join(cmake_install_dir, p),
os.path.join(cmake_install_dir, "cv2", target_rel_path),
hide_listing=False,
)
final_install_relpaths.append(os.path.join("cv2", target_rel_path))
del install_relpaths, fslash_install_relpaths
for package_name, relpaths_re in cls.package_paths_re.items():
package_dest_reldir = package_name.replace(".", os.path.sep)
for relpath_re in relpaths_re:
found = False
r = re.compile(relpath_re + "$")
for fslash_relpath, relpath in relpaths_zip:
m = r.match(fslash_relpath)
if not m:
continue
found = True
new_install_relpath = os.path.join(
package_dest_reldir, os.path.basename(relpath)
)
cls._setuptools_wrap._copy_file(
os.path.join(cmake_install_dir, relpath),
os.path.join(cmake_install_dir, new_install_relpath),
hide_listing=False,
)
final_install_relpaths.append(new_install_relpath)
del m, fslash_relpath, new_install_relpath
else:
# gapi can be missed if ADE was not downloaded (network issue)
if not found and "gapi" not in relpath_re:
raise Exception("Not found: '%s'" % relpath_re)
del r, found
del relpaths_zip
print("Copying files from non-default sourcetree locations")
for package_name, paths in cls.files_outside_package.items():
package_dest_reldir = package_name.replace(".", os.path.sep)
expanded_paths = []
for path in paths:
expanded_paths += [path] if '*' not in path else glob.glob(path)
for path in expanded_paths:
new_install_relpath = os.path.join(
package_dest_reldir,
# Don't yet have a need to copy
# to subdirectories of package dir
os.path.basename(path),
)
cls._setuptools_wrap._copy_file(
path,
os.path.join(cmake_install_dir, new_install_relpath),
hide_listing=False,
)
final_install_relpaths.append(new_install_relpath)
final_install_paths = [
os.path.join(cmake_install_dir, p) for p in final_install_relpaths
]
return (cls.wraps._classify_installed_files)(
final_install_paths,
package_data,
package_prefixes,
py_modules,
new_py_modules,
scripts,
new_scripts,
data_files,
# To get around a check that prepends source dir to paths and breaks package detection code.
cmake_source_dir="",
_cmake_install_dir=cmake_install_reldir,
)
def generate_version_file(contrib, headless, rolling, cuda_arch_bin, cuda_arch_ptx):
version = {}
# generate version.py
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
# TODO(@Breakthrough): Update this so that we just use the tag name directly as the version
# identifier. We might need to strip off a "v" suffix if we include that in the repo, but it
# will greatly simplify things. This can also get out of sync since we cache artifacts now.
if len(tag) == 1:
# tag identifies the build and should be a sequential revision number
version = tag[0]
opencv_version += ".{}".format(version)
# rolling has converted into string using generate_version_file() function in setup.py
elif rolling == "True":
# rolling version identifier, will be published in a dedicated rolling PyPI repository
version = date.today().strftime('%Y%m%d')
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("rolling = {}\n".format(rolling))
f.write("cuda_arch_bin = {}".format(cuda_arch_bin))
f.write("cuda_arch_ptx = {}".format(cuda_arch_ptx))
return opencv_version, contrib, headless, rolling
def get_build_env_var_by_name(flag_name):
flag_set = False
try:
flag_set = bool(int(os.getenv("ENABLE_" + flag_name.upper(), None)))
except Exception:
pass
if not flag_set:
try:
flag_set = bool(int(open(flag_name + ".enabled").read(1)))
except Exception:
pass
return flag_set
# 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):
def __len__(self):
return 1
if __name__ == "__main__":
main()