Skip to content

Commit 847a8e9

Browse files
Revathyvenugopal162pyansys-ci-botRobPasMue
committed
fix: autoapi extension (#472)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 6719ff7 commit 847a8e9

File tree

11 files changed

+25
-25
lines changed

11 files changed

+25
-25
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@ doc/source/_autosummary/
161161
doc/source/examples/gallery-examples/
162162
doc/source/sg_execution_times.rst
163163
# rendering of sphinx autoapi examples
164-
doc/source/examples/examples/
164+
doc/source/examples/api/

doc/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPHINXOPTS =
66
SPHINXBUILD = sphinx-build
77
SOURCEDIR = source
88
BUILDDIR = _build
9-
AUTOAPI_OUTDIR = source/examples/examples
9+
AUTOAPI_OUTDIR = source/examples/api
1010
GALLERY_EXAMPLES = gallery-examples
1111

1212
# Put it first so that "make" without argument is like "make help".

doc/changelog.d/472.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: autoapi extension

doc/make.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if "%SPHINXBUILD%" == "" (
1010
set SOURCEDIR=source
1111
set BUILDDIR=_build
1212
set GALLERY_EXAMPLES=%SOURCEDIR%\examples\gallery-examples
13-
set AUTOAPI_OUTDIR=%SOURCEDIR%\examples\examples\
13+
set AUTOAPI_OUTDIR=%SOURCEDIR%\examples\api\
1414

1515
if "%1" == "" goto help
1616
if "%1" == "pdf" goto pdf

doc/source/conf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"ansys_sphinx_theme_autoapi": {
7070
"project": project,
7171
"directory": "src/ansys_sphinx_theme/examples",
72-
"output": "examples/",
72+
"output": "examples/api",
7373
"own_page_level": "function",
74-
"add_toctree_entry": False,
74+
"package_depth": 1,
7575
},
7676
"logo": "ansys",
7777
}
@@ -93,11 +93,9 @@
9393
"sphinx.ext.intersphinx",
9494
"sphinx.ext.todo",
9595
"sphinx_copybutton",
96-
"sphinx_design",
9796
"sphinx.ext.intersphinx",
9897
"sphinx.ext.todo",
9998
"sphinx_gallery.gen_gallery",
100-
"sphinx_jinja",
10199
"notfound.extension",
102100
]
103101

doc/source/examples/sphinx-autoapi.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ This example shows how the Ansys Sphinx Theme renders API documentation using th
77

88
.. toctree::
99
:titlesonly:
10-
:maxdepth: 5
10+
:maxdepth: 1
1111

12-
<span class="nf nf-md-package"></span> The examples package<examples/index.rst>
12+
api/index

doc/source/user-guide/autoapi.rst

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and set the ``ansys_sphinx_theme_autoapi`` theme options in the ``html_theme_opt
2727
- ``ignore``: The list of directories to ignore. By default, this is empty.
2828
- ``add_toctree_entry``: If set to ``True``, the autoapi extension adds the generated files to the TOC tree.
2929
By default, this is set to ``False``.
30+
- ``package_depth``: The depth of the package. By default, this is set to ``3``. This is the ``namespace`` depth of the package.
31+
For example, if the package is ``ansys``, the depth is ``1``. If the package is ``ansys.foo``, the depth is ``2``.
3032

3133
All these options can be set in the ``conf.py`` file of your Sphinx project.
3234

@@ -51,6 +53,7 @@ All these options can be set in the ``conf.py`` file of your Sphinx project.
5153
"class_content": "class",
5254
"ignore": [],
5355
"add_toctree_entry": False,
56+
"package_depth": 3,
5457
}
5558
}
5659

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030

3131
[project.optional-dependencies]
3232
autoapi = [
33-
"sphinx-autoapi==3.1.1",
33+
"sphinx-autoapi==3.2.1",
3434
"sphinx-design==0.6.1",
3535
"sphinx-jinja==2.0.2",
3636
]

src/ansys_sphinx_theme/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ def fix_edit_html_page_context(
211211
212212
Notes
213213
-----
214-
.. [1] Originally implemented by `Alex Kaszynski <https://github.com/akaszynski>`_ in
215-
`PyVista <https://github.com/pyvista/pyvista>`_,
214+
[1] Originally implemented by `Alex Kaszynski <https://github.com/akaszynski>`_ in
215+
`PyVista <https://github.com/pyvista/pyvista>`_ ,
216216
see https://github.com/pyvista/pyvista/pull/4113
217217
"""
218218

@@ -265,7 +265,7 @@ def fix_edit_link_page(link: str) -> str:
265265
logging.debug(f"An error occurred: {e}") # Log the exception as debug info
266266
return link
267267

268-
elif pagename in ["autoapi", "api"]:
268+
elif "api" in pagename:
269269
for obj_node in list(doctree.findall(addnodes.desc)):
270270
domain = obj_node.get("domain")
271271
if domain != "py":
@@ -275,7 +275,7 @@ def fix_edit_link_page(link: str) -> str:
275275
if not isinstance(signode, addnodes.desc_signature):
276276
continue
277277

278-
fullname = signode["module"]
278+
fullname = signode["fullname"]
279279
modname = fullname.replace(".", "/")
280280

281281
if github_source:

src/ansys_sphinx_theme/extension/autoapi.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Module for adding the autoapi extension with the theme."""
2-
31
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates.
42
# SPDX-License-Identifier: MIT
53
#
@@ -44,12 +42,6 @@ def add_autoapi_theme_option(app: Sphinx) -> None:
4442
if not autoapi:
4543
return
4644

47-
# HACK: The ``sphinx_jinja`` and ``sphinx_design`` should be added to the extensions.
48-
required_extensions = ["sphinx_jinja", "sphinx_design"]
49-
50-
for extension in required_extensions:
51-
if extension not in app.config["extensions"]:
52-
app.config["extensions"].append(extension)
5345
AUTOAPI_OPTIONS = [
5446
"members",
5547
"undoc-members",
@@ -68,6 +60,7 @@ def add_autoapi_theme_option(app: Sphinx) -> None:
6860
def prepare_jinja_env(jinja_env) -> None:
6961
"""Prepare the Jinja environment for the theme."""
7062
jinja_env.globals["project_name"] = autoapi_project_name
63+
jinja_env.globals["autoapi_depth"] = autoapi.get("package_depth", 3)
7164

7265
# Set the autoapi options
7366

@@ -104,8 +97,12 @@ def setup(app: Sphinx) -> Dict[str, Any]:
10497
Dict[str, Any]
10598
A dictionary containing the version and parallel read/write safety flags.
10699
"""
107-
# HACK: The ``autoapi.extension`` should add here to initialize the extension.
108-
app.setup_extension("autoapi.extension")
100+
# HACK: The ``autoapi.extension``, ``sphinx_design``, and ``sphinx_jinja`` extensions should be
101+
# added to the Sphinx
102+
required_extensions = ["sphinx_design", "sphinx_jinja", "autoapi.extension"]
103+
for extension in required_extensions:
104+
if extension not in app.config["extensions"]:
105+
app.setup_extension(extension)
109106
app.connect("builder-inited", add_autoapi_theme_option, priority=400)
110107
return {
111108
"version": __version__,

src/ansys_sphinx_theme/theme/ansys_sphinx_theme/_templates/autoapi/index.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ to interact with them programmatically.
99
:maxdepth: 3
1010

1111
{% for page in pages %}
12-
{% if (page.top_level_object or page.name.split('.') | length == 3) and page.display %}
12+
{% set length = autoapi_depth | int %}
13+
{% if (page.top_level_object or page.name.split('.') | length == length) and page.display %}
1314
<span class="nf nf-md-package"></span> {{ page.name }}<{{ page.include_path }}>
1415
{% endif %}
1516
{% endfor %}

0 commit comments

Comments
 (0)