22
33from datetime import datetime
44import os
5+ from pathlib import Path
56import platform
7+ import shutil
68import subprocess
79import sys
810
911import ansys .fluent .core as pyfluent
12+ from ansys .fluent .core .docker .utils import get_grpc_launcher_args_for_gh_runs
1013from ansys_sphinx_theme import ansys_favicon , get_version_match , pyansys_logo_black
1114import numpy as np
1215import pyvista
135138copybutton_prompt_is_regexp = True
136139
137140
138- def _stop_fluent_container (gallery_conf , fname ):
139- try :
140- is_linux = platform .system () == "Linux"
141- container_names = (
142- subprocess .check_output (
143- "docker container ls --format {{.Names}}" , shell = is_linux
141+ def _reset_modules_hook (gallery_conf , fname , when ):
142+ if when == "before" :
143+ # Absolute path to doc/source/
144+ doc_src = Path (gallery_conf ["src_dir" ])
145+ # Project root = parent of the examples_root
146+ project_root = doc_src .parent .parent
147+ # Source = top-level project directory / certs
148+ source = project_root / "certs"
149+ # Destination = directory of the example file / certs
150+ destination = project_root / "examples" / "00-post_processing" / "certs"
151+ print (f"Copying certs from { source } to { destination } " )
152+ shutil .copytree (source , destination , dirs_exist_ok = True )
153+ elif when == "after" :
154+ try :
155+ is_linux = platform .system () == "Linux"
156+ container_names = (
157+ subprocess .check_output (
158+ "docker container ls --format {{.Names}}" , shell = is_linux
159+ )
160+ .decode ("utf-8" )
161+ .strip ()
162+ .split ()
144163 )
145- .decode ("utf-8" )
146- .strip ()
147- .split ()
148- )
149- for container_name in container_names :
150- subprocess .run (f"docker stop { container_name } " , shell = is_linux )
151- except Exception :
152- pass
164+ for container_name in container_names :
165+ subprocess .run (f"docker stop { container_name } " , shell = is_linux )
166+ except Exception :
167+ pass
153168
154169
155170# -- Sphinx Gallery Options ---------------------------------------------------
@@ -176,8 +191,8 @@ def _stop_fluent_container(gallery_conf, fname):
176191 "doc_module" : "ansys-fluent-core" ,
177192 "image_scrapers" : ("pyvista" , "matplotlib" ),
178193 "thumbnail_size" : (350 , 350 ),
179- "reset_modules_order" : "after " ,
180- "reset_modules" : (_stop_fluent_container ,),
194+ "reset_modules_order" : "both " ,
195+ "reset_modules" : (_reset_modules_hook ,),
181196}
182197
183198
@@ -288,3 +303,19 @@ def _stop_fluent_container(gallery_conf, fname):
288303
289304# PyAnsys tags configuration
290305html_context = {"pyansys_tags" : ["Fluids" ]}
306+
307+
308+ # TODO: Remove this workaround when a cleaner solution to override
309+ # pyfluent launch args is available.
310+
311+ launch_fluent_original = pyfluent .launch_fluent
312+
313+
314+ def launch_fluent_secure (* args , ** kwargs ):
315+ """Launch Fluent in secure mode for documentation generation."""
316+ kwargs .update (get_grpc_launcher_args_for_gh_runs ())
317+ return launch_fluent_original (* args , ** kwargs )
318+
319+
320+ if "FLUENT_IMAGE_TAG" in os .environ :
321+ pyfluent .launch_fluent = launch_fluent_secure
0 commit comments