8000 [MRG] Enables CircleCI to fail when sphinx warns (#15633) · panpiort8/scikit-learn@4849954 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4849954

Browse files
thomasjpfanPan Jan
authored andcommitted
[MRG] Enables CircleCI to fail when sphinx warns (scikit-learn#15633)
1 parent c8549f9 commit 4849954

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

build_tools/circle/build_doc.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,44 @@ get_build_type() {
5858
return
5959
fi
6060
changed_examples=$(echo "$filenames" | grep -E "^examples/(.*/)*plot_")
61+
62+
# The following is used to extract the list of filenames of example python
63+
# files that sphinx-gallery needs to run to generate png files used as
64+
# figures or images in the .rst files from the documentation.
65+
# If the contributor changes a .rst file in a PR we need to run all
66+
# the examples mentioned in that file to get sphinx build the
67+
# documentation without generating spurious warnings related to missing
68+
# png files.
69+
70+
if [[ -n "$filenames" ]]
71+
then
72+
# get rst files
73+
rst_files="$(echo "$filenames" | grep -E "rst$")"
74+
75+
# get lines with figure or images
76+
img_fig_lines="$(echo "$rst_files" | xargs grep -shE "(figure|image)::")"
77+
78+
# get only auto_examples
79+
auto_example_files="$(echo "$img_fig_lines" | grep auto_examples | awk -F "/" '{print $NF}')"
80+
81+
# remove "sphx_glr_" from path and accept replace _(\d\d\d|thumb).png with .py
82+
scripts_names="$(echo "$auto_example_files" | sed 's/sphx_glr_//' | sed -e 's/_([[:digit:]][[:digit:]][[:digit:]]|thumb).png/.py/')"
83+
84+
# get unique values
85+
examples_in_rst="$(echo "$scripts_names" | uniq )"
86+
fi
87+
88+
# executed only if there are examples in the modified rst files
89+
if [[ -n "$examples_in_rst" ]]
90+
then
91+
if [[ -n "$changed_examples" ]]
92+
then
93+
changed_examples="$changed_examples|$examples_in_rst"
94+
else
95+
changed_examples="$examples_in_rst"
96+
fi
97+
fi
98+
6199
if [[ -n "$changed_examples" ]]
62100
then
63101
echo BUILD: detected examples/ filename modified in $git_range: $changed_examples
@@ -204,5 +242,12 @@ then
204242
echo "$warnings" | sed 's/\/home\/circleci\/project\//<li>/g'
205243
echo '</ul></body></html>'
206244
) > 'doc/_build/html/stable/_changed.html'
245+
246+
if [ "$warnings" != "/home/circleci/project/ no warnings" ]
247+
then
248+
echo "Sphinx generated warnings when building the documentation related to files modified in this PR."
249+
echo "Please check doc/_build/html/stable/_changed.html"
250+
exit 1
251+
fi
207252
fi
208253

0 commit comments

Comments
 (0)
0