Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for pylsl #573

Merged
merged 13 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ jobs:
brew install pango
# Install libdiscid (dependency of discid python package).
brew install libdiscid
# Install lsl library for pylsl
brew install labstreaminglayer/tap/lsl

- name: Install dependencies
shell: bash
Expand Down
1 change: 1 addition & 0 deletions news/573.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add hook for ``pylsl``
4 changes: 3 additions & 1 deletion requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ minecraft-launcher-lib==5.3; python_version >= '3.8'
scikit-learn==1.2.2; python_version >= '3.8'
scikit-image==0.20.0; python_version >= '3.8'


# ------------------- Platform (OS) specifics

# PyEnchant only pre-builds macOS and Windows
Expand All @@ -140,5 +139,8 @@ pywin32-ctypes==0.2.0; sys_platform == 'win32'
# pymediainfo on linux does not bundle mediainfo shared library, and requires system one.
pymediainfo==6.0.1; sys_platform == 'darwin' or sys_platform == 'win32'

# the required library can be installed with "brew install labstreaminglayer/tap/lsl" on macOS, or with "conda install liblsl" on any platform
pylsl==1.16.1; sys_platform == "darwin"

# Include the requirements for testing
-r requirements-test.txt
41 changes: 41 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

import os
from PyInstaller.utils.hooks import logger, isolated


def find_library():
try:
# the import will fail it the library cannot be found
from pylsl import pylsl

# the find_liblsl_libraries() is a generator function that yields multiple possibilities
for libfile in pylsl.find_liblsl_libraries():
if libfile:
break
except (ImportError, ModuleNotFoundError, RuntimeError) as error:
print(error)
libfile = None
return libfile


# whenever a hook needs to load a 3rd party library, it needs to be done in an isolated subprocess
libfile = isolated.call(find_library)

if libfile:
# add the liblsl library to the binaries
# it gets packaged in pylsl/lib, which is where pylsl will look first
binaries = [(libfile, os.path.join('pylsl', 'lib'))]
else:
logger.warning("liblsl shared library not found - pylsl will likely fail to work!")
binaries = []
9 changes: 9 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ def test_markdown(pyi_builder):
""")


@importorskip('pylsl')
def test_pylsl(pyi_builder):
pyi_builder.test_source(
"""
import pylsl
print(pylsl.version.__version__)
""")


@importorskip('lxml')
def test_lxml_isoschematron(pyi_builder):
pyi_builder.test_source(
Expand Down