8
8
from pathlib import Path
9
9
from pprint import pformat
10
10
from docutils .nodes import document
11
-
12
- # import re
13
11
import shutil
14
12
from typing import Any
15
13
from sphinx .application import Sphinx
16
- import sys
17
- import warnings
18
14
19
- # from sphinx_gallery.sorting import FileNameSortKey
20
15
from ansys_sphinx_theme import (
21
16
ansys_favicon ,
22
17
ansys_logo_white ,
23
18
ansys_logo_white_cropped ,
24
- # get_version_match,
25
19
latex ,
26
20
pyansys_logo_black ,
27
21
watermark ,
51
45
cname = os .getenv ("DOCUMENTATION_CNAME" , "nocname.com" )
52
46
release = version = "0.1.dev0"
53
47
54
- # os.environ["PYAEDT_NON_GRAPHICAL"] = "1"
55
- # os.environ["PYAEDT_DOC_GENERATION"] = "1"
56
-
57
48
# -- Connect functions (hooks) to Sphinx events -----------------------------
58
49
59
50
class PrettyPrintDirective (Directive ):
@@ -73,33 +64,6 @@ def run(self):
73
64
return [addnodes .desc_name (text = member_name ), addnodes .desc_content ("" , literal )]
74
65
75
66
76
- # Sphinx builder specific events hook
77
-
78
-
79
- def check_example_error (app : Sphinx , pagename : str , templatename :str , context :dict [str , Any ], doctree : document ):
80
- """Log an error if the execution of an example as a notebook triggered an error.
81
-
82
- Since the documentation build might not stop if the execution of a notebook triggered
83
- an error, we use a flag to log that an error is spotted in the html page context.
84
- """
85
- # Check if the HTML contains an error message
86
- if pagename .startswith ("examples" ) and not pagename .endswith ("/index" ):
87
- if any (
88
- map (
89
- lambda msg : msg in context ["body" ],
90
- [
91
- "UsageError" ,
92
- "NameError" ,
93
- "DeadKernelError" ,
94
- "NotebookError" ,
95
- "CellExecutionError" ,
96
- ],
97
- )
98
- ):
99
- logger .error (f"An error was detected in file { pagename } " )
100
- app .builder .config .html_context ["build_error" ] = True
101
-
102
-
103
67
# Sphinx generic event hooks
104
68
105
69
@@ -236,8 +200,8 @@ def check_build_finished_without_error(app: Sphinx, exception: None | Exception)
236
200
exception : None or Exception
237
201
Exception raised during the build process.
238
202
"""
239
- if app . builder . config . html_context . get ( "build_error" , False ) :
240
- 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. " )
241
205
exit (1 )
242
206
243
207
def remove_doctree (app : Sphinx , exception : None | Exception ):
@@ -270,8 +234,6 @@ def setup(app):
270
234
Sphinx instance containing all the configuration for the documentation build.
271
235
"""
272
236
app .add_directive ("pprint" , PrettyPrintDirective )
273
- # Builder specific hook
274
- app .connect ("html-page-context" , check_example_error )
275
237
# Builder inited hooks
276
238
app .connect ("builder-inited" , copy_examples )
277
239
app .connect ("builder-inited" , check_pandoc_installed )
@@ -343,20 +305,6 @@ def setup(app):
343
305
# separating the parameter name and type",
344
306
}
345
307
346
- # numpydoc_validation_exclude = { # set of regex
347
- # r"\.AEDTMessageManager.add_message$", # bad SS05
348
- # r"\.Modeler3D\.create_choke$", # bad RT05
349
- # r"HistoryProps.", # bad RT05 because of the base class named OrderedDict
350
- # }
351
-
352
- # # Add any paths that contain templates here, relative to this directory.
353
- # templates_path = ["_templates"]
354
-
355
- # # disable generating the sphinx nested documentation
356
- # if "PYAEDT_CI_NO_AUTODOC" in os.environ:
357
- # templates_path.clear()
358
-
359
-
360
308
# Copy button customization ---------------------------------------------------
361
309
# exclude traditional Python prompts from the copied code
362
310
copybutton_prompt_text = r">>> ?|\.\.\. "
@@ -370,21 +318,9 @@ def setup(app):
370
318
# directories to ignore when looking for source files.
371
319
# This pattern also affects html_static_path and html_extra_path.
372
320
exclude_patterns = [
373
- # "_build",
374
- # "sphinx_boogergreen_theme_1",
375
- # "Thumbs.db",
376
- # ".DS_Store",
377
- # "*.txt",
378
321
"conf.py" ,
379
- # "constants.py",
380
322
]
381
323
382
- # inheritance_graph_attrs = dict(rankdir="RL", size='"8.0, 10.0"', fontsize=14, ratio="compress")
383
- # inheritance_node_attrs = dict(
384
- # shape="ellipse", fontsize=14, height=0.75, color="dodgerblue1", style="filled"
385
- # )
386
-
387
-
388
324
# -- Options for HTML output -------------------------------------------------
389
325
390
326
source_suffix = {".rst" : "restructuredtext" , ".md" : "markdown" }
@@ -410,47 +346,15 @@ def setup(app):
410
346
}
411
347
412
348
# Pyvista customization
413
- # pyvista.set_error_output_file("errors.txt")
414
- # Ensure that offscreen rendering is used for docs generation
415
- # pyvista.OFF_SCREEN = True
416
- # Preferred plotting style for documentation
417
- # pyvista.set_plot_theme('document')
418
- # must be less than or equal to the XVFB window size
349
+
350
+ # Must be less than or equal to the XVFB window size
419
351
pyvista .global_theme ["window_size" ] = np .array ([1024 , 768 ])
420
352
421
353
# Save figures in specified directory
422
354
pyvista .FIGURE_PATH = os .path .join (os .path .abspath ("./images/" ), "auto-generated/" )
423
355
if not os .path .exists (pyvista .FIGURE_PATH ):
424
356
os .makedirs (pyvista .FIGURE_PATH )
425
357
426
- # # suppress annoying matplotlib bug
427
- # warnings.filterwarnings(
428
- # "ignore",
429
- # category=UserWarning,
430
- # message="Matplotlib is currently using agg so figures are not shown.",
431
- # )
432
-
433
- # necessary for pyvista when building the sphinx gallery
434
- # pyvista.BUILDING_GALLERY = True
435
-
436
- # jinja_contexts = {
437
- # "main_toctree": {
438
- # "run_examples": config["run_examples"],
439
- # },
440
- # }
441
- # def prepare_jinja_env(jinja_env) -> None:
442
- # """
443
- # Customize the jinja env.
444
- #
445
- # Notes
446
- # -----
447
- # See https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment
448
- # """
449
- # jinja_env.globals["project_name"] = project
450
- #
451
- #
452
- # autoapi_prepare_jinja_env = prepare_jinja_env
453
-
454
358
# -- Options for HTML output -------------------------------------------------
455
359
html_short_title = html_title = "PyAEDT Examples"
456
360
html_theme = "ansys_sphinx_theme"
0 commit comments