hook-gi.repository.Gio.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 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 PyInstaller.log as logging
  21. from PyInstaller.compat import base_prefix, is_darwin, is_linux, is_win
  22. from PyInstaller.utils.hooks.gi import get_gi_libdir, get_gi_typelibs
  23. logger = logging.getLogger(__name__)
  24. binaries, datas, hiddenimports = get_gi_typelibs('Gio', '2.0')
  25. libdir = get_gi_libdir('Gio', '2.0')
  26. path = None
  27. if is_win:
  28. pattern = os.path.join(libdir, 'gio', 'modules', '*.dll')
  29. elif is_darwin or is_linux:
  30. gio_libdir = os.path.join(libdir, 'gio', 'modules')
  31. if not os.path.exists(gio_libdir):
  32. # homebrew installs the files elsewhere..
  33. gio_libdir = os.path.join(os.path.commonprefix([base_prefix, gio_libdir]), 'lib', 'gio', 'modules')
  34. pattern = os.path.join(gio_libdir, '*.so')
  35. if pattern:
  36. for f in glob.glob(pattern):
  37. binaries.append((f, 'gio_modules'))
  38. else:
  39. # To add a new platform add a new elif above with the proper is_<platform> and proper pattern for finding the Gio
  40. # modules on your platform.
  41. logger.warning('Bundling Gio modules is currently not supported on your platform.')
  42. # Bundle the mime cache -- might not be needed on Windows
  43. # -> this is used for content type detection (also used by GdkPixbuf)
  44. # -> gio/xdgmime/xdgmime.c looks for mime/mime.cache in the users home directory, followed by XDG_DATA_DIRS if specified
  45. # in the environment, otherwise it searches /usr/local/share/ and /usr/share/
  46. if not is_win:
  47. _mime_searchdirs = ['/usr/local/share', '/usr/share']
  48. if 'XDG_DATA_DIRS' in os.environ:
  49. _mime_searchdirs.insert(0, os.environ['XDG_DATA_DIRS'])
  50. for sd in _mime_searchdirs:
  51. spath = os.path.join(sd, 'mime', 'mime.cache')
  52. if os.path.exists(spath):
  53. datas.append((spath, 'share/mime'))
  54. break