@@ -108,12 +108,32 @@ def main():
108108 # Naming conventions vary so widely between versions and OSes
109109 # had to give up on checking them.
110110 [
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"
113121 ],
114122 "cv2.data" : [ # OPENCV_OTHER_INSTALL_PATH
115123 ("etc" if os .name == "nt" else "share/opencv4" ) + r"/haarcascades/.*\.xml"
116124 ],
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+ ],
117137 }
118138
119139 # Files in sourcetree outside package dir that should be copied to package.
@@ -137,8 +157,6 @@ def main():
137157 "-DBUILD_opencv_python2=OFF" ,
138158 # Disable the Java build by default as it is not needed
139159 "-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" ,
142160 # Relative dir to install the built module to in the build tree.
143161 # The default is generated from sysconfig, we'd rather have a constant for simplicity
144162 "-DOPENCV_PYTHON3_INSTALL_PATH=python" ,
@@ -358,6 +376,22 @@ def _classify_installed_files_override(
358376
359377 print ("Copying files from CMake output" )
360378
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+
361395 for package_name , relpaths_re in cls .package_paths_re .items ():
362396 package_dest_reldir = package_name .replace ("." , os .path .sep )
363397 for relpath_re in relpaths_re :
0 commit comments