Skip to content

Commit

Permalink
build system preparation for release 0.11.0
Browse files Browse the repository at this point in the history
_soundfile_data now contains up-to-date binaries for Windows 32/64 and macOS intel/arm.
build scripts have been amended to use the new binaries

changelog is not yet updated
windows binaries use different C runtime than python, do not support file descriptors
  • Loading branch information
bastibe committed Feb 9, 2022
1 parent d41120a commit acffb86
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build_wheels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil

architectures = dict(darwin=['64bit'],
architectures = dict(darwin=['x86_64', 'arm64'],
win32=['32bit', '64bit'],
noplatform='noarch')

Expand Down
26 changes: 8 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,14 @@
from setuptools.command.test import test as TestCommand
import sys

PYTHON_INTERPRETERS = '.'.join([
'cp26', 'cp27',
'cp32', 'cp33', 'cp34', 'cp35', 'cp36',
'pp27',
'pp32', 'pp33',
])
MACOSX_VERSIONS = '.'.join([
'macosx_10_5_x86_64',
'macosx_10_6_intel',
'macosx_10_9_intel',
'macosx_10_9_x86_64',
])

# environment variables for cross-platform package creation
platform = os.environ.get('PYSOUNDFILE_PLATFORM', sys.platform)
architecture0 = os.environ.get('PYSOUNDFILE_ARCHITECTURE', architecture()[0])

if platform == 'darwin':
libname = 'libsndfile.dylib'
libname = 'libsndfile_' + architecture0 + '.dylib'
elif platform == 'win32':
libname = 'libsndfile' + architecture0 + '.dll'
libname = 'libsndfile_' + architecture0 + '.dll'
else:
libname = None

Expand Down Expand Up @@ -70,9 +57,12 @@ class bdist_wheel_half_pure(bdist_wheel):
"""Create OS-dependent, but Python-independent wheels."""

def get_tag(self):
pythons = 'py2.py3.' + PYTHON_INTERPRETERS
pythons = 'py2.py3'
if platform == 'darwin':
oses = MACOSX_VERSIONS
if architecture0 == 'x86_64':
oses = 'macosx-10.x-x86_64'
else:
oses = 'macosx-10.x-arm64'
elif platform == 'win32':
if architecture0 == '32bit':
oses = 'win32'
Expand All @@ -87,7 +77,7 @@ def get_tag(self):

setup(
name='soundfile',
version='0.10.3post1',
version='0.11.0b1',
description='An audio library based on libsndfile, CFFI and NumPy',
author='Bastian Bechtold',
author_email='[email protected]',
Expand Down
40 changes: 24 additions & 16 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
For further information, see https://python-soundfile.readthedocs.io/.
"""
__version__ = "0.10.3"
__version__ = "0.11.0"

import os as _os
import sys as _sys
from platform import machine as _machine
from os import SEEK_SET, SEEK_CUR, SEEK_END
from ctypes.util import find_library as _find_library
from _soundfile import ffi as _ffi
Expand Down Expand Up @@ -144,10 +143,16 @@
_snd = _ffi.dlopen(_libname)
except OSError:
if _sys.platform == 'darwin':
from platform import machine as _machine
_packaged_libname = 'libsndfile_' + machine() + '.dylib'
_libname = 'libsndfile.dylib'
elif _sys.platform == 'win32':
from platform import architecture as _architecture
_libname = 'libsndfile' + _architecture()[0] + '.dll'
_packaged_libname = 'libsndfile_' + _architecture()[0] + '.dll'
_libname = 'libsndfile.dll'
elif _sys.platform == 'linux':
_packaged_libname = 'libsndfile.so' # not provided!
_libname = 'libsndfile.so'
else:
raise

Expand All @@ -160,16 +165,19 @@
while not _os.path.isdir(_path):
_path = _os.path.abspath(_os.path.join(_path, '..'))

# Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of
# `/usr/local/lib`. We are making sure we pick that up.
if _sys.platform == 'darwin' and _machine() == 'arm64':
_hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \
else '/usr/local/lib/'
_snd = _ffi.dlopen(_os.path.join(
_hbrew_path, _libname))
else:
_snd = _ffi.dlopen(_os.path.join(
_path, '_soundfile_data', _libname))
try: # packaged libsndfile:
_snd = _ffi.dlopen(_os.path.join(_path, '_soundfile_data', _packaged_libname))
except OSError: # try system-wide libsndfile:
# Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of
# `/usr/local/lib`. We are making sure we pick that up.
from platform import machine as _machine
if _sys.platform == 'darwin' and _machine() == 'arm64':
_hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \
else '/usr/local/lib/'
_snd = _ffi.dlopen(_os.path.join(_hbrew_path, _libname))
else:
# Try explicit file name, if the general does not work (e.g. on nixos)
_snd = _ffi.dlopen(_libname)

__libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
if __libsndfile_version__.startswith('libsndfile-'):
Expand Down Expand Up @@ -1368,9 +1376,9 @@ def copy_metadata(self):
-------
metadata: dict[str, str]
A dict with all metadata. Possible keys are: 'title', 'copyright',
'software', 'artist', 'comment', 'date', 'album', 'license',
'tracknumber' and 'genre'.
A dict with all metadata. Possible keys are: 'title', 'copyright',
'software', 'artist', 'comment', 'date', 'album', 'license',
'tracknumber' and 'genre'.
"""
strs = {}
for strtype, strid in _str_types.items():
Expand Down

0 comments on commit acffb86

Please sign in to comment.