blob: f096868660849569028ecabe90412b7127e06aac [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=(
ncteisenacbf0652017-12-12 10:58:19 -080026 '*protoc_lib_deps.py' # this file is auto-generated
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000027)
Masood Malekghassemi06dea572016-05-11 12:01:40 -070028
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000029VIRTUALENV=yapf_virtual_environment
Masood Malekghassemi06dea572016-05-11 12:01:40 -070030
31virtualenv $VIRTUALENV
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000032PYTHON=$(realpath "${VIRTUALENV}/bin/python")
Nathaniel Manista8bba3bf2017-06-26 16:33:25 +000033$PYTHON -m pip install --upgrade pip==9.0.1
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000034$PYTHON -m pip install --upgrade futures
Ken Payson2fa5f2f2017-02-06 10:27:09 -080035$PYTHON -m pip install yapf==0.16.0
Masood Malekghassemi06dea572016-05-11 12:01:40 -070036
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000037yapf() {
38 local exclusion exclusion_args=()
39 for exclusion in "${EXCLUSIONS[@]}"; do
40 exclusion_args+=( "--exclude" "$1/${exclusion}" )
41 done
42 $PYTHON -m yapf -i -r --style=setup.cfg -p "${exclusion_args[@]}" "${1}"
43}
Masood Malekghassemi06dea572016-05-11 12:01:40 -070044
Nathaniel Manista9f1e5ab2017-03-02 23:29:52 +000045if [[ -z "${TEST}" ]]; then
46 for dir in "${DIRS[@]}"; do
47 yapf "${dir}"
48 done
49else
50 ok=yes
51 for dir in "${DIRS[@]}"; do
52 tempdir=$(mktemp -d)
53 cp -RT "${dir}" "${tempdir}"
54 yapf "${tempdir}"
55 diff -ru "${dir}" "${tempdir}" || ok=no
56 rm -rf "${tempdir}"
57 done
58 if [[ ${ok} == no ]]; then
59 false
60 fi
61fi