-
Notifications
You must be signed in to change notification settings - Fork 9
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
failover to python-magic detection if vendored library not present #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you ++
See some minor nitpicking of mine for your kind consideration.
@@ -79,18 +79,60 @@ | |||
TYPECODE_LIBMAGIC_DATABASE = 'typecode.libmagic.db' | |||
|
|||
|
|||
def load_lib_failover(): | |||
# loader from python-magic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's nice extra credits but not needed IMHO since Adam is already credited at the top for the whole file.
src/typecode/magic2.py
Outdated
# Copyright: Adam Hupp | ||
libmagic = None | ||
# Let's try to find magic or magic1 | ||
dll = ctypes.util.find_library('magic') \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of line continuations and end-of-line comments. I reckon you copied the code from upstream, butw what about instead something along these lines:
dll = (ctypes.util.find_library('magic')
or ctypes.util.find_library('magic1')
or ctypes.util.find_library('cygmagic-1')
or ctypes.util.find_library('libmagic-1')
or ctypes.util.find_library('msys-magic-1')
)
|
||
if not libmagic or not libmagic._name: | ||
return None | ||
return libmagic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if there could be a way to test/check the version of this libmagic? Because unless this is close enough to the one provided as a plugin, there could be some magic database inconsistencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do a check, but we don't really know what threshold we should really put there. How would you define close enough?
I would suggest to leave a warning, and let the community report any issue.
We could have a TAINTED flag like linux does which could be put in the typecode dependent reports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well in hindsight, let's leave it this way.... after all in https://github.com/nexB/scancode-plugins/blob/main/builtins/typecode_libmagic_system_provided/src/typecode_libmagic/__init__.py I do not even check for version
Something that's a head scratcher to me is: where is the magic DB obtained from when not provided by a plugin? |
5362fc5
to
b892dea
Compare
as per doc:
I added the version api which might help in case of a later bug report |
This allows scancode to work on platforms not supported by typecode-libmagic e.g. M1 Macs or windows WSL Most of this code is from https://github.com/ahupp/python-magic/blob/e0ccc6d/magic/loader.py by Adam Hupp, MIT License, compatible with typecode's Apache Signed-off-by: Pierre Tardy <[email protected]>
@pombredanne shall we merge this? I think you may need to re run flaky azure pipelines. |
Signed-off-by: Philippe Ombredanne <[email protected]>
Merged in #20 |
This allows scancode to work on platforms not supported by typecode-libmagic
e.g. M1 Macs or windows WSL
100% tests pass with this change on my M1 Mac