1#!/bin/bash
2# Copyright 2021 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
16set -ex
17
18ACTION=${1:---overwrite-in-place}
19[[ $ACTION == '--overwrite-in-place' ]] || [[ $ACTION == '--diff' ]]
20
21if [[ $ACTION == '--diff' ]]; then
22    ACTION="--diff --check"
23fi
24
25# Change to root
26cd "$(dirname "${0}")/../.."
27
28DIRS=(
29    'examples/python'
30    'src/python'
31    'test'
32    'tools'
33    'setup.py'
34    'tools/run_tests/xds_k8s_test_driver'
35)
36
37VIRTUALENV=isort_virtual_environment
38
39python3 -m virtualenv $VIRTUALENV
40PYTHON=${VIRTUALENV}/bin/python
41"$PYTHON" -m pip install isort==5.9.2
42
43$PYTHON -m isort $ACTION \
44  --force-sort-within-sections \
45  --force-single-line-imports --single-line-exclusions=typing \
46  --src "examples/python/data_transmission" \
47  --src "examples/python/async_streaming" \
48  --src "tools/run_tests/xds_k8s_test_driver" \
49  --src "src/python/grpcio_tests" \
50  --src "tools/run_tests" \
51  --project "examples" \
52  --project "src" \
53  --thirdparty "grpc" \
54  --skip-glob "third_party/*" \
55  --skip-glob "*/env/*" \
56  --skip-glob "*pb2*.py" \
57  --skip-glob "*pb2*.pyi" \
58  --skip-glob "**/site-packages/**/*" \
59  --dont-follow-links \
60  "${DIRS[@]}"
61