Skip to content

Commit edae9d0

Browse files
committed
fixed: load error due to new magic.mgc file
* load system installed version (/usr/share/file/magic.mgc) of magic.mgc on linux systems
1 parent 48fa4a9 commit edae9d0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pandasqt/encoding.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,28 @@
1313
import magic
1414
AUTODETECT = True
1515
except ImportError, e:
16-
if sys.platform == 'darwin':
17-
raise ImportError('Please install libmagic')
16+
#if sys.platform == 'darwin':
17+
raise ImportError('Please install libmagic')
1818
AUTODETECT = False
1919

2020

2121
class Detector(object):
22+
2223
def __init__(self):
2324
if AUTODETECT:
24-
magic_db = os.path.join(BASEDIR, '_lib', 'magic', 'db', 'magic.mgc')
25+
if sys.platform.startswith('linux'):
26+
# use the system wide installed version comming with windows, the included magic.mgc might be incompatible
27+
magic_db = os.path.join('/usr/share/file', 'magic.mgc')
28+
else:
29+
magic_db = os.path.join(BASEDIR, '_lib', 'magic', 'db', 'magic.mgc')
30+
if not os.path.exists(magic_db):
31+
raise ImportError('Please install libmagic.')
2532
self.magic = magic.Magic(magic_file=magic_db, mime_encoding=True)
2633
else:
2734
self.magic = False
2835

29-
3036
def detect(self, filepath):
3137
if self.magic:
3238
encoding = self.magic.from_file(filepath)
3339
return encoding
34-
return None
35-
36-
40+
return None

0 commit comments

Comments
 (0)