hook-netCDF4.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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.compat import is_win
  13. from PyInstaller.utils.hooks import is_module_satisfies
  14. # netCDF4 (tested with v.1.1.9) has some hidden imports
  15. hiddenimports = ['netCDF4.utils']
  16. # Around netCDF4 1.4.0, netcdftime changed name to cftime
  17. if is_module_satisfies("netCDF4 < 1.4.0"):
  18. hiddenimports += ['netcdftime']
  19. else:
  20. hiddenimports += ['cftime']
  21. # Starting with netCDF 1.6.4, certifi is a hidden import made in
  22. # netCDF4/_netCDF4.pyx.
  23. if is_module_satisfies("netCDF4 >= 1.6.4"):
  24. hiddenimports += ['certifi']
  25. # netCDF 1.6.2 is the first version that uses `delvewheel` for bundling DLLs in Windows PyPI wheels. While contemporary
  26. # PyInstaller versions automatically pick up DLLs from external `netCDF4.libs` directory, this does not work on Anaconda
  27. # python 3.8 and 3.9 due to defunct `os.add_dll_directory`, which forces `delvewheel` to use the old load-order file
  28. # approach. So we need to explicitly ensure that load-order file as well as DLLs are collected.
  29. if is_win and is_module_satisfies("netCDF4 >= 1.6.2"):
  30. if is_module_satisfies("PyInstaller >= 5.6"):
  31. from PyInstaller.utils.hooks import collect_delvewheel_libs_directory
  32. datas, binaries = collect_delvewheel_libs_directory("netCDF4")