Last active
December 14, 2021 03:54
-
-
Save umr55766/ece111837cfb468211ccacb9e65fb5be to your computer and use it in GitHub Desktop.
A pre-commit hook to blacked the python code before verfying it with flake8 , this hook only blacken and verify those files which have extension "py" i.e. [*.py] and have been added to stage for committing. Unstaged files and other files are not considered. This hook also abort commit if flake8 throws any message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# blacken the staged files | |
for file in $(git diff --cached --name-only | grep -E '\.(py)$') | |
do | |
black "$file" | |
$(git add "$file") | |
done | |
for file in $(git diff --cached --name-only | grep -E '\.(py)$') | |
do | |
flake8 "$file" | |
if [ $? -ne 0 ]; then | |
echo "flake8 failed on staged file '$file'. Please check your code and try again. To check output manually run flake8 $file" | |
exit 1 # exit with failure status | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[flake8] | |
exclude = .git | |
max-line-length = 119 | |
ignore = E203, W503 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@karan-freightwalla
https://gist.githubusercontent.com/umr55766/ece111837cfb468211ccacb9e65fb5be/raw/d8e2047ad704759e5f2450be76aa3ed24a225d6d/setup.cfg