forked from pyinstaller/pyinstaller-hooks-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook-cairocffi.py
40 lines (33 loc) · 1.28 KB
/
hook-cairocffi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ------------------------------------------------------------------
# Copyright (c) 2021 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
import ctypes.util
import os
from PyInstaller.depend.utils import _resolveCtypesImports
from PyInstaller.utils.hooks import collect_data_files, logger
datas = collect_data_files("cairocffi")
binaries = []
# NOTE: Update this if cairocffi requires more libraries
libs = ["cairo-2", "cairo", "libcairo-2"]
try:
lib_basenames = []
for lib in libs:
libname = ctypes.util.find_library(lib)
if libname is not None:
lib_basenames += [os.path.basename(libname)]
if lib_basenames:
resolved_libs = _resolveCtypesImports(lib_basenames)
for resolved_lib in resolved_libs:
binaries.append((resolved_lib[1], '.'))
except Exception as e:
logger.warning("Error while trying to find system-installed Cairo library: %s", e)
if not binaries:
logger.warning("Cairo library not found - cairocffi will likely fail to work!")