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

Build script improvements #221

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 17 additions & 20 deletions build_wheels.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import os
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

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

subprocess.run() is a Python 3 feature, so this should probably be python3?

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')
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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='[email protected]',
Expand Down
5 changes: 4 additions & 1 deletion soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions tests/test_pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down