Skip to content

Commit

Permalink
Merge pull request #2 from spencer-hanson/master
Browse files Browse the repository at this point in the history
ManyLinux Binary Support
  • Loading branch information
julian-r authored May 16, 2020
2 parents 9a2d137 + c56fe3c commit 6029e2d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
deb_dist
python_magic.egg-info
*.egg-info
build/*
dist/*
.python-version
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# python-magic-bin
This is a fork of the `python-magic` library but with binary packages for windows and mac.
This is a fork of the `python-magic` library but with binary packages for windows, mac and linux.


[![PyPI version](https://badge.fury.io/py/python-magic.svg)](https://badge.fury.io/py/python-magic)
Expand Down
16 changes: 16 additions & 0 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ rm -rf build
cp /usr/local/Cellar/libmagic/5.32/share/misc/magic.mgc ${LIBMAGIC_TARGET_DIR}/
cp /usr/local/Cellar/libmagic/5.32/lib/libmagic.dylib ${LIBMAGIC_TARGET_DIR}/
python setup.py bdist_wheel -p macosx-10.6-intel

# manylinux x86-64
rm -rf ${LIBMAGIC_TARGET_DIR}/*
rm -rf build
wget https://github.com/spencer-hanson/linux-file/releases/download/FILE5_35_manylinux/file-manylinux-x86-64.zip
unzip file-manylinux-x86-64.zip -d ${LIBMAGIC_TARGET_DIR}
rm file-manylinux-x86-64.zip
python setup.py bdist_wheel -p manylinux1_x86_64

# manylinux i686
rm -rf ${LIBMAGIC_TARGET_DIR}/*
rm -rf build
wget https://github.com/spencer-hanson/linux-file/releases/download/FILE5_35_manylinux/file-manylinux-i686.zip
unzip file-manylinux-i686.zip -d ${LIBMAGIC_TARGET_DIR}
rm file-manylinux-i686.zip
python setup.py bdist_wheel -p manylinux1_i686
8 changes: 6 additions & 2 deletions magic/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def from_buffer(buffer, mime=False):
if dll:
libmagic = ctypes.CDLL(dll)

import pkg_resources

if not libmagic or not libmagic._name:
windows_dlls = ['magic1.dll','cygmagic-1.dll','libmagic-1.dll','msys-magic-1.dll']
platform_to_lib = {'darwin': ['/opt/local/lib/libmagic.dylib',
Expand All @@ -178,7 +180,9 @@ def from_buffer(buffer, mime=False):
glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'),
'win32': windows_dlls,
'cygwin': windows_dlls,
'linux': ['libmagic.so.1'], # fallback for some Linuxes (e.g. Alpine) where library search does not work
# fallback for some Linuxes (e.g. Alpine) where library search does not work
# package resources for virtualenv support
'linux': [pkg_resources.resource_filename(__name__, "libmagic/libmagic.so.1")],
}
platform = 'linux' if sys.platform.startswith('linux') else sys.platform
for dll in platform_to_lib.get(platform, []):
Expand All @@ -190,7 +194,7 @@ def from_buffer(buffer, mime=False):

if not libmagic or not libmagic._name:
# It is better to raise an ImportError since we are importing magic module
raise ImportError('failed to find libmagic. Check your installation')
raise ImportError('failed to find libmagic. Check your installation.')

magic_t = ctypes.c_void_p

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

setup(name='python-magic-bin',
description='File type identification using libmagic binary package',
author='Julian David Rath',
author_email='[email protected]',
author='Adam Hupp, Julian David Rath, Spencer Hanson',
author_email='[email protected], julian.rath@gmail.com, spencer.hanson@swimlane.com',
url="http://github.com/julian-r/python-magic",
version='0.4.13',
version='0.4.14',
package_data={
'magic': ['libmagic/*.dll', 'libmagic/*.dylib', 'libmagic/*.mgc'],
'magic': ['libmagic/*.dll', 'libmagic/*.dylib', 'libmagic/*.mgc', 'libmagic/*.so*', 'libmagic/*.la']
},
zip_safe=False,
packages=['magic'],
Expand All @@ -28,4 +28,4 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
],
)
)

0 comments on commit 6029e2d

Please sign in to comment.