Skip to content

Commit 41bf7a0

Browse files
tkknightpp-mo
andauthored
Adopt sphinx-apidoc and retire complex sphinxext (SciTools#5264)
* baseline. * updated whatsnew * updated conda yml and lock files * lockfile update * lockfiles updated * Update docs/src/whatsnew/latest.rst Co-authored-by: Patrick Peglar <[email protected]> --------- Co-authored-by: Patrick Peglar <[email protected]>
1 parent cb287ce commit 41bf7a0

File tree

15 files changed

+106
-462
lines changed

15 files changed

+106
-462
lines changed

docs/src/common_links.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
.. _SciTools: https://github.com/SciTools
3636
.. _scitools-iris: https://pypi.org/project/scitools-iris/
3737
.. _sphinx: https://www.sphinx-doc.org/en/master/
38+
.. _sphinx-apidoc: https://github.com/sphinx-contrib/apidoc
3839
.. _test-iris-imagehash: https://github.com/SciTools/test-iris-imagehash
3940
.. _using git: https://docs.github.com/en/github/using-git
4041
.. _requirements: https://github.com/SciTools/iris/tree/main/requirements

docs/src/conf.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _dotv(version):
143143
"""
144144

145145
# Add any Sphinx extension module names here, as strings. They can be
146-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
146+
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
147147
# ones.
148148
extensions = [
149149
"sphinx.ext.todo",
@@ -166,8 +166,8 @@ def _dotv(version):
166166
if skip_api == "1":
167167
autolog("Skipping the API docs generation (SKIP_API=1)")
168168
else:
169-
# better api documentation (custom)
170-
extensions.extend(["custom_data_autodoc", "generate_package_rst"])
169+
extensions.extend(["sphinxcontrib.apidoc"])
170+
extensions.extend(["api_rst_formatting"])
171171

172172
# -- Napoleon extension -------------------------------------------------------
173173
# See https://sphinxcontrib-napoleon.readthedocs.io/en/latest/sphinxcontrib.napoleon.html
@@ -198,13 +198,36 @@ def _dotv(version):
198198
# api generation configuration
199199
autodoc_member_order = "groupwise"
200200
autodoc_default_flags = ["show-inheritance"]
201+
202+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_typehints
201203
autodoc_typehints = "none"
202204
autosummary_generate = True
203205
autosummary_imported_members = True
204206
autopackage_name = ["iris"]
205-
autoclass_content = "init"
207+
autoclass_content = "both"
206208
modindex_common_prefix = ["iris"]
207209

210+
# -- apidoc extension ---------------------------------------------------------
211+
# See https://github.com/sphinx-contrib/apidoc
212+
source_code_root = (Path(__file__).parents[2]).absolute()
213+
module_dir = source_code_root / "lib"
214+
apidoc_module_dir = str(module_dir)
215+
apidoc_output_dir = str(Path(__file__).parent / "generated/api")
216+
apidoc_toc_file = False
217+
218+
apidoc_excluded_paths = [
219+
str(module_dir / "iris/tests"),
220+
str(module_dir / "iris/experimental/raster.*"), # gdal conflicts
221+
]
222+
223+
apidoc_module_first = True
224+
apidoc_separate_modules = True
225+
apidoc_extra_args = []
226+
227+
autolog(f"[sphinx-apidoc] source_code_root = {source_code_root}")
228+
autolog(f"[sphinx-apidoc] apidoc_excluded_paths = {apidoc_excluded_paths}")
229+
autolog(f"[sphinx-apidoc] apidoc_output_dir = {apidoc_output_dir}")
230+
208231
# Add any paths that contain templates here, relative to this directory.
209232
templates_path = ["_templates"]
210233

@@ -381,13 +404,8 @@ def _dotv(version):
381404
}
382405

383406
# -----------------------------------------------------------------------------
384-
# Remove matplotlib agg warnings from generated doc when using plt.show
385-
warnings.filterwarnings(
386-
"ignore",
387-
category=UserWarning,
388-
message="Matplotlib is currently using agg, which is a"
389-
" non-GUI backend, so cannot show the figure.",
390-
)
407+
# Remove warnings
408+
warnings.filterwarnings("ignore")
391409

392410
# -- numfig options (built-in) ------------------------------------------------
393411
# Enable numfig.

docs/src/developers_guide/contributing_documentation_full.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ achieved via::
4343

4444
make html-noplot
4545

46-
Another option is to skip the :ref:`iris` documentation creation. This can be
46+
Another option is to skip the :doc:`../generated/api/iris` documentation creation. This can be
4747
useful as it reduces the time to build the documentation, however you may have
4848
some build warnings as there maybe references to the API documentation.
4949
This can be achieved via::
5050

5151
make html-noapi
5252

5353
You can combine both the above and skip the
54-
:ref:`contributing.documentation.gallery` and :ref:`iris` documentation
55-
completely. This can be achieved via::
54+
:ref:`contributing.documentation.gallery` and :doc:`../generated/api/iris`
55+
documentation completely. This can be achieved via::
5656

5757
make html-quick
5858

docs/src/developers_guide/documenting/docstrings.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Docstrings
66

77
Every public object in the Iris package should have an appropriate docstring.
88
This is important as the docstrings are used by developers to understand
9-
the code and may be read directly in the source or via the :ref:`Iris`.
9+
the code and may be read directly in the source or via the
10+
:doc:`../../generated/api/iris`.
1011

1112
.. note::
1213
As of April 2022 we are looking to adopt `numpydoc`_ strings as standard.

docs/src/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ The legacy support resources:
191191
:maxdepth: 1
192192
:hidden:
193193

194-
generated/api/iris
194+
Iris API <generated/api/iris>
195195

196196

197197
.. toctree::
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright Iris contributors
2+
#
3+
# This file is part of Iris and is released under the LGPL license.
4+
# See COPYING and COPYING.LESSER in the root of the repository for full
5+
# licensing details.
6+
7+
# This script will process all .rst files that have been created by
8+
# sphinxcontrib.apidoc extension and perform minor changes, specifically:
9+
#
10+
# - Remove the suffix for "package" and " module".
11+
#
12+
13+
import ntpath
14+
from pathlib import Path
15+
16+
17+
def main_api_rst_formatting(app):
18+
src_dir = Path("generated/api")
19+
20+
print(f"[{ntpath.basename(__file__)}] Processing RST files", end="")
21+
22+
for file in src_dir.iterdir():
23+
print(f".", end="")
24+
25+
with open(file, "r") as f:
26+
lines = f.read()
27+
28+
lines = lines.replace(" package\n=", "\n")
29+
lines = lines.replace(" module\n=", "\n")
30+
31+
with open(file, "w") as f:
32+
f.write(lines)
33+
print("")
34+
35+
def setup(app):
36+
app.connect("builder-inited", main_api_rst_formatting)

docs/src/sphinxext/custom_data_autodoc.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)