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

pysoundfile 0.12.1 ❄️ #1

Open
wants to merge 8 commits into
base: main
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
1 change: 1 addition & 0 deletions .gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions abs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
upload_channels:
- sfe1ed40
channels:
- https://staging.continuum.io/prefect/fs/libsndfile-feedstock/pr2/ea7b20f

72 changes: 72 additions & 0 deletions recipe/0001-unvendoring-libsndfile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 67185b5da578ed5db010e3fd4f4e3972c0c7548d Mon Sep 17 00:00:00 2001
From: Udo-Peter Steyer <[email protected]>
Date: Fri, 27 Sep 2024 15:04:50 -0500
Subject: [PATCH] unvendoring libsndfile

---
soundfile.py | 49 ++++---------------------------------------------
1 file changed, 4 insertions(+), 45 deletions(-)

diff --git a/soundfile.py b/soundfile.py
index cc13192..11b9245 100644
--- a/soundfile.py
+++ b/soundfile.py
@@ -145,51 +145,10 @@ _ffi_types = {
'int16': 'short'
}

-try: # packaged lib (in _soundfile_data which should be on python path)
- if _sys.platform == 'darwin':
- from platform import machine as _machine
- _packaged_libname = 'libsndfile_' + _machine() + '.dylib'
- elif _sys.platform == 'win32':
- from platform import architecture as _architecture
- _packaged_libname = 'libsndfile_' + _architecture()[0] + '.dll'
- elif _sys.platform == 'linux':
- from platform import machine as _machine
- _packaged_libname = 'libsndfile_' + _machine() + '.so'
- else:
- raise OSError('no packaged library for this platform')
-
- import _soundfile_data # ImportError if this doesn't exist
- _path = _os.path.dirname(_soundfile_data.__file__) # TypeError if __file__ is None
- _full_path = _os.path.join(_path, _packaged_libname)
- _snd = _ffi.dlopen(_full_path) # OSError if file doesn't exist or can't be loaded
-
-except (OSError, ImportError, TypeError):
- try: # system-wide libsndfile:
- _libname = _find_library('sndfile')
- if _libname is None:
- raise OSError('sndfile library not found using ctypes.util.find_library')
- _snd = _ffi.dlopen(_libname)
-
- except OSError:
- # Try explicit file name, if the general does not work (e.g. on nixos)
- if _sys.platform == 'darwin':
- _explicit_libname = 'libsndfile.dylib'
- elif _sys.platform == 'win32':
- _explicit_libname = 'libsndfile.dll'
- elif _sys.platform == 'linux':
- _explicit_libname = 'libsndfile.so'
- else:
- raise
-
- # 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, _explicit_libname))
- else:
- _snd = _ffi.dlopen(_explicit_libname)
+_libname = _find_library('sndfile')
+if _libname is None:
+ raise OSError('sndfile library not found using ctypes.util.find_library')
+_snd = _ffi.dlopen(_libname)

__libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
if __libsndfile_version__.startswith('libsndfile-'):
--
2.39.3 (Apple Git-146)

42 changes: 28 additions & 14 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,58 @@ source:
sha256: e8e1017b2cf1dda767aef19d2fd9ee5ebe07e050d430f77a0a7c66ba08b8cdae

build:
number: 1
noarch: python
number: 0
script:
# We are currently building a noarch package, but pysoundfile contains a
# install-time check for the OS and injects the sf_wchar_open function
# conditionally. If this variable is not set, opening files on Windows doesn't work
# Fix coming hopefully with https://github.com/bastibe/python-soundfile/pull/288
# Original issue on conda-forge: https://github.com/conda-forge/libsndfile-feedstock/issues/14
- export PYSOUNDFILE_PLATFORM=win32
- python -m pip install . --no-deps -vv
# To make sure we really do not bring in _soundfile_data
- rm -rf _soundfile_data # [not win]
- delete _soundfile_data # [win]
- python -m pip install . -vv --no-deps --no-build-isolation
skip: true # [py<36 or s390x or win]
patches:
- 0001-unvendoring-libsndfile.patch

requirements:
build:
- patch # [not win]
- m2-patch # [win]
host:
- pip
- python >=3.6
- python
- setuptools
- wheel
- cffi
run:
- python >=3.6
- python
- cffi
- numpy
- libsndfile >=1.2

test:
source_files:
- tests
requires:
- pytest
imports:
- soundfile
commands:
# Verify that soundfile is linking the correct libsndfile object
python -c "import soundfile; print(soundfile._libname)"

# Verify that soundfile is linking the correct libsndfile object
- python -c "import soundfile; print(soundfile._libname)"
Copy link

Choose a reason for hiding this comment

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

what should be the correct libname? It might be nicer to fail if not correct

Copy link
Author

Choose a reason for hiding this comment

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

This came in when forked from conda-forge. I can remove it and see if it's necessary.

Copy link

Choose a reason for hiding this comment

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

You could pipe the output from this into something that checks that the text output from print(soundfile._libname) is correct

#- pytest -vv . -k "not (test_available_formats or test_available_subtypes)"
- pytest -vv .

about:
home: https://python-soundfile.readthedocs.io/
license: BSD-3-Clause
license_family: BSD
license_file: LICENSE
summary: 'SoundFile is an audio library based on libsndfile, CFFI, and NumPy'
description: |
The soundfile module can read and write sound files. File reading/writing is
supported through libsndfile, which is a free, cross-platform, open-source
(LGPL) library for reading and writing many different sampled sound file formats
that runs on many platforms including Windows, OS X, and Unix
dev_url: https://github.com/bastibe/python-soundfile
doc_url: https://python-soundfile.readthedocs.io/en/latest/

extra:
recipe-maintainers:
Expand Down