Skip to content

Commit 3b77a5b

Browse files
authored
ci(doc): add doc build examples caching (#2342)
1 parent 155b589 commit 3b77a5b

File tree

5 files changed

+60
-42
lines changed

5 files changed

+60
-42
lines changed

.github/workflows/docs.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,41 @@ jobs:
117117
run: |
118118
choco install pandoc
119119
120+
- name: "Restore doc build cache"
121+
id: cache-doc-build-restore
122+
uses: actions/cache/restore@v4
123+
with:
124+
path: |
125+
doc/source/examples
126+
# Cache key is composed of branch name, ansys version, hash of requirements_doc,
127+
# and run_id to work around immutability
128+
# We should also track version of pandoc, of graphviz, of packages installed by headless-display, and even of pydpf-core?
129+
key: doc-build-${{ github.ref_name }}-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-${{ github.run_id }}
130+
restore-keys: |
131+
doc-build-${{ github.ref_name }}-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-
132+
doc-build-master-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-
133+
120134
- name: "Build HTML Documentation"
121135
shell: bash
122136
run: |
123137
tox -e doc-html --installpkg dist/${{ steps.wheel.outputs.wheel_name }} -x testenv:doc-html.setenv+='VIRTUALENV_SYSTEM_SITE_PACKAGES=true'
124138
125-
- name: "Retrieve package version"
126-
shell: bash
127-
run: |
128-
echo "VERSION=$(python -c "from ansys.dpf.${{env.MODULE}} import __version__; print(__version__)")" >> GITHUB_OUTPUT
129-
echo "${{env.PACKAGE_NAME}} version is: $(python -c "from ansys.dpf.${{env.MODULE}} import __version__; print(__version__)")"
130-
id: version
131-
if: always()
132-
133139
- name: "Upload Documentation Build log"
134140
uses: actions/upload-artifact@v4
135141
with:
136142
name: doc-${{env.PACKAGE_NAME}}-log
137143
path: doc/*.txt
138144
if: always()
139145

146+
- name: "Save doc-build cache"
147+
id: cache-doc-build-save
148+
uses: actions/cache/save@v4
149+
with:
150+
path: |
151+
doc/build
152+
doc/source/examples
153+
key: ${{ steps.cache-doc-build-restore.outputs.cache-primary-key }}
154+
140155
- name: "Zip HTML Documentation"
141156
shell: pwsh
142157
run: |

doc/source/conf.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from glob import glob
33
import os
4+
import sys
45
from pathlib import Path
56
import subprocess
67

@@ -16,6 +17,9 @@
1617
from ansys.dpf.core import __version__, server, server_factory
1718
from ansys.dpf.core.examples import get_example_required_minimum_dpf_version
1819

20+
# Make sphinx_utilities modules importable
21+
sys.path.append(os.path.join(os.path.dirname(__file__), "../sphinx_utilities"))
22+
1923
# Manage errors
2024
pyvista.set_error_output_file("errors.txt")
2125
# Ensure that offscreen rendering is used for docs generation
@@ -56,12 +60,13 @@
5660
server_version = server_instance.version
5761
server.shutdown_all_session_servers()
5862
print(f"DPF version: {server_version}")
63+
print(f"DPF install: {server_instance.ansys_path}")
5964

6065
# Build ignore pattern
6166
ignored_pattern = r"(ignore"
6267
header_flag = "\"\"\""
6368
note_flag = r".. note::"
64-
for example in glob(r"../../examples/**/*.py"):
69+
for example in sorted(glob(r"../../examples/**/*.py")):
6570
minimum_version_str = get_example_required_minimum_dpf_version(example)
6671
if float(server_version) - float(minimum_version_str) < -0.05:
6772
example_name = example.split(os.path.sep)[-1]
@@ -124,8 +129,7 @@
124129
typehints_defaults = "comma"
125130
typehints_use_signature = True
126131
simplify_optional_unions = False
127-
suppress_warnings = ['autosectionlabel.*']
128-
132+
autosectionlabel_prefix_document = True
129133
# Intersphinx mapping
130134
intersphinx_mapping = {
131135
"pyvista": ("https://docs.pyvista.org/", None),
@@ -163,32 +167,6 @@
163167

164168

165169
# -- Sphinx Gallery Options
166-
from sphinx_gallery.sorting import FileNameSortKey
167-
168-
169-
def reset_servers(gallery_conf, fname, when):
170-
import gc
171-
172-
import psutil
173-
174-
from ansys.dpf.core import server
175-
176-
gc.collect()
177-
server.shutdown_all_session_servers()
178-
179-
proc_name = "Ans.Dpf.Grpc"
180-
nb_procs = 0
181-
for proc in psutil.process_iter():
182-
try:
183-
# check whether the process name matches
184-
if proc_name in proc.name():
185-
proc.kill()
186-
nb_procs += 1
187-
except psutil.NoSuchProcess:
188-
pass
189-
print(f"Counted {nb_procs} {proc_name} processes {when} example {fname}.")
190-
191-
192170
sphinx_gallery_conf = {
193171
# convert rst to md for ipynb
194172
"pypandoc": True,
@@ -205,15 +183,15 @@ def reset_servers(gallery_conf, fname, when):
205183
# Remove the "Download all examples" button from the top level gallery
206184
"download_all_examples": False,
207185
# Sort gallery example by file name instead of number of lines (default)
208-
"within_subsection_order": FileNameSortKey,
186+
"within_subsection_order": "FileNameSortKey",
209187
# directory where function granular galleries are stored
210188
"backreferences_dir": None,
211189
"image_scrapers": ("pyvista", "matplotlib"),
212190
# 'first_notebook_cell': ("%matplotlib inline\n"
213191
# "from pyvista import set_plot_theme\n"
214192
# "set_plot_theme('document')"),
215193
"reset_modules_order": 'both',
216-
"reset_modules": (reset_servers,),
194+
"reset_modules": ("reset_servers.reset_servers",),
217195
}
218196

219197

@@ -272,6 +250,9 @@ def reset_servers(gallery_conf, fname, when):
272250
"design.grid",
273251
"config.cache",
274252
"design.fa-build",
253+
"autosectionlabel.*",
254+
"ref.python",
255+
"toc.not_included"
275256
]
276257

277258
# Add any paths that contain custom static files (such as style sheets) here,
@@ -405,4 +386,4 @@ def reset_servers(gallery_conf, fname, when):
405386

406387
BUILD_EXAMPLES = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False
407388
if BUILD_EXAMPLES:
408-
extensions.extend(["sphinx_gallery.gen_gallery"])
389+
extensions.extend(["sphinx_gallery.gen_gallery"])
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
def reset_servers(gallery_conf, fname, when):
3+
import gc
4+
5+
import psutil
6+
7+
from ansys.dpf.core import server
8+
9+
gc.collect()
10+
server.shutdown_all_session_servers()
11+
12+
proc_name = "Ans.Dpf.Grpc"
13+
nb_procs = 0
14+
for proc in psutil.process_iter():
15+
try:
16+
# check whether the process name matches
17+
if proc_name in proc.name():
18+
proc.kill()
19+
nb_procs += 1
20+
except psutil.NoSuchProcess:
21+
pass
22+
print(f"Counted {nb_procs} {proc_name} processes {when} example {fname}.")

requirements/requirements_docs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ansys-sphinx-theme[autoapi]==1.4.4
1+
ansys-sphinx-theme[autoapi]==1.5.3
22
enum-tools[sphinx]==0.13.0
33
graphviz==0.21
44
imageio==2.37.0

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ commands =
227227
# Remove previously rendered documentation
228228
clean: python -c "import shutil, sys; shutil.rmtree(sys.argv[1], ignore_errors=True)" "{toxinidir}/{env:BUILD_DIR}"
229229

230-
# Clean files from previous build
230+
# Clean examples from previous build
231231
clean: python -c "\
232232
clean: from os.path import exists; import shutil; \
233233
clean: [(shutil.rmtree(p) if exists(p) else None) for p in ['{env:SOURCE_DIR}/images/auto-generated']]; \

0 commit comments

Comments
 (0)