hook-gi.repository.GLib.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2023, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. import glob
  12. import os
  13. from PyInstaller.compat import is_win
  14. from PyInstaller.utils.hooks import get_hook_config
  15. from PyInstaller.utils.hooks.gi import GiModuleInfo, collect_glib_share_files, collect_glib_translations
  16. def hook(hook_api):
  17. module_info = GiModuleInfo('GLib', '2.0')
  18. if not module_info.available:
  19. return
  20. binaries, datas, hiddenimports = module_info.collect_typelib_data()
  21. # Collect platform-specific module, otherwise it may be opportunistically loaded from the run-time system.
  22. hiddenimports += ['gi.repository.GLib' + ('Win32' if is_win else 'Unix')]
  23. # Collect translations
  24. lang_list = get_hook_config(hook_api, "gi", "languages")
  25. datas += collect_glib_translations('glib20', lang_list)
  26. # Collect schemas
  27. datas += collect_glib_share_files('glib-2.0', 'schemas')
  28. # On Windows, glib needs a spawn helper for g_spawn* API
  29. if is_win:
  30. pattern = os.path.join(module_info.get_libdir(), 'gspawn-*-helper*.exe')
  31. for f in glob.glob(pattern):
  32. binaries.append((f, '.'))
  33. hook_api.add_datas(datas)
  34. hook_api.add_binaries(binaries)
  35. hook_api.add_imports(*hiddenimports)