Skip to content

Commit 478fa63

Browse files
tkknightwjbenfold
andauthored
Comment rendering (#4689)
* used numpy docstrings to fix docs rendering * comment rejig * apply numpydoc strings * corrected notes * updated docstring guidance. * added explicit mention of numpydoc strings * added whatsnew * added whatsnew PR ref * Update lib/iris/fileformats/nimrod_load_rules.py Co-authored-by: Will Benfold <[email protected]> * Update docs/src/whatsnew/latest.rst Co-authored-by: Will Benfold <[email protected]> * review actions. Co-authored-by: Will Benfold <[email protected]>
1 parent 732800d commit 478fa63

File tree

6 files changed

+262
-307
lines changed

6 files changed

+262
-307
lines changed

docs/src/developers_guide/contributing_pull_request_checklist.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ is merged. Before submitting a pull request please consider this list.
3434
should be generated too, see :ref:`cirrus_test_env`.
3535

3636
#. **Check the source documentation been updated to explain all new or changed
37-
features**. See :ref:`docstrings`.
37+
features**. Note, we now use numpydoc strings. Any touched code should
38+
be updated to use the docstrings formatting. See :ref:`docstrings`.
3839

3940
#. **Include code examples inside the docstrings where appropriate**. See
4041
:ref:`contributing.documentation.testing`.

docs/src/developers_guide/documenting/docstrings.rst

Lines changed: 11 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ 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
99
the code and may be read directly in the source or via the :ref:`Iris`.
1010

11-
This document has been influenced by the following PEP's,
12-
13-
* Attribute Docstrings :pep:`224`
14-
* Docstring Conventions :pep:`257`
11+
.. note::
12+
As of April 2022 we are looking to adopt `numpydoc`_ strings as standard.
13+
We aim to complete the adoption over time as we do changes to the codebase.
14+
For examples of use see `numpydoc`_ and `sphinxcontrib-napoleon`_
1515

1616
For consistency always use:
1717

@@ -20,91 +20,14 @@ For consistency always use:
2020
docstrings.
2121
* ``u"""Unicode triple-quoted string"""`` for Unicode docstrings
2222

23-
All docstrings should be written in reST (reStructuredText) markup. See the
24-
:ref:`reST_quick_start` for more detail.
25-
26-
There are two forms of docstrings: **single-line** and **multi-line**
27-
docstrings.
28-
29-
30-
Single-Line Docstrings
31-
======================
32-
33-
The single line docstring of an object must state the **purpose** of that
34-
object, known as the **purpose section**. This terse overview must be on one
35-
line and ideally no longer than 80 characters.
36-
37-
38-
Multi-Line Docstrings
39-
=====================
40-
41-
Multi-line docstrings must consist of at least a purpose section akin to the
42-
single-line docstring, followed by a blank line and then any other content, as
43-
described below. The entire docstring should be indented to the same level as
44-
the quotes at the docstring's first line.
45-
46-
47-
Description
48-
-----------
49-
50-
The multi-line docstring *description section* should expand on what was
51-
stated in the one line *purpose section*. The description section should try
52-
not to document *argument* and *keyword argument* details. Such information
53-
should be documented in the following *arguments and keywords section*.
54-
55-
56-
Sample Multi-Line Docstring
57-
---------------------------
58-
59-
Here is a simple example of a standard docstring:
60-
61-
.. literalinclude:: docstrings_sample_routine.py
62-
63-
This would be rendered as:
64-
65-
.. currentmodule:: documenting.docstrings_sample_routine
66-
67-
.. automodule:: documenting.docstrings_sample_routine
68-
:members:
69-
:undoc-members:
70-
71-
Additionally, a summary can be extracted automatically, which would result in:
72-
73-
.. autosummary::
74-
75-
documenting.docstrings_sample_routine.sample_routine
76-
77-
78-
Documenting Classes
79-
===================
80-
81-
The class constructor should be documented in the docstring for its
82-
``__init__`` or ``__new__`` method. Methods should be documented by their own
83-
docstring, not in the class header itself.
84-
85-
If a class subclasses another class and its behaviour is mostly inherited from
86-
that class, its docstring should mention this and summarise the differences.
87-
Use the verb "override" to indicate that a subclass method replaces a
88-
superclass method and does not call the superclass method; use the verb
89-
"extend" to indicate that a subclass method calls the superclass method
90-
(in addition to its own behaviour).
91-
92-
93-
Attribute and Property Docstrings
94-
---------------------------------
95-
96-
Here is a simple example of a class containing an attribute docstring and a
97-
property docstring:
98-
99-
.. literalinclude:: docstrings_attribute.py
23+
All docstrings can use reST (reStructuredText) markup to augment the
24+
rendered formatting. See the :ref:`reST_quick_start` for more detail.
10025

101-
This would be rendered as:
26+
For more information including examples pleasee see:
10227

103-
.. currentmodule:: documenting.docstrings_attribute
28+
* `numpydoc`_
29+
* `sphinxcontrib-napoleon`_
10430

105-
.. automodule:: documenting.docstrings_attribute
106-
:members:
107-
:undoc-members:
10831

109-
.. note:: The purpose section of the property docstring **must** state whether
110-
the property is read-only.
32+
.. _numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html#style-guide
33+
.. _sphinxcontrib-napoleon: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html

docs/src/whatsnew/latest.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ This document explains the changes made to Iris for this release
114114
#. `@tkknight`_ adopted the `PyData Sphinx Theme`_ for the documentation.
115115
(:discussion:`4344`, :pull:`4661`)
116116

117+
#. `@tkknight`_ updated our developers guidance to show our intent to adopt
118+
numpydoc strings and fixed some API documentation rendering.
119+
See :ref:`docstrings`. (:issue:`4657`, :pull:`4689`)
120+
117121

118122
💼 Internal
119123
===========

lib/iris/fileformats/dot.py

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,18 @@ def _dot_path():
5959

6060

6161
def save(cube, target):
62-
"""Save a dot representation of the cube.
63-
64-
Args:
62+
"""
63+
Save a dot representation of the cube.
6564
66-
* cube - A :class:`iris.cube.Cube`.
67-
* target - A filename or open file handle.
65+
Args
66+
----
67+
cube: :class:`iris.cube.Cube`.
68+
target
69+
A filename or open file handle.
6870
69-
See also :func:`iris.io.save`.
71+
See Also
72+
--------
73+
:func:`iris.io.save`.
7074
7175
"""
7276
if isinstance(target, str):
@@ -87,19 +91,23 @@ def save(cube, target):
8791

8892
def save_png(source, target, launch=False):
8993
"""
90-
Produces a "dot" instance diagram by calling dot and optionally launching the resulting image.
91-
92-
Args:
94+
Produce a "dot" instance diagram by calling dot and optionally launching
95+
the resulting image.
9396
94-
* source - A :class:`iris.cube.Cube`, or dot filename.
95-
* target - A filename or open file handle.
96-
If passing a file handle, take care to open it for binary output.
97+
Args
98+
----
99+
source: :class:`iris.cube.Cube`, or dot filename.
100+
target
101+
A filename or open file handle.
102+
If passing a file handle, take care to open it for binary output.
97103
98-
Kwargs:
104+
**kwargs
105+
* launch
106+
Display the image. Default is False.
99107
100-
* launch - Display the image. Default is False.
101-
102-
See also :func:`iris.io.save`.
108+
See Also
109+
--------
110+
:func:`iris.io.save`.
103111
104112
"""
105113
# From cube or dot file?
@@ -152,11 +160,13 @@ def save_png(source, target, launch=False):
152160

153161

154162
def cube_text(cube):
155-
"""Return a DOT text representation a `iris.cube.Cube`.
156-
157-
Args:
163+
"""
164+
Return a DOT text representation a `iris.cube.Cube`.
158165
159-
* cube - The cube for which to create DOT text.
166+
Args
167+
----
168+
cube
169+
The cube for which to create DOT text.
160170
161171
"""
162172
# We use r'' type string constructor as when we type \n in a string without the r'' constructor
@@ -283,13 +293,14 @@ def cube_text(cube):
283293

284294
def _coord_text(label, coord):
285295
"""
286-
Returns a string containing the dot representation for a single coordinate node.
287-
288-
Args:
296+
Return a string containing the dot representation for a single coordinate
297+
node.
289298
290-
* label
299+
Args
300+
----
301+
label
291302
The dot ID of the coordinate node.
292-
* coord
303+
coord
293304
The coordinate to convert.
294305
295306
"""
@@ -315,14 +326,16 @@ def _coord_text(label, coord):
315326

316327
def _coord_system_text(cs, uid):
317328
"""
318-
Returns a string containing the dot representation for a single coordinate system node.
329+
Return a string containing the dot representation for a single coordinate
330+
system node.
319331
320-
Args:
321-
322-
* cs
332+
Args
333+
----
334+
cs
323335
The coordinate system to convert.
324-
* uid
325-
The uid allows/distinguishes non-identical CoordSystems of the same type.
336+
uid
337+
The uid allows/distinguishes non-identical CoordSystems of the same
338+
type.
326339
327340
"""
328341
attrs = []
@@ -341,15 +354,15 @@ def _coord_system_text(cs, uid):
341354

342355
def _dot_node(indent, id, name, attributes):
343356
"""
344-
Returns a string containing the dot representation for a single node.
345-
346-
Args:
357+
Return a string containing the dot representation for a single node.
347358
348-
* id
359+
Args
360+
----
361+
id
349362
The ID of the node.
350-
* name
363+
name
351364
The visual name of the node.
352-
* attributes
365+
attributes
353366
An iterable of (name, value) attribute pairs.
354367
355368
"""

0 commit comments

Comments
 (0)