hook-gi.repository.Gio.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2025, 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 import compat
  14. import PyInstaller.log as logging
  15. from PyInstaller.utils.hooks.gi import GiModuleInfo
  16. logger = logging.getLogger(__name__)
  17. module_info = GiModuleInfo('Gio', '2.0')
  18. if module_info.available:
  19. binaries, datas, hiddenimports = module_info.collect_typelib_data()
  20. # Collect platform-specific module, otherwise it may be opportunistically loaded from the run-time system.
  21. hiddenimports += ['gi.repository.Gio' + ('Win32' if compat.is_win else 'Unix')]
  22. # Find Gio modules
  23. libdir = module_info.get_libdir()
  24. modules_pattern = None
  25. gio_libdir = os.path.join(libdir, 'gio', 'modules')
  26. runtime_path = 'gio_modules'
  27. lib_ext = '*.so'
  28. if compat.is_win:
  29. lib_ext = '*.dll'
  30. if not os.path.exists(gio_libdir):
  31. # homebrew/MSYS2 may install the files elsewhere...
  32. gio_libdir = os.path.join(os.path.commonprefix([compat.base_prefix, gio_libdir]), 'lib', 'gio', 'modules')
  33. if os.path.exists(gio_libdir):
  34. modules_pattern = os.path.join(gio_libdir, lib_ext)
  35. else:
  36. logger.warning('Could not determine Gio modules path!')
  37. if modules_pattern:
  38. for f in glob.glob(modules_pattern):
  39. binaries.append((f, runtime_path))
  40. cache_file = os.path.join(gio_libdir, 'giomodule.cache')
  41. if os.path.isfile(cache_file):
  42. datas.append((cache_file, runtime_path))
  43. else:
  44. # To add a new platform add a new elif above with the proper is_<platform> and proper pattern for finding the
  45. # Gio modules on your platform.
  46. logger.warning('Bundling Gio modules is not supported on your platform.')
  47. # Bundle the mime cache -- might not be needed on Windows
  48. # -> this is used for content type detection (also used by GdkPixbuf)
  49. # -> gio/xdgmime/xdgmime.c looks for mime/mime.cache in the users home directory, followed by XDG_DATA_DIRS if
  50. # specified in the environment, otherwise it searches /usr/local/share/ and /usr/share/
  51. if not compat.is_win:
  52. _mime_searchdirs = ['/usr/local/share', '/usr/share']
  53. if 'XDG_DATA_DIRS' in os.environ:
  54. _mime_searchdirs.insert(0, os.environ['XDG_DATA_DIRS'])
  55. for sd in _mime_searchdirs:
  56. spath = os.path.join(sd, 'mime', 'mime.cache')
  57. if os.path.exists(spath):
  58. datas.append((spath, 'share/mime'))
  59. break