Skip to content

Commit dfdc6a9

Browse files
DOCS: Refactor examples (#1260)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 762f1cc commit dfdc6a9

20 files changed

+4395
-384
lines changed

.github/workflows/ci_cd.yml

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -642,55 +642,28 @@ jobs:
642642
ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 0
643643
run: |
644644
. /env/bin/activate
645-
# Make html or pdf doc
646-
make_doc() {
647-
# $1 is the type of file we are creating (html or pdf)
648645
649-
# Need to unset PYMECHANICAL_PORT and PYMECHANICAL_START_INSTANCE when running code containing remote sessions
650-
unset PYMECHANICAL_PORT
651-
unset PYMECHANICAL_START_INSTANCE
646+
apt update
647+
apt install -y libjbig-dev
648+
# Add the /usr/lib/x86_64-linux-gnu/ path to the LD_LIBRARY_PATH (where libjbig-dev .so files are)
649+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/
652650
653-
output_file=doc_$1_output.txt
654-
if [ "${{ needs.container-stability-check.outputs.container_stable_exit }}" = "true" ]; then
655-
xvfb-run mechanical-env make -C doc $1
656-
else
657-
xvfb-run mechanical-env make -C doc $1 > $output_file 2>&1 || true
658-
cat $output_file
659-
echo done running make
660-
validate_output $output_file
661-
fi
662-
}
663-
664-
# Validate that the html or pdf build succeeded
665-
validate_output() {
666-
echo "validating output of build"
667-
# $1 is the file we are checking
668-
# cat $1
669-
#
670-
# Check if "build succeeded" string is present in doc_build_output.txt
671-
#
672-
if grep -q "build succeeded" $1; then
651+
if [ "${{ needs.container-stability-check.outputs.container_stable_exit }}" = "true" ]; then
652+
xvfb-run mechanical-env make -C doc html
653+
else
654+
xvfb-run mechanical-env make -C doc html > output.txt 2>&1 || true
655+
cat output.txt
656+
if grep -q "build succeeded" output.txt; then
673657
echo "Documentation building succeeded"
674658
else
675659
echo "Documentation building failed"
676660
exit 1
677661
fi
678-
}
679-
680-
# Install libjbig-dev so quarto doesn't fail its PDF build on v242
681-
apt update
682-
apt install -y libjbig-dev
683-
# Add the /usr/lib/x86_64-linux-gnu/ path to the LD_LIBRARY_PATH (where libjbig-dev .so files are)
684-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/
685-
686-
# Make the html doc & validate results
687-
make_doc html
688-
689-
# Make the pdf doc & validate results
690-
make_doc pdf
691-
692-
# Make the pdf doc & validate results
693-
make_doc linkcheck
662+
fi
663+
- name: Check links
664+
run: |
665+
. /env/bin/activate
666+
make -C doc linkcheck
694667
695668
- name: Upload HTML Documentation
696669
uses: actions/upload-artifact@v4
@@ -699,13 +672,6 @@ jobs:
699672
path: doc/_build/html
700673
retention-days: 7
701674

702-
- name: Upload PDF Documentation
703-
uses: actions/upload-artifact@v4
704-
with:
705-
name: documentation-pdf
706-
path: doc/_build/latex/*.pdf
707-
retention-days: 7
708-
709675
coverage:
710676
name: Merging coverage
711677
needs: [remote-connect, embedding-tests, embedding-scripts-tests, launch-tests]

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ doc/source/api/*
199199
!doc/source/api/path.rst
200200

201201
# Examples files downloaded when building docs
202-
examples/embedding_n_remote/download/*
202+
examples/01_basic/out/*
203203

204204
# pymechanical-specific
205205
mylocal.ip

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repos:
6363
tests/scripts/run_python_error.py |
6464
tests/scripts/run_python_success.py |
6565
tests/scripts/log_message.py |
66-
examples/embedding_n_remote/embedding_remote.py
66+
examples/.*$
6767
)$
6868
6969
- repo: https://github.com/pre-commit/pre-commit-hooks

doc/changelog.d/1260.documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor examples

doc/source/conf.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import warnings
1414

1515
from ansys_sphinx_theme import ansys_favicon, get_version_match
16+
import pyvista
17+
from pyvista.plotting.utilities.sphinx_gallery import DynamicScraper
1618
from sphinx_gallery.sorting import FileNameSortKey
1719

1820
import ansys.mechanical.core as pymechanical
@@ -21,6 +23,13 @@
2123
# necessary when building the sphinx gallery
2224
pymechanical.BUILDING_GALLERY = True
2325

26+
# Ensure that offscreen rendering is used for docs generation
27+
pyvista.OFF_SCREEN = True
28+
29+
# necessary when building the sphinx gallery
30+
pyvista.BUILDING_GALLERY = True
31+
32+
2433
# Whether or not to build the cheatsheet
2534
BUILD_CHEATSHEET = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False
2635

@@ -60,6 +69,8 @@
6069
"sphinx_autodoc_typehints",
6170
"sphinx_copybutton",
6271
"sphinx_design",
72+
"pyvista.ext.plot_directive",
73+
"pyvista.ext.viewer_directive",
6374
]
6475

6576
if pymechanical.BUILDING_GALLERY:
@@ -175,8 +186,7 @@
175186
# path to your examples scripts
176187
"examples_dirs": ["../../examples/"],
177188
# path where to save gallery generated examples
178-
"gallery_dirs": ["examples/gallery_examples"],
179-
# Pattern to search for example files
189+
"gallery_dirs": ["examples/gallery_examples"], # Pattern to search for example files
180190
"filename_pattern": r"\.py",
181191
# Remove the "Download all examples" button from the top level gallery
182192
"download_all_examples": False,
@@ -186,7 +196,7 @@
186196
"backreferences_dir": None,
187197
# Modules for which function level galleries are created. In
188198
"doc_module": "ansys-mechanical-core",
189-
"image_scrapers": ("matplotlib"),
199+
"image_scrapers": (DynamicScraper(), "matplotlib"),
190200
"ignore_pattern": "flycheck*",
191201
"thumbnail_size": (350, 350),
192202
}
@@ -229,7 +239,6 @@
229239
"sidebar_pages": ["changelog", "index"],
230240
},
231241
"ansys_sphinx_theme_autoapi": {"project": project, "templates": "_templates/autoapi"},
232-
"navigation_depth": 10,
233242
}
234243

235244
if BUILD_CHEATSHEET:
@@ -245,7 +254,6 @@
245254

246255
html_sidebars = {
247256
"changelog": [],
248-
"examples/index": [],
249257
"contributing": [],
250258
}
251259

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _ref_remote_examples:
2+
3+
Advanced Examples
4+
-----------------
5+
6+
This section contains examples that demonstrates advanced capabilities of Mechanical
7+
using Pymechanical.
8+
For more information, see `Advanced examples <pymechanical_embedding_ex_basic_>`_.

doc/source/examples/index.rst

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
.. _ref_examples:
22

3+
========
34
Examples
45
========
56

6-
Here are examples using Mechanical with the ``ansys-mechanical-core`` library through
7-
an embedded instance or remote session.
7+
Here is a series of examples using Mechanical with the ``ansys-mechanical-core`` library.
8+
9+
.. === EXAMPLES Gallery ===
10+
11+
..
12+
We have to include this rather than include it in a tree.
13+
14+
.. include:: gallery_examples/index.rst
15+
:start-line: 2
16+
17+
18+
.. === ADVANCED EXAMPLES ===
19+
20+
.. toctree::
21+
:hidden:
22+
:maxdepth: 3
23+
24+
Advanced Examples <https://embedding.examples.mechanical.docs.pyansys.com/examples/index.html>
825

9-
.. grid:: 1 2 2 2
1026

11-
.. grid-item-card:: Embedding Examples
12-
:padding: 2 2 2 2
13-
:link: https://embedding.examples.mechanical.docs.pyansys.com/examples/index.html
27+
.. include:: advanced_examples/index.rst
28+
:start-line: 2
1429

15-
Uses PyMechanical to embed an instance of Mechanical directly within Python as a Python object.
1630

17-
.. grid-item-card:: Remote Session Examples
18-
:padding: 2 2 2 2
19-
:link: https://examples.mechanical.docs.pyansys.com/examples/index.html
31+
.. === REMOTE EXAMPLES ===
2032
21-
Uses PyMechanical as a client to a remote Mechanical instance.
33+
.. toctree::
34+
:hidden:
35+
:maxdepth: 3
2236

23-
.. grid:: 1
37+
Remote Sessions <https://examples.mechanical.docs.pyansys.com/index.html>
2438

25-
.. grid-item-card:: Embedding Instance & Remote Session Example
26-
:padding: 2 2 2 2
27-
:link: gallery_examples/embedding_n_remote/embedding_remote.html
2839

29-
Demonstrates the same model setup in both an embedded instance and remote session,
30-
as well as examples using a combination of embedded instances and remote sessions.
40+
.. include:: remote_examples/index.rst
41+
:start-line: 2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _ref_remote_session_examples:
2+
3+
Remote examples
4+
---------------
5+
6+
Remote examples demonstrate the basic simulation capabilities of Mechanical using remote sessions.
7+
8+
For more information, see `Remote sessions examples <pymechanical_remote_ex_all_>`_.

doc/source/user_guide_session/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ to a remote Mechanical session.
1616

1717
self
1818
server-launcher
19-
mechanical
2019
pool
2120

2221
Overview

0 commit comments

Comments
 (0)