Skip to content

Commit a90451a

Browse files
authored
Merge da570a8 into 5c18504
2 parents 5c18504 + da570a8 commit a90451a

Some content is hidden

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

49 files changed

+573
-528
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,11 @@ repos:
7676
- id: numpydoc-validation
7777
exclude: "^lib/iris/tests/|docs/gallery_code/"
7878
types: [file, python]
79+
80+
- repo: local
81+
hooks:
82+
- id: check-attribute-comment
83+
name: use triple quote docstring proceding attribute
84+
types: [python]
85+
entry: '#:'
86+
language: pygrep

benchmarks/benchmarks/generate_data/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
from iris._lazy_data import as_concrete_data
2727
from iris.fileformats import netcdf
2828

29-
#: Python executable used by :func:`run_function_elsewhere`, set via env
30-
#: variable of same name. Must be path of Python within an environment that
31-
#: includes Iris (including dependencies and test modules) and Mule.
3229
try:
3330
DATA_GEN_PYTHON = environ["DATA_GEN_PYTHON"]
31+
"""Python executable used by :func:`run_function_elsewhere`, set via env variable of same name.
32+
Must be path of Python within an environment that
33+
includes Iris (including dependencies and test modules) and Mule."""
34+
3435
_ = check_output([DATA_GEN_PYTHON, "-c", "a = True"])
3536
except KeyError:
3637
error = "Env variable DATA_GEN_PYTHON not defined."

docs/src/conf.py

Lines changed: 83 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import datetime
2323
from importlib.metadata import version as get_version
2424
from inspect import getsource
25-
import ntpath
2625
import os
2726
from pathlib import Path
2827
import re
@@ -32,10 +31,32 @@
3231
from urllib.parse import quote
3332
import warnings
3433

34+
from sphinx.util import logging
35+
from sphinx.util.console import colorize
3536

36-
# function to write useful output to stdout, prefixing the source.
37-
def autolog(message):
38-
print("[{}] {}".format(ntpath.basename(__file__), message))
37+
38+
def autolog(message: str, section: str | None = None, color: str | None = None) -> None:
39+
"""Log the diagnostics `message` with optional `section` prefix.
40+
41+
Parameters
42+
----------
43+
message : str
44+
The diagnostics message.
45+
section : str, optional
46+
The prefix text for the diagnostics message.
47+
color : str, optional
48+
The color of the `section` prefix text.
49+
50+
"""
51+
if color is None:
52+
color = "brown"
53+
54+
section = colorize(color, colorize("bold", f"[{section}] ")) if section else ""
55+
msg = f'{colorize(color, section)}{colorize("darkblue", f"{message}")}'
56+
logger.info(msg)
57+
58+
59+
logger = logging.getLogger("sphinx-iris")
3960

4061

4162
# -- Check for dev make options to build quicker
@@ -63,17 +84,20 @@ def autolog(message):
6384
# rtd_version = "my_branch" # useful for testing
6485

6586
if on_rtd:
66-
autolog("Build running on READTHEDOCS server")
87+
autolog("Build running on READTHEDOCS server", section="ReadTheDocs")
6788

6889
# list all the READTHEDOCS environment variables that may be of use
69-
autolog("Listing all environment variables on the READTHEDOCS server...")
90+
autolog(
91+
"Listing all environment variables on the READTHEDOCS server...",
92+
section="ReadTheDocs",
93+
)
7094

7195
for item, value in os.environ.items():
72-
autolog("[READTHEDOCS] {} = {}".format(item, value))
96+
autolog("{} = {}".format(item, value), section="ReadTheDocs")
7397

7498
# -- Path setup --------------------------------------------------------------
7599

76-
# If extensions (or modules to document with autodoc) are in another directory,
100+
# If extensions (or modules to document with api) are in another directory,
77101
# add these directories to sys.path here. If the directory is relative to the
78102
# documentation root, use os.path.abspath to make it absolute, like shown here.
79103

@@ -101,8 +125,8 @@ def autolog(message):
101125
# |version|, also used in various other places throughout the built documents.
102126
version = get_version("scitools-iris")
103127
release = version
104-
autolog(f"Iris Version = {version}")
105-
autolog(f"Iris Release = {release}")
128+
autolog(f"Iris Version = {version}", section="General", color="blue")
129+
autolog(f"Iris Release = {release}", section="General", color="blue")
106130

107131
# -- General configuration ---------------------------------------------------
108132

@@ -148,14 +172,13 @@ def _dotv(version):
148172
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
149173
# ones.
150174
extensions = [
175+
"sphinx.ext.autodoc",
151176
"sphinx.ext.todo",
152177
"sphinx.ext.duration",
153178
"sphinx.ext.coverage",
154179
"sphinx.ext.viewcode",
155-
"sphinx.ext.autosummary",
156180
"sphinx.ext.doctest",
157181
"sphinx.ext.extlinks",
158-
"sphinx.ext.autodoc",
159182
"sphinx.ext.intersphinx",
160183
"sphinx_copybutton",
161184
"sphinx.ext.napoleon",
@@ -166,10 +189,10 @@ def _dotv(version):
166189
]
167190

168191
if skip_api == "1":
169-
autolog("Skipping the API docs generation (SKIP_API=1)")
192+
autolog("Skipping the API docs generation (SKIP_API=1)", section="General")
170193
else:
171-
extensions.extend(["sphinxcontrib.apidoc"])
172-
extensions.extend(["api_rst_formatting"])
194+
# build will break if this is not one of the first extensions loaded.
195+
extensions.insert(0, "autoapi.extension")
173196

174197
# -- Napoleon extension -------------------------------------------------------
175198
# See https://sphinxcontrib-napoleon.readthedocs.io/en/latest/sphinxcontrib.napoleon.html
@@ -195,49 +218,57 @@ def _dotv(version):
195218

196219
# sphinx.ext.todo configuration -----------------------------------------------
197220
# See https://www.sphinx-doc.org/en/master/usage/extensions/todo.html
198-
todo_include_todos = False
199-
todo_emit_warnings = False
221+
todo_include_todos = True
200222

201-
# sphinx.ext.autodoc configuration --------------------------------------------
202-
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_default_options
203-
autodoc_default_options = {
204-
"members": True,
205-
"member-order": "alphabetical",
206-
"undoc-members": True,
207-
"private-members": False,
208-
"special-members": False,
209-
"inherited-members": True,
210-
"show-inheritance": True,
211-
}
223+
# -- autodoc options ---------------------------------------------------------
224+
# See https://sphinx-autoapi.readthedocs.io/en/latest/how_to.html#how-to-include-type-annotations-as-types-in-rendered-docstrings
225+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
226+
autodoc_typehints = "description"
227+
autodoc_typehints_description_target = "documented"
212228

213-
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_typehints
214-
autodoc_typehints = "none"
215-
autosummary_generate = True
216-
autosummary_imported_members = True
217-
autopackage_name = ["iris"]
218-
autoclass_content = "both"
219-
modindex_common_prefix = ["iris"]
229+
# -- autoapi extensions -------------------------------------------------------
230+
# See https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html
231+
# https://github.com/readthedocs/sphinx-autoapi
232+
todo_include_todos = False
233+
todo_emit_warnings = False
220234

221235
# -- apidoc extension ---------------------------------------------------------
222236
# See https://github.com/sphinx-contrib/apidoc
223-
source_code_root = (Path(__file__).parents[2]).absolute()
224-
module_dir = source_code_root / "lib"
225-
apidoc_module_dir = str(module_dir)
226-
apidoc_output_dir = str(Path(__file__).parent / "generated/api")
227-
apidoc_toc_file = False
228-
229-
apidoc_excluded_paths = [
230-
str(module_dir / "iris/tests"),
231-
str(module_dir / "iris/experimental/raster.*"), # gdal conflicts
232-
]
233237

234-
apidoc_module_first = True
235-
apidoc_separate_modules = True
236-
apidoc_extra_args = []
238+
if skip_api != "1":
239+
source_code_root = (Path(__file__).parents[2]).absolute()
240+
module_dir = source_code_root / "lib"
241+
242+
autoapi_dirs = [module_dir]
243+
autoapi_root = "generated/api"
244+
autoapi_ignore = [
245+
str(module_dir / "iris/tests/*"),
246+
str(module_dir / "iris/experimental/raster.*"), # gdal conflicts
247+
]
248+
autoapi_member_order = "alphabetical"
249+
autoapi_options = [
250+
"members",
251+
"inherited-members",
252+
"undoc-members",
253+
# 'private-members',
254+
# "special-members",
255+
"show-inheritance",
256+
# "show-inheritance-diagram",
257+
"show-module-summary",
258+
"imported-members",
259+
]
260+
261+
autoapi_python_class_content = "both"
262+
autoapi_keep_files = True
263+
autoapi_add_toctree_entry = False
264+
265+
# https://sphinx-autoapi.readthedocs.io/en/latest/reference/config.html#suppressing-warnings
266+
suppress_warnings = ["autoapi.python_import_resolution"]
237267

238-
autolog(f"[sphinx-apidoc] source_code_root = {source_code_root}")
239-
autolog(f"[sphinx-apidoc] apidoc_excluded_paths = {apidoc_excluded_paths}")
240-
autolog(f"[sphinx-apidoc] apidoc_output_dir = {apidoc_output_dir}")
268+
autolog(f"[autoapi] source_code_root = {source_code_root}", section="AutoAPI")
269+
autolog(f"[autoapi] autoapi_dirs = {autoapi_dirs}", section="AutoAPI")
270+
autolog(f"[autoapi] autoapi_ignore = {autoapi_ignore}", section="AutoAPI")
271+
autolog(f"[autoapi] autoapi_root = {autoapi_root}", section="AutoAPI")
241272

242273
# Add any paths that contain templates here, relative to this directory.
243274
templates_path = ["_templates"]
@@ -307,7 +338,7 @@ def _dotv(version):
307338
"footer_end": ["custom_footer"],
308339
"navigation_depth": 3,
309340
"navigation_with_keys": False,
310-
"show_toc_level": 2,
341+
"show_toc_level": 3,
311342
"show_prev_next": True,
312343
"navbar_align": "content",
313344
# removes the search box from the top bar

docs/src/developers_guide/contributing_documentation_full.rst

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

4444
make html-noplot
4545

46-
Another option is to skip the :doc:`../generated/api/iris` documentation creation. This can be
47-
useful as it reduces the time to build the documentation, however you may have
48-
some build warnings as there maybe references to the API documentation.
49-
This can be achieved via::
46+
Another option is to skip the :doc:`Iris API </generated/api/iris/index>` documentation
47+
creation. This can be useful as it reduces the time to build the documentation,
48+
however you may have some build warnings as there maybe references to the API
49+
documentation. 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 :doc:`../generated/api/iris`
55-
documentation completely. This can be achieved via::
54+
:ref:`contributing.documentation.gallery` and
55+
:doc:`Iris API </generated/api/iris/index>` documentation completely. This can
56+
be achieved via::
5657

5758
make html-quick
5859

docs/src/developers_guide/contributing_getting_involved.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ If you are new to using GitHub we recommend reading the
5959
:caption: Reference
6060
:hidden:
6161

62-
../generated/api/iris
62+
Iris API <../generated/api/iris/index>
6363
../whatsnew/index
6464
../copyright
6565
../voted_issues

docs/src/developers_guide/documenting/docstrings.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. include:: ../../common_links.inc
12
.. _docstrings:
23

34
==========
@@ -7,7 +8,7 @@ Docstrings
78
Every public object in the Iris package should have an appropriate docstring.
89
This is important as the docstrings are used by developers to understand
910
the code and may be read directly in the source or via the
10-
:doc:`../../generated/api/iris`.
11+
:doc:`Iris API </generated/api/iris/index>`.
1112

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

docs/src/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For more information see :ref:`why_iris`.
8282
Browse full Iris functionality by module.
8383

8484
+++
85-
.. button-ref:: generated/api/iris
85+
.. button-ref:: generated/api/iris/index
8686
:ref-type: doc
8787
:color: primary
8888
:outline:
@@ -200,7 +200,7 @@ The legacy support resources:
200200
:maxdepth: 1
201201
:hidden:
202202

203-
Iris API <generated/api/iris>
203+
Iris API <generated/api/iris/index>
204204

205205

206206
.. todolist::

docs/src/sphinxext/api_rst_formatting.py

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

lib/iris/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,14 @@ def context(self, **kwargs):
243243
self.__dict__.update(current_state)
244244

245245

246-
#: Object containing all the Iris run-time options.
247246
FUTURE = Future()
247+
"""Object containing all the Iris run-time options."""
248248

249-
250-
# Initialise the site configuration dictionary.
251-
#: Iris site configuration dictionary.
252249
site_configuration: dict[
253250
Literal["cf_profile", "cf_patch", "cf_patch_conventions"],
254251
Callable | Literal[False] | None,
255252
] = {}
253+
"""Initialise the site configuration dictionary."""
256254

257255
try:
258256
from iris.site_config import update as _update

0 commit comments

Comments
 (0)