Skip to content

Commit

Permalink
hooks: support opencv-python 4.8.0 [msys2] (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte authored Jul 22, 2023
1 parent 4c35f15 commit fb5d11b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions cx_Freeze/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
IS_LINUX = PLATFORM.startswith("linux")
IS_MACOS = PLATFORM.startswith("macos")
IS_MINGW = PLATFORM.startswith("mingw")
IS_MINGW64 = PLATFORM.startswith("mingw_x86_64")
IS_WINDOWS = PLATFORM.startswith("win")

IS_CONDA = Path(sys.prefix, "conda-meta").is_dir()
30 changes: 16 additions & 14 deletions cx_Freeze/hooks/cv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
from pathlib import Path

from .._compat import IS_MACOS, IS_WINDOWS
from .._compat import IS_MACOS, IS_MINGW, IS_MINGW64, IS_WINDOWS
from ..common import TemporaryPath
from ..finder import ModuleFinder
from ..module import Module
Expand All @@ -26,14 +26,19 @@ def load_cv2(finder: ModuleFinder, module: Module) -> None:
if module.distribution is None:
module.update_distribution("opencv-python")

source_dir = module.file.parent
target_dir = Path("lib", "cv2")

# conda-forge and msys2: cv2 4.6.0 is a extension module
if module.path is None:
# msys2 files is on share subdirectory
source = Path(sys.base_prefix, "plugins/platforms")
if not source.is_dir():
source = Path(sys.base_prefix, "share/qt5/plugins/platforms")
# msys2 files is on 'share' subdirectory
if IS_MINGW:
if IS_MINGW64:
source = Path(sys.base_prefix, "share/qt6/plugins/platforms")
else:
source = Path(sys.base_prefix, "share/qt5/plugins/platforms")
else:
source = Path(sys.base_prefix, "plugins/platforms")
if source.is_dir():
finder.include_files(source, target_dir / "plugins" / "platforms")
source = Path(sys.base_prefix, "fonts")
Expand All @@ -45,17 +50,14 @@ def load_cv2(finder: ModuleFinder, module: Module) -> None:
lines = ["[Paths]", f"Prefix = {target_dir.as_posix()}"]
with qt_conf.open(mode="w", encoding="utf_8", newline="") as file:
file.write("\n".join(lines))
finder.include_files(qt_conf, qt_conf.name)
if IS_MACOS:
target_qt_conf = "Contents/Resources/qt.conf"
else:
target_qt_conf = qt_conf.name
finder.include_files(qt_conf, target_qt_conf)
finder.include_files(qt_conf, "Contents/Resources/qt.conf")
return

# Use optmized mode
module.in_file_system = 2
finder.include_package("cv2")
source_dir = module.path[0]
for path in source_dir.glob("config*.py"):
finder.include_files(path, target_dir / path.name)
data_dir = source_dir / "data"
Expand All @@ -65,11 +67,11 @@ def load_cv2(finder: ModuleFinder, module: Module) -> None:
# Copy all binary files
if IS_WINDOWS:
return

if IS_MACOS:
source_dylibs = source_dir / ".dylibs"
if source_dylibs.exists():
for file in source_dylibs.iterdir():
finder.include_files(file, file.name)
libs_dir = source_dir / ".dylibs"
if libs_dir.exists():
finder.include_files(libs_dir, "lib/cv2/.dylibs")
return

# Linux and others
Expand Down

0 comments on commit fb5d11b

Please sign in to comment.