Skip to content

Commit eba05b6

Browse files
committed
Fix compat.py now that bundled libmagic is preferred
1 parent e112de3 commit eba05b6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

magic/compat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'''
66

77
import ctypes
8+
import os
89

910
from collections import namedtuple
1011

@@ -16,6 +17,13 @@
1617

1718
_libraries = {}
1819
_libraries['magic'] = loader.load_lib()
20+
magic_file = None
21+
if not os.environ.get("MAGIC"):
22+
# wheels package the mime database in this directory
23+
# prefer it when no magic file is specified by the user
24+
mime_db = os.path.join(os.path.dirname(__file__), 'magic.mgc')
25+
if os.path.exists(mime_db):
26+
magic_file = mime_db
1927

2028
# Flag constants for open and setflags
2129
MAGIC_NONE = NONE = 0
@@ -178,7 +186,7 @@ def setflags(self, flags):
178186
"""
179187
return _setflags(self._magic_t, flags)
180188

181-
def load(self, filename=None):
189+
def load(self, filename=magic_file):
182190
"""
183191
Must be called to load entries in the colon separated list of database
184192
files passed as argument or the default database file if no argument

0 commit comments

Comments
 (0)