Skip to content

[Tools] move precommit checks to tools/#1781

Merged
tdavidcl merged 1 commit intoShamrock-code:mainfrom
tdavidcl:move_precommit_tools
Apr 26, 2026
Merged

[Tools] move precommit checks to tools/#1781
tdavidcl merged 1 commit intoShamrock-code:mainfrom
tdavidcl:move_precommit_tools

Conversation

@tdavidcl
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates several pre-commit check scripts to a new tools directory and introduces a shamrock_tool_banner utility for standardized output. The review identifies critical bugs in the banner script, specifically an incorrect project path calculation and a typo in the git status logic. Further recommendations include replacing a bare except clause, using the subprocess module instead of os.popen, and eliminating redundant path calculations across scripts by leveraging the variables now provided by the banner utility.

"""
# end allow utf-8

abs_proj_dir = os.path.abspath(os.path.join(__file__, "../../.."))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The project directory calculation is incorrect. Using os.path.join(__file__, "../../..") on a file located in tools/ resolves to the parent of the project root, not the root itself. It should be two levels up from the file path to reach the root.

Suggested change
abs_proj_dir = os.path.abspath(os.path.join(__file__, "../../.."))
abs_proj_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))


try:
col_cnt = os.get_terminal_size().columns
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Avoid using bare except: clauses as they catch all exceptions, including SystemExit and KeyboardInterrupt. Use except Exception: or a more specific exception type like OSError.

Suggested change
except:
except Exception:

git_head = "\033[1;92m" + git_head[0] + "\033[0;0m"
else:
git_head = (
"\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[0] + "\033[0;0m"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There is a typo here where git_head[0] is used twice. When multiple references are present in the git log decoration, the second one should likely be git_head[1].

Suggested change
"\033[1;92m" + git_head[0] + "\033[0;0m , \033[1;91m" + git_head[0] + "\033[0;0m"
"\033[1;92m" + git_head[0].strip() + "\033[0;0m , \033[1;91m" + git_head[1].strip() + "\033[0;0m"

print(" \033[1;93mcommit \033[0;0m: ", git_hash)
print(" \033[1;36mHEAD \033[0;0m: ", git_head)
print(" \033[1;31mmodified files\033[0;0m (since last commit):")
print(os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using os.popen is discouraged in favor of the subprocess module, which provides better error handling and security. Since subprocess is already imported and used elsewhere in this file, it should be used here as well.

Suggested change
print(os.popen('git diff-index --name-only HEAD -- | sed "s/^/ /g"').read())
diff_proc = subprocess.run(["git", "diff-index", "--name-only", "HEAD", "--"], capture_output=True, text=True, check=True)
for line in diff_proc.stdout.splitlines():
print(" " + line)

Comment on lines +8 to +9
abs_proj_dir = os.path.join(os.path.dirname(__file__), "..")
abs_src_dir = os.path.join(abs_proj_dir, "src")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The calculation of abs_proj_dir and abs_src_dir is duplicated across multiple scripts. Since shamrock_tool_banner already defines these variables, they should be reused to improve maintainability.

Suggested change
abs_proj_dir = os.path.join(os.path.dirname(__file__), "..")
abs_src_dir = os.path.join(abs_proj_dir, "src")
abs_proj_dir = shamrock_tool_banner.abs_proj_dir
abs_src_dir = shamrock_tool_banner.abs_src_dir
References
  1. Refactor duplicated logic into a helper function or lambda to improve readability and maintainability.

Comment thread tools/check_licencing.py
Comment on lines +8 to +9
abs_proj_dir = os.path.join(os.path.dirname(__file__), "..")
abs_src_dir = os.path.join(abs_proj_dir, "src")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The calculation of abs_proj_dir and abs_src_dir is duplicated here as well. Reusing the variables from shamrock_tool_banner would improve maintainability.

Suggested change
abs_proj_dir = os.path.join(os.path.dirname(__file__), "..")
abs_src_dir = os.path.join(abs_proj_dir, "src")
abs_proj_dir = shamrock_tool_banner.abs_proj_dir
abs_src_dir = shamrock_tool_banner.abs_src_dir
References
  1. Refactor duplicated logic into a helper function or lambda to improve readability and maintainability.

@github-actions
Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 8d09382
Commiter email is [email protected]
GitHub page artifact URL GitHub page artifact link (can expire)

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
cmake-format.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Clang-tidy diff report

No relevant changes found.
Well done!

You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review.

Doxygen diff with main

Removed warnings : 0
New warnings : 0
Warnings count : 8283 → 8283 (0.0%)

Detailed changes :

@tdavidcl tdavidcl merged commit 6afece9 into Shamrock-code:main Apr 26, 2026
81 checks passed
@tdavidcl tdavidcl deleted the move_precommit_tools branch April 26, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant