Skip to content

Commit

Permalink
Use python-magic API when available
Browse files Browse the repository at this point in the history
The usage of the python-magic -> libmagic API comatibility [1] raises a
deprecation warning. This patch uses the python-magic default API when
it's available and in other case it uses the libmagic default API.

Fix #1083

[1] https://github.com/ahupp/python-magic/blob/master/COMPAT.md
  • Loading branch information
danigm committed Aug 3, 2023
1 parent fa98be1 commit e8ed783
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,19 @@ def parse_deps(line):


def get_magic(path):
# python-magic & libmagic compatibility code
# https://github.com/ahupp/python-magic/blob/master/COMPAT.md
detect_magic = None
if hasattr(magic, 'from_file'):
# python-magic module
detect_magic = magic.from_file
else:
# libmagic python bindings
detect_magic = lambda x: magic.detect_from_filename(x).name

try:
return magic.detect_from_filename(path).name
except ValueError:
return detect_magic(path)
except (ValueError, FileNotFoundError):
return ''


Expand Down

0 comments on commit e8ed783

Please sign in to comment.