pre-commit 784 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # Create a link to this file at .git/hooks/pre-commit to
  3. # force PEP8 validation prior to committing
  4. #
  5. # Ignored violations:
  6. #
  7. # W504: Line break after binary operator
  8. # E501: Line too long
  9. exec 1>&2
  10. EXIT=0
  11. RED='\033[0;31m'
  12. NOCOLOR='\033[0m'
  13. if [ -d ./venv/ ]; then
  14. VENV="$PWD/venv"
  15. if [ -e $VENV/bin/python ]; then
  16. PATH=$VENV/bin:$PATH
  17. elif [ -e $VENV/Scripts/python.exe ]; then
  18. PATH=$VENV/Scripts:$PATH
  19. fi
  20. fi
  21. echo "Validating PEP8 compliance..."
  22. pycodestyle --ignore=W504,E501 netbox/
  23. if [ $? != 0 ]; then
  24. EXIT=1
  25. fi
  26. echo "Checking for missing migrations..."
  27. python netbox/manage.py makemigrations --dry-run --check
  28. if [ $? != 0 ]; then
  29. EXIT=1
  30. fi
  31. if [ $EXIT != 0 ]; then
  32. printf "${RED}COMMIT FAILED${NOCOLOR}\n"
  33. fi
  34. exit $EXIT