Skip to content

Instantly share code, notes, and snippets.

@eoranged
Created September 20, 2019 14:33
Show Gist options
  • Save eoranged/c3bd35913280fcc3fa11a34f80a928fb to your computer and use it in GitHub Desktop.
Save eoranged/c3bd35913280fcc3fa11a34f80a928fb to your computer and use it in GitHub Desktop.
Pre commit hook to check python files for print statements/functions
#!/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