hook-pypemicro.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2022 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. # Hook for the pypemicro module: https://github.com/nxpmicro/pypemicro
  13. import os
  14. from PyInstaller.utils.hooks import get_package_paths, is_module_satisfies
  15. from PyInstaller.log import logger
  16. from PyInstaller.compat import is_darwin
  17. binaries = list()
  18. if is_module_satisfies('pyinstaller >= 5.0'):
  19. from PyInstaller import isolated
  20. @isolated.decorate
  21. def get_safe_libs():
  22. from pypemicro import PyPemicro
  23. libs = PyPemicro.get_pemicro_lib_list()
  24. return libs
  25. pkg_base, pkg_dir = get_package_paths("pypemicro")
  26. for lib in get_safe_libs():
  27. source_path = lib['path']
  28. source_name = lib['name']
  29. dest = os.path.relpath(source_path, pkg_base)
  30. binaries.append((os.path.join(source_path, source_name), dest))
  31. if is_darwin:
  32. libusb = os.path.join(source_path, 'libusb.dylib')
  33. if os.path.exists(libusb):
  34. binaries.append((libusb, dest))
  35. else:
  36. logger.warning("libusb.dylib was not found for Mac OS, ignored")
  37. else:
  38. logger.warning("hook-pypemicro requires pyinstaller >= 5.0")