hook-astropy.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2020 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.utils.hooks import collect_data_files, collect_submodules, \
  13. copy_metadata, is_module_satisfies
  14. # Astropy includes a number of non-Python files that need to be present
  15. # at runtime, so we include these explicitly here.
  16. datas = collect_data_files('astropy')
  17. # In a number of places, astropy imports other sub-modules in a way that is not
  18. # always auto-discovered by pyinstaller, so we always include all submodules.
  19. hiddenimports = collect_submodules('astropy')
  20. # We now need to include the *_parsetab.py and *_lextab.py files for unit and
  21. # coordinate parsing, since these are loaded as files rather than imported as
  22. # sub-modules. We leverage collect_data_files to get all files in astropy then
  23. # filter these.
  24. ply_files = []
  25. for path, target in collect_data_files('astropy', include_py_files=True):
  26. if path.endswith(('_parsetab.py', '_lextab.py')):
  27. ply_files.append((path, target))
  28. datas += ply_files
  29. # Astropy version >= 5.0 queries metadata to get version information.
  30. if is_module_satisfies('astropy >= 5.0'):
  31. datas += copy_metadata('astropy')
  32. datas += copy_metadata('numpy')
  33. # In the Cython code, Astropy imports numpy.lib.recfunctions which isn't
  34. # automatically discovered by pyinstaller, so we add this as a hidden import.
  35. hiddenimports += ['numpy.lib.recfunctions']