diff --git a/pysoundfile_binaries/__init__.py b/pysoundfile_binaries/__init__.py new file mode 100644 index 0000000..0cd8e67 --- /dev/null +++ b/pysoundfile_binaries/__init__.py @@ -0,0 +1 @@ +# This is only a dummy package for PySoundFile's binaries diff --git a/pysoundfile_binaries/libsndfile_darwin.dylib b/pysoundfile_binaries/libsndfile_darwin.dylib new file mode 100644 index 0000000..ab75248 Binary files /dev/null and b/pysoundfile_binaries/libsndfile_darwin.dylib differ diff --git a/win/sndfile_license b/pysoundfile_binaries/libsndfile_license similarity index 100% rename from win/sndfile_license rename to pysoundfile_binaries/libsndfile_license diff --git a/win/sndfile32.dll b/pysoundfile_binaries/libsndfile_win32.dll similarity index 100% rename from win/sndfile32.dll rename to pysoundfile_binaries/libsndfile_win32.dll diff --git a/win/sndfile64.dll b/pysoundfile_binaries/libsndfile_win64.dll similarity index 100% rename from win/sndfile64.dll rename to pysoundfile_binaries/libsndfile_win64.dll diff --git a/setup.py b/setup.py index 483fa65..9448374 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,24 @@ #!/usr/bin/env python import sys -from setuptools import setup +from setuptools import setup, Distribution from setuptools.command.test import test as TestCommand from sys import platform from platform import architecture -import shutil -if platform == 'win32' and architecture()[0] == '32bit': - shutil.copy2('win/sndfile32.dll', 'win/sndfile.dll') - sndfile = [('', ['win/sndfile.dll', 'win/sndfile_license'])] -elif platform == 'win32' and architecture()[0] == '64bit': - shutil.copy2('win/sndfile64.dll', 'win/sndfile.dll') - sndfile = [('', ['win/sndfile.dll', 'win/sndfile_license'])] +if platform in ('darwin', 'win32'): + packages = ['pysoundfile_binaries'] + package_data = {'pysoundfile_binaries': + ['pysoundfile_binaries/libsndfile_license']} + if platform == 'darwin': + package_data['pysoundfile_binaries'] += \ + ['pysoundfile_binaries/libsndfile_darwin.dylib'] + elif platform == 'win32': + package_data['pysoundfile_binaries'] += \ + ['pysoundfile_binaries/libsndfile_win_{}.dll' + .format(architecture()[0])] else: - sndfile = [] + package_data = [] + packages = [] class PyTest(TestCommand): @@ -35,6 +40,11 @@ def run_tests(self): sys.exit(errno) +class BinaryDistribution(Distribution): + def is_pure(self): + return False + + setup( name='PySoundFile', version='0.6.0', @@ -43,8 +53,9 @@ def run_tests(self): author_email='basti@bastibe.de', url='https://github.com/bastibe/PySoundFile', keywords=['audio', 'libsndfile'], + packages=packages, + package_data=package_data, py_modules=['soundfile'], - data_files=sndfile, license='BSD 3-Clause License', install_requires=['numpy', 'cffi>=0.6'], @@ -66,4 +77,5 @@ def run_tests(self): long_description=open('README.rst').read(), tests_require=['pytest'], cmdclass={'test': PyTest}, + distclass=BinaryDistribution, ) diff --git a/soundfile.py b/soundfile.py index cddf40a..fe1079b 100644 --- a/soundfile.py +++ b/soundfile.py @@ -238,7 +238,24 @@ _np.dtype('int16'): 'short' } -_snd = _ffi.dlopen('sndfile') + +try: + _snd = _ffi.dlopen('sndfile') +except OSError as err: + from sys import platform as _platform + from platform import architecture as _architecture + + + if _platform in ('darwin', 'win32'): + to_here = _os.path.dirname(_os.path.abspath(__file__)) + if _platform == 'darwin': + from_here = 'pysoundfile_binaries/libsndfile_darwin.dylib' + elif _platform == 'win32': + from_here = ('pysoundfile_binaries/libsndfile_win_{}.dll' + .format(_architecture()[0])) + _snd = _ffi.dlopen(_os.path.join(to_here, from_here)) + else: + raise def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=True,