hook-cairocffi.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2021 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. import ctypes.util
  13. import os
  14. from PyInstaller.depend.utils import _resolveCtypesImports
  15. from PyInstaller.utils.hooks import collect_data_files, is_module_satisfies, logger
  16. datas = collect_data_files("cairocffi")
  17. binaries = []
  18. # NOTE: Update this if cairocffi requires more libraries
  19. libs = ["cairo-2", "cairo", "libcairo-2"]
  20. try:
  21. lib_basenames = []
  22. for lib in libs:
  23. libname = ctypes.util.find_library(lib)
  24. if libname is not None:
  25. lib_basenames += [os.path.basename(libname)]
  26. if lib_basenames:
  27. resolved_libs = _resolveCtypesImports(lib_basenames)
  28. for resolved_lib in resolved_libs:
  29. binaries.append((resolved_lib[1], '.'))
  30. except Exception as e:
  31. logger.warning("Error while trying to find system-installed Cairo library: %s", e)
  32. if not binaries:
  33. logger.warning("Cairo library not found - cairocffi will likely fail to work!")
  34. # cairocffi 1.6.0 requires cairocffi/constants.py source file, so make sure it is collected.
  35. # The module collection mode setting requires PyInstaller >= 5.3.
  36. if is_module_satisfies('cairocffi >= 1.6.0'):
  37. module_collection_mode = {'cairocffi.constants': 'pyz+py'}