Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute PySoundFile as wheels #116

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pysoundfile_binaries/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is only a dummy package for PySoundFile's binaries
Binary file added pysoundfile_binaries/libsndfile_darwin.dylib
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 22 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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']}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the repetition of pysoundfile_binaries intentional?
For me it doesn't work like this.

if platform == 'darwin':
package_data['pysoundfile_binaries'] += \
['pysoundfile_binaries/libsndfile_darwin.dylib']
elif platform == 'win32':
package_data['pysoundfile_binaries'] += \
['pysoundfile_binaries/libsndfile_win_{}.dll'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work for libsndfile_win_64bit.dll, but the file is named libsndfile_win64.dll!

.format(architecture()[0])]
else:
sndfile = []
package_data = []
packages = []


class PyTest(TestCommand):
Expand All @@ -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',
Expand All @@ -43,8 +53,9 @@ def run_tests(self):
author_email='[email protected]',
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'],
Expand All @@ -66,4 +77,5 @@ def run_tests(self):
long_description=open('README.rst').read(),
tests_require=['pytest'],
cmdclass={'test': PyTest},
distclass=BinaryDistribution,
)
19 changes: 18 additions & 1 deletion soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down