hook-Cryptodome.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Cryptodome module: https://pypi.python.org/pypi/pycryptodomex
  14. Tested with Cryptodomex 3.4.2, Python 2.7 & 3.5, Windows
  15. """
  16. import os
  17. import glob
  18. from PyInstaller.compat import EXTENSION_SUFFIXES
  19. from PyInstaller.utils.hooks import get_module_file_attribute
  20. # Include the modules as binaries in a subfolder named like the package.
  21. # Cryptodome's loader expects to find them inside the package directory for
  22. # the main module. We cannot use hiddenimports because that would add the
  23. # modules outside the package.
  24. binaries = []
  25. binary_module_names = [
  26. 'Cryptodome.Cipher',
  27. 'Cryptodome.Util',
  28. 'Cryptodome.Hash',
  29. 'Cryptodome.Protocol',
  30. 'Cryptodome.Math',
  31. 'Cryptodome.PublicKey',
  32. ]
  33. for module_name in binary_module_names:
  34. m_dir = os.path.dirname(get_module_file_attribute(module_name))
  35. for ext in EXTENSION_SUFFIXES:
  36. module_bin = glob.glob(os.path.join(m_dir, '_*%s' % ext))
  37. for f in module_bin:
  38. binaries.append((f, module_name.replace('.', '/')))