Skip to content

Commit 8f622d3

Browse files
RobPasMuepyansys-ci-botPipKatMaxJPRey
authored
docs: adding command for single example build (#1893)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Kathy Pippert <[email protected]> Co-authored-by: Maxime Rey <[email protected]>
1 parent 757cd1e commit 8f622d3

File tree

7 files changed

+143
-17
lines changed

7 files changed

+143
-17
lines changed

doc/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ html:
3737
# Linkcheck
3838
linkcheck:
3939
@$(SPHINXBUILD) -M linkcheck "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
40+
41+
# Single example target
42+
single-example:
43+
@if [ -z "$(example)" ]; then \
44+
echo "No example specified."; \
45+
echo "Usage --> make single-example example=examples/01_getting_started/01_math.mystnb"; \
46+
exit 1; \
47+
fi
48+
@echo "Building single example --> $(example)"
49+
@BUILD_API=False SKIP_BUILD_CHEAT_SHEET=True $(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" -j 1 $(O) -D "include_patterns=index.rst,examples.rst,$(example)"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
adding command for single example build

doc/make.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if "%1" == "clean" goto clean
2020
if "%1" == "pdf" goto pdf
2121
if "%1" == "html" goto html
2222
if "%1" == "linkcheck" goto linkcheck
23+
if "%1" == "single-example" goto single-example
2324

2425
%SPHINXBUILD% >NUL 2>NUL
2526
if errorlevel 9009 (
@@ -61,6 +62,19 @@ rmdir /s /q %BUILDDIR% > /NUL 2>&1
6162
rmdir /s /q %APIDIR% > /NUL 2>&1
6263
goto end
6364

65+
:single-example
66+
if "%2" == "" (
67+
echo. No example specified.
68+
echo. Example: ./make.bat single-example examples/01_getting_started/01_math.mystnb
69+
exit /b 1
70+
)
71+
echo Building single example: %2
72+
set BUILD_API=false
73+
set SKIP_BUILD_CHEAT_SHEET=true
74+
set SPHINXOPTS=-j auto
75+
%SPHINXBUILD% -M html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -D "include_patterns=index.rst,examples.rst,%2"
76+
goto end
77+
6478
:help
6579
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
6680
goto end

doc/source/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def intersphinx_pyansys_geometry(switcher_version: str):
314314
"examples/04_applied/01_naca_airfoils": "_static/thumbnails/naca_airfoils.png",
315315
"examples/04_applied/02_naca_fluent": "_static/thumbnails/naca_fluent.png",
316316
"examples/04_applied/03_ahmed_body_fluent": "_static/thumbnails/ahmed_body.png",
317+
"examples/99_misc/template": "_static/thumbnails/101_getting_started.png",
317318
}
318319
nbsphinx_epilog = """
319320
----
@@ -380,7 +381,9 @@ def intersphinx_pyansys_geometry(switcher_version: str):
380381
exclude_patterns = []
381382
BUILD_API = True if os.environ.get("BUILD_API", "true") == "true" else False
382383
if not BUILD_API:
383-
exclude_patterns.append("autoapi")
384+
exclude_patterns.append("api")
385+
html_theme_options.pop("ansys_sphinx_theme_autoapi")
386+
extensions.remove("ansys_sphinx_theme.extension.autoapi")
384387

385388
BUILD_EXAMPLES = True if os.environ.get("BUILD_EXAMPLES", "true") == "true" else False
386389
if not BUILD_EXAMPLES:

doc/source/contributing.rst

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,34 @@ To add a new example, follow these steps:
138138

139139
1. Create a new notebook in the ``doc/source/examples`` directory, under the appropriate
140140
folder for your example.
141-
2. Take as reference an existing example to see how the notebook should be structured.
141+
2. Use the ``doc\source\examples\99_misc\template.mystnb`` file as a reference for creating
142+
your example notebook. It contains the necessary metadata and structure for a
143+
PyAnsys Geometry example.
142144
3. Add the new notebook to the ``doc/source/examples.rst`` file.
143145
4. Store a thumbnail image of the example in the ``doc/source/_static/thumbnails`` directory.
144-
5. Link the thumbnail image to your example file in ``doc/source/conf.py`` as shown in the reference commit.
146+
5. Link the thumbnail image to your example file in the ``doc/source/conf.py`` file as shown in the reference commit.
145147

146148
You can also test the correct build process of a new example by performing the following steps:
147149

148150
1. Run the following command to install the documentation dependencies::
149151

150152
pip install -e .[doc]
151153

152-
2. Install ``myst-nb`` by running this command::
154+
2. Navigate to the ``doc`` directory and run the following command::
153155

154-
pip install myst-nb
156+
# On Linux or macOS
157+
make single-example examples/01_getting_started/01_math.mystnb
155158

156-
3. Run the following command to build a single example (that is, substitute
157-
``<PATH_TO_MY_EXAMPLE_FILE>`` with the path to your example file)::
159+
# On Windows
160+
./make.bat single-example examples/01_getting_started/01_math.mystnb
158161

159-
mystnb-docutils-html --nb-read-as-md=1 <PATH_TO_MY_EXAMPLE_FILE> output.html
162+
.. note::
160163

161-
4. Check the output file ``output.html`` to ensure that the example is correctly built.
162-
Rendered output does not have documentation styling but users should have the
163-
ability to see its proper execution.
164+
The example name must be the same as the notebook name, with its path
165+
starting at the ``examples`` directory.
164166

165-
.. note::
166-
167-
Plots are not be rendered in the output file, but the code and markdown cells should
168-
be correctly rendered. In case of failure during execution users can also see the error
169-
message in the output file.
167+
3. Check the ``doc/source/_build/html`` directory for the generated documentation
168+
and open the ``index.html`` file in your browser.
170169

171170
Run tests
172171
---------

doc/source/examples.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@ applications.
6363

6464
examples/04_applied/01_naca_airfoils.mystnb
6565
examples/04_applied/02_naca_fluent.mystnb
66-
examples/04_applied/03_ahmed_body_fluent.mystnb
66+
examples/04_applied/03_ahmed_body_fluent.mystnb
67+
68+
Miscellaneous examples
69+
----------------------
70+
71+
.. nbgallery::
72+
:caption: Miscellaneous examples
73+
74+
examples/99_misc/template.mystnb
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .mystnb
5+
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.14.1
8+
kernelspec:
9+
display_name: Python 3 (ipykernel)
10+
language: python
11+
name: python3
12+
---
13+
14+
# Miscellaneous: Example template
15+
16+
This example serves as a template for creating new examples in the documentation.
17+
It shows developers how to structure their code and comments for clarity and consistency.
18+
It also provides a basic outline for importing necessary modules, initializing the modeler,
19+
performing operations, and closing the modeler.
20+
21+
It is important to follow the conventions and formatting used in this example to ensure that
22+
the documentation is easy to read and understandable.
23+
24+
## Example imports
25+
26+
Perform the required imports for this example.
27+
This section should include all necessary imports for the example to run correctly.
28+
29+
```{code-cell} ipython3
30+
# Imports
31+
from ansys.geometry.core import launch_modeler
32+
from ansys.geometry.core.math import Point2D
33+
from ansys.geometry.core.sketch import Sketch
34+
```
35+
36+
## Initialize the modeler
37+
38+
```{code-cell} ipython3
39+
# Initialize the modeler for this example notebook
40+
m = launch_modeler()
41+
print(m)
42+
```
43+
44+
## Body of your example
45+
46+
Developers can add their code here to perform the desired operations.
47+
This section should include comments and explanations to explain what the code is doing.
48+
49+
### Example section: Initialize a design
50+
51+
Create a design named ``example-design``.
52+
53+
```{code-cell} ipython3
54+
# Initialize the example design
55+
design = m.create_design("example-design")
56+
```
57+
58+
### Example section: Include images
59+
60+
This section demonstrates how to include static images in the documentation.
61+
You should place these images in the ``doc/source/_static/`` directory.
62+
63+
You can then reference images in the documentation using the following syntax:
64+
65+
![image](../../_static/thumbnails/101_getting_started.png){align=center}
66+
67+
68+
### Example section: Create a sketch and plot it
69+
70+
This section demonstrates how to create a sketch and plot it.
71+
72+
```{code-cell} ipython3
73+
sketch = Sketch()
74+
sketch.box(Point2D([0, 0]), 10, 10)
75+
sketch.plot()
76+
```
77+
78+
### Example section: Extrude the sketch and create a body
79+
This section demonstrates how to extrude the sketch and create a body.
80+
81+
```{code-cell} ipython3
82+
design.extrude_sketch(f"BoxBody", sketch, distance=10)
83+
design.plot()
84+
```
85+
86+
## Close the modeler
87+
88+
```{code-cell} ipython3
89+
# Close the modeler
90+
m.close()
91+
```

0 commit comments

Comments
 (0)