Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filetype): handle missing libmagic library #3790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

metadaddy
Copy link

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.

pytest -v test_unstructured/file_utils succeeds:

(.venv) ppatterson@MBP-W7FQ7Y97F0 unstructured % pytest -v test_unstructured/file_utils
============================================== test session starts ==============================================
platform darwin -- Python 3.10.15, pytest-8.3.3, pluggy-1.5.0 -- /Users/ppatterson/src/unstructured/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/ppatterson/src/unstructured
configfile: setup.cfg
plugins: cov-5.0.0, mock-3.14.0, anyio-4.6.2.post1, requests-mock-1.12.1
collected 440 items      
...
================================== 411 passed, 28 skipped, 1 xfailed in 3.68s ===================================

@metadaddy
Copy link
Author

Rebased to main. pytest -v test_unstructured/file_utils still succeeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant