From 37de157b9e898606a2fa7b6bd31843044558f36e Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Mon, 24 Jun 2024 22:36:56 +0300 Subject: [PATCH 1/6] Refactored check-check-clang-format-version to a python script to fix crashes on win32. --- .pre-commit-config.yaml | 4 ++-- ci/check-clang-format-version.py | 20 ++++++++++++++++++++ ci/check-clang-format-version.sh | 12 ------------ 3 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 ci/check-clang-format-version.py delete mode 100755 ci/check-clang-format-version.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e8764b05e..eb7e5132f0 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: python ./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..c04c756784 --- /dev/null +++ b/ci/check-clang-format-version.py @@ -0,0 +1,20 @@ +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: + print(f'Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required.') + exit(1) + + print('Clang format version satisfied.') + exit(0) + + +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 From 0cb52f8ceae20961b7ffa67313a920c7f865e41c Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Mon, 24 Jun 2024 22:48:14 +0300 Subject: [PATCH 2/6] Lint --- ci/check-clang-format-version.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ci/check-clang-format-version.py b/ci/check-clang-format-version.py index c04c756784..0e1706345b 100644 --- a/ci/check-clang-format-version.py +++ b/ci/check-clang-format-version.py @@ -1,20 +1,22 @@ import subprocess -EXPECTED_CLANG_VERSION = '18.1.6' +EXPECTED_CLANG_VERSION = "18.1.6" def main(): - result = subprocess.run('clang-format --version', capture_output=True) + result = subprocess.run("clang-format --version", capture_output=True) result.check_returncode() - version_str = result.stdout.decode('utf-8').split(' ')[2].strip() + version_str = result.stdout.decode("utf-8").split(" ")[2].strip() if version_str != EXPECTED_CLANG_VERSION: - print(f'Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required.') + print( + f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required." + ) exit(1) - print('Clang format version satisfied.') + print("Clang format version satisfied.") exit(0) -if __name__ == '__main__': +if __name__ == "__main__": main() From c0b4713dd8414adaf1094083b957c39d25e6a11c Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Tue, 25 Jun 2024 11:49:19 +0300 Subject: [PATCH 3/6] Changed exit codes to ValueError exception. --- ci/check-clang-format-version.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ci/check-clang-format-version.py b/ci/check-clang-format-version.py index 0e1706345b..d546f7d80b 100644 --- a/ci/check-clang-format-version.py +++ b/ci/check-clang-format-version.py @@ -9,13 +9,9 @@ def main(): version_str = result.stdout.decode("utf-8").split(" ")[2].strip() if version_str != EXPECTED_CLANG_VERSION: - print( + raise ValueError( f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required." ) - exit(1) - - print("Clang format version satisfied.") - exit(0) if __name__ == "__main__": From c6efe07d84589dbc823e1342e074b92e7ad4a074 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Tue, 25 Jun 2024 11:50:55 +0300 Subject: [PATCH 4/6] Split subprocess arguments string. --- ci/check-clang-format-version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/check-clang-format-version.py b/ci/check-clang-format-version.py index d546f7d80b..501e326bff 100644 --- a/ci/check-clang-format-version.py +++ b/ci/check-clang-format-version.py @@ -4,7 +4,7 @@ def main(): - result = subprocess.run("clang-format --version", capture_output=True) + result = subprocess.run(("clang-format", "--version"), capture_output=True) result.check_returncode() version_str = result.stdout.decode("utf-8").split(" ")[2].strip() From aabbbba9b40cc7e07e3b74c449b647cface3b621 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Tue, 25 Jun 2024 11:55:18 +0300 Subject: [PATCH 5/6] Explicitly call python3. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb7e5132f0..8a7340763e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: hooks: - id: check-clang-format-version name: Check clang-format version - entry: python ./ci/check-clang-format-version.py + entry: python3 ./ci/check-clang-format-version.py language: system - id: clang-format name: Clang format From de4d3d8565ddab43fc6a75b2012d54bff20491d5 Mon Sep 17 00:00:00 2001 From: Dimitar Krastev Date: Tue, 25 Jun 2024 12:21:04 +0300 Subject: [PATCH 6/6] Changed string split to use default whitespace separators. --- ci/check-clang-format-version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/check-clang-format-version.py b/ci/check-clang-format-version.py index 501e326bff..7379a828a5 100644 --- a/ci/check-clang-format-version.py +++ b/ci/check-clang-format-version.py @@ -7,7 +7,7 @@ def main(): result = subprocess.run(("clang-format", "--version"), capture_output=True) result.check_returncode() - version_str = result.stdout.decode("utf-8").split(" ")[2].strip() + 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."