hook-gi.repository.Gio.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2005-2021, 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. """
  12. Import hook for Gio https://developer.gnome.org/gio/stable/ from the GLib library https://wiki.gnome.org/Projects/GLib
  13. introspected through PyGobject https://wiki.gnome.org/PyGObject via the GObject Introspection middleware layer
  14. https://wiki.gnome.org/Projects/GObjectIntrospection
  15. Tested with GLib 2.44.1, PyGObject 3.16.2, GObject Introspection 1.44.0 on Mac OS X 10.10.5 and
  16. GLib 2.42.2, PyGObject 3.14.0, and GObject Introspection 1.42 on Windows 7
  17. """
  18. import glob
  19. import os
  20. import sys
  21. import PyInstaller.log as logging
  22. from PyInstaller.compat import is_darwin, is_win, is_linux, base_prefix
  23. from PyInstaller.utils.hooks.gi import get_gi_typelibs, get_gi_libdir
  24. logger = logging.getLogger(__name__)
  25. binaries, datas, hiddenimports = get_gi_typelibs('Gio', '2.0')
  26. libdir = get_gi_libdir('Gio', '2.0')
  27. path = None
  28. if is_win:
  29. pattern = os.path.join(libdir, 'gio', 'modules', '*.dll')
  30. elif is_darwin or is_linux:
  31. gio_libdir = os.path.join(libdir, 'gio', 'modules')
  32. if not os.path.exists(gio_libdir):
  33. # homebrew installs the files elsewhere..
  34. gio_libdir = os.path.join(os.path.commonprefix([base_prefix, gio_libdir]), 'lib', 'gio', 'modules')
  35. pattern = os.path.join(gio_libdir, '*.so')
  36. if pattern:
  37. for f in glob.glob(pattern):
  38. binaries.append((f, 'gio_modules'))
  39. else:
  40. # To add a new platform add a new elif above with the proper is_<platform> and
  41. # proper pattern for finding the Gio modules on your platform.
  42. logger.warning('Bundling Gio modules is currently not supported on your platform.')
  43. # Bundle the mime cache -- might not be needed on Windows
  44. # -> this is used for content type detection (also used by GdkPixbuf)
  45. # -> gio/xdgmime/xdgmime.c looks for mime/mime.cache in the users home directory,
  46. # followed by XDG_DATA_DIRS if specified in the environment, otherwise
  47. # it searches /usr/local/share/ and /usr/share/
  48. if not is_win:
  49. _mime_searchdirs = ['/usr/local/share', '/usr/share']
  50. if 'XDG_DATA_DIRS' in os.environ:
  51. _mime_searchdirs.insert(0, os.environ['XDG_DATA_DIRS'])
  52. for sd in _mime_searchdirs:
  53. spath = os.path.join(sd, 'mime', 'mime.cache')
  54. if os.path.exists(spath):
  55. datas.append((spath, 'share/mime'))
  56. break