Created
September 20, 2019 14:33
-
-
Save eoranged/c3bd35913280fcc3fa11a34f80a928fb to your computer and use it in GitHub Desktop.
Pre commit hook to check python files for print statements/functions
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 | |
# BSD regex for finding Python print statements | |
find_print='\+[[:space:]]*print[[:space:](]' | |
# Save output to $out var | |
out=`git diff --staged | grep -e ${find_print}` | |
# Count number of prints | |
count=`echo "${out}" | grep -e '\w' | wc -l` | |
if [ $count -gt 0 ]; then | |
echo "================================================================================" | |
echo "$out" | |
echo "================================================================================" | |
echo | |
echo "$count print statement(s) found in commit! aborting" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment