44import os
55from pathlib import Path
66import subprocess
7- from typing import List
7+ from typing import Dict , List
88
99from github import Github
10+ import plotly .io as pio
1011import pyvista
1112import requests
13+ from sphinx .application import Sphinx
1214from sphinx .builders .latex import LaTeXBuilder
1315
1416from ansys_sphinx_theme import (
2527 watermark ,
2628)
2729
30+ pio .renderers .default = "sphinx_gallery"
2831THIS_PATH = Path (__file__ ).parent .resolve ()
2932PYANSYS_LIGHT_SQUARE = (THIS_PATH / "_static" / "pyansys_light_square.png" ).resolve ()
3033EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples" ).resolve ()
7578 },
7679}
7780
81+ html_js_files = ["https://cdn.plot.ly/plotly-3.0.1.min.js" ]
82+
83+
7884index_patterns = {
7985 "examples/api/" : ALL_NODES ,
8086 "examples/sphinx_examples/" : TITLES + PARAGRAPHS ,
140146exclude_patterns = [
141147 "links.rst" ,
142148 "examples/sphinx-gallery/README.rst" ,
143- "examples/gallery-examples/*.ipynb" ,
144149 "sg_execution_times.rst" ,
150+ "examples/gallery-examples/*.ipynb" ,
145151]
146152rst_epilog = ""
147153with Path .open (THIS_PATH / "links.rst" , "r" ) as f :
@@ -245,8 +251,6 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
245251
246252if not BUILD_EXAMPLES :
247253 exclude_patterns .extend (["examples.rst" , "examples/**" , "examples/api/**" ])
248-
249-
250254else :
251255 # Autoapi examples
252256 extensions .append ("ansys_sphinx_theme.extension.autoapi" )
@@ -262,30 +266,29 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
262266 extensions .extend (["nbsphinx" , "sphinx_gallery.gen_gallery" ])
263267 sphinx_gallery_conf = {
264268 # path to your examples scripts
265- "examples_dirs" : ["examples/sphinx-gallery" ],
269+ "examples_dirs" : ["examples/sphinx-gallery/ " ],
266270 # path where to save gallery generated examples
267- "gallery_dirs" : ["examples/gallery-examples" ],
271+ "gallery_dirs" : ["examples/gallery-examples/ " ],
268272 # Pattern to search for example files
269- "filename_pattern" : r"sphinx_gallery \.py" ,
273+ "filename_pattern" : r"\.py" ,
270274 # Remove the "Download all examples" button from the top level gallery
271275 "download_all_examples" : False ,
272276 # Modules for which function level galleries are created. In
273- "image_scrapers" : ("pyvista" , "matplotlib" ),
277+ "image_scrapers" : ("pyvista" , "matplotlib" , "plotly.io._sg_scraper.plotly_sg_scraper" ),
274278 "default_thumb_file" : str (PYANSYS_LIGHT_SQUARE ),
275279 }
280+ pyvista .BUILDING_GALLERY = True
281+ pyvista .OFF_SCREEN = True
276282
277283 nbsphinx_prolog = """
278284Download this example as a :download:`Jupyter notebook </{{ env.docname }}.ipynb>`.
279285
280286----
281287"""
282- nbsphinx_execute = "always"
283288 nbsphinx_thumbnails = {
284289 "examples/nbsphinx/jupyter-notebook" : "_static/pyansys_light_square.png" ,
285290 }
286291
287- pyvista .BUILDING_GALLERY = True
288-
289292 # Third party examples
290293 example_links = extract_example_links (
291294 "executablebooks/sphinx-design" ,
@@ -309,3 +312,30 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
309312jinja_globals = {
310313 "ANSYS_SPHINX_THEME_VERSION" : version ,
311314}
315+
316+
317+ def revert_exclude_patterns (app , env ):
318+ """Revert the exclude patterns.
319+
320+ Parameters
321+ ----------
322+ app : Sphinx
323+ Sphinx application instance.
324+ env : BuildEnvironment
325+ The build environment.
326+
327+ Notes
328+ -----
329+ Remove the examples/gallery-examples/*.ipynb pattern from the exclude patterns.
330+ When the nbsphinx extension is enabled, the exclude patterns are modified
331+ to exclude the examples/gallery-examples/*.ipynb pattern. This function reverts
332+ the exclude patterns to their original state.
333+ """
334+ excluded_pattern = env .config .exclude_patterns
335+ excluded_pattern .remove ("examples/gallery-examples/*.ipynb" )
336+ env .config .exclude_patterns = excluded_pattern
337+
338+
339+ def setup (app : Sphinx ) -> Dict :
340+ """Sphinx hooks to add to the setup."""
341+ app .connect ("env-updated" , revert_exclude_patterns )
0 commit comments