Skip to content

Commit a25a2a8

Browse files
author
Andrey Senyaev
committed
Added lines for a proper work using pylint and an autocomplete in IDE
1 parent 84bfd76 commit a25a2a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ def _classify_installed_files_override(
377377

378378
print("Copying files from CMake output")
379379

380+
# lines for a proper work using pylint and an autocomplete in IDE
381+
with open("%spython/cv2/__init__.py"
382+
% cmake_install_dir, 'r') as opencv_init:
383+
opencv_init_lines = opencv_init.readlines()
384+
extra_imports = 'from .cv2 import *\nglobals().update(importlib.import_module("cv2.cv2").__dict__)'
385+
free_line_after_imports = 6
386+
opencv_init_lines.insert(free_line_after_imports, extra_imports)
387+
opencv_init_data = ""
388+
for line in opencv_init_lines:
389+
opencv_init_replacement = line.replace('importlib.import_module("cv2")', 'importlib.import_module("cv2.cv2")')
390+
opencv_init_data = opencv_init_data + opencv_init_replacement
391+
392+
with open("%spython/cv2/__init__.py"
393+
% cmake_install_dir, 'w') as opencv_final_init:
394+
opencv_final_init.write(opencv_init_data)
395+
380396
# add lines from the old __init__.py file to the config file
381397
with open('scripts/__init__.py', 'r') as custom_init:
382398
custom_init_data = custom_init.read()

0 commit comments

Comments
 (0)