Skip to content

Commit 6a2c349

Browse files
Revathyvenugopal162pyansys-ci-botjorgepilotoPipKatSMoraisAnsys
authored
docs: reformat the documentation (#396)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Jorge Martinez <[email protected]> Co-authored-by: Kathy Pippert <[email protected]> Co-authored-by: Sébastien Morais <[email protected]>
1 parent 77647cc commit 6a2c349

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+798
-408
lines changed

.github/workflows/ci_cd.yml

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
uses: ansys/actions/doc-build@v6
6161
with:
6262
python-version: ${{ env.MAIN_PYTHON_VERSION }}
63+
add-pdf-html-docs-as-assets: true
64+
requires-xvfb: true
65+
dependencies: 'pandoc'
6366

6467
doc-deploy-development:
6568
name: Doc dev version deploy

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,8 @@ cython_debug/
157157

158158
# Sphinx auto-generated
159159
doc/source/_autosummary/
160+
# rendering of sphinx gallery examples
161+
doc/source/examples/gallery-examples/
162+
doc/source/sg_execution_times.rst
163+
# rendering of sphinx autoapi examples
164+
doc/source/examples/examples/

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ repos:
1010
- id: isort
1111

1212
- repo: https://github.com/PyCQA/flake8
13-
rev: 7.0.0
13+
rev: 7.1.0
1414
hooks:
1515
- id: flake8
1616

1717
- repo: https://github.com/codespell-project/codespell
18-
rev: v2.2.6
18+
rev: v2.3.0
1919
hooks:
2020
- id: codespell
2121

@@ -41,7 +41,7 @@ repos:
4141

4242
# this validates our github workflow files
4343
- repo: https://github.com/python-jsonschema/check-jsonschema
44-
rev: 0.28.4
44+
rev: 0.28.5
4545
hooks:
4646
- id: check-github-workflows
4747

@@ -54,7 +54,7 @@ repos:
5454
exclude: 'src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/'
5555

5656
- repo: https://github.com/ansys/pre-commit-hooks
57-
rev: v0.3.1
57+
rev: v0.3.2
5858
hooks:
5959
- id: add-license-headers
6060
args:

doc/Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@ SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
77
SOURCEDIR = source
88
BUILDDIR = _build
9+
AUTOAPI_OUTDIR = source/examples/examples
10+
GALLERY_EXAMPLES = gallery-examples
911

1012
# Put it first so that "make" without argument is like "make help".
1113
help:
1214
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1315

14-
.PHONY: help Makefile
16+
.PHONY: help Makefile clean pdf
1517

1618
# Catch-all target: route all unknown targets to Sphinx using the new
1719
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1820
%: Makefile
1921
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
2022

21-
# customized clean due to api examples
23+
# customized clean due to api examples and sphinx-gallery
2224
clean:
2325
rm -rf $(BUILDDIR)
24-
find . -type d -name "_autosummary" -exec rm -rf {} +
26+
find . -type d -name "$(GALLERY_EXAMPLES)" -exec rm -rf {} +
27+
find . -type d -path "./$(AUTOAPI_OUTDIR)" -exec rm -rf {} +
28+
echo Cleanup complete.
2529

2630
# customized pdf due to svg issue
2731
pdf:

doc/changelog.d/396.dependencies.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs: reformat the documentation

doc/make.bat

+12-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ if "%SPHINXBUILD%" == "" (
99
)
1010
set SOURCEDIR=source
1111
set BUILDDIR=_build
12+
set GALLERY_EXAMPLES=%SOURCEDIR%\examples\gallery-examples
13+
set AUTOAPI_OUTDIR=%SOURCEDIR%\examples\examples\
1214

1315
if "%1" == "" goto help
1416
if "%1" == "pdf" goto pdf
17+
if "%1" == "clean" goto clean
1518

1619
%SPHINXBUILD% >NUL 2>NUL
1720
if errorlevel 9009 (
@@ -33,10 +36,15 @@ goto end
3336
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
3437

3538
:pdf
36-
%SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
37-
cd "%BUILDDIR%\latex"
38-
for %%f in (*.tex) do (
39-
pdflatex "%%f" --interaction=nonstopmode)
39+
%SPHINXBUILD% -M latex %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
40+
cd "%BUILDDIR%\latex"
41+
for %%f in (*.tex) do (
42+
pdflatex "%%f" --interaction=nonstopmode)
43+
44+
:clean
45+
if exist %BUILDDIR% rmdir /S /Q %BUILDDIR%
46+
if exist %GALLERY_EXAMPLES% rmdir /S /Q %GALLERY_EXAMPLES%
47+
if exist %AUTOAPI_OUTDIR% rmdir /S /Q %AUTOAPI_OUTDIR%
4048

4149
:end
4250
popd

doc/source/conf.py

+81-43
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
from datetime import datetime
44
import os
5+
from pathlib import Path
6+
from typing import List
57

68
from github import Github
9+
import pyvista
10+
import requests
711
from sphinx.builders.latex import LaTeXBuilder
812

9-
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
10-
1113
from ansys_sphinx_theme import (
1214
__version__,
1315
ansys_favicon,
@@ -21,6 +23,10 @@
2123
watermark,
2224
)
2325

26+
THIS_PATH = Path(__file__).parent.resolve()
27+
EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve()
28+
API_TEMPLATES = (THIS_PATH / "examples" / "autoapi").resolve()
29+
2430
# Project information
2531
project = "ansys_sphinx_theme"
2632
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
@@ -29,21 +35,23 @@
2935
cname = os.getenv("DOCUMENTATION_CNAME", "sphinxdocs.ansys.com")
3036
switcher_version = get_version_match(__version__)
3137

32-
# use the default ansys logo
38+
# HTML configuration
3339
html_logo = ansys_logo_black
40+
html_favicon = ansys_favicon
3441
html_theme = "ansys_sphinx_theme"
42+
html_short_title = html_title = "Ansys Sphinx Theme"
43+
# static path
44+
html_static_path = ["_static"]
45+
# Add any paths that contain templates here, relative to this directory.
46+
templates_path = ["_templates"]
3547

36-
37-
# In the html_context dictionary in conf.py
3848
html_context = {
3949
"github_user": "ansys",
4050
"github_repo": "ansys-sphinx-theme",
4151
"github_version": "main",
4252
"doc_path": "doc/source",
4353
}
4454

45-
46-
# specify the location of your github repo
4755
html_theme_options = {
4856
"github_url": "https://github.com/ansys/ansys-sphinx-theme",
4957
"contact_mail": "[email protected]",
@@ -61,20 +69,30 @@
6169
f"ansys-sphinx-theme-v{convert_version_to_pymeilisearch(__version__)}": "ansys-sphinx-theme", # noqa: E501
6270
},
6371
},
72+
"ansys_sphinx_theme_autoapi": {
73+
"project": project,
74+
"directory": "src/ansys_sphinx_theme/examples",
75+
"output": "examples/",
76+
"own_page_level": "function",
77+
},
6478
}
6579

66-
html_short_title = html_title = "Ansys Sphinx Theme"
67-
6880
# Sphinx extensions
6981
extensions = [
82+
"ansys_sphinx_theme.extension.autoapi",
83+
"nbsphinx",
84+
"numpydoc",
7085
"sphinx.ext.autodoc",
7186
"sphinx.ext.autosummary",
72-
"numpydoc",
7387
"sphinx.ext.intersphinx",
74-
"notfound.extension",
88+
"sphinx.ext.todo",
7589
"sphinx_copybutton",
7690
"sphinx_design",
91+
"sphinx.ext.intersphinx",
92+
"sphinx.ext.todo",
93+
"sphinx_gallery.gen_gallery",
7794
"sphinx_jinja",
95+
"notfound.extension",
7896
]
7997

8098
# Intersphinx mapping
@@ -86,33 +104,19 @@
86104
# numpydoc configuration
87105
numpydoc_show_class_members = False
88106
numpydoc_xref_param_type = True
89-
90-
# Consider enabling numpydoc validation. See:
91-
# https://numpydoc.readthedocs.io/en/latest/validation.html#
92107
numpydoc_validate = True
93108
numpydoc_validation_checks = {
94109
"GL06", # Found unknown section
95110
"GL07", # Sections are in the wrong order.
96-
"GL08", # The object does not have a docstring
97111
"GL09", # Deprecation warning should precede extended summary
98112
"GL10", # reST directives {directives} must be followed by two colons
99113
"SS01", # No summary found
100114
"SS02", # Summary does not start with a capital letter
101-
# "SS03", # Summary does not end with a period
102115
"SS04", # Summary contains heading whitespaces
103-
# "SS05", # Summary must start with infinitive verb, not third person
104-
"RT02", # The first line of the Returns section should contain only the
105-
# type, unless multiple values are being returned"
116+
"RT02", # The first line of the Returns section should contain only the type
106117
}
107118

108-
# Favicon
109-
html_favicon = ansys_favicon
110-
111-
# static path
112-
html_static_path = ["_static"]
113-
114-
# Add any paths that contain templates here, relative to this directory.
115-
templates_path = ["_templates"]
119+
suppress_warnings = ["config.cache"]
116120

117121
# The suffix(es) of source filenames.
118122
source_suffix = ".rst"
@@ -121,39 +125,57 @@
121125
master_doc = "index"
122126

123127
# additional logos for the latex coverpage
128+
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
124129
latex_additional_files = [watermark, ansys_logo_white, ansys_logo_white_cropped]
125-
126-
# change the preamble of latex with customized title page
127-
# variables are the title of pdf, watermark
128130
latex_elements = {"preamble": latex.generate_preamble(html_title)}
129131

130132
# Not found page
131133
notfound_context = {
132134
"body": generate_404(),
133135
}
134-
135136
notfound_no_urls_prefix = True
136137

137138
# ONLY FOR ANSYS-SPHINX-THEME
139+
exclude_patterns = [
140+
"links.rst",
141+
"examples/sphinx-gallery/README.rst",
142+
"examples/gallery-examples/*.ipynb",
143+
]
144+
rst_epilog = ""
145+
with open("links.rst") as f:
146+
rst_epilog += f.read()
147+
148+
sphinx_gallery_conf = {
149+
# path to your examples scripts
150+
"examples_dirs": ["examples/sphinx-gallery"],
151+
# path where to save gallery generated examples
152+
"gallery_dirs": ["examples/gallery-examples"],
153+
# Pattern to search for example files
154+
"filename_pattern": r"sphinx_gallery\.py",
155+
# Remove the "Download all examples" button from the top level gallery
156+
"download_all_examples": False,
157+
# Modules for which function level galleries are created. In
158+
"image_scrapers": ("pyvista", "matplotlib"),
159+
"default_thumb_file": "source/_static/pyansys_light_square.png",
160+
}
161+
nbsphinx_execute = "always"
162+
nbsphinx_thumbnails = {
163+
"examples/nbsphinx/jupyter-notebook": "_static/pyansys_light_square.png",
164+
}
138165

139-
from pathlib import Path
140-
from typing import List
141-
142-
import requests
143-
144-
THIS_PATH = Path(__file__).parent.resolve()
145-
146-
EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve()
166+
# Ensure that offscreen rendering is used for docs generation
167+
# Preferred plotting style for documentation
168+
pyvista.BUILDING_GALLERY = True
147169

148-
linkcheck_ignore = []
170+
linkcheck_ignore = ["https://sphinxdocs.ansys.com/version/dev/*"]
149171
if switcher_version != "dev":
150172
linkcheck_ignore.append(
151173
f"https://github.com/ansys/ansys-sphinx-theme/releases/tag/v{__version__}"
152174
)
153175

154176

155177
def extract_example_links(
156-
repo_fullname: str, path_relative_to_root: str, exclude_files: List[str]
178+
repo_fullname: str, path_relative_to_root: str, exclude_files: List[str] = []
157179
) -> List[str]:
158180
"""
159181
Extract example links from a specific GitHub repository.
@@ -175,7 +197,8 @@ def extract_example_links(
175197
g = Github()
176198
repo = g.get_repo(repo_fullname)
177199
contents = repo.get_contents(path_relative_to_root)
178-
200+
if not isinstance(contents, list):
201+
contents = [contents]
179202
example_links = []
180203
for content in contents:
181204
if content.type == "dir":
@@ -225,4 +248,19 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
225248
)
226249
file_names = download_and_process_files(example_links)
227250

228-
jinja_contexts = {"examples": {"inputs_examples": file_names}}
251+
admonitions_links = extract_example_links(
252+
"pydata/pydata-sphinx-theme",
253+
"docs/examples/kitchen-sink/admonitions.rst",
254+
)
255+
256+
admonitions_links = download_and_process_files(admonitions_links)
257+
todo_include_todos = True # admonition todo needs this to be True
258+
259+
jinja_contexts = {
260+
"examples": {"inputs_examples": file_names},
261+
"admonitions": {"inputs_admonitions": admonitions_links},
262+
"install_guide": {
263+
"version": f"v{version}" if not version.endswith("dev0") else "main",
264+
},
265+
"pdf_guide": {"version": get_version_match(__version__)}, # noqa: E501
266+
}

0 commit comments

Comments
 (0)