ahupp / python-magic

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

Please make `from_file` work on directories #296

Closed rrthomas closed 11 months ago

rrthomas commented 11 months ago

At present, an attempt to call from_file on a directory gives an error, but libmagic is quite happy to tell me that a directory is of type inode/directory.

ahupp commented 11 months ago

I realize libmagic behaves that way, but I disagree with that behavior. And even if not, python-magic has behaved this way for 10 years it would be a breaking change to allow it.

rrthomas commented 11 months ago

Thanks for getting back to me so fast! It turns out that I'm the author of the libmagic Python bindings (I admit I had forgotten), so I guess I can use them, and change them if needed.

rrthomas commented 11 months ago

Please can you tag this issue wontfix for future reference?

ahupp commented 11 months ago

@rrthomas wow! our paths finally cross. I wrote this (using SWIG) for a personal project in maybe 2003, then switched to ctypes and put on pypi a few years later. I don't know when libmagic started shipping bindings but I wasn't aware of them at the time.

I got so many bug reports due to libmagic and python-magic bindings both using the magic package name that I added a copy of the libmagic bindings as a compatibility layer:

https://github.com/ahupp/python-magic/blob/master/magic/compat.py

This these are re-exported from magic along with a DeprecationWarning. So you can just do magic.detect_from_filename and it will work like you intend.

rrthomas commented 11 months ago

Haha, I worked on file from about 2007, mostly up to around 2011; I rewrote the Python bindings in January 2011, says CVS. Thanks for reminding me about the compat layer.