diff options
-rwxr-xr-x | toolchain_utils_githooks/pre-push | 33 | ||||
-rwxr-xr-x | toolchain_utils_githooks/pre-push.real | 71 | ||||
-rw-r--r-- | utils/pstat.py | 10 |
3 files changed, 82 insertions, 32 deletions
diff --git a/toolchain_utils_githooks/pre-push b/toolchain_utils_githooks/pre-push index 2eff76ef..eef8a09a 100755 --- a/toolchain_utils_githooks/pre-push +++ b/toolchain_utils_githooks/pre-push @@ -1,30 +1,9 @@ -#!/bin/sh +#!/bin/bash # -# Copyright (c) 2015 Google Inc. +# Copyright (c) 2016 Google Inc. # -# This is a pre-push hook that allows the user to run the unit tests -# before uploading a CL for review. -run_UnitTests() { - save_dir=`pwd` - status=0 - valid=0 - exec < /dev/tty - while [ $valid -eq 0 ] ; do - read -p "Run unit tests? [y/n] " choice - case "$choice" in - n|N ) valid=1 ;; - y|Y ) valid=1; cd crosperf; ./run_tests.sh; status=$? ; - cd $save_dir;; - * ) echo "Must choose y or n." - esac - done - if [ $status -ne 0 ] - then - exit $status - fi -} - -run_UnitTests - -exit 0 +# Just execute our custom pre-push script. +# Do this trick so that this file does not need to be updated each time +# we modify our pre-push script +exec ./toolchain_utils_githooks/pre-push.real "$@" diff --git a/toolchain_utils_githooks/pre-push.real b/toolchain_utils_githooks/pre-push.real new file mode 100755 index 00000000..0f6856ee --- /dev/null +++ b/toolchain_utils_githooks/pre-push.real @@ -0,0 +1,71 @@ +#!/bin/bash +# +# Copyright (c) 2015 Google Inc. +# +# This is a pre-push hook that does the following before uploading a +# CL for review: +# 1) check that python sources have been formatted with pyformat. +# 2) allows the user to run the unit tests. + +# This redirects stdin. Make sure to run after stdin has been read. +run_UnitTests() { + save_dir=$(pwd) + status=0 + valid=0 + + # Make sure we can read the stdin from terminal + exec < /dev/tty + + while [[ $valid -eq 0 ]] ; do + read -p "Run unit tests? [y/n] " choice + case "$choice" in + n|N ) valid=1 ;; + y|Y ) valid=1; cd crosperf; ./run_tests.sh; status=$? ; + cd $save_dir;; + * ) echo "Must choose y or n." + esac + done + if [[ $status -ne 0 ]]; then + exit $status + fi +} + +run_PyFormat() { + pyformat="./bin/tc_pyformat" + range=$1 + files=$(git show --pretty="format:" --name-only $range) + for f in $files; do + [[ $f == *.py ]] || continue + # File could have been removed as part of the commit. + [[ -e $f ]] || continue + diffs=$($pyformat -d $f) + if [[ $? -ne 0 ]]; then + echo "Error: $pyformat $f returned with error code $?" + exit 1 + fi + if [[ -n "$diffs" ]]; then + echo -e "Error: $f is not formatted correctly. Run $pyformat -i $f\n" + echo -e "diffs:\n$diffs\n" + exit 2 + fi + done +} + +z40=0000000000000000000000000000000000000000 + +while IFS=' ' read local_ref local_sha remote_ref remote_sha; do + if [[ "$local_sha" != $z40 ]]; then + if [[ "$remote_sha" == $z40 ]]; then + # New branch, examine commit on top of branch. + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + run_PyFormat $range + fi +done + +run_UnitTests + +exit 0 diff --git a/utils/pstat.py b/utils/pstat.py index b145c9df..602fc0c7 100644 --- a/utils/pstat.py +++ b/utils/pstat.py @@ -8,10 +8,10 @@ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -101,7 +101,7 @@ functions/methods. Their inclusion here is for function name consistency. ## 12/05/98 ... updated doc-strings ## added features to collapse() function ## added flat() function for lists -## fixed a broken asortrows() +## fixed a broken asortrows() ## 11/16/98 ... fixed minor bug in aput for 1D arrays ## ## 11/08/98 ... fixed aput to output large arrays correctly @@ -979,8 +979,8 @@ Returns: an array of equal length containing 1s where the two rows had """ return if row1.dtype.char == 'O' or row2.dtype == 'O': - cmpvect = N.logical_not(abs(N.array(map(cmp, row1, row2))) - ) # cmp fcn gives -1,0,1 + cmpvect = N.logical_not( + abs(N.array(map(cmp, row1, row2)))) # cmp fcn gives -1,0,1 else: cmpvect = N.equal(row1, row2) return cmpvect |