python-magic icon indicating copy to clipboard operation
python-magic copied to clipboard

Doesn't work if using musl libc: find_library is broken

Open thomwiggers opened this issue 9 years ago • 3 comments

I'm trying to construct a Docker image based on Alpine Linux, which uses the musl libc implementation. There is an existing issue in python that causes the find_library call to fail, which is rather unfortunate.

It's also reported on the Docker image repository. It's not really an issue with this library I guess, but this report could be helpful to others coming here with the same issue.

thomwiggers avatar Sep 04 '16 13:09 thomwiggers

I'm not following the issue. What would the fix look like?

ahupp avatar Sep 06 '16 05:09 ahupp

This issue is really the result of a bug in Python, but this library could work around it (although I'd understand it if you wouldn't want to). I patched magic.py by making line 150 just return libmagic.so.1, but that is perhaps a bit messy. You could do what ctypes.utils.find_library should probably do: just look in /usr/lib/ if libmagic.so exists.

thomwiggers avatar Sep 07 '16 10:09 thomwiggers

Is this package not maintained anymore?

makesitgood avatar Jun 01 '17 23:06 makesitgood

Alpine has been tested for a while so this seems to be fixed.

ahupp avatar Aug 25 '23 18:08 ahupp

find_library is no longer used on Linux: https://github.com/ahupp/python-magic/blob/2a01b18ae0fe27e51977a54f0589910ddcc05804/magic/loader.py#L32-L34

thomwiggers avatar Aug 28 '23 09:08 thomwiggers

That function is a generator that produces candidate libraries, a the top ever platform calls find_library("magic"):

https://github.com/ahupp/python-magic/blob/2a01b18ae0fe27e51977a54f0589910ddcc05804/magic/loader.py#L9

On Mon, Aug 28, 2023, 2:29 AM Thom Wiggers @.***> wrote:

find_library is no longer used on Linux: https://github.com/ahupp/python-magic/blob/2a01b18ae0fe27e51977a54f0589910ddcc05804/magic/loader.py#L32-L34

— Reply to this email directly, view it on GitHub https://github.com/ahupp/python-magic/issues/114#issuecomment-1695357211, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAJ5ERQRZN3PDRS4BXC6YLXXRQHTANCNFSM4COSEVRA . You are receiving this because you modified the open/close state.Message ID: @.***>

ahupp avatar Aug 28 '23 14:08 ahupp

Right, anyway, the quoted lines then indeed still tackle musl

thomwiggers avatar Aug 28 '23 14:08 thomwiggers