Skip to content

Commit

Permalink
Refactored clang version check into a python script. (#1471)
Browse files Browse the repository at this point in the history
* Refactored check-check-clang-format-version to a python script to fix crashes on win32.

* Lint

* Changed exit codes to ValueError exception.

* Split subprocess arguments string.

* Explicitly call python3.

* Changed string split to use default whitespace separators.
  • Loading branch information
Dimi1010 authored Jun 25, 2024
1 parent 06d15d7 commit 2b22d02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions ci/check-clang-format-version.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 0 additions & 12 deletions ci/check-clang-format-version.sh

This file was deleted.

0 comments on commit 2b22d02

Please sign in to comment.