Skip to content

Commit 008accc

Browse files
Merge remote-tracking branch 'origin/doc/jupyter_examples' into doc/jupyter_examples
2 parents 3c68888 + e59503f commit 008accc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.github/workflows/build_documentation.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ jobs:
7474

7575
- name: Install doc build requirements
7676
run: |
77-
sudo apt install graphviz
78-
sudo apt install -y pandoc
77+
sudo apt install -y graphviz pandoc
7978
8079
# run doc build, without creating the examples directory
8180
# note that we have to add the examples file here since it won't

doc/source/User_guide/pyaedt_file_data/project.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ File structure examples:
3333

3434
:download:`HFSS 3D Layout Example <../../Resources/hfss3dlayout_project_example.json>`
3535

36-
.. code-block:: json
36+
.. code-block::
3737
3838
{
3939
"general": {

doc/source/conf.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def remove_examples(app, exception):
117117
DESTINATION_DIRECTORY = pathlib.Path(app.srcdir) / "examples"
118118
size = directory_size(DESTINATION_DIRECTORY)
119119
logger.info(f"Removing directory {DESTINATION_DIRECTORY} ({size} MB).")
120-
shutil.rmtree(DESTINATION_DIRECTORY)
120+
shutil.rmtree(DESTINATION_DIRECTORY, ignore_errors=True)
121121
logger.info(f"Directory removed.")
122122

123123
def add_ipython_time(app, docname, source):
@@ -201,6 +201,22 @@ def remove_ipython_time_from_html(app, pagename, templatename, context, doctree)
201201
pattern = r'<span class="o">%%time<\/span>\n'
202202
context['body'] = re.sub(pattern, '', context['body'])
203203

204+
def check_example_error(app, pagename, templatename, context, doctree):
205+
"""Log an error if the execution of an example as a notebook triggered an error.
206+
207+
Since the documentation build might not stop if the execution of a notebook triggered
208+
an error, we use a flag to log that an error is spotted in the html page context.
209+
"""
210+
# Check if the HTML contains an error message
211+
if pagename.startswith("examples") and not pagename.endswith("/index"):
212+
if any(map(lambda msg: msg in context['body'], ['UsageError', 'NameError'])):
213+
logger.error(f"An error was detected in file {pagename}")
214+
app.builder.config.html_context['build_error'] = True
215+
216+
def check_build_finished_without_error(app, exception):
217+
"""Check that no error is detected along the documentation build process."""
218+
if app.builder.config.html_context.get('build_error', False):
219+
raise Exception('Build failed due to error in html-page-context')
204220

205221
def setup(app):
206222
app.add_directive('pprint', PrettyPrintDirective)
@@ -209,8 +225,10 @@ def setup(app):
209225
app.connect('source-read', add_ipython_time)
210226
app.connect('source-read', adjust_image_path)
211227
app.connect('html-page-context', remove_ipython_time_from_html)
228+
app.connect('html-page-context', check_example_error)
212229
app.connect('build-finished', remove_examples)
213230
app.connect('build-finished', remove_doctree)
231+
app.connect('build-finished', check_build_finished_without_error)
214232

215233
local_path = os.path.dirname(os.path.realpath(__file__))
216234
module_path = pathlib.Path(local_path)

examples/Readme.txt examples/index.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
.. _ref_example_gallery:
1+
.. _ref_examples:
2+
3+
.. toctree::
4+
:hidden:
5+
:maxdepth: 2
6+
7+
00-EDB/index
28

39
Examples
410
========

0 commit comments

Comments
 (0)