pylint_code.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Copyright 2017 The gRPC Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -ex
  16. # NOTE(rbellevi): We ignore generated code.
  17. IGNORE_PATTERNS=--ignore-patterns='.*pb2\.py,.*pb2_grpc\.py'
  18. # change to root directory
  19. cd "$(dirname "$0")/../.."
  20. DIRS=(
  21. 'src/python/grpcio/grpc'
  22. 'src/python/grpcio_channelz/grpc_channelz'
  23. 'src/python/grpcio_health_checking/grpc_health'
  24. 'src/python/grpcio_reflection/grpc_reflection'
  25. 'src/python/grpcio_testing/grpc_testing'
  26. 'src/python/grpcio_status/grpc_status'
  27. )
  28. TEST_DIRS=(
  29. 'src/python/grpcio_tests/tests'
  30. 'src/python/grpcio_tests/tests_gevent'
  31. )
  32. VIRTUALENV=python_pylint_venv
  33. python3 -m virtualenv $VIRTUALENV -p $(which python3)
  34. PYTHON=$VIRTUALENV/bin/python
  35. $PYTHON -m pip install --upgrade pip==19.3.1
  36. # TODO(https://github.com/grpc/grpc/issues/23394): Update Pylint.
  37. $PYTHON -m pip install --upgrade astroid==2.3.3 pylint==2.2.2 "isort>=4.3.0,<5.0.0"
  38. EXIT=0
  39. for dir in "${DIRS[@]}"; do
  40. $PYTHON -m pylint --rcfile=.pylintrc -rn "$dir" ${IGNORE_PATTERNS} || EXIT=1
  41. done
  42. for dir in "${TEST_DIRS[@]}"; do
  43. $PYTHON -m pylint --rcfile=.pylintrc-tests -rn "$dir" ${IGNORE_PATTERNS} || EXIT=1
  44. done
  45. find examples/python \
  46. -iname "*.py" \
  47. -not -name "*_pb2.py" \
  48. -not -name "*_pb2_grpc.py" \
  49. | xargs $PYTHON -m pylint --rcfile=.pylintrc-examples -rn ${IGNORE_PATTERNS}
  50. exit $EXIT