summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2015-07-01 17:12:27 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2015-07-01 17:27:07 +0200
commit1689a1642e054750d9e17574eb012f242f0991c0 (patch)
tree8a309cf67a37cab47ee17ec8ed339a800d2158c4
parent0529a60f464801f27817817b68410e5cd1e088f6 (diff)
Add submodule with binaries and adapt setup procedure
-rw-r--r--.gitmodules3
-rw-r--r--CONTRIBUTING.rst8
-rw-r--r--README.rst3
m---------_sounddevice_data0
-rwxr-xr-xmake_dist.sh29
-rw-r--r--setup.py57
-rw-r--r--sounddevice.py17
7 files changed, 114 insertions, 3 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..9010351
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "_sounddevice_data"]
+ path = _sounddevice_data
+ url = https://github.com/spatialaudio/portaudio-binaries.git
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 0f168d8..3cd9ed0 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -9,7 +9,7 @@ Contributions are always welcome!
Instead of pip-installing the latest release from PyPI, you should get the newest
development version from Github_::
- git clone https://github.com/spatialaudio/python-sounddevice.git
+ git clone --recursive https://github.com/spatialaudio/python-sounddevice.git
cd python-sounddevice
python setup.py develop --user
@@ -24,6 +24,12 @@ If you prefer, you can also replace the last command with::
... where ``-e`` stands for ``--editable``.
+If you used the ``--recursive`` option when cloning, the dynamic libraries for
+Mac OS X and Windows should be available.
+If not, you can get the submodule with::
+
+ git submodule update --init --recursive
+
If you make changes to the documentation, you can re-create the HTML pages
using Sphinx_.
You can install it and a few other necessary packages with::
diff --git a/README.rst b/README.rst
index 4f0d518..95f1749 100644
--- a/README.rst
+++ b/README.rst
@@ -45,7 +45,8 @@ PortAudio library:
The PortAudio_ library must be installed on your system (and CFFI must be
able to find it). Again, you should use your package manager to install it.
If you prefer, you can of course also download the sources and compile the
- library yourself.
+ library yourself. If you are using Mac OS X or Windows, the library will be
+ installed automagically with *pip* (see "Installation" below).
NumPy (optional):
NumPy_ is only needed if you want to play back and record NumPy arrays.
diff --git a/_sounddevice_data b/_sounddevice_data
new file mode 160000
+Subproject 435e05f0b21cd9342968bd2dc1e296cefcc6dab
diff --git a/make_dist.sh b/make_dist.sh
new file mode 100755
index 0000000..0713b49
--- /dev/null
+++ b/make_dist.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Create a source distribution and platform-specific wheel distributions.
+
+PYTHON=python3
+
+make_wheel()
+{
+ $PYTHON setup.py clean --all
+ PYTHON_SOUNDDEVICE_PLATFORM=$1 PYTHON_SOUNDDEVICE_ARCHITECTURE=$2 \
+ $PYTHON setup.py bdist_wheel
+}
+
+rm -rf sounddevice.egg-info/
+$PYTHON setup.py clean --all
+
+$PYTHON setup.py sdist
+
+# This creates a "pure" wheel:
+make_wheel Linux
+
+# This is always 64bit:
+make_wheel Darwin
+
+make_wheel Windows 32bit
+
+make_wheel Windows 64bit
+
+$PYTHON setup.py clean --all
diff --git a/setup.py b/setup.py
index bd9145a..2dfa3c5 100644
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,5 @@
+import os
+import platform
from setuptools import setup
__version__ = "unknown"
@@ -8,10 +10,64 @@ for line in open("sounddevice.py"):
exec(line)
break
+PYTHON_INTERPRETERS = '.'.join([
+ 'cp26', 'cp27',
+ 'cp32', 'cp33', 'cp34', 'cp35',
+ 'pp27',
+ 'pp32',
+])
+MACOSX_VERSIONS = '.'.join([
+ 'macosx_10_6_x86_64',
+])
+
+# environment variables for cross-platform package creation
+system = os.environ.get('PYTHON_SOUNDDEVICE_PLATFORM', platform.system())
+architecture0 = os.environ.get('PYTHON_SOUNDDEVICE_ARCHITECTURE',
+ platform.architecture()[0])
+
+if system == 'Darwin':
+ libname = 'libportaudio.dylib'
+elif system == 'Windows':
+ libname = 'libportaudio' + architecture0 + '.dll'
+else:
+ libname = None
+
+if libname:
+ packages = ['_sounddevice_data']
+ package_data = {'_sounddevice_data': [libname, 'README.md']}
+else:
+ packages = None
+ package_data = None
+
+try:
+ from wheel.bdist_wheel import bdist_wheel
+except ImportError:
+ cmdclass = {}
+else:
+ class bdist_wheel_half_pure(bdist_wheel):
+ """Create OS-dependent, but Python-independent wheels."""
+ def get_tag(self):
+ pythons = 'py2.py3.' + PYTHON_INTERPRETERS
+ if system == 'Darwin':
+ oses = MACOSX_VERSIONS
+ elif system == 'Windows':
+ if architecture0 == '32bit':
+ oses = 'win32'
+ else:
+ oses = 'win_amd64'
+ else:
+ pythons = 'py2.py3'
+ oses = 'any'
+ return pythons, 'none', oses
+
+ cmdclass = {'bdist_wheel': bdist_wheel_half_pure}
+
setup(
name="sounddevice",
version=__version__,
py_modules=["sounddevice"],
+ packages=packages,
+ package_data=package_data,
install_requires=["CFFI"],
extras_require={"NumPy": ["NumPy"]},
author="Matthias Geier",
@@ -31,4 +87,5 @@ setup(
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Sound/Audio",
],
+ cmdclass=cmdclass,
)
diff --git a/sounddevice.py b/sounddevice.py
index b1c377a..b4f505f 100644
--- a/sounddevice.py
+++ b/sounddevice.py
@@ -27,6 +27,8 @@ __version__ = "0.1.0"
import atexit as _atexit
from cffi import FFI as _FFI
+import os as _os
+import platform as _platform
import sys as _sys
_ffi = _FFI()
@@ -222,7 +224,20 @@ PaError Pa_GetSampleSize( PaSampleFormat format );
void Pa_Sleep( long msec );
""")
-_lib = _ffi.dlopen("portaudio")
+try:
+ _lib = _ffi.dlopen('portaudio')
+except OSError:
+ if _platform.system() == 'Darwin':
+ _libname = 'libportaudio.dylib'
+ elif _platform.system() == 'Windows':
+ _libname = 'libportaudio' + _platform.architecture()[0] + '.dll'
+ else:
+ raise
+ _lib = _ffi.dlopen(_os.path.join(
+ _os.path.dirname(_os.path.abspath(__file__)),
+ '_sounddevice_data',
+ _libname
+ ))
_sampleformats = {
'float32': _lib.paFloat32,