-
Notifications
You must be signed in to change notification settings - Fork 675
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
Refactored clang version check into a python script. #1471
Conversation
… crashes on win32.
ci/check-clang-format-version.py
Outdated
|
||
|
||
def main(): | ||
result = subprocess.run("clang-format --version", capture_output=True) |
There was a problem hiding this comment.
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"]...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed c6efe07
.pre-commit-config.yaml
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly use Python3?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed aabbbba
ci/check-clang-format-version.py
Outdated
print( | ||
f"Error: Found clang-format version {version_str}, but {EXPECTED_CLANG_VERSION} is required." | ||
) | ||
exit(1) |
There was a problem hiding this comment.
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.")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed c0b4713
ci/check-clang-format-version.py
Outdated
exit(1) | ||
|
||
print("Clang format version satisfied.") | ||
exit(0) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed c0b4713
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, otherwise LGTM
ci/check-clang-format-version.py
Outdated
result = subprocess.run(("clang-format", "--version"), capture_output=True) | ||
result.check_returncode() | ||
|
||
version_str = result.stdout.decode("utf-8").split(" ")[2].strip() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Updated in de4d3d8
Fixes #1470
The PR changes the clang version check script from a bash script to a python script. The idea is that since pre-commit is a python package, the system running it will (hopefully) have a system-wide python interpreter installed and can run the checker script regardless of the OS.