@@ -19,18 +19,18 @@ set -e
1919set -o pipefail
2020
2121PROJECT=RaRe-Technologies/gensim
22- PROJECT_URL=https://github.com/$PROJECT .git
22+ PROJECT_URL=https://github.com/${ PROJECT} .git
2323
2424# Find the remote with the project name (upstream in most cases)
25- REMOTE=$( git remote -v | grep $PROJECT | cut -f1 | head -1 || echo ' ' )
25+ REMOTE=$( git remote -v | grep ${ PROJECT} | cut -f1 | head -1 || echo ' ' )
2626
2727# Add a temporary remote if needed. For example this is necessary when
2828# Travis is configured to run in a fork. In this case 'origin' is the
2929# fork and not the reference repo we want to diff against.
3030if [[ -z " $REMOTE " ]]; then
3131 TMP_REMOTE=tmp_reference_upstream
32- REMOTE=$TMP_REMOTE
33- git remote add $REMOTE $ PROJECT_URL
32+ REMOTE=${ TMP_REMOTE}
33+ git remote add ${ REMOTE} ${ PROJECT_URL}
3434fi
3535
3636echo " Remotes:"
@@ -56,15 +56,15 @@ if [[ "$TRAVIS" == "true" ]]; then
5656 echo " New branch, no commit range from Travis so passing this test by convention"
5757 exit 0
5858 fi
59- COMMIT_RANGE=$TRAVIS_COMMIT_RANGE
59+ COMMIT_RANGE=${ TRAVIS_COMMIT_RANGE}
6060 fi
6161 else
6262 # We want to fetch the code as it is in the PR branch and not
6363 # the result of the merge into develop. This way line numbers
6464 # reported by Travis will match with the local code.
65- LOCAL_BRANCH_REF=travis_pr_$TRAVIS_PULL_REQUEST
65+ LOCAL_BRANCH_REF=travis_pr_${ TRAVIS_PULL_REQUEST}
6666 # In Travis the PR target is always origin
67- git fetch origin pull/$TRAVIS_PULL_REQUEST /head:refs/$LOCAL_BRANCH_REF
67+ git fetch origin pull/${ TRAVIS_PULL_REQUEST} /head:refs/${ LOCAL_BRANCH_REF}
6868 fi
6969fi
7070
@@ -76,49 +76,55 @@ if [[ -z "$COMMIT_RANGE" ]]; then
7676 fi
7777 echo -e " \nLast 2 commits in $LOCAL_BRANCH_REF :"
7878 echo ' --------------------------------------------------------------------------------'
79- git log -2 $LOCAL_BRANCH_REF
79+ git log -2 ${ LOCAL_BRANCH_REF}
8080
8181 REMOTE_MASTER_REF=" $REMOTE /develop"
8282 # Make sure that $REMOTE_MASTER_REF is a valid reference
8383 echo -e " \nFetching $REMOTE_MASTER_REF "
8484 echo ' --------------------------------------------------------------------------------'
85- git fetch $REMOTE develop:refs/remotes/$REMOTE_MASTER_REF
86- LOCAL_BRANCH_SHORT_HASH=$( git rev-parse --short $LOCAL_BRANCH_REF )
87- REMOTE_MASTER_SHORT_HASH=$( git rev-parse --short $REMOTE_MASTER_REF )
85+ git fetch ${ REMOTE} develop:refs/remotes/${ REMOTE_MASTER_REF}
86+ LOCAL_BRANCH_SHORT_HASH=$( git rev-parse --short ${ LOCAL_BRANCH_REF} )
87+ REMOTE_MASTER_SHORT_HASH=$( git rev-parse --short ${ REMOTE_MASTER_REF} )
8888
89- COMMIT=$( git merge-base $LOCAL_BRANCH_REF $ REMOTE_MASTER_REF) || \
90- echo " No common ancestor found for $( git show $LOCAL_BRANCH_REF -q) and $( git show $REMOTE_MASTER_REF -q) "
89+ COMMIT=$( git merge-base ${ LOCAL_BRANCH_REF} ${ REMOTE_MASTER_REF} ) || \
90+ echo " No common ancestor found for $( git show ${ LOCAL_BRANCH_REF} -q) and $( git show ${ REMOTE_MASTER_REF} -q) "
9191
9292 if [ -z " $COMMIT " ]; then
9393 exit 1
9494 fi
9595
96- COMMIT_SHORT_HASH=$( git rev-parse --short $COMMIT )
96+ COMMIT_SHORT_HASH=$( git rev-parse --short ${ COMMIT} )
9797
9898 echo -e " \nCommon ancestor between $LOCAL_BRANCH_REF ($LOCAL_BRANCH_SHORT_HASH )" \
9999 " and $REMOTE_MASTER_REF ($REMOTE_MASTER_SHORT_HASH ) is $COMMIT_SHORT_HASH :"
100100 echo ' --------------------------------------------------------------------------------'
101- git show --no-patch $COMMIT_SHORT_HASH
101+ git show --no-patch ${ COMMIT_SHORT_HASH}
102102
103103 COMMIT_RANGE=" $COMMIT_SHORT_HASH ..$LOCAL_BRANCH_SHORT_HASH "
104104
105105 if [[ -n " $TMP_REMOTE " ]]; then
106- git remote remove $TMP_REMOTE
106+ git remote remove ${ TMP_REMOTE}
107107 fi
108108
109109else
110110 echo " Got the commit range from Travis: $COMMIT_RANGE "
111111fi
112112
113113echo -e ' \nRunning flake8 on the diff in the range' " $COMMIT_RANGE " \
114- " ($( git rev-list $COMMIT_RANGE | wc -l) commit(s)):"
114+ " ($( git rev-list ${ COMMIT_RANGE} | wc -l) commit(s)):"
115115echo ' --------------------------------------------------------------------------------'
116116
117117# We ignore files from sklearn/externals.
118118# Excluding vec files since they contain non-utf8 content and flake8 raises exception for non-utf8 input
119119# We need the following command to exit with 0 hence the echo in case
120120# there is no match
121- MODIFIED_FILES=" $( git diff --name-only $COMMIT_RANGE -- . ' :(exclude)*.vec' || echo " no_match" ) "
121+ MODIFIED_PY_FILES=" $( git diff --name-only ${COMMIT_RANGE} | grep ' [a-zA-Z0-9]*.py$' || echo " no_match" ) "
122+ MODIFIED_IPYNB_FILES=" $( git diff --name-only ${COMMIT_RANGE} | grep ' [a-zA-Z0-9]*.ipynb$' || echo " no_match" ) "
123+
124+
125+ echo " *.py files: " ${MODIFIED_PY_FILES}
126+ echo " *.ipynb files: " ${MODIFIED_IPYNB_FILES}
127+
122128
123129check_files () {
124130 files=" $1 "
@@ -127,13 +133,23 @@ check_files() {
127133 if [ -n " $files " ]; then
128134 # Conservative approach: diff without context (--unified=0) so that code
129135 # that was not changed does not create failures
130- git diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --show-source $options
136+ git diff --unified=0 ${ COMMIT_RANGE} -- ${ files} | flake8 --diff --show-source ${ options}
131137 fi
132138}
133139
134- if [[ " $MODIFIED_FILES " == " no_match" ]]; then
135- echo " No file has been modified"
140+ if [[ " $MODIFIED_PY_FILES " == " no_match" ]]; then
141+ echo " No .py files has been modified"
136142else
137- check_files " $( echo " $MODIFIED_FILES " ) " " --ignore=E501,E731,E12,W503 --exclude=*.sh,*.md,*.yml,*.rst,*.ipynb,*.txt,*.csv,*.vec,Dockerfile*,*.c,*.pyx,*.inc "
143+ check_files " $( echo " $MODIFIED_PY_FILES " ) " " --ignore=E501,E731,E12,W503"
138144fi
139145echo -e " No problem detected by flake8\n"
146+
147+ if [[ " $MODIFIED_IPYNB_FILES " == " no_match" ]]; then
148+ echo " No .ipynb file has been modified"
149+ else
150+ for fname in ${MODIFIED_IPYNB_FILES}
151+ do
152+ echo " File: $fname "
153+ jupyter nbconvert --to script --stdout ${fname} | flake8 - --show-source --ignore=E501,E731,E12,W503,E402 --builtins=get_ipython || true
154+ done
155+ fi
0 commit comments