Add pre commit git hooks to automatically run autoformat script #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Automatically run autopep8 in place, recursively each time you commit based on rules from autoformat_python.sh,
if there are some errors, your commit will get rejected (no commit) and your code will be modified in place,
just run git add and git commit again.
This pre-commit hook will only modify the
.py
files that you have changed.Note: To skip commit hooks during a commit, you can use the
--no-verify
option with git commit.How to use:
pip install pre-commit
pre-commit install
to set up the git hook scriptsgit add
git commit
Note: If you don't follow either step 1 or step 2, then the workflow will be same as usual (no git hooks will be run).
Why do we need this ?
One of the problems with GNU Radio codebase is that there is autoformat
script that is needed to run manually to pass format test in git action,
so I think it will be a good idea to add pre-commit git hook to handle the
formatting before commit.
Related Issue
Which blocks/areas does this affect?
Every
.py
filesTesting Done
Make a commit that violating our code convention in
.py
files, also make commit to modify non.py
fileChange non
.py
fileChange
.py
file while violating code convention:Checklist