lint-python.sh 649 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. set -e
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "${script_path}/.." || exit 1
  5. if [ "$#" -eq "0" ]; then
  6. mapfile -t files < <(
  7. git ls-files '*.py'
  8. )
  9. else
  10. files=()
  11. for file in "$@"; do
  12. if [[ "${file}" == *".py" ]]; then
  13. files+=("${file}")
  14. fi
  15. done
  16. fi
  17. if (( ${#files[@]} )); then
  18. if ! command -v flake8 >/dev/null 2>&1 ; then
  19. echo "flake8 is not available, but python files need linting! Either skip this script, or install flake8."
  20. exit 1
  21. fi
  22. flake8 "${files[@]}" --max-line-length=120
  23. else
  24. echo "No py files to check."
  25. fi