Skip to content

Commit 03e3012

Browse files
committed
Exclude sklearn/externals from diff for flake8
1 parent be94946 commit 03e3012

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

build_tools/travis/flake8_diff.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# turn-around
1515

1616
set -e
17+
# pipefail is necessary to propagate exit codes
18+
set -o pipefail
1719

1820
PROJECT=scikit-learn/scikit-learn
1921
PROJECT_URL=https://github.com/$PROJECT.git
@@ -79,7 +81,20 @@ echo -e '\nRunning flake8 on the diff in the range'\
7981
"($(git rev-list $COMMIT.. | wc -l) commit(s)):"
8082
echo '--------------------------------------------------------------------------------'
8183

82-
# Conservative approach: diff without context so that code that was
83-
# not changed does not create failures
84-
git diff --unified=0 $COMMIT | flake8 --diff --show-source
84+
# We ignore files from sklearn/externals. Unfortunately there is no
85+
# way to do it with flake8 directly (the --exclude does not seem to
86+
# work with --diff). We could use the exclude magic in the git pathspec
87+
# ':!sklearn/externals' but it is only available on git 1.9 and Travis
88+
# uses git 1.8.
89+
# We need the following command to exit with 0 hence the echo in case
90+
# there is no match
91+
MODIFIED_FILES=$(git diff --name-only $COMMIT | grep -v 'sklearn/externals' || echo "no_match")
92+
93+
if [[ "$MODIFIED_FILES" == "no_match" ]]; then
94+
echo "No file outside sklearn/externals has been modified"
95+
else
96+
# Conservative approach: diff without context so that code that
97+
# was not changed does not create failures
98+
git diff --unified=0 $COMMIT -- $MODIFIED_FILES | flake8 --diff --show-source
99+
fi
85100
echo -e "No problem detected by flake8\n"

0 commit comments

Comments
 (0)