@@ -4,63 +4,180 @@ Docstring Standards
44###################
55When writing docstrings for PyAnsys libraries, use the `numpydoc `_
66documentation style. To use `numpydoc `_, add the following to your
7- ``conf.py ``:
7+ ``conf.py `` file :
88
99.. code :: python
1010
1111 extensions = [' numpydoc' ,
1212 # other extensions
1313 ]
1414
15+ For consistency within PyAnsys libraries, always use ``""" `` to introduce and conclude a
16+ docstring, keeping the line length shorter than 70 characters. Ensure that there are
17+ no blank spaces at the end of a line because they will cause errors in build checks that you
18+ will then have to resolve.
1519
16- Minimum Requirements
17- --------------------
18- PyAnsys library docstrings contain at a minimum the following
19- `numpydoc `_ sections:
20+ A blank line signifies the start of a new paragraph. To create a bulleted or numbered list,
21+ ensure that there is a blank line before the first item and after the last item. Because you
22+ use the same markup in your docstrings as you do in RST files, see this `quick reference
23+ <https://docutils.sourceforge.io/docs/user/rst/quickref.html> `_.
24+
25+ Surround any text that you want to set apart as literal text in double back ticks to render
26+ it in a monospace gold font. Use double back ticks to surround the names of files, folders,
27+ classes, methods, and variables. For example::
28+
29+ """Initialize the ``Desktop`` class with the version of AEDT to use.``
30+
31+
32+ .. note ::
33+ The PyAnsys style uses two back ticks to surround the names of classes, methods, and
34+ variables, not the single back tick that is recommended by the `numpydoc `_ documentation
35+ style.
36+
37+
38+ Minimum Section Requirements
39+ ----------------------------
40+ PyAnsys library docstrings contain these `numpydoc `_ sections as a minimum:
2041
2142* `Short description <https://numpydoc.readthedocs.io/en/latest/format.html#short-summary >`_.
2243* `Extended Summary <https://numpydoc.readthedocs.io/en/latest/format.html#extended-summary >`_ if applicable
2344* `Parameters <https://numpydoc.readthedocs.io/en/latest/format.html#parameters >`_ if applicable
2445* `Returns <https://numpydoc.readthedocs.io/en/latest/format.html#returns >`_ if applicable
2546* `Examples <https://numpydoc.readthedocs.io/en/latest/format.html#examples >`_
2647
27- These sections should follow the numpydoc standards. To avoid
28- inconsistencies between PyAnsys libraries, adhere to the additional
29- standards that follow.
48+ These sections should follow numpydoc standards. To avoid inconsistencies between
49+ PyAnsys libraries, adhere to the additional standards that follow.
50+
51+ Classes
52+ ~~~~~~~
53+ A class is a "noun" representing a collection of methods. For consistency within PyAnsys libraries,
54+ always start the brief description for a class with a verb ending in "s", followed by an extended
55+ summary if applicable::
56+
57+ class FieldAnalysis3D(Analysis):
58+ """Manages 3D field analysis setup in HFSS, Maxwell 3D, and Q3D.
59+
60+ This class is automatically initialized by an application call from one of
61+ the 3D tools. For parameter definitions, see the application function.
62+
63+ ...
64+ """
65+
66+
67+ Ensure that there is a line break between the end of a class docstring and the subsequent methods.
68+
69+ Methods
70+ ~~~~~~~
71+ A method is a "verb" representing an action that can be performed. For consistency within PyAnsys
72+ libraries, always start the brief description for a method with a verb not ending in "s", followed
73+ by an extended summary if applicable::
74+
75+ def export_mesh_stats(self, setup_name, variation_string="", mesh_path=None):
76+ """Export mesh statistics to a file."
77+
3078
79+ Methods with a leading underscore (_) are 'protected' methods, meaning that they are not rendered in the
80+ documentation unless an explicit request is made to add them using Sphinx directives. However, clearing
81+ documenting private methods is still important.
82+
83+ If a method has the decorator ``@property ``, it is turned into a property, which is described as a
84+ 'noun' rather than a 'verb'. Because the resulting property cannot have parameters, you remove
85+ the 'Parameters' section for this method. If a setter follows the decorator ``@property ``, do not
86+ add a docstring for the setter. A setter simply exposes both the GET and SET methods rather
87+ just the GET method. Examples should be included to demonstrate usage.
3188
3289Parameters
3390~~~~~~~~~~
34- Always specify the type, and whenever necessary, provide the full class name::
91+ Both classes and methods have parameters in their function signatures. All parameters in a function
92+ signature should appear in the 'Parameters' section for the class or method.
93+
94+ Here is an example of a 'Parameters' section for a class in PyAEDT::
3595
3696 Parameters
3797 ----------
38- my_obj : :class:`ansys.<product>.<library>.FooClass`
39- Description of FooClass.
40- some_int : int
41- Some integer value.
42-
43- .. note ::
44- Parameter descriptions have punctuation. While the brief description itself
45- need not be a sentence, any text following it should a clear, complete
46- sentence.
47-
48-
98+ application : str
99+ 3D application that is to initialize the call.
100+ projectname : str, optional
101+ Name of the project to select or the full path to the project
102+ or AEDTZ archive to open. The default is ``None``, in which
103+ case an attempt is made to get an active project. If no
104+ projects are present, an empty project is created.
105+ designname : str, optional
106+ Name of the design to select. The default is ``None``, in
107+ which case an attempt is made to get an active design. If no
108+ designs are present, an empty design is created.
109+ solution_type : str, optional
110+ Solution type to apply to the design. The default is
111+ ``None``, in which case the default type is applied.
112+ setup_name : str, optional
113+ Name of the setup to use as the nominal. The default is
114+ ``None``, in which case the active setup is used or
115+ nothing is used.
116+ specified_version : str, optional
117+ Version of AEDT to use. The default is ``None``, in which case
118+ the active version or latest installed version is used.
119+ non_graphical : bool, optional
120+ Whether to run AEDT in the non-graphical mode. The default
121+ is ``False``, in which case AEDT is launched in the graphical mode.
122+ new_desktop_session : bool, optional
123+ Whether to launch an instance of AEDT in a new thread, even if
124+ another instance of the ``specified_version`` is active on the
125+ machine. The default is ``True``.
126+ close_on_exit : bool, optional
127+ Whether to release AEDT on exit. The default is ``False``.
128+ student_version : bool, optional
129+ Whether to enable the student version of AEDT. The default
130+ is ``False``.
131+
132+ The name of each parameter is followed by a space, a colon, a space, and then
133+ the data type. A parameter is optional if its keyword argument has a default shown
134+ in the function signature. For an optional parameter, the data type is followed by a
135+ comma and ``optional ``.
136+
137+ The brief description for a parameter is generally a sentence fragment. However,
138+ additional information is provided in clear, complete sentences. For an optional
139+ parameter, the description specifies the default along with any information that might
140+ be needed about the behavior that occurs when the default is used.
141+
49142Returns
50143~~~~~~~
51- The Returns section contains only the return type and (not the name and type)
52- and a brief description ::
144+ The ' Returns' section contains only the return data type and a brief description
145+ that concludes with a period ::
53146
54147 Returns
55148 -------
56- int
57- Description of some return value.
149+ dict
150+ Dictionary of components with their absolute paths.
151+
152+
153+ A class does not have a 'Returns' section. If a Boolean is returned, format the
154+ 'Returns` section like this::
155+
156+ Returns
157+ --------
158+ bool
159+ ``True`` when successful, ``False`` when failed.
160+
161+
162+ It is possible for more than one item to be returned::
163+
164+ Returns
165+ --------
166+ type
167+ Ground object.
168+ str
169+ Ground name.
170+
171+
172+ If a method does not have a decorator, the basic implementation of Python
173+ methods is used. In this case, ``None `` is returned but you do not document it.
174+ Consequently, such a method does not have a 'Returns' section.
58175
59176Example Docstrings
60177------------------
61178Methods and functions should generally be documented within the
62- `` Examples `` docstring section to make the usage of the method or
63- function clear. Here is a sample function:
179+ ' Examples' section to make the usage of the method or function clear.
180+ Here is a sample function:
64181
65182.. literalinclude :: sample_func.py
66183
@@ -79,25 +196,28 @@ This directive renders the sample function as:
79196Validation
80197----------
81198Enable validation of docstrings during the Sphinx build by adding the
82- following line to ``conf.py ``::
199+ following line to the ``conf.py `` file ::
83200
84201 numpydoc_validation_checks = {"GL08"}
85202
86- This will issue the following warning for any objects without a docstring::
203+ This will issue the following warning for any object without a docstring::
87204
88205 "The object does not have a docstring"
89206
90207The ``"GL08" `` code is required at minimum for PyAnsys libraries.
91- Other codes may be enforced at a later date. For a full listing, see
92- ` numpydoc Validation Check
93- <https://numpydoc.readthedocs.io/en/latest/validation.html#validation> `_ .
208+ Other codes may be enforced at a later date. For a full listing, in the ` numpydoc `_,
209+ see the ` Validation < https://numpydoc.readthedocs.io/en/latest/validation.html#validation >`_
210+ topic .
94211
95212
96213Additional Information
97214----------------------
98215Additional examples and notes can be found at `numpydoc `_. Reference
99216this documentation as the primary source of information regarding
100- docstring styles for directives not covered here.
217+ docstring styles for directives that are not covered here. For example,
218+ you would use the ``note:: `` directive to highlight important information
219+ and the ``warning:: `` directive to point out an action that might result
220+ in data loss.
101221
102222.. _numpydoc : https://numpydoc.readthedocs.io/en/latest/format.html
103223.. _googledoc : https://google.github.io/styleguide/
0 commit comments