22
22
import datetime
23
23
from importlib .metadata import version as get_version
24
24
from inspect import getsource
25
- import ntpath
26
25
import os
27
26
from pathlib import Path
28
27
import re
32
31
from urllib .parse import quote
33
32
import warnings
34
33
34
+ from sphinx .util import logging
35
+ from sphinx .util .console import colorize
35
36
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" )
39
60
40
61
41
62
# -- Check for dev make options to build quicker
@@ -63,17 +84,20 @@ def autolog(message):
63
84
# rtd_version = "my_branch" # useful for testing
64
85
65
86
if on_rtd :
66
- autolog ("Build running on READTHEDOCS server" )
87
+ autolog ("Build running on READTHEDOCS server" , section = "ReadTheDocs" )
67
88
68
89
# 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
+ )
70
94
71
95
for item , value in os .environ .items ():
72
- autolog ("[READTHEDOCS] {} = {}" .format (item , value ))
96
+ autolog ("{} = {}" .format (item , value ), section = "ReadTheDocs" )
73
97
74
98
# -- Path setup --------------------------------------------------------------
75
99
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,
77
101
# add these directories to sys.path here. If the directory is relative to the
78
102
# documentation root, use os.path.abspath to make it absolute, like shown here.
79
103
@@ -101,8 +125,8 @@ def autolog(message):
101
125
# |version|, also used in various other places throughout the built documents.
102
126
version = get_version ("scitools-iris" )
103
127
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" )
106
130
107
131
# -- General configuration ---------------------------------------------------
108
132
@@ -148,14 +172,13 @@ def _dotv(version):
148
172
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
149
173
# ones.
150
174
extensions = [
175
+ "sphinx.ext.autodoc" ,
151
176
"sphinx.ext.todo" ,
152
177
"sphinx.ext.duration" ,
153
178
"sphinx.ext.coverage" ,
154
179
"sphinx.ext.viewcode" ,
155
- "sphinx.ext.autosummary" ,
156
180
"sphinx.ext.doctest" ,
157
181
"sphinx.ext.extlinks" ,
158
- "sphinx.ext.autodoc" ,
159
182
"sphinx.ext.intersphinx" ,
160
183
"sphinx_copybutton" ,
161
184
"sphinx.ext.napoleon" ,
@@ -166,10 +189,10 @@ def _dotv(version):
166
189
]
167
190
168
191
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" )
170
193
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" )
173
196
174
197
# -- Napoleon extension -------------------------------------------------------
175
198
# See https://sphinxcontrib-napoleon.readthedocs.io/en/latest/sphinxcontrib.napoleon.html
@@ -195,49 +218,57 @@ def _dotv(version):
195
218
196
219
# sphinx.ext.todo configuration -----------------------------------------------
197
220
# 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
200
222
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"
212
228
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
220
234
221
235
# -- apidoc extension ---------------------------------------------------------
222
236
# 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
- ]
233
237
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" ]
237
267
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" )
241
272
242
273
# Add any paths that contain templates here, relative to this directory.
243
274
templates_path = ["_templates" ]
@@ -307,7 +338,7 @@ def _dotv(version):
307
338
"footer_end" : ["custom_footer" ],
308
339
"navigation_depth" : 3 ,
309
340
"navigation_with_keys" : False ,
310
- "show_toc_level" : 2 ,
341
+ "show_toc_level" : 3 ,
311
342
"show_prev_next" : True ,
312
343
"navbar_align" : "content" ,
313
344
# removes the search box from the top bar
0 commit comments