Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2015 gRPC authors. |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 15 | |
| 16 | set -ex |
| 17 | |
| 18 | # change to root directory |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 19 | cd "$(dirname "${0}")/../.." |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 20 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 21 | DIRS=( |
| 22 | 'src/python' |
ncteisen | 5f8bf79 | 2017-12-11 18:09:31 -0800 | [diff] [blame] | 23 | 'tools' |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 24 | ) |
| 25 | EXCLUSIONS=( |
ncteisen | acbf065 | 2017-12-12 10:58:19 -0800 | [diff] [blame^] | 26 | '*protoc_lib_deps.py' # this file is auto-generated |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 27 | ) |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 28 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 29 | VIRTUALENV=yapf_virtual_environment |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 30 | |
| 31 | virtualenv $VIRTUALENV |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 32 | PYTHON=$(realpath "${VIRTUALENV}/bin/python") |
Nathaniel Manista | 8bba3bf | 2017-06-26 16:33:25 +0000 | [diff] [blame] | 33 | $PYTHON -m pip install --upgrade pip==9.0.1 |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 34 | $PYTHON -m pip install --upgrade futures |
Ken Payson | 2fa5f2f | 2017-02-06 10:27:09 -0800 | [diff] [blame] | 35 | $PYTHON -m pip install yapf==0.16.0 |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 36 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 37 | yapf() { |
| 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 Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 44 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 45 | if [[ -z "${TEST}" ]]; then |
| 46 | for dir in "${DIRS[@]}"; do |
| 47 | yapf "${dir}" |
| 48 | done |
| 49 | else |
| 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 |
| 61 | fi |