Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored clang version check into a python script. #1471

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: python ./ci/check-clang-format-version.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly use Python3?

Copy link
Collaborator Author

@Dimi1010 Dimi1010 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. subprocess.run is not supported pre python 3.5 anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed aabbbba

language: system
- id: clang-format
name: Clang format
entry: clang-format
Expand Down
22 changes: 22 additions & 0 deletions ci/check-clang-format-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess

EXPECTED_CLANG_VERSION = "18.1.6"


def main():
result = subprocess.run("clang-format --version", capture_output=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subprocess.run(["clang-format", "--version"]...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed c6efe07

result.check_returncode()

version_str = result.stdout.decode("utf-8").split(" ")[2].strip()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the default split character is space, so you can just do: .split()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Updated in de4d3d8

if version_str != EXPECTED_CLANG_VERSION:
print(
f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required."
)
exit(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python the convention is to throw an exception. It's exit value is 1:

raise ValueError(f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required.")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed c0b4713


print("Clang format version satisfied.")
exit(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not needed. The default exit value is 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed c0b4713



if __name__ == "__main__":
main()
12 changes: 0 additions & 12 deletions ci/check-clang-format-version.sh

This file was deleted.

Loading