diff --git a/MANIFEST.in b/MANIFEST.in index 90a504a..010e7b1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include LICENSE +graft win recursive-include doc *.py *.rst *.txt Makefile recursive-include tests *.py *.wav *.raw diff --git a/pysoundfile.py b/pysoundfile.py index 7b58944..d4ae079 100644 --- a/pysoundfile.py +++ b/pysoundfile.py @@ -14,6 +14,8 @@ import os as _os from cffi import FFI as _FFI from os import SEEK_SET, SEEK_CUR, SEEK_END +from sys import platform as _platform +from platform import architecture as _architecture _ffi = _FFI() _ffi.cdef(""" @@ -238,7 +240,16 @@ _np.dtype('int16'): 'short' } -_snd = _ffi.dlopen('sndfile') +try: + _snd = _ffi.dlopen('sndfile') +except OSError as e: + if _platform == 'win32': + try: + _snd = _ffi.dlopen('libsndfile-1') + except OSError: + _snd = _ffi.dlopen('sndfile' + _architecture()[0]) + else: + raise e def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=True, diff --git a/setup.py b/setup.py index c4d3eb3..e7b68dc 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,6 @@ #!/usr/bin/env python -import sys from setuptools import setup 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'])] -else: - sndfile = [] class PyTest(TestCommand): @@ -30,6 +17,7 @@ def finalize_options(self): def run_tests(self): # import here, cause outside the eggs aren't loaded + import sys import pytest errno = pytest.main(self.pytest_args) sys.exit(errno) @@ -44,7 +32,13 @@ def run_tests(self): url='https://github.com/bastibe/PySoundFile', keywords=['audio', 'libsndfile'], py_modules=['pysoundfile'], - data_files=sndfile, + data_files=[ + ('', [ + 'win/sndfile64bit.dll', + 'win/sndfile32bit.dll', + 'win/sndfile_license' + ]) + ], license='BSD 3-Clause License', install_requires=['numpy', 'cffi>=0.6'], diff --git a/win/sndfile32.dll b/win/sndfile32bit.dll similarity index 100% rename from win/sndfile32.dll rename to win/sndfile32bit.dll diff --git a/win/sndfile64.dll b/win/sndfile64bit.dll similarity index 100% rename from win/sndfile64.dll rename to win/sndfile64bit.dll