diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 13:26:22 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-30 15:44:45 +0300 |
commit | 0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch) | |
tree | 291d72dbd7e9865399f668c84d11ed86fb190bbf /contrib/python/python-magic/py3/magic/loader.py | |
parent | cb2c8d75065e5b3c47094067cb4aa407d4813298 (diff) | |
download | ydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz |
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'contrib/python/python-magic/py3/magic/loader.py')
-rw-r--r-- | contrib/python/python-magic/py3/magic/loader.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/python/python-magic/py3/magic/loader.py b/contrib/python/python-magic/py3/magic/loader.py new file mode 100644 index 0000000000..931f16193e --- /dev/null +++ b/contrib/python/python-magic/py3/magic/loader.py @@ -0,0 +1,50 @@ +from ctypes.util import find_library +import ctypes +import sys +import glob +import os.path + +def _lib_candidates(): + + yield find_library('magic') + + if sys.platform == 'darwin': + + paths = [ + '/opt/local/lib', + '/usr/local/lib', + '/opt/homebrew/lib', + ] + glob.glob('/usr/local/Cellar/libmagic/*/lib') + + for i in paths: + yield os.path.join(i, 'libmagic.dylib') + + elif sys.platform in ('win32', 'cygwin'): + + prefixes = ['libmagic', 'magic1', 'cygmagic-1', 'libmagic-1', 'msys-magic-1'] + + for i in prefixes: + # find_library searches in %PATH% but not the current directory, + # so look for both + yield './%s.dll' % (i,) + yield find_library(i) + + elif sys.platform == 'linux': + # This is necessary because alpine is bad + yield 'libmagic.so.1' + + +def load_lib(): + + for lib in _lib_candidates(): + # find_library returns None when lib not found + if lib is None: + continue + try: + return ctypes.CDLL(lib) + except OSError: + pass + else: + # It is better to raise an ImportError since we are importing magic module + raise ImportError('failed to find libmagic. Check your installation') + |