Skip to content

Commit 1689a16

Browse files
committed
Add submodule with binaries and adapt setup procedure
1 parent 0529a60 commit 1689a16

File tree

7 files changed

+115
-3
lines changed

7 files changed

+115
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "_sounddevice_data"]
2+
path = _sounddevice_data
3+
url = https://github.com/spatialaudio/portaudio-binaries.git

CONTRIBUTING.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Contributions are always welcome!
99
Instead of pip-installing the latest release from PyPI, you should get the newest
1010
development version from Github_::
1111

12-
git clone https://github.com/spatialaudio/python-sounddevice.git
12+
git clone --recursive https://github.com/spatialaudio/python-sounddevice.git
1313
cd python-sounddevice
1414
python setup.py develop --user
1515

@@ -24,6 +24,12 @@ If you prefer, you can also replace the last command with::
2424

2525
... where ``-e`` stands for ``--editable``.
2626

27+
If you used the ``--recursive`` option when cloning, the dynamic libraries for
28+
Mac OS X and Windows should be available.
29+
If not, you can get the submodule with::
30+
31+
git submodule update --init --recursive
32+
2733
If you make changes to the documentation, you can re-create the HTML pages
2834
using Sphinx_.
2935
You can install it and a few other necessary packages with::

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ PortAudio library:
4545
The PortAudio_ library must be installed on your system (and CFFI must be
4646
able to find it). Again, you should use your package manager to install it.
4747
If you prefer, you can of course also download the sources and compile the
48-
library yourself.
48+
library yourself. If you are using Mac OS X or Windows, the library will be
49+
installed automagically with *pip* (see "Installation" below).
4950

5051
NumPy (optional):
5152
NumPy_ is only needed if you want to play back and record NumPy arrays.

_sounddevice_data

Submodule _sounddevice_data added at 435e05f

make_dist.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
# Create a source distribution and platform-specific wheel distributions.
4+
5+
PYTHON=python3
6+
7+
make_wheel()
8+
{
9+
$PYTHON setup.py clean --all
10+
PYTHON_SOUNDDEVICE_PLATFORM=$1 PYTHON_SOUNDDEVICE_ARCHITECTURE=$2 \
11+
$PYTHON setup.py bdist_wheel
12+
}
13+
14+
rm -rf sounddevice.egg-info/
15+
$PYTHON setup.py clean --all
16+
17+
$PYTHON setup.py sdist
18+
19+
# This creates a "pure" wheel:
20+
make_wheel Linux
21+
22+
# This is always 64bit:
23+
make_wheel Darwin
24+
25+
make_wheel Windows 32bit
26+
27+
make_wheel Windows 64bit
28+
29+
$PYTHON setup.py clean --all

setup.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import platform
13
from setuptools import setup
24

35
__version__ = "unknown"
@@ -8,10 +10,64 @@
810
exec(line)
911
break
1012

13+
PYTHON_INTERPRETERS = '.'.join([
14+
'cp26', 'cp27',
15+
'cp32', 'cp33', 'cp34', 'cp35',
16+
'pp27',
17+
'pp32',
18+
])
19+
MACOSX_VERSIONS = '.'.join([
20+
'macosx_10_6_x86_64',
21+
])
22+
23+
# environment variables for cross-platform package creation
24+
system = os.environ.get('PYTHON_SOUNDDEVICE_PLATFORM', platform.system())
25+
architecture0 = os.environ.get('PYTHON_SOUNDDEVICE_ARCHITECTURE',
26+
platform.architecture()[0])
27+
28+
if system == 'Darwin':
29+
libname = 'libportaudio.dylib'
30+
elif system == 'Windows':
31+
libname = 'libportaudio' + architecture0 + '.dll'
32+
else:
33+
libname = None
34+
35+
if libname:
36+
packages = ['_sounddevice_data']
37+
package_data = {'_sounddevice_data': [libname, 'README.md']}
38+
else:
39+
packages = None
40+
package_data = None
41+
42+
try:
43+
from wheel.bdist_wheel import bdist_wheel
44+
except ImportError:
45+
cmdclass = {}
46+
else:
47+
class bdist_wheel_half_pure(bdist_wheel):
48+
"""Create OS-dependent, but Python-independent wheels."""
49+
def get_tag(self):
50+
pythons = 'py2.py3.' + PYTHON_INTERPRETERS
51+
if system == 'Darwin':
52+
oses = MACOSX_VERSIONS
53+
elif system == 'Windows':
54+
if architecture0 == '32bit':
55+
oses = 'win32'
56+
else:
57+
oses = 'win_amd64'
58+
else:
59+
pythons = 'py2.py3'
60+
oses = 'any'
61+
return pythons, 'none', oses
62+
63+
cmdclass = {'bdist_wheel': bdist_wheel_half_pure}
64+
1165
setup(
1266
name="sounddevice",
1367
version=__version__,
1468
py_modules=["sounddevice"],
69+
packages=packages,
70+
package_data=package_data,
1571
install_requires=["CFFI"],
1672
extras_require={"NumPy": ["NumPy"]},
1773
author="Matthias Geier",
@@ -31,4 +87,5 @@
3187
"Programming Language :: Python :: 3",
3288
"Topic :: Multimedia :: Sound/Audio",
3389
],
90+
cmdclass=cmdclass,
3491
)

sounddevice.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import atexit as _atexit
2929
from cffi import FFI as _FFI
30+
import os as _os
31+
import platform as _platform
3032
import sys as _sys
3133

3234
_ffi = _FFI()
@@ -222,7 +224,20 @@
222224
void Pa_Sleep( long msec );
223225
""")
224226

225-
_lib = _ffi.dlopen("portaudio")
227+
try:
228+
_lib = _ffi.dlopen('portaudio')
229+
except OSError:
230+
if _platform.system() == 'Darwin':
231+
_libname = 'libportaudio.dylib'
232+
elif _platform.system() == 'Windows':
233+
_libname = 'libportaudio' + _platform.architecture()[0] + '.dll'
234+
else:
235+
raise
236+
_lib = _ffi.dlopen(_os.path.join(
237+
_os.path.dirname(_os.path.abspath(__file__)),
238+
'_sounddevice_data',
239+
_libname
240+
))
226241

227242
_sampleformats = {
228243
'float32': _lib.paFloat32,

0 commit comments

Comments
 (0)