Skip to content

Commit d8adb66

Browse files
committed
Slightly simplify library search (#55)
1 parent 2096d6a commit d8adb66

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

chromaprint.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,26 @@ def _guess_lib_name():
3333

3434

3535
def _load_library(name):
36+
"""Try to load a dynamic library with ctypes, or return None if the
37+
library is not available.
38+
"""
3639
if sys.platform == 'win32':
37-
try:
38-
return ctypes.cdll.LoadLibrary(ctypes.util.find_library(name))
39-
except TypeError:
40-
raise OSError()
41-
else:
40+
# On Windows since Python 3.8, we need an extra call to
41+
# `find_library` to search standard library paths.
42+
name = ctypes.util.find_library(name)
43+
if not name:
44+
return None
45+
46+
try:
4247
return ctypes.cdll.LoadLibrary(name)
48+
except OSError:
49+
return None
4350

4451

4552
for name in _guess_lib_name():
46-
try:
47-
_libchromaprint = _load_library(name)
53+
_libchromaprint = _load_library(name)
54+
if _libchromaprint:
4855
break
49-
except OSError:
50-
pass
5156
else:
5257
raise ImportError("couldn't find libchromaprint")
5358

0 commit comments

Comments
 (0)