-
Notifications
You must be signed in to change notification settings - Fork 161
/
hook-sounddevice.py
74 lines (62 loc) · 2.65 KB
/
hook-sounddevice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# ------------------------------------------------------------------
# Copyright (c) 2020 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
# ------------------------------------------------------------------
"""
sounddevice:
https://github.com/spatialaudio/python-sounddevice/
"""
import os
import pathlib
from PyInstaller.compat import is_darwin
from PyInstaller.utils.hooks import get_module_file_attribute, logger
binaries = []
datas = []
# PyPI wheels for Windows and macOS ship the sndfile shared library in _sounddevice_data directory,
# located next to the sounddevice.py module file (i.e., in the site-packages directory).
module_dir = pathlib.Path(get_module_file_attribute('sounddevice')).parent
data_dir = module_dir / '_sounddevice_data' / 'portaudio-binaries'
if is_darwin:
# for Macos Big Sur, the stable portaudio (19.6.0) makes Friture freeze on startup
# so we build our own and bundle it manually here
path = "/usr/local/lib/libportaudio.dylib"
destdir = str(data_dir.relative_to(module_dir))
binaries += [(path, destdir)]
if not os.path.isfile(path):
raise ValueError('libportaudio could not be found')
elif data_dir.is_dir():
destdir = str(data_dir.relative_to(module_dir))
# Collect the shared library (known variants: libportaudio64bit.dll, libportaudio32bit.dll, libportaudio.dylib)
for lib_file in data_dir.glob("libportaudio*.*"):
binaries += [(str(lib_file), destdir)]
# Collect the README.md file
readme_file = data_dir / "README.md"
if readme_file.is_file():
datas += [(str(readme_file), destdir)]
else:
# On linux and in Anaconda in all OSes, the system-installed portaudio library needs to be collected.
def _find_system_portaudio_library():
import os
import ctypes.util
from PyInstaller.depend.utils import _resolveCtypesImports
libname = ctypes.util.find_library("portaudio")
if libname is not None:
resolved_binary = _resolveCtypesImports([os.path.basename(libname)])
if resolved_binary:
return resolved_binary[0][1]
try:
lib_file = _find_system_portaudio_library()
except Exception as e:
logger.warning("Error while trying to find system-installed portaudio library: %s", e)
lib_file = None
if lib_file:
binaries += [(lib_file, '.')]
if not binaries:
logger.warning("portaudio shared library not found - sounddevice will likely fail to work!")