Author: efferre79 Date: 2026-03-21T17:25:29+04:00 New Revision: 656fce889c65157daa0aea7f9fd1080e0f04d7dd
URL: https://github.com/llvm/llvm-project/commit/656fce889c65157daa0aea7f9fd1080e0f04d7dd DIFF: https://github.com/llvm/llvm-project/commit/656fce889c65157daa0aea7f9fd1080e0f04d7dd.diff LOG: [libclang/python] export libclang version to the bindings (#86931) It's useful to know which clang library the python bindings are running. --------- Co-authored-by: Vlad Serebrennikov <[email protected]> Added: clang/bindings/python/tests/cindex/test_version.py Modified: clang/bindings/python/clang/cindex.py clang/docs/ReleaseNotes.rst Removed: ################################################################################ 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 b13171f7ecafc..b92f1ab34aa51 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -545,6 +545,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 -------------- _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
