diff --git a/build_wheels.py b/build_wheels.py old mode 100644 new mode 100755 index 9ad90e1..1343a76 --- a/build_wheels.py +++ b/build_wheels.py @@ -1,23 +1,20 @@ -import os +#!/usr/bin/env python +import sys +import subprocess import shutil -architectures = dict(darwin=['64bit'], - win32=['32bit', '64bit'], - noplatform='noarch') +def make_dist(platform, arch, dist): + print("removing 'SoundFile.egg-info' (and everything under it)") + shutil.rmtree('SoundFile.egg-info', ignore_errors=True) + subprocess.run([sys.executable, 'setup.py', 'clean', '--all']) + subprocess.run([sys.executable, 'setup.py', dist], env={ + 'PYSOUNDFILE_PLATFORM': platform, + 'PYSOUNDFILE_ARCHITECTURE': arch + }) -def cleanup(): - shutil.rmtree('build', ignore_errors=True) - try: - os.remove('_soundfile.py') - except: - pass - -for platform, archs in architectures.items(): - os.environ['PYSOUNDFILE_PLATFORM'] = platform - for arch in archs: - os.environ['PYSOUNDFILE_ARCHITECTURE'] = arch - cleanup() - os.system('python setup.py bdist_wheel') - -cleanup() -os.system('python setup.py sdist') +if __name__ == '__main__': + make_dist('darwin', '64bit', 'bdist_wheel') + make_dist('win32', '32bit', 'bdist_wheel') + make_dist('win32', '64bit', 'bdist_wheel') + make_dist('', '', 'bdist_wheel') + make_dist('', '', 'sdist') diff --git a/setup.py b/setup.py index ee55881..55a75b4 100644 --- a/setup.py +++ b/setup.py @@ -5,6 +5,13 @@ from setuptools.command.test import test as TestCommand import sys +for line in open('soundfile.py'): + if line.startswith('__version__'): + exec(line) + break +else: + raise RuntimeError('No version number found') + PYTHON_INTERPRETERS = '.'.join([ 'cp26', 'cp27', 'cp32', 'cp33', 'cp34', 'cp35', 'cp36', @@ -87,7 +94,7 @@ def get_tag(self): setup( name='SoundFile', - version='0.10.1', + version=__version__, description='An audio library based on libsndfile, CFFI and NumPy', author='Bastian Bechtold', author_email='basti@bastibe.de', diff --git a/soundfile.py b/soundfile.py index b19c38e..a4229ce 100644 --- a/soundfile.py +++ b/soundfile.py @@ -8,7 +8,7 @@ For further information, see http://pysoundfile.readthedocs.org/. """ -__version__ = "0.10.0" +__version__ = "0.10.2" import os as _os import sys as _sys @@ -614,6 +614,9 @@ def __init__(self, file, mode='r', samplerate=None, channels=None, >>> assert myfile.closed """ + # resolve PathLike objects (see PEP519 for details): + # can be replaced with _os.fspath(file) for Python >= 3.6 + file = file.__fspath__() if hasattr(file, '__fspath__') else file self._name = file if mode is None: mode = getattr(file, 'mode', None) diff --git a/tests/test_pysoundfile.py b/tests/test_pysoundfile.py index 7c1ed6e..e1c200a 100644 --- a/tests/test_pysoundfile.py +++ b/tests/test_pysoundfile.py @@ -21,8 +21,11 @@ filename_new = 'tests/delme.please' -open_variants = 'name', 'fd', 'obj' - +if sys.version_info >= (3, 6): + import pathlib + open_variants = 'name', 'fd', 'obj', 'pathlib' +else: + open_variants = 'name', 'fd', 'obj' xfail_from_buffer = pytest.mark.xfail(cffi.__version_info__ < (0, 9), reason="from_buffer() since CFFI 0.9") @@ -31,6 +34,8 @@ def _file_existing(request, filename, fdarg, objarg=None): if request.param == 'name': return filename + if request.param == 'pathlib': + return pathlib.Path(filename) elif request.param == 'fd': fd = os.open(filename, fdarg) @@ -660,7 +665,8 @@ def test_seek_in_rplus_mode(sf_stereo_rplus): @pytest.mark.parametrize("use_default", [True, False]) def test_truncate(file_stereo_rplus, use_default): - if isinstance(file_stereo_rplus, (str, int)): + if (isinstance(file_stereo_rplus, (str, int)) + or hasattr(file_stereo_rplus, '__fspath__')): with sf.SoundFile(file_stereo_rplus, 'r+', closefd=False) as f: if use_default: f.seek(2)