blob: 4f75163748c7c8d58e5a1d0a355e0712c8ef1996 [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'
23)
24EXCLUSIONS=(
25 'grpcio/grpc_*.py'
26 'grpcio_health_checking/grpc_*.py'
27 'grpcio_reflection/grpc_*.py'
28 'grpcio_tests/grpc_*.py'
29)
Masood Malekghassemi06dea572016-05-11 12:01:40 -070030
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000031VIRTUALENV=yapf_virtual_environment
Masood Malekghassemi06dea572016-05-11 12:01:40 -070032
33virtualenv $VIRTUALENV
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000034PYTHON=$(realpath "${VIRTUALENV}/bin/python")
35$PYTHON -m pip install --upgrade pip
36$PYTHON -m pip install --upgrade futures
Ken Payson2fa5f2f2017-02-06 10:27:09 -080037$PYTHON -m pip install yapf==0.16.0
Masood Malekghassemi06dea572016-05-11 12:01:40 -070038
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000039yapf() {
40 local exclusion exclusion_args=()
41 for exclusion in "${EXCLUSIONS[@]}"; do
42 exclusion_args+=( "--exclude" "$1/${exclusion}" )
43 done
44 $PYTHON -m yapf -i -r --style=setup.cfg -p "${exclusion_args[@]}" "${1}"
45}
Masood Malekghassemi06dea572016-05-11 12:01:40 -070046
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000047if [[ -z "${TEST}" ]]; then
48 for dir in "${DIRS[@]}"; do
49 yapf "${dir}"
50 done
51else
52 ok=yes
53 for dir in "${DIRS[@]}"; do
54 tempdir=$(mktemp -d)
55 cp -RT "${dir}" "${tempdir}"
56 yapf "${tempdir}"
57 diff -ru "${dir}" "${tempdir}" || ok=no
58 rm -rf "${tempdir}"
59 done
60 if [[ ${ok} == no ]]; then
61 false
62 fi
63fi