As reported in #3781, the check for availability of the libmagic library is not correct. The existing code checks whether the magic module is available, but the attempt to import magic fails if thelibmagic library is not also available. On the Mac, libmagic is not installed by default; the user must install it manually, typically via brew install libmagic.
This PR detects whether libmagic is installed by importing the magic module in a try block, setting LIBMAGIC_AVAILABLE accordingly. MAGIC_AVAILABLE is set to true if the magic module is installed so that an appropriate warning can be displayed if the fallback filetype module returns None for a mime type. Tests that rely on libmagic being installed are skipped if it is not.
As reported in #3781, the check for availability of the
libmagic
library is not correct. The existing code checks whether themagic
module is available, but the attempt toimport magic
fails if thelibmagic
library is not also available. On the Mac,libmagic
is not installed by default; the user must install it manually, typically viabrew install libmagic
.This PR detects whether
libmagic
is installed by importing themagic
module in atry
block, settingLIBMAGIC_AVAILABLE
accordingly.MAGIC_AVAILABLE
is set to true if themagic
module is installed so that an appropriate warning can be displayed if the fallbackfiletype
module returnsNone
for a mime type. Tests that rely onlibmagic
being installed are skipped if it is not.pytest -v test_unstructured/file_utils
succeeds: