From 6708c44e4d1b56888fc6670a02ab3631cfbbcb60 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sat, 13 May 2023 19:41:58 +0200 Subject: [PATCH] Add hook for librosa --- requirements-test-libraries.txt | 1 + .../hooks/stdhooks/hook-librosa.py | 22 +++++++++++++++++++ .../tests/test_libraries.py | 13 +++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-librosa.py diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index ecceca8c6..8757ee8e5 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -124,6 +124,7 @@ NBT==1.5.1 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' +librosa==0.10.0.post2 # ------------------- Platform (OS) specifics diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-librosa.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-librosa.py new file mode 100644 index 000000000..241fdae3c --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-librosa.py @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------ +# 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` +datas = collect_data_files("librosa", excludes=['**/__pycache__']) + +# And because modules are lazily loaded, we need to collect them all. +hiddenimports = collect_submodules("librosa") diff --git a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py index be8b04ada..c3b628a46 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -1552,3 +1552,16 @@ def test_moviepy_editor(pyi_builder): pyi_builder.test_source(""" import moviepy.editor """) + + +@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 + """)