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

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented Jun 24, 2024

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.

@Dimi1010 Dimi1010 added the CI label Jun 24, 2024
@Dimi1010 Dimi1010 requested a review from seladb as a code owner June 24, 2024 19:49
@Dimi1010 Dimi1010 linked an issue Jun 24, 2024 that may be closed by this pull request


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

@@ -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

Comment on lines 12 to 15
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

exit(1)

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

Copy link
Owner

@seladb seladb left a 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

result = subprocess.run(("clang-format", "--version"), capture_output=True)
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

@tigercosmos tigercosmos merged commit 2b22d02 into seladb:dev Jun 25, 2024
39 checks passed
@Dimi1010 Dimi1010 deleted the fix/clang-version-checker-win32 branch June 25, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

check clang-version on Windows
3 participants