hook-toga.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2024 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ------------------------------------------------------------------
  12. from PyInstaller import compat
  13. from PyInstaller.utils.hooks import collect_data_files, collect_submodules, copy_metadata, is_module_satisfies
  14. hiddenimports = []
  15. # Select the platform-specific backend.
  16. if compat.is_darwin:
  17. backend = 'cocoa'
  18. elif compat.is_linux:
  19. backend = 'gtk'
  20. elif compat.is_win:
  21. backend = 'winforms'
  22. else:
  23. backend = None
  24. if backend is not None:
  25. hiddenimports += [f'toga_{backend}', f'toga_{backend}.factory']
  26. # Collect metadata for toga-core dist, which is used by toga module to determine its version.
  27. datas = copy_metadata("toga-core")
  28. # Prevent `toga` from pulling `setuptools_scm` into frozen application, as it makes no sense in that context.
  29. excludedimports = ["setuptools_scm"]
  30. # `toga` 0.5.0 refactored its `__init__.py` to lazy-load its core modules. Therefore, we now need to collect
  31. # submodules via `collect_submodules`...
  32. if is_module_satisfies("toga >= 0.5.0"):
  33. hiddenimports += collect_submodules("toga")
  34. # Starting with `toga` 0.5.2, we need to collect .pyi files.
  35. if is_module_satisfies("toga >= 0.5.2"):
  36. datas += collect_data_files("toga")