Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d60d3c8
ci(doc): add doc build caching
PProfizi Jun 5, 2025
676d60a
Add generated examples to cached build directory
PProfizi Jun 5, 2025
70c9e45
Workaround immutable cache
PProfizi Jun 5, 2025
ede4392
Merge branch 'master' into ci/add_doc_build_cache
PProfizi Jun 5, 2025
67c8c06
Improve cache key logic
PProfizi Jun 6, 2025
ec9a34b
Print DPF server path at beginning of doc generation
PProfizi Jun 6, 2025
3cd65e4
Merge branch 'master' into ci/add_doc_build_cache
PProfizi Jun 6, 2025
eae0f80
clean examples only in doc-clean tox environment
PProfizi Jun 6, 2025
16a9b75
Cache the doc/source/examples folder
PProfizi Jun 6, 2025
9cd9511
Generate examples in doc/source/examples
PProfizi Jun 6, 2025
cb3c999
Fix autoapi detection of changed configuration
PProfizi Jun 6, 2025
544630e
Try with sphinx-autoapi instead of ansys-sphinx-theme[autoapi] extension
PProfizi Jun 12, 2025
c32650d
Add autosectionlabel_prefix_document = True in conf.py
PProfizi Jun 13, 2025
b59ff8b
Revert "Try with sphinx-autoapi instead of ansys-sphinx-theme[autoapi…
PProfizi Jun 13, 2025
39dae0d
Fix suppress_warnings config in conf.py
PProfizi Jun 13, 2025
a749326
Target the dev branch of ansys-sphinx-theme for testing the autoapi c…
PProfizi Jun 13, 2025
ddd1e2c
Merge branch 'master' into ci/add_doc_build_cache
PProfizi Jun 17, 2025
e31af90
Target released ansys-sphinx-theme==1.5.3
PProfizi Jul 11, 2025
c68d46d
Merge branch 'master' into ci/add_doc_build_cache
PProfizi Jul 11, 2025
ba22ac7
Try caching only examples
PProfizi Jul 11, 2025
7c76627
Fix cache restore-keys
PProfizi Jul 11, 2025
cbc9e34
Remove run-id from cache key
PProfizi Jul 11, 2025
0364e39
Merge branch 'master' into ci/add_doc_build_cache
PProfizi Jul 23, 2025
35f2ffd
Add run_id back into the key
PProfizi Jul 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,41 @@ jobs:
run: |
choco install pandoc

- name: "Restore doc build cache"
id: cache-doc-build-restore
uses: actions/cache/restore@v4
with:
path: |
doc/source/examples
# Cache key is composed of branch name, ansys version, hash of requirements_doc,
# and run_id to work around immutability
# We should also track version of pandoc, of graphviz, of packages installed by headless-display, and even of pydpf-core?
key: doc-build-${{ github.ref_name }}-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-${{ github.run_id }}
restore-keys: |
doc-build-${{ github.ref_name }}-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-
doc-build-master-DPF_${{inputs.ANSYS_VERSION}}${{inputs.standalone_suffix}}-${{hashfiles('requirements/requirements_docs.txt')}}-

- name: "Build HTML Documentation"
shell: bash
run: |
tox -e doc-html --installpkg dist/${{ steps.wheel.outputs.wheel_name }} -x testenv:doc-html.setenv+='VIRTUALENV_SYSTEM_SITE_PACKAGES=true'

- name: "Retrieve package version"
shell: bash
run: |
echo "VERSION=$(python -c "from ansys.dpf.${{env.MODULE}} import __version__; print(__version__)")" >> GITHUB_OUTPUT
echo "${{env.PACKAGE_NAME}} version is: $(python -c "from ansys.dpf.${{env.MODULE}} import __version__; print(__version__)")"
id: version
if: always()

- name: "Upload Documentation Build log"
uses: actions/upload-artifact@v4
with:
name: doc-${{env.PACKAGE_NAME}}-log
path: doc/*.txt
if: always()

- name: "Save doc-build cache"
id: cache-doc-build-save
uses: actions/cache/save@v4
with:
path: |
doc/build
doc/source/examples
key: ${{ steps.cache-doc-build-restore.outputs.cache-primary-key }}

- name: "Zip HTML Documentation"
shell: pwsh
run: |
Expand Down
45 changes: 13 additions & 32 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from glob import glob
import os
import sys
from pathlib import Path
import subprocess

Expand All @@ -16,6 +17,9 @@
from ansys.dpf.core import __version__, server, server_factory
from ansys.dpf.core.examples import get_example_required_minimum_dpf_version

# Make sphinx_utilities modules importable
sys.path.append(os.path.join(os.path.dirname(__file__), "../sphinx_utilities"))

# Manage errors
pyvista.set_error_output_file("errors.txt")
# Ensure that offscreen rendering is used for docs generation
Expand Down Expand Up @@ -56,12 +60,13 @@
server_version = server_instance.version
server.shutdown_all_session_servers()
print(f"DPF version: {server_version}")
print(f"DPF install: {server_instance.ansys_path}")

# Build ignore pattern
ignored_pattern = r"(ignore"
header_flag = "\"\"\""
note_flag = r".. note::"
for example in glob(r"../../examples/**/*.py"):
for example in sorted(glob(r"../../examples/**/*.py")):
minimum_version_str = get_example_required_minimum_dpf_version(example)
if float(server_version) - float(minimum_version_str) < -0.05:
example_name = example.split(os.path.sep)[-1]
Expand Down Expand Up @@ -124,8 +129,7 @@
typehints_defaults = "comma"
typehints_use_signature = True
simplify_optional_unions = False
suppress_warnings = ['autosectionlabel.*']

autosectionlabel_prefix_document = True
# Intersphinx mapping
intersphinx_mapping = {
"pyvista": ("https://docs.pyvista.org/", None),
Expand Down Expand Up @@ -163,32 +167,6 @@


# -- Sphinx Gallery Options
from sphinx_gallery.sorting import FileNameSortKey


def reset_servers(gallery_conf, fname, when):
import gc

import psutil

from ansys.dpf.core import server

gc.collect()
server.shutdown_all_session_servers()

proc_name = "Ans.Dpf.Grpc"
nb_procs = 0
for proc in psutil.process_iter():
try:
# check whether the process name matches
if proc_name in proc.name():
proc.kill()
nb_procs += 1
except psutil.NoSuchProcess:
pass
print(f"Counted {nb_procs} {proc_name} processes {when} example {fname}.")


sphinx_gallery_conf = {
# convert rst to md for ipynb
"pypandoc": True,
Expand All @@ -205,15 +183,15 @@ def reset_servers(gallery_conf, fname, when):
# Remove the "Download all examples" button from the top level gallery
"download_all_examples": False,
# Sort gallery example by file name instead of number of lines (default)
"within_subsection_order": FileNameSortKey,
"within_subsection_order": "FileNameSortKey",
# directory where function granular galleries are stored
"backreferences_dir": None,
"image_scrapers": ("pyvista", "matplotlib"),
# 'first_notebook_cell': ("%matplotlib inline\n"
# "from pyvista import set_plot_theme\n"
# "set_plot_theme('document')"),
"reset_modules_order": 'both',
"reset_modules": (reset_servers,),
"reset_modules": ("reset_servers.reset_servers",),
}


Expand Down Expand Up @@ -272,6 +250,9 @@ def reset_servers(gallery_conf, fname, when):
"design.grid",
"config.cache",
"design.fa-build",
"autosectionlabel.*",
"ref.python",
"toc.not_included"
]

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

BUILD_EXAMPLES = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False
if BUILD_EXAMPLES:
extensions.extend(["sphinx_gallery.gen_gallery"])
extensions.extend(["sphinx_gallery.gen_gallery"])
22 changes: 22 additions & 0 deletions doc/sphinx_utilities/reset_servers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
def reset_servers(gallery_conf, fname, when):
import gc

import psutil

from ansys.dpf.core import server

gc.collect()
server.shutdown_all_session_servers()

proc_name = "Ans.Dpf.Grpc"
nb_procs = 0
for proc in psutil.process_iter():
try:
# check whether the process name matches
if proc_name in proc.name():
proc.kill()
nb_procs += 1
except psutil.NoSuchProcess:
pass
print(f"Counted {nb_procs} {proc_name} processes {when} example {fname}.")
2 changes: 1 addition & 1 deletion requirements/requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ansys-sphinx-theme[autoapi]==1.4.4
ansys-sphinx-theme[autoapi]==1.5.3
enum-tools[sphinx]==0.13.0
graphviz==0.21
imageio==2.37.0
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ commands =
# Remove previously rendered documentation
clean: python -c "import shutil, sys; shutil.rmtree(sys.argv[1], ignore_errors=True)" "{toxinidir}/{env:BUILD_DIR}"

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