lint-python.sh 708 B

123456789101112131415161718192021222324252627282930313233
  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. files=()
  7. while IFS= read -r file; do
  8. files+=("$file")
  9. done < <(
  10. git ls-files '*.py'
  11. )
  12. else
  13. files=()
  14. for file in "$@"; do
  15. if [[ "${file}" == *".py" ]]; then
  16. files+=("${file}")
  17. fi
  18. done
  19. fi
  20. if (( ${#files[@]} )); then
  21. if ! command -v flake8 >/dev/null 2>&1 ; then
  22. echo "flake8 is not available, but python files need linting! Either skip this script, or install flake8."
  23. exit 1
  24. fi
  25. flake8 "${files[@]}" --max-line-length=120
  26. else
  27. echo "No py files to check."
  28. fi