Debian Codegraph @

tools/run_tests/xds_k8s_test_driver/bin/yapf.sh

raw
1 #!/usr/bin/env bash
2 # Copyright 2021 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 -eo pipefail
17
18 display_usage() {
19 cat <<EOF >/dev/stderr
20 A helper to run yapf formatter.
21
22 USAGE: $0 [--diff]
23 --diff: Do not apply changes, only show the diff
24
25 ENVIRONMENT:
26 XDS_K8S_DRIVER_VENV_DIR: the path to python virtual environment directory
27 Default: $XDS_K8S_DRIVER_DIR/venv
28 EXAMPLES:
29 $0
30 $0 --diff
31 EOF
32 exit 1
33 }
34
35 if [[ "$1" == "-h" || "$1" == "--help" ]]; then
36 display_usage
37 fi
38
39 SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
40 readonly SCRIPT_DIR
41 readonly XDS_K8S_DRIVER_DIR="${SCRIPT_DIR}/.."
42
43 cd "${XDS_K8S_DRIVER_DIR}"
44
45 # Relative paths not yet supported by shellcheck.
46 # shellcheck source=/dev/null
47 source "${XDS_K8S_DRIVER_DIR}/bin/ensure_venv.sh"
48
49 if [[ "$1" == "--diff" ]]; then
50 readonly MODE="--diff"
51 else
52 readonly MODE="--in-place"
53 readonly VERBOSE="--verbose" # print out file names while processing
54 fi
55
56 exec python -m yapf "${MODE}" ${VERBOSE:-} \
57 --parallel --recursive --style=../../../setup.cfg \
58 framework bin tests