hook-pylsl.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2023 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 logger, isolated
  14. def find_library():
  15. # Try importing pylsl - this will fail if the shared library is unavailable.
  16. try:
  17. import pylsl # noqa: F401
  18. except Exception:
  19. return None
  20. # Return the path to shared library that is used by pylsl.
  21. try:
  22. from pylsl.lib import lib as cdll # pylsl >= 0.17.0
  23. except ImportError:
  24. from pylsl.pylsl import lib as cdll # older versions
  25. return cdll._name
  26. # whenever a hook needs to load a 3rd party library, it needs to be done in an isolated subprocess
  27. libfile = isolated.call(find_library)
  28. if libfile:
  29. # add the liblsl library to the binaries
  30. # it gets packaged in pylsl/lib, which is where pylsl will look first
  31. binaries = [(libfile, os.path.join('pylsl', 'lib'))]
  32. else:
  33. logger.warning("liblsl shared library not found - pylsl will likely fail to work!")
  34. binaries = []