Skip to content

Commit fbfae7c

Browse files
PipKatakaszynskiMaxJPRey
authored
doc/enhance doc practices info (#42)
* doc/enhance doc practices info * doc/enhance doc practices info further * doc/enhance doc practices info further * Apply suggestions from code review Co-authored-by: Maxime Rey <[email protected]> Co-authored-by: Alex Kaszynski <[email protected]> Co-authored-by: Maxime Rey <[email protected]>
1 parent e5279db commit fbfae7c

File tree

4 files changed

+202
-49
lines changed

4 files changed

+202
-49
lines changed

doc/source/documentation_style/docstrings.rst

Lines changed: 152 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,180 @@ Docstring Standards
44
###################
55
When writing docstrings for PyAnsys libraries, use the `numpydoc`_
66
documentation 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

3289
Parameters
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+
49142
Returns
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

59176
Example Docstrings
60177
------------------
61178
Methods 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:
79196
Validation
80197
----------
81198
Enable 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

90207
The ``"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

96213
Additional Information
97214
----------------------
98215
Additional examples and notes can be found at `numpydoc`_. Reference
99216
this 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/

doc/source/documentation_style/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The documentation for a PyAnsys library should contain:
2626
:ref:`docstrings`.
2727
* Full gallery of examples. See `PyMAPDL Examples
2828
<https://mapdldocs.pyansys.com/examples/index.html>`_
29-
* User guide for the library.
29+
* Developer's guide for the library.
3030
* Link to this developer's guide.
3131

3232
.. toctree::

doc/source/guidelines/doc_practices.rst

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@
22

33
Documentation Practices
44
=======================
5-
The generation of documentation uses `Sphinx <https://www.sphinx-doc.org/en/master/>`__
6-
and an Ansys-branded theme. Documentation is built from docstrings, reStructuredText
7-
(RST) files, and Python (PY) example files.
5+
PyAnsys documentation must not only be written but also maintained. If you are new
6+
to writing developer documentation, see the `Google Developer Documentation Style
7+
Guide <https://developers.google.com/style/articles>`_. It provides editorial guidelines
8+
for writing clear and consistent developer documentation, allowing this guide to supply
9+
guidance specific to PyAnsys library documentation.
10+
11+
When writing developer documentation, the relationship between code and documenation is
12+
key. To keep documentation up to date with rapdily evolving code:
13+
14+
- Minimize the content footprint
15+
- Write `timeless documentation <https://developers.google.com/style/timeless-documentation>`_
16+
- Support contributions from both inside and outside of the development team
17+
- Perform periodic reviews
18+
19+
The generation of PyAnsys documentation uses `Sphinx <https://www.sphinx-doc.org/en/master/>`__
20+
and an Ansys-branded theme (pyansys-sphinx-theme) to assemble content comes from docstrings,
21+
reStructuredText (RST) files, and Python (PY) example files.
822

923
Docstrings
1024
----------
@@ -28,7 +42,10 @@ style docstrings, refers you to the `Google Python Style Guide <https://google.g
2842

2943
Regardless of the extension that you choose for generating documentation, we
3044
recommend the use of numpy-style docstrings so that there is consistency
31-
across PyAnsys libraries. For more information, see :ref:`api_documentation`.
45+
across PyAnsys libraries. For more information, see:
46+
47+
- :ref:`docstrings`
48+
- :ref:`api_documentation`
3249

3350
RST Files
3451
---------
@@ -57,16 +74,29 @@ index file referenced for each section must be named ``index.rst``. If you open
5774
in ``doc\source\overview``, you can see that it describes how the PyAnsys project provides
5875
Python libraries that expose Ansys technologies to the Python ecosystem.
5976

60-
After you build documenatation locally as described in :ref:`doc_building`, the first-level
77+
After you build documentation locally as described in :ref:`doc_building`, the first-level
6178
heading in the ``index.rst`` file for each docuemntation section is shown as clickable link
62-
in the header of the documentation's generated HTML output.
63-
64-
You can nest RST files. Plenty of examples of nested RST files are available in the PyAnsys
65-
libraries on GitHub. Because you need to be familiar with the content in the *PyAnsys Developer's
66-
Guide*, paging through this doc and exploring its repository will help you better
67-
understand how RST files are used. For more information on defining documentation
68-
structure, see the `Sphinx Getting Started <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_
69-
documentation.
79+
in the header of the documentation's generated HTML output. For more information on defining
80+
a documentation structure, see the `Sphinx Getting Started <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_
81+
guide.
82+
83+
Within RST files, heading titles are followed by a line having a string of characters that is
84+
the same length as the heading title. If the length of the characters
85+
under the heading title do not match the length of the heading title, Sphinx will generate a warning.
86+
87+
For consistency within PyAnsys libraries, the use of these special characters is recommended for
88+
headings but are not enforced:
89+
90+
- For first-level headings, use ====.
91+
- For second-level headings, use ---.
92+
- For third-level headings, use ~~~.
93+
94+
For comprehensive syntax information, see the `reStrucutredText Markup Specification
95+
<https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html>`_.
96+
97+
Because you need to be familiar with the content in the *PyAnsys Developer's Guide*, page through
98+
its HTML pages and then explore the RST files in its repository. This will help you to understand
99+
the syntax and see how RST files are nested to create this guide.
70100

71101
Examples
72102
--------

doc/source/overview/index.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ These libraries play a vital role in:
1818
- Workflow orchestration
1919
- Data manipulation and export
2020

21-
The libraries also include plugins and interfaces to the vast python
21+
The libraries also include plugins and interfaces to the vast Python
2222
ecosystem. Examples include:
2323

2424
- Arrays using `NumPy <https://numpy.org/>`_
@@ -28,10 +28,13 @@ ecosystem. Examples include:
2828
- Advanced scientific computing using `SciPy <https://www.scipy.org/>`_
2929
- Machine learning using `TensorFlow <https://www.tensorflow.org/>`_
3030

31+
.. note::
32+
If you are new to GitHub, we suggest that you visit `The ReadMe Project <https://github.com/readme>`_.
33+
It is a dedicated platform for highlighting the best from the open source software community.
34+
Monthly newletters provide feature articles, developer stories, guides, and podcasts.
3135

3236
Project Organization
3337
~~~~~~~~~~~~~~~~~~~~
34-
3538
The PyAnsys project is hosted on GitHub at `PyAnsys
3639
<https://github.com/pyansys>`_. It contains several repositories with
3740
Python libraries that interface with Ansys products or services.
@@ -48,7 +51,7 @@ If you want to create, develop, or contribute to a PyAnsys library,
4851
visit these links:
4952

5053
* `PyAnsys Project Developer's Guide <https://github.com/pyansys/about>`_
51-
* `PyAnsys Documentation Theme <https://github.com/pyansys/pyansys-sphinx-theme>`_
54+
* `PyAnsys Sphinx Theme Documentation <https://github.com/pyansys/pyansys-sphinx-theme>`_
5255
* `gRPC Hello-world Example <https://github.com/pyansys/pyansys-helloworld>`_
5356
* `Material Example Data <https://github.com/pyansys/example-data>`_
5457

0 commit comments

Comments
 (0)