hook-cairosvg.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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, logger
  16. datas = collect_data_files("cairosvg")
  17. binaries = []
  18. # NOTE: Update this if cairosvg 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 - cairosvg will likely fail to work!")