checkpep8 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # Copyright (C) 1994-2017 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  16. # PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License along
  19. # with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Commercial License Information:
  22. #
  23. # The PBS Pro software is licensed under the terms of the GNU Affero General
  24. # Public License agreement ("AGPL"), except where a separate commercial license
  25. # agreement for PBS Pro version 14 or later has been executed in writing with Altair.
  26. #
  27. # Altair’s dual-license business model allows companies, individuals, and
  28. # organizations to create proprietary derivative works of PBS Pro and distribute
  29. # them - whether embedded or bundled with other software - under a commercial
  30. # license agreement.
  31. #
  32. # Use of Altair’s trademarks, including but not limited to "PBS™",
  33. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  34. # trademark licensing policies.
  35. checkdir="$(readlink -f $(dirname $0))"
  36. errors=0
  37. which pep8 1>/dev/null 2>/dev/null
  38. if [ $? -ne 0 ]; then
  39. echo "Could not find pep8 command" 1>&2
  40. exit 1
  41. fi
  42. cd ${checkdir}/..
  43. is_python_file() {
  44. name=$(basename ${1})
  45. # special case
  46. # if .rst file then it will be considered
  47. # as a plain text file
  48. if [ "x${name##*.}" == "xrst" ]; then
  49. return 1
  50. fi
  51. # special case
  52. # if __init__.py does not contain any code then file
  53. # command will consider it as plain text file
  54. if [ "x${name}" == "x__init__.py" ]; then
  55. return 0
  56. fi
  57. if [ "x$(file --mime-type -b ${1})" == "xtext/x-python" ]; then
  58. return 0
  59. fi
  60. return 1
  61. }
  62. check_pep8() {
  63. pep8 --show-source ${1} >out_check_pep8 2>&1
  64. return $?
  65. }
  66. for f in $(find test -type f)
  67. do
  68. if is_python_file ${f}
  69. then
  70. if ! check_pep8 ${f}
  71. then
  72. cat out_check_pep8 1>&2
  73. rm -f out_check_pep8
  74. errors=$((errors + 1))
  75. fi
  76. if [ -x "${f}" ]; then
  77. echo "${f}: executable bit set" 1>&2
  78. errors=$((errors + 1))
  79. fi
  80. fi
  81. done
  82. if [ ${errors} -ne 0 ]; then
  83. exit 1
  84. else
  85. exit 0
  86. fi