Skip to content

Commit 3afcce7

Browse files
committed
Reformat docstrings.rst file
1 parent 228452d commit 3afcce7

File tree

2 files changed

+95
-51
lines changed

2 files changed

+95
-51
lines changed

doc/source/doc-style/docstrings.rst

Lines changed: 93 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
NumPy Docstrings
2-
================
1+
Numpydoc docstrings
2+
###################
33

44
When writing docstrings for PyAnsys libraries, use the `numpydoc`_
55
style, regardless as to whether you are using this Sphinx extension or the
@@ -40,10 +40,11 @@ classes, methods, and variables. For example::
4040

4141

4242
Required Docstring Sections
43-
---------------------------
43+
===========================
44+
4445
PyAnsys library docstrings contain these `numpydoc`_ sections as a minimum:
4546

46-
* `Short description <https://numpydoc.readthedocs.io/en/latest/format.html#short-summary>`_
47+
* `Short Summary <https://numpydoc.readthedocs.io/en/latest/format.html#short-summary>`_
4748
* `Extended Summary <https://numpydoc.readthedocs.io/en/latest/format.html#extended-summary>`_ if applicable
4849
* `Parameters <https://numpydoc.readthedocs.io/en/latest/format.html#parameters>`_ if applicable
4950
* `Returns <https://numpydoc.readthedocs.io/en/latest/format.html#returns>`_ if applicable
@@ -52,11 +53,29 @@ PyAnsys library docstrings contain these `numpydoc`_ sections as a minimum:
5253
These sections should follow numpydoc style. To avoid inconsistencies between
5354
PyAnsys libraries, adhere to the additional style guidelines that follow.
5455

55-
Classes
56-
~~~~~~~
56+
57+
Short Summary
58+
-------------
59+
This is a single-line which goes right after the declaration of the function or
60+
class and provides a quick overview about the final goal of the code. The
61+
``short summary`` is mandatory. If not present, :ref:`Doc Style Tools` will
62+
raise an error.
63+
64+
The short summary can be declared on the same line as the opening quotes or on
65+
the next line. Both ways are accepted by `PEP 257
66+
<https://peps.python.org/pep-0257>`_ but you must be consistent across your
67+
project. In case you decide to declare the short summary on the same line,
68+
please refer to :ref:`Numpydoc Validation`, as ``"GL01"`` check needs to be
69+
disabled.
70+
71+
Depending in whether you are documenting a ``Class`` or a ``function``, you will
72+
need to apply different ``short-summary`` guidelines.
73+
74+
Short Summary for Classes
75+
~~~~~~~~~~~~~~~~~~~~~~~~~
5776
A class is a 'noun' representing a collection of methods. For consistency within PyAnsys libraries,
5877
always start the brief description for a class with a verb ending in 's', followed by an extended
59-
summary if applicable::
78+
summary in a new line if applicable::
6079

6180
class FieldAnalysis3D(Analysis):
6281
"""Manages 3D field analysis setup in HFSS, Maxwell 3D, and Q3D.
@@ -67,19 +86,20 @@ summary if applicable::
6786
...
6887
"""
6988

70-
7189
Ensure that there is a line break between the end of a class docstring and the subsequent methods.
7290

73-
Methods
74-
~~~~~~~
91+
Short Summary for Methods
92+
~~~~~~~~~~~~~~~~~~~~~~~~~
7593
A method is a 'verb' representing an action that can be performed. For consistency within PyAnsys
7694
libraries, always start the brief description for a method with a verb not ending in 's', followed
77-
by an extended summary if applicable::
95+
by an extended summary in a new line if applicable::
7896

7997
def export_mesh_stats(self, setup_name, variation_string="", mesh_path=None):
80-
"""Export mesh statistics to a file."""
98+
"""Export mesh statistics to a file.
99+
100+
...
101+
"""
81102
82-
83103
Methods with a leading underscore (_) are 'protected' methods, meaning that they are not rendered in the
84104
documentation unless an explicit request is made to add them using Sphinx directives. However, clearly
85105
written descriptions for private methods are still important.
@@ -91,11 +111,13 @@ add a docstring for the setter. A setter simply exposes both the GET and SET met
91111
just the GET method. Examples should be included to demonstrate usage.
92112

93113
Parameters
94-
~~~~~~~~~~
114+
----------
95115
Both classes and methods have parameters in their function signatures. All parameters in a function
96-
signature should appear in the 'Parameters' section for the class or method.
116+
signature should appear in the ``Parameters`` section for the class or method.
117+
118+
Here is an example of a ``Parameters`` section for a class in PyAEDT:
97119

98-
Here is an example of a 'Parameters' section for a class in PyAEDT::
120+
.. code-block:: rst
99121
100122
Parameters
101123
----------
@@ -144,41 +166,81 @@ parameter, the description specifies the default along with any information that
144166
be needed about the behavior that occurs when the default is used.
145167

146168
Returns
147-
~~~~~~~
148-
The 'Returns' section contains only the return data type and a brief description
149-
that concludes with a period::
169+
-------
170+
The ``Returns`` section contains only the return data type and a brief description
171+
that concludes with a period:
172+
173+
.. code-block:: rst
150174
151175
Returns
152176
-------
153-
dict
177+
dict
154178
Dictionary of components with their absolute paths.
155179
156180
157-
A class does not have a 'Returns' section. If a Boolean is returned, format the
158-
'Returns` section like this::
181+
A class does not have a ``Returns`` section. If a ``Boolean`` is returned, format the
182+
``Returns`` section like this:
183+
184+
.. code-block:: rst
159185
160186
Returns
161-
--------
162-
bool
187+
-------
188+
bool
163189
``True`` when successful, ``False`` when failed.
164190
191+
It is possible for the ``Returns`` section to look like the ``Parameters`` one
192+
if variable names are provided:
165193

166-
It is possible for more than one item to be returned::
194+
.. code-block:: rst
167195
168196
Returns
169-
--------
170-
type
197+
-------
198+
has_succeeded : bool
199+
``True`` when successful, ``False`` when failed.
200+
201+
It is possible for more than one item to be returned:
202+
203+
.. code-block:: rst
204+
205+
Returns
206+
-------
207+
type
171208
Ground object.
172-
str
209+
str
173210
Ground name.
174211
175-
176212
If a method does not have a decorator, the basic implementation of Python
177213
methods is used. In this case, while ``None`` is returned, you do not document it.
178214
Consequently, such a method does not have a 'Returns' section.
179215

216+
Examples
217+
--------
218+
219+
The ``Examples`` section provides a quick reference on how to use a method or
220+
function. This section needs to be compliant with the `doctest
221+
<https://docs.python.org/3/library/doctest.html>`_ format and is not supposed to
222+
be a replacement of your test suite but a complement to it. An an example,
223+
consider the following function:
224+
225+
.. code-block:: rst
226+
227+
Examples
228+
--------
229+
Create an instance of HFSS and connect to an existing HFSS
230+
design or create a new HFSS design if one does not exist.
231+
232+
>>> from pyaedt import Hfss
233+
>>> hfss = Hfss()
234+
pyaedt info: No project is defined...
235+
pyaedt info: Active design is set to...
236+
237+
238+
Notice that if the definition of the function gets updated, this
239+
section needs to be updated too.
240+
241+
180242
Example Docstrings
181-
------------------
243+
==================
182244
Methods and functions should generally be documented within the
183245
'Examples' section to make the usage of the method or function clear.
184246
Here is a sample function:
@@ -196,26 +258,8 @@ This directive renders the sample function as:
196258

197259
.. autofunction:: pyansys_sphinx_theme.sample_func.func
198260

199-
200-
Validation
201-
----------
202-
Enable validation of docstrings during the Sphinx build by adding the
203-
following line to the ``conf.py`` file::
204-
205-
numpydoc_validation_checks = {"GL08"}
206-
207-
This will issue the following warning for any object without a docstring::
208-
209-
"The object does not have a docstring"
210-
211-
The ``"GL08"`` code is required at minimum for PyAnsys libraries.
212-
Other codes may be enforced at a later date. For a full listing,
213-
see `Validation <https://numpydoc.readthedocs.io/en/latest/validation.html#validation>`_
214-
in the `numpydoc`_.
215-
216-
217261
Additional Information
218-
----------------------
262+
======================
219263
You can find additional information and examples at `numpydoc`_. Reference
220264
this documentation as the primary source regarding docstring styles for directives
221265
that are not covered here. For example, you use the ``note::`` directive to highlight

doc/source/doc-style/formatting-tools.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Formatting Tools
2-
================
1+
Doc Style Tools
2+
===============
33

44
There are plenty of tools for documentation style and coverage. This section
55
presents some of the most popular ones in the Python ecosystem. A minimum

0 commit comments

Comments
 (0)