Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
os: ["ubuntu-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
include:
- os: macos-latest
python-version: '3.13'
python-version: "3.13"
# - os: windows-latest # TODO: Fix the Windows test that runs in an infinite loop
# python-version: '3.13'
runs-on: ${{ matrix.os }}
Expand All @@ -28,4 +28,4 @@ jobs:
run: pip install python-magic-bin
- run: LC_ALL=en_US.UTF-8 pytest
shell: bash
timeout-minutes: 15 # Limit Windows infinite loop.
timeout-minutes: 15 # Limit Windows infinite loop.
16 changes: 10 additions & 6 deletions magic/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

logger = logging.getLogger(__name__)


def _lib_candidates_linux():
"""Yield possible libmagic library names on Linux.

Expand Down Expand Up @@ -51,7 +52,7 @@ def _lib_candidates():
"darwin": _lib_candidates_macos,
"linux": _lib_candidates_linux,
"win32": _lib_candidates_windows,
"sunos5": _lib_candidates_linux,
"sunos5": _lib_candidates_linux,
}.get(sys.platform)
if func is None:
raise ImportError("python-magic: Unsupported platform: " + sys.platform)
Expand All @@ -61,17 +62,20 @@ def _lib_candidates():


def load_lib():
exc = []
for lib in _lib_candidates():
# find_library returns None when lib not found
if lib is None:
continue
if not os.path.exists(lib):
continue

try:
return ctypes.CDLL(lib)
except OSError:
logger.warning("Failed to load: " + lib, exc_info=True)
except OSError as e:
exc.append(e)

msg = "\n".join([str(e) for e in exc])

# It is better to raise an ImportError since we are importing magic module
raise ImportError("python-magic: failed to find libmagic. Check your installation")
raise ImportError(
"python-magic: failed to find libmagic. Check your installation: \n" + msg
)
56 changes: 29 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,43 @@

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


setuptools.setup(
name='python-magic',
description='File type identification using libmagic',
author='Adam Hupp',
author_email='adam@hupp.org',
name="python-magic",
description="File type identification using libmagic",
author="Adam Hupp",
author_email="adam@hupp.org",
url="http://github.com/ahupp/python-magic",
version='0.4.28',
long_description=read('README.md'),
long_description_content_type='text/markdown',
packages=['magic'],
version="0.4.28",
long_description=read("README.md"),
long_description_content_type="text/markdown",
packages=["magic"],
package_data={
'magic': ['py.typed', '*.pyi', '**/*.pyi'],
"magic": ["py.typed", "*.pyi", "**/*.pyi"],
},
keywords="mime magic file",
license="MIT",
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
],
)

Loading