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