Add test behavior to yapf_code.sh

With this change yapf_code no longer changes the code under test when
executed from within the sanity tests.
pull/9965/head
Nathaniel Manista 8 years ago
parent 98a4c6f33f
commit 9f1e5ab3c9
  1. 2
      .gitignore
  2. 59
      tools/distrib/yapf_code.sh

2
.gitignore vendored

@ -8,7 +8,7 @@ objs
# Python items # Python items
cython_debug/ cython_debug/
python_build/ python_build/
python_format_venv/ yapf_virtual_environment/
python_pylint_venv/ python_pylint_venv/
.coverage* .coverage*
.eggs .eggs

@ -31,31 +31,48 @@
set -ex set -ex
# change to root directory # change to root directory
cd $(dirname $0)/../.. cd "$(dirname "${0}")/../.."
DIRS=src/python DIRS=(
EXCLUSIONS='src/python/grpcio/grpc_*.py src/python/grpcio_health_checking/grpc_*.py src/python/grpcio_reflection/grpc_*.py src/python/grpcio_tests/grpc_*.py' 'src/python'
)
EXCLUSIONS=(
'grpcio/grpc_*.py'
'grpcio_health_checking/grpc_*.py'
'grpcio_reflection/grpc_*.py'
'grpcio_tests/grpc_*.py'
)
VIRTUALENV=python_format_venv VIRTUALENV=yapf_virtual_environment
virtualenv $VIRTUALENV virtualenv $VIRTUALENV
PYTHON=`realpath $VIRTUALENV/bin/python` PYTHON=$(realpath "${VIRTUALENV}/bin/python")
$PYTHON -m pip install futures $PYTHON -m pip install --upgrade pip
$PYTHON -m pip install --upgrade futures
$PYTHON -m pip install yapf==0.16.0 $PYTHON -m pip install yapf==0.16.0
exclusion_args="" yapf() {
for exclusion in $EXCLUSIONS; do local exclusion exclusion_args=()
exclusion_args="$exclusion_args --exclude $exclusion" for exclusion in "${EXCLUSIONS[@]}"; do
done exclusion_args+=( "--exclude" "$1/${exclusion}" )
done
$PYTHON -m yapf -i -r --style=setup.cfg -p "${exclusion_args[@]}" "${1}"
}
script_result=0 if [[ -z "${TEST}" ]]; then
for dir in $DIRS; do for dir in "${DIRS[@]}"; do
tempdir=`mktemp -d` yapf "${dir}"
cp -RT $dir $tempdir done
$PYTHON -m yapf -i -r -p $exclusion_args $dir else
if ! diff -r $dir $tempdir; then ok=yes
script_result=1 for dir in "${DIRS[@]}"; do
fi tempdir=$(mktemp -d)
rm -rf $tempdir cp -RT "${dir}" "${tempdir}"
done yapf "${tempdir}"
exit $script_result diff -ru "${dir}" "${tempdir}" || ok=no
rm -rf "${tempdir}"
done
if [[ ${ok} == no ]]; then
false
fi
fi

Loading…
Cancel
Save