@@ -108,12 +108,32 @@ def main():
108
108
# Naming conventions vary so widely between versions and OSes
109
109
# had to give up on checking them.
110
110
[
111
- "python/cv2[^/]*%(ext)s"
112
- % {"ext" : re .escape (sysconfig .get_config_var ("EXT_SUFFIX" ))}
111
+ "python/cv2/python-%s.%s/cv2[^/]*%s"
112
+ % (sys .version_info [0 ], sys .version_info [1 ], re .escape (sysconfig .get_config_var ("EXT_SUFFIX" )))
113
+ ]
114
+ +
115
+ [
116
+ r"python/cv2/__init__.py"
117
+ ]
118
+ +
119
+ [
120
+ r"python/cv2/.*config.*.py"
113
121
],
114
122
"cv2.data" : [ # OPENCV_OTHER_INSTALL_PATH
115
123
("etc" if os .name == "nt" else "share/opencv4" ) + r"/haarcascades/.*\.xml"
116
124
],
125
+ "cv2.gapi" : [
126
+ "python/cv2" + r"/gapi/.*\.py"
127
+ ],
128
+ "cv2.mat_wrapper" : [
129
+ "python/cv2" + r"/mat_wrapper/.*\.py"
130
+ ],
131
+ "cv2.misc" : [
132
+ "python/cv2" + r"/misc/.*\.py"
133
+ ],
134
+ "cv2.utils" : [
135
+ "python/cv2" + r"/utils/.*\.py"
136
+ ],
117
137
}
118
138
119
139
# Files in sourcetree outside package dir that should be copied to package.
@@ -137,8 +157,6 @@ def main():
137
157
"-DBUILD_opencv_python2=OFF" ,
138
158
# Disable the Java build by default as it is not needed
139
159
"-DBUILD_opencv_java=%s" % build_java ,
140
- # When off, adds __init__.py and a few more helper .py's. We use our own helper files with a different structure.
141
- "-DOPENCV_SKIP_PYTHON_LOADER=ON" ,
142
160
# Relative dir to install the built module to in the build tree.
143
161
# The default is generated from sysconfig, we'd rather have a constant for simplicity
144
162
"-DOPENCV_PYTHON3_INSTALL_PATH=python" ,
@@ -358,6 +376,22 @@ def _classify_installed_files_override(
358
376
359
377
print ("Copying files from CMake output" )
360
378
379
+ with open ('%spython/cv2/__init__.py'
380
+ % cmake_install_dir , 'r' ) as opencv_init :
381
+ opencv_init_data = ""
382
+ for line in opencv_init :
383
+ opencv_init_replacement = line .replace ('importlib.import_module("cv2")' , 'importlib.import_module("cv2.cv2")' )
384
+ opencv_init_data = opencv_init_data + opencv_init_replacement
385
+ with open ('%spython/cv2/__init__.py'
386
+ % cmake_install_dir , 'w' ) as opencv_python_init :
387
+ opencv_python_init .write (opencv_init_data )
388
+
389
+ with open ('scripts/__init__.py' , 'r' ) as custom_init :
390
+ custom_init_data = custom_init .read ()
391
+ with open ('%spython/cv2/config-%s.%s.py'
392
+ % (cmake_install_dir , sys .version_info [0 ], sys .version_info [1 ]), 'a' ) as opencv_init_config :
393
+ opencv_init_config .write (custom_init_data )
394
+
361
395
for package_name , relpaths_re in cls .package_paths_re .items ():
362
396
package_dest_reldir = package_name .replace ("." , os .path .sep )
363
397
for relpath_re in relpaths_re :
0 commit comments