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

Try explicit file name, and look system-wide for library #322

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 16 additions & 8 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
elif _sys.platform == 'win32':
from platform import architecture as _architecture
_libname = 'libsndfile' + _architecture()[0] + '.dll'
elif _sys.platform == 'linux':
# Try explicit file name, if the general does not work (e.g. on nixos)
_libname = 'libsndfile.so'
bastibe marked this conversation as resolved.
Show resolved Hide resolved
else:
raise

Expand All @@ -160,16 +163,21 @@
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:
try:
bastibe marked this conversation as resolved.
Show resolved Hide resolved
_snd = _ffi.dlopen(_os.path.join(
_path, '_soundfile_data', _libname))
except OSError:
# if no local installed library sndfile, try system-wide

# 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':
Copy link
Owner

Choose a reason for hiding this comment

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

why did you drop 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(_libname)

__libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
if __libsndfile_version__.startswith('libsndfile-'):
Expand Down