ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

Add os.PathLike detection for support of pathlib #251

Closed danieldjewell closed 2 years ago

danieldjewell commented 2 years ago

Change Notes

This change implements support for "PathLike" objects being passed into magic.from_file as the filename parameter. An example of this might be using a pathlib.Path object. Python's own open() function supports the use of PathLike objects as do many other projects. See PEP-519 for more info.

Caveats

os.PathLike is not available on Python 2.7 or 3.5 (or earlier). Both of these are EOL (AFAIK) but python-magic is marked as supporting earlier versions in setup.py as well as including tests for py2.7 and py3.5 (which fail).

I could add the logic to test the version and enable detection? (Actually, probably the best way would be to use a simple try/except ImportError)

I wasn't sure what the policy was on python-magic EOLing py2.7/3.5....

ahupp commented 2 years ago

I pushed a modified version of this (with back compat) in 7f7542fcbc192fef6e4939f4eb748e941a720b2c. Thanks!