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 librosa #582

Merged
merged 1 commit into from
May 14, 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
1 change: 1 addition & 0 deletions news/582.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add hook for ``librosa``.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ scikit-learn==1.2.2; python_version >= '3.8'
scikit-image==0.20.0; python_version >= '3.8'
customtkinter==5.1.3
fastparquet==2023.4.0; python_version >= '3.8'
librosa==0.10.0.post2

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

Expand Down
25 changes: 25 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-librosa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ------------------------------------------------------------------
# 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
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_data_files, collect_submodules

# Collect all data files from the package. These include:
# - package's and subpackages' .pyi files for `lazy_loader`
# - example data in librosa/util, required by `librosa.util.files`
# - librosa/core/intervals.msgpack, required by `librosa.core.intervals`
#
# We explicitly exclude `__pycache__` because it might contain .nbi and .nbc files from `numba` cache, which are not
# re-used by `numba` codepaths in the frozen application and are instead re-compiled in user-global cache directory.
datas = collect_data_files("librosa", excludes=['**/__pycache__'])
bwoodsend marked this conversation as resolved.
Show resolved Hide resolved

# And because modules are lazily loaded, we need to collect them all.
hiddenimports = collect_submodules("librosa")
27 changes: 27 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,3 +1588,30 @@ def test_fastparquet(pyi_builder):
pyi_builder.test_source("""
import fastparquet
""")


@importorskip('librosa')
def test_librosa(pyi_builder):
pyi_builder.test_source("""
import librosa

# Requires intervals.msgpack data file
import librosa.core.intervals

# Requires example files on import
import librosa.util.files
""")


@importorskip('librosa')
def test_librosa_util_function(pyi_builder):
# Test that functions from `librosa.util` that use `numba` vectorization can be run in frozen application.
pyi_builder.test_source("""
import librosa.util
import numpy as np

x = np.array([1, 0, 1, 2, -1, 0, -2, 1])
result = librosa.util.localmin(x)
expected = np.array([False, True, False, False, True, False, True, False])
assert (result == expected).all()
""")