From aceb73cc52522fd10bafa417594003c207a196c5 Mon Sep 17 00:00:00 2001 From: Joel Nothman <joel.nothman@gmail.com> Date: Wed, 14 Dec 2016 04:08:30 +1100 Subject: [PATCH] [MRG + 1] CI some improvements to the flake8 CI (#8036) Examples now cannot fail due to 'E402 module level import not at top of file' --- build_tools/travis/flake8_diff.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/build_tools/travis/flake8_diff.sh b/build_tools/travis/flake8_diff.sh index b39d16a4c9..a0d0255384 100755 --- a/build_tools/travis/flake8_diff.sh +++ b/build_tools/travis/flake8_diff.sh @@ -120,14 +120,22 @@ echo '-------------------------------------------------------------------------- # uses git 1.8. # We need the following command to exit with 0 hence the echo in case # there is no match -MODIFIED_FILES=$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' | \ - grep -v 'doc/sphinxext/sphinx_gallery' || echo "no_match") +MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' | \ + grep -v 'doc/sphinxext/sphinx_gallery' || echo "no_match")" + +check_files() { + files="$1" + options="$2" + # Conservative approach: diff without context (--unified=0) so that code + # that was not changed does not create failures + git diff --unified=0 $COMMIT -- $files | flake8 --diff --show-source $options +} if [[ "$MODIFIED_FILES" == "no_match" ]]; then echo "No file outside sklearn/externals and doc/sphinxext/sphinx_gallery has been modified" else - # Conservative approach: diff without context so that code that - # was not changed does not create failures - git diff --unified=0 $COMMIT -- $MODIFIED_FILES | flake8 --diff --show-source + check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)" + # Examples are allowed to not have imports at top of file + check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" --ignore=E402 fi echo -e "No problem detected by flake8\n" -- GitLab