hook-zmq.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. Hook for PyZMQ. Cython based Python bindings for messaging library ZeroMQ.
  14. http://www.zeromq.org/
  15. """
  16. import os
  17. import glob
  18. from PyInstaller.utils.hooks import collect_submodules
  19. from PyInstaller.utils.hooks import is_module_satisfies, get_module_file_attribute
  20. from PyInstaller.compat import is_win
  21. binaries = []
  22. datas = []
  23. hiddenimports = ['zmq.utils.garbage']
  24. # PyZMQ comes with two backends, cython and cffi. Calling collect_submodules()
  25. # on zmq.backend seems to trigger attempt at compilation of C extension
  26. # module for cffi backend, which will fail if ZeroMQ development files
  27. # are not installed on the system. On non-English locales, the resulting
  28. # localized error messages may cause UnicodeDecodeError. Collecting each
  29. # backend individually, however, does not seem to cause any problems.
  30. hiddenimports += ['zmq.backend']
  31. # cython backend
  32. hiddenimports += collect_submodules('zmq.backend.cython')
  33. # cffi backend: contains extra data that needs to be collected
  34. # (e.g., _cdefs.h)
  35. #
  36. # NOTE: the cffi backend requires compilation of C extension at runtime,
  37. # which appears to be broken in frozen program. So avoid collecting
  38. # it altogether...
  39. if False:
  40. from PyInstaller.utils.hooks import collect_data_files
  41. hiddenimports += collect_submodules('zmq.backend.cffi')
  42. datas += collect_data_files('zmq.backend.cffi', excludes=['**/__pycache__', ])
  43. # Starting with pyzmq 22.0.0, the DLLs in Windows wheel are located in
  44. # site-packages/pyzmq.libs directory along with a .load_order file. This
  45. # file is required on python 3.7 and earlier. On later versions of python,
  46. # the pyzmq.libs is required to exist.
  47. if is_win and is_module_satisfies('pyzmq >= 22.0.0'):
  48. zmq_root = os.path.dirname(get_module_file_attribute('zmq'))
  49. libs_dir = os.path.join(zmq_root, os.path.pardir, 'pyzmq.libs')
  50. # .load_order file (22.0.3 replaced underscore with dash and added
  51. # version suffix on this file, hence the glob)
  52. load_order_file = glob.glob(os.path.join(libs_dir, '.load*'))
  53. datas += [(filename, 'pyzmq.libs') for filename in load_order_file]
  54. # We need to collect DLLs into _MEIPASS, to avoid duplication due to
  55. # subsequent binary analysis
  56. dll_files = glob.glob(os.path.join(libs_dir, "*.dll"))
  57. binaries += [(dll_file, '.') for dll_file in dll_files]