hook-numba.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #
  13. # NumPy aware dynamic Python compiler using LLVM
  14. # https://github.com/numba/numba
  15. #
  16. # Tested with:
  17. # numba 0.26 (Anaconda 4.1.1, Windows), numba 0.28 (Linux)
  18. from PyInstaller.utils.hooks import is_module_satisfies
  19. excludedimports = ["IPython", "scipy"]
  20. hiddenimports = ["llvmlite"]
  21. # numba 0.59.0 updated its vendored version of cloudpickle to 3.0.0; this version keeps `cloudpickle_fast` module
  22. # around for backward compatibility with existing pickled data, but does not import it directly anymore.
  23. if is_module_satisfies("numba >= 0.59.0"):
  24. hiddenimports += ["numba.cloudpickle.cloudpickle_fast"]
  25. # numba 0.61 introduced new type system with several dynamic redirects using `numba.core.utils._RedirectSubpackage`;
  26. # depending on the run-time value of `numba.config.USE_LEGACY_TYPE_SYSTEM`, either "old" or "new" module variant is
  27. # loaded. All of these seem to be loaded when `numba` is imported, so there is no need for finer granularity. Also,
  28. # as the config value might be manipulated at run-time (e.g., via environment variable), we need to collect both old
  29. # and new module variants.
  30. # numba 0.62 reverted the change, removing the new type system.
  31. if is_module_satisfies("numba >= 0.61.0rc1, < 0.62.0rc1"):
  32. # NOTE: `numba.core.typing` is also referenced indirectly via `_RedirectSubpackage`, but we do not need a
  33. # hidden import entry for it, because we have entries for its submodules.
  34. modules_old = [
  35. 'numba.core.datamodel.old_models',
  36. 'numba.core.old_boxing',
  37. 'numba.core.types.old_scalars',
  38. 'numba.core.typing.old_builtins',
  39. 'numba.core.typing.old_cmathdecl',
  40. 'numba.core.typing.old_mathdecl',
  41. 'numba.cpython.old_builtins',
  42. 'numba.cpython.old_hashing',
  43. 'numba.cpython.old_mathimpl',
  44. 'numba.cpython.old_numbers',
  45. 'numba.cpython.old_tupleobj',
  46. 'numba.np.old_arraymath',
  47. 'numba.np.random.old_distributions',
  48. 'numba.np.random.old_random_methods',
  49. ]
  50. modules_new = [name.replace('.old_', '.new_') for name in modules_old]
  51. hiddenimports += modules_old + modules_new