blob: 85a45b6a11c1cd406c48b042e229ec33ca16202e [file] [log] [blame]
Masood Malekghassemi06dea572016-05-11 12:01:40 -07001#!/bin/bash
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2015 gRPC authors.
Masood Malekghassemi06dea572016-05-11 12:01:40 -07003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# 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
Masood Malekghassemi06dea572016-05-11 12:01:40 -07007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Masood Malekghassemi06dea572016-05-11 12:01:40 -07009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# 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.
Masood Malekghassemi06dea572016-05-11 12:01:40 -070015
16set -ex
17
18# change to root directory
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000019cd "$(dirname "${0}")/../.."
Masood Malekghassemi06dea572016-05-11 12:01:40 -070020
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000021DIRS=(
22 'src/python'
ncteisen5f8bf792017-12-11 18:09:31 -080023 'tools'
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000024)
25EXCLUSIONS=(
26 'grpcio/grpc_*.py'
27 'grpcio_health_checking/grpc_*.py'
28 'grpcio_reflection/grpc_*.py'
Nathaniel Manista69b72312017-07-21 03:18:11 +000029 'grpcio_testing/grpc_*.py'
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000030 'grpcio_tests/grpc_*.py'
31)
Masood Malekghassemi06dea572016-05-11 12:01:40 -070032
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000033VIRTUALENV=yapf_virtual_environment
Masood Malekghassemi06dea572016-05-11 12:01:40 -070034
35virtualenv $VIRTUALENV
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000036PYTHON=$(realpath "${VIRTUALENV}/bin/python")
Nathaniel Manista8bba3bf2017-06-26 16:33:25 +000037$PYTHON -m pip install --upgrade pip==9.0.1
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000038$PYTHON -m pip install --upgrade futures
Ken Payson2fa5f2f2017-02-06 10:27:09 -080039$PYTHON -m pip install yapf==0.16.0
Masood Malekghassemi06dea572016-05-11 12:01:40 -070040
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000041yapf() {
42 local exclusion exclusion_args=()
43 for exclusion in "${EXCLUSIONS[@]}"; do
44 exclusion_args+=( "--exclude" "$1/${exclusion}" )
45 done
46 $PYTHON -m yapf -i -r --style=setup.cfg -p "${exclusion_args[@]}" "${1}"
47}
Masood Malekghassemi06dea572016-05-11 12:01:40 -070048
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000049if [[ -z "${TEST}" ]]; then
50 for dir in "${DIRS[@]}"; do
51 yapf "${dir}"
52 done
53else
54 ok=yes
55 for dir in "${DIRS[@]}"; do
56 tempdir=$(mktemp -d)
57 cp -RT "${dir}" "${tempdir}"
58 yapf "${tempdir}"
59 diff -ru "${dir}" "${tempdir}" || ok=no
60 rm -rf "${tempdir}"
61 done
62 if [[ ${ok} == no ]]; then
63 false
64 fi
65fi