Skip to content

Commit 2d59625

Browse files
moe-adjorgepiloto
andauthored
doc: use sphinx-autoapi for API reference (#1952)
* feat: first commit that results in sucessful documentation build * feat: bumped sphinx version manually to 8.1.3 * feat: cleaned up conf.py * doc: sphinx 7.4.7 works for autoapi * fix: ci doc build resulting in error * fix: check if modifying action file fixes doc-build error * fix: quick test * fix: trialing another fix * fix: modified docs.yml file * doc: todo to address warnings that are being suppressed * fix: duplicated dependency --------- Co-authored-by: Jorge Martínez <[email protected]>
1 parent 6f7cde8 commit 2d59625

File tree

5 files changed

+114
-50
lines changed

5 files changed

+114
-50
lines changed

.ci/build_doc.bat

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
set SPHINX_APIDOC_OPTIONS=inherited-members
2-
call sphinx-apidoc -o ../doc/source/api ../src/ansys ../src/ansys/dpf/core/log.py ^
3-
../src/ansys/dpf/core/help.py ../src/ansys/dpf/core/mapping_types.py ../src/ansys/dpf/core/ipconfig.py ^
4-
../src/ansys/dpf/core/field_base.py ../src/ansys/dpf/core/cache.py ../src/ansys/dpf/core/misc.py ^
5-
../src/ansys/dpf/core/check_version.py ../src/ansys/dpf/core/operators/build.py ../src/ansys/dpf/core/operators/specification.py ^
6-
../src/ansys/dpf/core/vtk_helper.py ../src/ansys/dpf/core/label_space.py ../src/ansys/dpf/core/examples/python_plugins/* ^
7-
../src/ansys/dpf/core/examples/examples.py ../src/ansys/dpf/gate/* ../src/ansys/dpf/gatebin/* ../src/ansys/grpc/dpf/* ^
8-
../src/ansys/dpf/core/property_fields_container.py ^
9-
-f --implicit-namespaces --separate --no-headings
1+
@echo off
2+
3+
REM Move to the documentation directory
104
pushd .
115
cd ../doc/
6+
7+
REM Clean the previous build
128
call make clean
9+
10+
REM Build the HTML documentation
1311
call make html -v -v -v -P
1412

13+
REM Display the directory contents for verification
1514
dir
1615

17-
rem Patch pyVista issue with elemental plots
16+
REM Patch pyVista issue with elemental plots by copying necessary images
17+
xcopy source\examples\04-advanced\02-volume_averaged_stress\sphx_glr_02-volume_averaged_stress_001.png build\html\_images\ /y /f
18+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_001.png build\html\_images\ /y /f
19+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_002.png build\html\_images\ /y /f
20+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_003.png build\html\_images\ /y /f
21+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_004.png build\html\_images\ /y /f
22+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_005.png build\html\_images\ /y /f
23+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_006.png build\html\_images\ /y /f
24+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_007.png build\html\_images\ /y /f
25+
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_thumb.png build\html\_images\ /y /f
1826

19-
xcopy source\examples\04-advanced\02-volume_averaged_stress\sphx_glr_02-volume_averaged_stress_001.png build\html\_images\ /y /f
20-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_001.png build\html\_images\ /y /f
21-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_002.png build\html\_images\ /y /f
22-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_003.png build\html\_images\ /y /f
23-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_004.png build\html\_images\ /y /f
24-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_005.png build\html\_images\ /y /f
25-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_006.png build\html\_images\ /y /f
26-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_007.png build\html\_images\ /y /f
27-
xcopy source\examples\12-fluids\02-fluids_results\sphx_glr_02-fluids_results_thumb.png build\html\_images\ /y /f
27+
REM Return to the original directory
2828
popd

.github/workflows/docs.yml

+34-14
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,33 @@ jobs:
7373
with:
7474
python-version: ${{ inputs.python_version }}
7575

76+
- name: "Create virtual environment in the current workspace"
77+
shell: pwsh
78+
run: python -m venv .venv --system-site-packages
79+
80+
- name: "Update PATH for virtual environment"
81+
run: |
82+
echo "${{ github.workspace }}\.venv\Scripts" >> $env:GITHUB_PATH
83+
84+
- name: "Update pip to the latest version"
85+
shell: pwsh
86+
run: |
87+
python -m pip install -U pip
88+
7689
- name: "Install requirements"
77-
run: pip install -r requirements/requirements_build.txt
90+
shell: pwsh
91+
run: |
92+
python -m pip install -r requirements/requirements_build.txt
7893
7994
- name: "Build the wheel"
80-
shell: bash
95+
shell: pwsh
8196
run: |
82-
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
83-
export platform="manylinux_2_17"
84-
else
85-
export platform="win"
86-
fi
97+
$os = "${{ matrix.os }}"
98+
if ($os -eq "ubuntu-latest") {
99+
$platform = "manylinux_2_17"
100+
} else {
101+
$platform = "win"
102+
}
87103
python .ci/build_wheel.py -p $platform -w
88104
89105
- name: "Expose the wheel"
@@ -96,9 +112,9 @@ jobs:
96112
echo "wheel_name=${name[0]}" >> $GITHUB_OUTPUT
97113
98114
- name: "Install package wheel"
99-
shell: bash
115+
shell: pwsh
100116
run: |
101-
pip install dist/${{ steps.wheel.outputs.wheel_name }}[plotting]
117+
python -m pip install dist/${{ steps.wheel.outputs.wheel_name }}[plotting]
102118
103119
- name: "Install DPF"
104120
id: set-server-path
@@ -112,9 +128,10 @@ jobs:
112128
uses: ansys/pydpf-actions/[email protected]
113129

114130
- name: "Test import"
115-
shell: bash
131+
shell: pwsh
116132
working-directory: tests
117-
run: python -c "from ansys.dpf import core"
133+
run: |
134+
python -c "from ansys.dpf import core"
118135
119136
- name: "Setup headless display"
120137
uses: pyvista/setup-headless-display-action@v2
@@ -127,20 +144,23 @@ jobs:
127144
choco install pandoc
128145
129146
- name: "Install documentation packages for Python"
147+
shell: pwsh
130148
run: |
131-
pip install -r requirements/requirements_docs.txt
149+
python -m pip install -r requirements/requirements_docs.txt
132150
133151
- name: "Kill all servers"
134152
uses: ansys/pydpf-actions/[email protected]
135153

136154
- name: "Ensure VTK compatibility"
155+
shell: pwsh
137156
run: |
138157
python -m pip uninstall --yes vtk
139158
python -m pip install --extra-index-url https://wheels.vtk.org vtk-osmesa==${{ env.VTK_OSMESA_VERSION }}
140159
141160
- name: "List installed packages"
142-
shell: bash
143-
run: pip list
161+
shell: pwsh
162+
run: |
163+
python -m pip list
144164
145165
- name: "Build HTML Documentation"
146166
shell: cmd /D /E:ON /V:OFF /C "CALL "{0}""

doc/source/api/index.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
.. _ref_api_section:
2-
3-
=============
41
API reference
52
=============
3+
4+
This section describes PyDPF-Core endpoints, their capabilities, and how
5+
to interact with them programmatically.
6+
67
.. toctree::
7-
:maxdepth: 2
8-
:caption: API reference
9-
10-
ansys.dpf.core
8+
:titlesonly:
9+
:maxdepth: 3
10+
11+
<span class="nf nf-md-package"></span> ansys.dpf.core</api/ansys/dpf/core/index>

doc/source/conf.py

+51-8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@
6464
ignored_pattern += "|06-distributed_stress_averaging.py"
6565
ignored_pattern += r")"
6666

67+
# Autoapi ignore pattern
68+
autoapi_ignore_list = [
69+
"*/log.py",
70+
"*/help.py",
71+
"*/mapping_types.py",
72+
"*/ipconfig.py",
73+
"*/field_base.py",
74+
"*/cache.py",
75+
"*/misc.py",
76+
"*/check_version.py",
77+
"*/operators/build.py",
78+
"*/operators/specification.py",
79+
"*/vtk_helper.py",
80+
"*/label_space.py",
81+
"*/examples/python_plugins/*",
82+
"*/examples/examples.py",
83+
"*/gate/*",
84+
"*/gatebin/*",
85+
"*/grpc/*",
86+
"*/property_fields_container.py"
87+
]
88+
6789
# -- General configuration ---------------------------------------------------
6890

6991
# If your documentation needs a minimal Sphinx version, state it here.
@@ -75,18 +97,16 @@
7597
# ones.
7698
extensions = [
7799
"enum_tools.autoenum",
78-
"nbsphinx",
79100
"sphinx.ext.autosectionlabel",
80-
"sphinx.ext.autodoc",
81101
"sphinx.ext.graphviz",
82102
"sphinx.ext.intersphinx",
83103
"sphinx.ext.napoleon",
84104
"sphinx.ext.todo",
85-
"sphinx_autodoc_typehints",
86105
"sphinx_copybutton",
87106
"sphinx_design",
88107
"sphinx_gallery.gen_gallery",
89108
'sphinx_reredirects',
109+
"ansys_sphinx_theme.extension.autoapi",
90110
]
91111

92112
redirects = {
@@ -105,9 +125,8 @@
105125
"pyvista": ("https://docs.pyvista.org/", None),
106126
}
107127

108-
autosummary_generate = True
128+
autosummary_generate = False
109129

110-
autodoc_mock_imports = ["ansys.dpf.core.examples.python_plugins"]
111130

112131
# Add any paths that contain templates here, relative to this directory.
113132
# templates_path = ['_templates']
@@ -189,8 +208,6 @@ def reset_servers(gallery_conf, fname, when):
189208
"reset_modules": (reset_servers,),
190209
}
191210

192-
autodoc_member_order = "bysource"
193-
194211

195212
# -- Options for HTML output -------------------------------------------------
196213
html_short_title = html_title = "PyDPF-Core"
@@ -217,9 +234,35 @@ def reset_servers(gallery_conf, fname, when):
217234
"min_chars_for_search": 2,
218235
"ignoreLocation": True,
219236
},
237+
"ansys_sphinx_theme_autoapi": {
238+
"project": project,
239+
"output": "api",
240+
"directory": "src/ansys",
241+
"use_implicit_namespaces": True,
242+
"keep_files": True,
243+
"own_page_level": "class",
244+
"type": "python",
245+
"options": [
246+
"members",
247+
"undoc-members",
248+
"show-inheritance",
249+
"show-module-summary",
250+
"special-members",
251+
],
252+
"class_content": "class",
253+
"ignore": autoapi_ignore_list,
254+
"add_toctree_entry": True,
255+
"member_order": "bysource",
256+
}
220257
}
221258

222-
259+
# Configuration for Sphinx autoapi
260+
suppress_warnings = [
261+
"autoapi.python_import_resolution", # Todo: remove suppression of this warning in the future
262+
"design.grid",
263+
"config.cache",
264+
"design.fa-build",
265+
]
223266

224267
# Add any paths that contain custom static files (such as style sheets) here,
225268
# relative to this directory. They are copied after the builtin static files,

requirements/requirements_docs.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ansys-sphinx-theme==1.2.2
1+
ansys-sphinx-theme[autoapi]==1.2.2
22
enum-tools[sphinx]==0.12.0
33
graphviz==0.20.1
44
imageio==2.36.0
@@ -7,7 +7,7 @@ nbsphinx==0.9.5
77
pypandoc==1.14
88
pytest-sphinx==0.6.3
99
pyvista==0.44.2
10-
sphinx==7.1.0
10+
sphinx==7.4.7
1111
sphinx-copybutton==0.5.2
1212
sphinx-gallery==0.18.0
1313
sphinx-notfound-page==1.0.4

0 commit comments

Comments
 (0)