Skip to content

Commit

Permalink
PR Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed May 26, 2024
1 parent 9bf2e9c commit f7341ce
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions magic/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

def _lib_candidates_linux():
"""Yield possible libmagic library names on Linux."""
prefixes = ('libmagic.so.1', 'libmagic.so')
fnames = ('libmagic.so.1', 'libmagic.so')

for i in prefixes:
for fname in fnames:
# libmagic bundled in the wheel
yield os.path.join(here, i)
yield os.path.join(here, fname)
# libmagic in the current working directory
yield os.path.join(os.path.abspath('.'), i)
yield os.path.join(os.path.abspath('.'), fname)
# libmagic install from source default destination path
yield os.path.join('/usr/local/lib', i)
yield os.path.join('/usr/local/lib', fname)
# on some linux systems (musl/alpine), find_library('magic') returns None
# first try finding libmagic using ldconfig
# otherwise fall back to /usr/lib/
yield subprocess.check_output(
"( ldconfig -p | grep '{0}' | grep -o '/.*' ) || echo '/usr/lib/{0}'".format(i),
"( ldconfig -p | grep '{0}' | grep -o '/.*' ) || echo '/usr/lib/{0}'".format(fname),
shell=True,
universal_newlines=True,
).strip()
Expand All @@ -43,13 +43,13 @@ def _lib_candidates_macos():
'/opt/homebrew/lib',
] + glob.glob('/usr/local/Cellar/libmagic/*/lib')

for i in paths:
yield os.path.join(i, 'libmagic.dylib')
for path in paths:
yield os.path.join(path, 'libmagic.dylib')


def _lib_candidates_windows():
"""Yield possible libmagic library names on Windows."""
prefixes = (
fnames = (
"libmagic",
"magic1",
"magic-1",
Expand All @@ -58,13 +58,13 @@ def _lib_candidates_windows():
"msys-magic-1",
)

for i in prefixes:
for fname in fnames:
# libmagic bundled in the wheel
yield os.path.join(here, '%s.dll' % i)
yield os.path.join(here, '%s.dll' % fname)
# libmagic in the current working directory
yield os.path.join(os.path.abspath('.'), '%s.dll' % i)
yield os.path.join(os.path.abspath('.'), '%s.dll' % fname)
# find_library searches in %PATH% but not the current directory
yield find_library(i)
yield find_library(fname)


def _lib_candidates():
Expand Down

0 comments on commit f7341ce

Please sign in to comment.