Skip to content
Open
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
15 changes: 14 additions & 1 deletion ctypeslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import ctypes
import os
import platform
import re
import sys
import warnings
Expand Down Expand Up @@ -106,7 +107,19 @@ def __configure_clang_cindex():
from clang import cindex
from ctypeslib.codegen.codegenerator import translate, translate_files

__clang_py_version__ = importlib.metadata.version('clang')
try:
__clang_py_version__ = importlib.metadata.version("clang")
except PackageNotFoundError:
# Python packages are not required to provide a version that
# is queryable via the importlib metadata.
if sys.platform == "linux" and platform.freedesktop_os_release()["ID"] == "debian":
# The path for the library filename in Debian can provide a hint as
# to the major version of the clang library without loading it.
# @see https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/19/debian/patches/python-clangpath.diff
__clang_py_version__ = cindex.conf.get_filename().split("-")[1].split(".")[0]
else:
raise ImportError("Could not determine clang.py version")

__clang_library_filename = __configure_clang_cindex()
if __clang_library_filename is None:
warnings.warn("Could not find the clang library. please install llvm libclang", RuntimeWarning)
Expand Down