From 12b71e8201f5303e586a7a2c4fead175d161e056 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 18 May 2020 17:48:07 +0200 Subject: [PATCH 1/8] add grep --- build_tools/circle/linting.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index dad7ad95ce7c1..c8a34ef2f11c6 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -161,3 +161,17 @@ then echo $bad_deprecation_property_order exit 1 fi + +echo -e '\nChecking default doctest directives not present in the diff in the range' \ + "$COMMIT_RANGE" \ + "($(git rev-list $COMMIT_RANGE | wc -l) commit(s)):" +echo '--------------------------------------------------------------------------------' + +check_files() { + files="$1" + if [ -n "$files" ]; then + # Conservative approach: diff without context (--unified=0) so that code + # that was not changed does not create failures + git diff --unified=0 $COMMIT_RANGE -- $files | grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)' + fi +} From 420baff7fe1b068da1d2cc62c6ebb695de6d2bf1 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 18 May 2020 17:48:20 +0200 Subject: [PATCH 2/8] directs to test CI --- doc/modules/tree.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index e12b63adb48c4..8baf5d00b88e9 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -118,11 +118,11 @@ labels are [-1, 1]) classification and multiclass (where the labels are Using the Iris dataset, we can construct a tree as follows:: - >>> from sklearn.datasets import load_iris - >>> from sklearn import tree - >>> X, y = load_iris(return_X_y=True) - >>> clf = tree.DecisionTreeClassifier() - >>> clf = clf.fit(X, y) + >>> from sklearn.datasets import load_iris # doctest: +NORMALIZE_WHITESPACE + >>> from sklearn import tree # doctest: +NORMALIZE_WHITESPACE + >>> X, y = load_iris(return_X_y=True) # doctest: +NORMALIZE_WHITESPACE + >>> clf = tree.DecisionTreeClassifier() # doctest: +ELLIPSIS + >>> clf = clf.fit(X, y) # doctest: +ELLIPSIS Once trained, you can plot the tree with the :func:`plot_tree` function:: From 43fd775c99494701a3b269171ed57011caa46a28 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 18 May 2020 19:16:01 +0200 Subject: [PATCH 3/8] attempt2 --- build_tools/circle/linting.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index c8a34ef2f11c6..37626ebd605ce 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -162,16 +162,13 @@ then exit 1 fi -echo -e '\nChecking default doctest directives not present in the diff in the range' \ - "$COMMIT_RANGE" \ - "($(git rev-list $COMMIT_RANGE | wc -l) commit(s)):" -echo '--------------------------------------------------------------------------------' +# Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE -check_files() { - files="$1" - if [ -n "$files" ]; then - # Conservative approach: diff without context (--unified=0) so that code - # that was not changed does not create failures - git diff --unified=0 $COMMIT_RANGE -- $files | grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)' - fi -} +doctest_directive=$(grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)') + +if [ ! -z "$doctest_directive" ] +then + echo "Default doctest directives found:" + echo $doctest_directive + exit 1 +fi From fa87a1ed3d54998cc52b6bc4413bbdda3d8a36f3 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 18 May 2020 22:37:05 +0200 Subject: [PATCH 4/8] better output format --- build_tools/circle/linting.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index 37626ebd605ce..b6c14fe780464 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -164,11 +164,11 @@ fi # Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE -doctest_directive=$(grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)') +doctest_directive="$(grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)')" if [ ! -z "$doctest_directive" ] then - echo "Default doctest directives found:" - echo $doctest_directive + echo "Default doctest directives found:\n" + echo "$doctest_directive" exit 1 fi From cdef6b4c48fefe0fc17c28e1094db48fdfda1b29 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Tue, 19 May 2020 11:45:56 +0200 Subject: [PATCH 5/8] use find --- build_tools/circle/linting.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index b6c14fe780464..f8d5928cc4fb2 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -164,11 +164,11 @@ fi # Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE -doctest_directive="$(grep --include=\*.{py,rst} -rnw -E '# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)')" +doctest_directive="$(find . -type f \( -name "*.py" -o -name "*.rst" \) -exec grep -nw -E "# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)" {} \;)" if [ ! -z "$doctest_directive" ] then - echo "Default doctest directives found:\n" + echo "Default doctest directives found:" echo "$doctest_directive" exit 1 fi From 95ee9d9811841139b15f407f736a64ccfcd916e4 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Tue, 19 May 2020 12:54:25 +0200 Subject: [PATCH 6/8] revert test rst file --- doc/modules/tree.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index 8baf5d00b88e9..e12b63adb48c4 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -118,11 +118,11 @@ labels are [-1, 1]) classification and multiclass (where the labels are Using the Iris dataset, we can construct a tree as follows:: - >>> from sklearn.datasets import load_iris # doctest: +NORMALIZE_WHITESPACE - >>> from sklearn import tree # doctest: +NORMALIZE_WHITESPACE - >>> X, y = load_iris(return_X_y=True) # doctest: +NORMALIZE_WHITESPACE - >>> clf = tree.DecisionTreeClassifier() # doctest: +ELLIPSIS - >>> clf = clf.fit(X, y) # doctest: +ELLIPSIS + >>> from sklearn.datasets import load_iris + >>> from sklearn import tree + >>> X, y = load_iris(return_X_y=True) + >>> clf = tree.DecisionTreeClassifier() + >>> clf = clf.fit(X, y) Once trained, you can plot the tree with the :func:`plot_tree` function:: From 84add8551fdffcc14852673915a55d45941b2bbd Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Tue, 19 May 2020 13:07:42 +0200 Subject: [PATCH 7/8] better message --- build_tools/circle/linting.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index f8d5928cc4fb2..05b8b98789cf5 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -168,7 +168,7 @@ doctest_directive="$(find . -type f \( -name "*.py" -o -name "*.rst" \) -exec gr if [ ! -z "$doctest_directive" ] then - echo "Default doctest directives found:" + echo "ELLIPSIS and NORMALIZE_WHITESPACE doctest directives are enabled by default, but were found in:" echo "$doctest_directive" exit 1 fi From b919261e38124904d3dc60fce50f7b65703e29a6 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Tue, 19 May 2020 14:50:51 +0200 Subject: [PATCH 8/8] faster grep --- build_tools/circle/linting.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_tools/circle/linting.sh b/build_tools/circle/linting.sh index 05b8b98789cf5..c23cd80d3afd6 100755 --- a/build_tools/circle/linting.sh +++ b/build_tools/circle/linting.sh @@ -164,7 +164,7 @@ fi # Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE -doctest_directive="$(find . -type f \( -name "*.py" -o -name "*.rst" \) -exec grep -nw -E "# doctest: \+(ELLIPSIS|NORMALIZE_WHITESPACE)" {} \;)" +doctest_directive="$(git grep -nw -E "# doctest\: \+(ELLIPSIS|NORMALIZE_WHITESPACE)")" if [ ! -z "$doctest_directive" ] then