8000 [MRG + 1] CI some improvements to the flake8 CI (#8036) · paulha/scikit-learn@44c464a · GitHub
[go: up one dir, main page]

Skip to content

Commit 44c464a

Browse files
jnothmanpaulha
authored andcommitted
[MRG + 1] CI some improvements to the flake8 CI (scikit-learn#8036)
Examples now cannot fail due to 'E402 module level import not at top of file'
1 parent 0b60293 commit 44c464a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

build_tools/travis/flake8_diff.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,22 @@ echo '--------------------------------------------------------------------------
120120
# uses git 1.8.
121121
# We need the following command to exit with 0 hence the echo in case
122122
# there is no match
123-
MODIFIED_FILES=$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' | \
124-
grep -v 'doc/sphinxext/sphinx_gallery' || echo "no_match")
123+
MODIFIED_FILES="$(git diff --name-only $COMMIT_RANGE | grep -v 'sklearn/externals' | \
124+
grep -v 'doc/sphinxext/sphinx_gallery' || echo "no_match")"
125+
126+
check_files() {
127+
files="$1"
128+
options="$2"
129+
# Conservative approach: diff without context (--unified=0) so that code
130+
# that was not changed does not create failures
131+
git diff --unified=0 $COMMIT -- $files | flake8 --diff --show-source $options
132+
}
125133

126134
if [[ "$MODIFIED_FILES" == "no_match" ]]; then
127135
echo "No file outside sklearn/externals and doc/sphinxext/sphinx_gallery has been modified"
128136
else
129-
# Conservative approach: diff without context so that code that
130-
# was not changed does not create failures
131-
git diff --unified=0 $COMMIT -- $MODIFIED_FILES | flake8 --diff --show-source
137+
check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)"
138+
# Examples are allowed to not have imports at top of file
139+
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" --ignore=E402
132140
fi
133141
echo -e "No problem detected by flake8\n"

0 commit comments

Comments
 (0)
0