Debian Codegraph @

tools/distrib/pylint_code.sh

raw
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
16 set -ex
17
18 # NOTE(rbellevi): We ignore generated code.
19 IGNORE_PATTERNS=--ignore-patterns='.*pb2\.py,.*pb2_grpc\.py'
20
21 # change to root directory
22 cd "$(dirname "$0")/../.."
23
24 DIRS=(
25 'src/python/grpcio/grpc'
26 'src/python/grpcio_channelz/grpc_channelz'
27 'src/python/grpcio_health_checking/grpc_health'
28 'src/python/grpcio_reflection/grpc_reflection'
29 'src/python/grpcio_testing/grpc_testing'
30 'src/python/grpcio_status/grpc_status'
31 'tools/run_tests/xds_k8s_test_driver/bin'
32 'tools/run_tests/xds_k8s_test_driver/framework'
33 )
34
35 TEST_DIRS=(
36 'src/python/grpcio_tests/tests'
37 'src/python/grpcio_tests/tests_gevent'
38 'tools/run_tests/xds_k8s_test_driver/tests'
39 )
40
41 VIRTUALENV=python_pylint_venv
42 python3 -m virtualenv $VIRTUALENV -p $(which python3)
43
44 PYTHON=$VIRTUALENV/bin/python
45
46 $PYTHON -m pip install --upgrade pip==19.3.1
47
48 # TODO(https://github.com/grpc/grpc/issues/23394): Update Pylint.
49 $PYTHON -m pip install --upgrade astroid==2.3.3 pylint==2.2.2 "isort>=4.3.0,<5.0.0"
50
51 EXIT=0
52 for dir in "${DIRS[@]}"; do
53 $PYTHON -m pylint --rcfile=.pylintrc -rn "$dir" ${IGNORE_PATTERNS} || EXIT=1
54 done
55
56 for dir in "${TEST_DIRS[@]}"; do
57 $PYTHON -m pylint --rcfile=.pylintrc-tests -rn "$dir" ${IGNORE_PATTERNS} || EXIT=1
58 done
59
60 find examples/python \
61 -iname "*.py" \
62 -not -name "*_pb2.py" \
63 -not -name "*_pb2_grpc.py" \
64 | xargs $PYTHON -m pylint --rcfile=.pylintrc-examples -rn ${IGNORE_PATTERNS}
65
66 exit $EXIT