Skip to content

Commit efbade0

Browse files
committed
Merge pull request #125 from bastibe/lib-handling
Move DLLs to submodule
2 parents d8657c1 + d2dd2de commit efbade0

File tree

7 files changed

+38
-516
lines changed

7 files changed

+38
-516
lines changed

.gitmodules

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

pysoundfile_data

Submodule pysoundfile_data added at fcf9ddc

setup.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
#!/usr/bin/env python
2-
import sys
2+
import os
3+
from platform import architecture
34
from setuptools import setup
45
from setuptools.command.test import test as TestCommand
5-
from sys import platform
6-
from platform import architecture
7-
import shutil
6+
import sys
7+
8+
# environment variables for cross-platform package creation
9+
platform = os.environ.get('PYSOUNDFILE_PLATFORM', sys.platform)
10+
architecture0 = os.environ.get('PYSOUNDFILE_ARCHITECTURE', architecture()[0])
11+
12+
if platform == 'darwin':
13+
libname = 'libsndfile.dylib'
14+
elif platform == 'win32':
15+
libname = 'libsndfile' + architecture0 + '.dll'
16+
else:
17+
libname = None
818

9-
if platform == 'win32' and architecture()[0] == '32bit':
10-
shutil.copy2('win/sndfile32.dll', 'win/sndfile.dll')
11-
sndfile = [('', ['win/sndfile.dll', 'win/sndfile_license'])]
12-
elif platform == 'win32' and architecture()[0] == '64bit':
13-
shutil.copy2('win/sndfile64.dll', 'win/sndfile.dll')
14-
sndfile = [('', ['win/sndfile.dll', 'win/sndfile_license'])]
19+
if libname:
20+
packages = ['pysoundfile_data']
21+
package_data = {'pysoundfile_data': [libname, 'COPYING']}
1522
else:
16-
sndfile = []
23+
packages = None
24+
package_data = None
1725

1826

1927
class PyTest(TestCommand):
@@ -44,7 +52,8 @@ def run_tests(self):
4452
url='https://github.com/bastibe/PySoundFile',
4553
keywords=['audio', 'libsndfile'],
4654
py_modules=['soundfile'],
47-
data_files=sndfile,
55+
packages=packages,
56+
package_data=package_data,
4857
license='BSD 3-Clause License',
4958
install_requires=['numpy',
5059
'cffi>=0.6'],

soundfile.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,19 @@
245245
_np.dtype('int16'): 'short'
246246
}
247247

248-
_snd = _ffi.dlopen('sndfile')
248+
try:
249+
_snd = _ffi.dlopen('sndfile')
250+
except OSError as err:
251+
if _sys.platform == 'darwin':
252+
_libname = 'libsndfile.dylib'
253+
elif _sys.platform == 'win32':
254+
from platform import architecture as _architecture
255+
_libname = 'libsndfile' + _architecture()[0] + '.dll'
256+
else:
257+
raise
258+
_snd = _ffi.dlopen(_os.path.join(
259+
_os.path.dirname(_os.path.abspath(__file__)),
260+
'pysoundfile_data', _libname))
249261

250262

251263
def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=True,

win/sndfile32.dll

-2.2 MB
Binary file not shown.

win/sndfile64.dll

-2.27 MB
Binary file not shown.

win/sndfile_license

Lines changed: 0 additions & 503 deletions
This file was deleted.

0 commit comments

Comments
 (0)