hook-importlib_resources.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2019-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. `importlib_resources` is a backport of the 3.9+ module `importlib.resources`
  13. """
  14. import os
  15. from PyInstaller.utils.hooks import get_module_file_attribute, \
  16. is_module_satisfies
  17. if is_module_satisfies("importlib_resources >= 1.2.0"):
  18. # since 1.2.0 importlib.metadata is used which PyInstaller knows how to
  19. # handle.
  20. pass
  21. else:
  22. # include the version.txt file, used to set __version__
  23. res_loc = os.path.dirname(get_module_file_attribute('importlib_resources'))
  24. datas = [
  25. (os.path.join(res_loc, 'version.txt'), 'importlib_resources'),
  26. ]
  27. if is_module_satisfies("importlib_resources >= 1.3.1"):
  28. hiddenimports = ['importlib_resources.trees']
  29. # this is only required for python2 support
  30. excludedimports = ['importlib_resources._py2']