[clang] [libclang/python] export libclang version to the bindings (PR #86931)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 21 04:26:51 PDT 2026
https://github.com/efferre79 updated https://github.com/llvm/llvm-project/pull/86931
>From 1a7ccb5aaf97e3919ecbb24eff3d1dc8b4f4ccdb Mon Sep 17 00:00:00 2001
From: efferre79 <rossi.f at inwind.it>
Date: Thu, 19 Mar 2026 22:53:24 +0100
Subject: [PATCH] [libclang/python] export libclang version to the bindings
---
clang/bindings/python/clang/cindex.py | 6 ++++++
clang/bindings/python/tests/cindex/test_version.py | 11 +++++++++++
clang/docs/ReleaseNotes.rst | 2 ++
3 files changed, 19 insertions(+)
create mode 100755 clang/bindings/python/tests/cindex/test_version.py
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index c34a1c0db01e9..48b3f5bfef6b6 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -4339,6 +4339,7 @@ def set_property(self, property, value):
("clang_getCanonicalCursor", [Cursor], Cursor),
("clang_getCanonicalType", [Type], Type),
("clang_getChildDiagnostics", [Diagnostic], c_object_p),
+ ("clang_getClangVersion", [], _CXString),
("clang_getCompletionAvailability", [c_void_p], c_int),
("clang_getCompletionBriefComment", [c_void_p], _CXString),
("clang_getCompletionChunkCompletionString", [c_void_p, c_int], c_object_p),
@@ -4649,6 +4650,11 @@ def get_cindex_library(self) -> CDLL:
return library
+ def get_version(self):
+ """
+ Returns the libclang version string used by the bindings
+ """
+ return _CXString.from_result(self.lib.clang_getClangVersion())
conf = Config()
diff --git a/clang/bindings/python/tests/cindex/test_version.py b/clang/bindings/python/tests/cindex/test_version.py
new file mode 100755
index 0000000000000..0540185221daa
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_version.py
@@ -0,0 +1,11 @@
+import unittest
+import re
+from clang.cindex import Config
+
+
+class TestClangVersion(unittest.TestCase):
+ def test_get_version_format(self):
+ conf = Config()
+ version = conf.get_version()
+
+ self.assertRegex(version, r"^clang version \d+\.\d+\.\d+")
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45234c316eba8..22b4e4d5cf121 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@ Python Binding Changes
``CodeCompletionResults.results`` should be changed to directly use
``CodeCompletionResults``: it nows supports ``__len__`` and ``__getitem__``,
so it can be used the same as ``CodeCompletionResults.results``.
+- Added a new helper method ``get_version`` to the class ``Config`` to read the
+ version string of the libclang in use
OpenMP Support
--------------
More information about the cfe-commits
mailing list