diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e8764b05e..8a7340763e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,8 +5,8 @@ repos: hooks: - id: check-clang-format-version name: Check clang-format version - entry: ./ci/check-clang-format-version.sh - language: script + entry: python3 ./ci/check-clang-format-version.py + language: system - id: clang-format name: Clang format entry: clang-format diff --git a/ci/check-clang-format-version.py b/ci/check-clang-format-version.py new file mode 100644 index 0000000000..7379a828a5 --- /dev/null +++ b/ci/check-clang-format-version.py @@ -0,0 +1,18 @@ +import subprocess + +EXPECTED_CLANG_VERSION = "18.1.6" + + +def main(): + result = subprocess.run(("clang-format", "--version"), capture_output=True) + result.check_returncode() + + version_str = result.stdout.decode("utf-8").split()[2].strip() + if version_str != EXPECTED_CLANG_VERSION: + raise ValueError( + f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required." + ) + + +if __name__ == "__main__": + main() diff --git a/ci/check-clang-format-version.sh b/ci/check-clang-format-version.sh deleted file mode 100755 index ddb6aba2db..0000000000 --- a/ci/check-clang-format-version.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -EXPECTED_VERSION="18.1.6" - -# Get the installed clang-format version -INSTALLED_VERSION=$(clang-format --version | grep -oE '[0-9]+(\.[0-9]+)+') - -if [ "$INSTALLED_VERSION" != "$EXPECTED_VERSION" ]; then - echo "Error: clang-format version $INSTALLED_VERSION found, but $EXPECTED_VERSION is required." - exit 1 -fi - -exit 0