Skip to content

Commit 2bb9fa8

Browse files
committed
Merge branch 'master' of https://github.com/ahupp/python-magic into abi3-wheels
* 'master' of https://github.com/ahupp/python-magic: add support for python 3.13 Unbreak various things
2 parents d3e886c + 5a89644 commit 2bb9fa8

File tree

5 files changed

+166
-142
lines changed

5 files changed

+166
-142
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ jobs:
55
strategy:
66
fail-fast: false
77
matrix:
8-
os: ['ubuntu-latest']
9-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
8+
os: ["ubuntu-latest"]
9+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1010
include:
1111
- os: macos-latest
12-
python-version: '3.13'
12+
python-version: "3.13"
1313
# - os: windows-latest # TODO: Fix the Windows test that runs in an infinite loop
1414
# python-version: '3.13'
1515
runs-on: ${{ matrix.os }}
@@ -26,4 +26,4 @@ jobs:
2626
- run: pip install --editable .
2727
- run: LC_ALL=en_US.UTF-8 pytest
2828
shell: bash
29-
timeout-minutes: 15 # Limit Windows infinite loop.
29+
timeout-minutes: 15 # Limit Windows infinite loop.

magic/loader.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
logger = logging.getLogger(__name__)
1010
here = os.path.dirname(__file__)
1111

12+
1213
def _lib_candidates_linux():
1314
"""Yield possible libmagic library names on Linux."""
1415
fnames = ('libmagic.so.1', 'libmagic.so')
@@ -73,7 +74,7 @@ def _lib_candidates():
7374
"darwin": _lib_candidates_macos,
7475
"linux": _lib_candidates_linux,
7576
"win32": _lib_candidates_windows,
76-
"sunos5": _lib_candidates_linux,
77+
"sunos5": _lib_candidates_linux,
7778
}.get(sys.platform)
7879
if func is None:
7980
raise ImportError("python-magic: Unsupported platform: " + sys.platform)
@@ -86,17 +87,20 @@ def _lib_candidates():
8687

8788

8889
def load_lib():
90+
exc = []
8991
for lib in _lib_candidates():
9092
# find_library returns None when lib not found
9193
if lib is None:
9294
continue
93-
if not os.path.exists(lib):
94-
continue
9595

9696
try:
9797
return ctypes.CDLL(lib)
98-
except OSError:
99-
logger.warning("Failed to load: " + lib, exc_info=True)
98+
except OSError as e:
99+
exc.append(e)
100+
101+
msg = "\n".join([str(e) for e in exc])
100102

101103
# It is better to raise an ImportError since we are importing magic module
102-
raise ImportError("python-magic: failed to find libmagic. Check your installation")
104+
raise ImportError(
105+
"python-magic: failed to find libmagic. Check your installation: \n" + msg
106+
)

setup.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
def read(file_name):
1414
"""Read a text file and return the content as a string."""
15-
with io.open(os.path.join(os.path.dirname(__file__), file_name),
16-
encoding='utf-8') as f:
15+
with io.open(
16+
os.path.join(os.path.dirname(__file__), file_name), encoding="utf-8"
17+
) as f:
1718
return f.read()
1819

1920
def get_cmdclass():
@@ -39,37 +40,37 @@ def get_tag(self):
3940
cmdclass = get_cmdclass()
4041

4142
setuptools.setup(
42-
name='python-magic',
43-
description='File type identification using libmagic',
44-
author='Adam Hupp',
45-
author_email='adam@hupp.org',
43+
name="python-magic",
44+
description="File type identification using libmagic",
45+
author="Adam Hupp",
46+
author_email="adam@hupp.org",
4647
url="http://github.com/ahupp/python-magic",
47-
version='0.4.28',
48-
long_description=read('README.md'),
49-
long_description_content_type='text/markdown',
50-
packages=['magic'],
48+
version="0.4.28",
49+
long_description=read("README.md"),
50+
long_description_content_type="text/markdown",
51+
packages=["magic"],
5152
package_data={
52-
'magic': ['py.typed', '*.pyi', '*.dylib*', '*.dll', '*.so*', 'magic.mgc']
53+
"magic": ["py.typed", "*.pyi", "*.dylib*", "*.dll", "*.so*", "magic.mgc"]
5354
},
5455
cmdclass=cmdclass,
5556
keywords="mime magic file",
5657
license="MIT",
57-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
58+
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
5859
classifiers=[
59-
'Intended Audience :: Developers',
60-
'License :: OSI Approved :: MIT License',
61-
'Programming Language :: Python',
62-
'Programming Language :: Python :: 2.7',
63-
'Programming Language :: Python :: 3',
64-
'Programming Language :: Python :: 3.5',
65-
'Programming Language :: Python :: 3.6',
66-
'Programming Language :: Python :: 3.7',
67-
'Programming Language :: Python :: 3.8',
68-
'Programming Language :: Python :: 3.9',
69-
'Programming Language :: Python :: 3.10',
70-
'Programming Language :: Python :: 3.11',
71-
'Programming Language :: Python :: 3.12',
72-
'Programming Language :: Python :: Implementation :: CPython',
60+
"Intended Audience :: Developers",
61+
"License :: OSI Approved :: MIT License",
62+
"Programming Language :: Python",
63+
"Programming Language :: Python :: 2.7",
64+
"Programming Language :: Python :: 3",
65+
"Programming Language :: Python :: 3.5",
66+
"Programming Language :: Python :: 3.6",
67+
"Programming Language :: Python :: 3.7",
68+
"Programming Language :: Python :: 3.8",
69+
"Programming Language :: Python :: 3.9",
70+
"Programming Language :: Python :: 3.10",
71+
"Programming Language :: Python :: 3.11",
72+
"Programming Language :: Python :: 3.12",
73+
"Programming Language :: Python :: 3.13",
74+
"Programming Language :: Python :: Implementation :: CPython",
7375
],
7476
)
75-

0 commit comments

Comments
 (0)