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=( |
| 26 | 'grpcio/grpc_*.py' |
| 27 | 'grpcio_health_checking/grpc_*.py' |
| 28 | 'grpcio_reflection/grpc_*.py' |
Nathaniel Manista | 69b7231 | 2017-07-21 03:18:11 +0000 | [diff] [blame] | 29 | 'grpcio_testing/grpc_*.py' |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 30 | 'grpcio_tests/grpc_*.py' |
| 31 | ) |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 32 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 33 | VIRTUALENV=yapf_virtual_environment |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 34 | |
| 35 | virtualenv $VIRTUALENV |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 36 | PYTHON=$(realpath "${VIRTUALENV}/bin/python") |
Nathaniel Manista | 8bba3bf | 2017-06-26 16:33:25 +0000 | [diff] [blame] | 37 | $PYTHON -m pip install --upgrade pip==9.0.1 |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 38 | $PYTHON -m pip install --upgrade futures |
Ken Payson | 2fa5f2f | 2017-02-06 10:27:09 -0800 | [diff] [blame] | 39 | $PYTHON -m pip install yapf==0.16.0 |
Masood Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 40 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 41 | yapf() { |
| 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 Malekghassemi | 06dea57 | 2016-05-11 12:01:40 -0700 | [diff] [blame] | 48 | |
Nathaniel Manista | 9f1e5ab | 2017-03-02 23:29:52 +0000 | [diff] [blame] | 49 | if [[ -z "${TEST}" ]]; then |
| 50 | for dir in "${DIRS[@]}"; do |
| 51 | yapf "${dir}" |
| 52 | done |
| 53 | else |
| 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 |
| 65 | fi |