Skip to content

Add pre-commit hooks#316

Closed
jithunnair-amd wants to merge 2 commits intomasterfrom
jithunnair-amd-patch-1
Closed

Add pre-commit hooks#316
jithunnair-amd wants to merge 2 commits intomasterfrom
jithunnair-amd-patch-1

Conversation

@jithunnair-amd
Copy link
Copy Markdown
Collaborator

@jithunnair-amd jithunnair-amd commented Mar 9, 2026

Motivation

Adds a yml file with pre-commit hook configuration, so that it runs basic checks before commits, to catch any issues with conflict markers being present, or python/yaml/json/toml syntax.

Technical Details

Adds a .pre-commit-config.yaml as per https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file

Test Plan

Running locally by installing pre-commit and pre-commit-hooks:

pip install pre-commit
pip install pre-commit-hooks
<make a syntactically wrong change in setup.py>
git add setup.py
git commit

Test Result

root@83ee99e9756c:/data/apex# git commit 
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /root/.cache/pre-commit/patch1773082640-81166.
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing setup.py

check python ast.........................................................Failed
- hook id: check-ast
- exit code: 1

setup.py: failed parsing with CPython 3.12.3:

    Traceback (most recent call last):
      File "/root/.cache/pre-commit/repo4lc_w330/py_env-python3.12/lib/python3.12/site-packages/pre_commit_hooks/check_ast.py", line 21, in main
        ast.parse(f.read(), filename=filename)
      File "/usr/lib/python3.12/ast.py", line 52, in parse
        return compile(source, filename, mode, flags,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "setup.py", line 25
        >>>>>>
        ^^
    SyntaxError: invalid syntax

check json...........................................(no files to check)Skipped
check for merge conflicts................................................Passed
check toml...........................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
[WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes...
[INFO] Restored changes from /root/.cache/pre-commit/patch1773082640-81166.

Submission Checklist

@jithunnair-amd
Copy link
Copy Markdown
Collaborator Author

Closing in favor of #320

@jithunnair-amd jithunnair-amd deleted the jithunnair-amd-patch-1 branch March 23, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant