hook-discid.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. import os
  13. from PyInstaller.utils.hooks import get_module_attribute, logger
  14. from PyInstaller.depend.utils import _resolveCtypesImports
  15. binaries = []
  16. # Use the _LIB_NAME attribute of discid.libdiscid to resolve the shared library name. This saves us from having to
  17. # duplicate the name guessing logic from discid.libdiscid.
  18. # On error, PyInstaller >= 5.0 raises exception, earlier versions return an empty string.
  19. try:
  20. lib_name = get_module_attribute("discid.libdiscid", "_LIB_NAME")
  21. except Exception:
  22. lib_name = None
  23. if lib_name:
  24. lib_name = os.path.basename(lib_name)
  25. try:
  26. resolved_binary = _resolveCtypesImports([lib_name])
  27. lib_file = resolved_binary[0][1]
  28. except Exception as e:
  29. lib_file = None
  30. logger.warning("Error while trying to resolve %s: %s", lib_name, e)
  31. if lib_file:
  32. binaries += [(lib_file, '.')]
  33. else:
  34. logger.warning("Failed to determine name of libdiscid shared library from _LIB_NAME attribute of discid.libdiscid!")