Skip to content

Commit 87707b3

Browse files
committed
DOCS: Refact to exit on doc build failure
1 parent afa1635 commit 87707b3

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

doc/source/conf.py

+2-31
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,6 @@ def run(self):
6464
return [addnodes.desc_name(text=member_name), addnodes.desc_content("", literal)]
6565

6666

67-
# Sphinx builder specific events hook
68-
69-
70-
def check_example_error(app: Sphinx, pagename: str, templatename:str , context:dict[str, Any], doctree: document):
71-
"""Log an error if the execution of an example as a notebook triggered an error.
72-
73-
Since the documentation build might not stop if the execution of a notebook triggered
74-
an error, we use a flag to log that an error is spotted in the html page context.
75-
"""
76-
# Check if the HTML contains an error message
77-
if pagename.startswith("examples") and not pagename.endswith("/index"):
78-
if any(
79-
map(
80-
lambda msg: msg in context["body"],
81-
[
82-
"UsageError",
83-
"NameError",
84-
"DeadKernelError",
85-
"NotebookError",
86-
"CellExecutionError",
87-
],
88-
)
89-
):
90-
logger.error(f"An error was detected in file {pagename}")
91-
app.builder.config.html_context["build_error"] = True
92-
93-
9467
# Sphinx generic event hooks
9568

9669

@@ -227,8 +200,8 @@ def check_build_finished_without_error(app: Sphinx, exception: None | Exception)
227200
exception : None or Exception
228201
Exception raised during the build process.
229202
"""
230-
if app.builder.config.html_context.get("build_error", False):
231-
logger.info("Build failed due to an error in html-page-context")
203+
if exception is not None:
204+
logger.error("Build failed due to an error.")
232205
exit(1)
233206

234207
def remove_doctree(app: Sphinx, exception: None | Exception):
@@ -261,8 +234,6 @@ def setup(app):
261234
Sphinx instance containing all the configuration for the documentation build.
262235
"""
263236
app.add_directive("pprint", PrettyPrintDirective)
264-
# Builder specific hook
265-
app.connect("html-page-context", check_example_error)
266237
# Builder inited hooks
267238
app.connect("builder-inited", copy_examples)
268239
app.connect("builder-inited", check_pandoc_installed)

0 commit comments

Comments
 (0)