Skip to content

Commit 6a3be27

Browse files
authored
Restructuring of Contribution Section (#1550)
* Added Docstrings * Added Examples * Added references * Added Typings * Added Adominations * Made some more changes for docs to work * Fixed spelling mistake
1 parent e95aaa8 commit 6a3be27

File tree

7 files changed

+615
-593
lines changed

7 files changed

+615
-593
lines changed

docs/source/contributing.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ Contributing can be confusing, so here are a few guides:
3030
:maxdepth: 2
3131

3232
contributing/development
33-
contributing/documentation
33+
contributing/docstrings
34+
contributing/references
35+
contributing/examples
36+
contributing/typings
37+
contributing/admonitions
3438
contributing/testing
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
==================
2+
Adding Admonitions
3+
==================
4+
5+
Adding Blocks for Tip, Note, Important etc. (Admonitions)
6+
---------------------------------------------------------
7+
8+
The following directives are called Admonitions. You
9+
can use them to point out additional or important
10+
information. Here are some examples:
11+
12+
See also
13+
~~~~~~~~
14+
15+
.. code-block:: rest
16+
17+
.. seealso::
18+
Some ideas at :mod:`~.tex_mobject`, :class:`~.Mobject`, :meth:`~.Mobject.add_updater`, :attr:`~.Mobject.depth`, :func:`~.make_config_parser`
19+
20+
.. seealso::
21+
Some ideas at :mod:`~.tex_mobject`, :class:`~.Mobject`, :meth:`~.Mobject.add_updater`, :attr:`~.Mobject.depth`, :func:`~.make_config_parser`
22+
23+
.. index:: reST directives; note
24+
25+
26+
27+
Note
28+
~~~~
29+
30+
.. code-block:: rest
31+
32+
.. note::
33+
A note
34+
35+
.. note::
36+
A note
37+
38+
Tip
39+
~~~
40+
41+
.. code-block:: rest
42+
43+
.. tip::
44+
A tip
45+
46+
.. tip::
47+
A tip
48+
49+
You may also use the admonition **hint**, but this is very similar
50+
and **tip** is more commonly used in the documentation.
51+
52+
Important
53+
~~~~~~~~~
54+
55+
.. code-block:: rest
56+
57+
.. important::
58+
Some important information which should be considered.
59+
60+
.. important::
61+
Some important information which should be considered.
62+
63+
Warning
64+
~~~~~~~
65+
66+
.. code-block:: rest
67+
68+
.. warning::
69+
Some text pointing out something that people should be warned about.
70+
71+
.. warning::
72+
Some text pointing out something that people should be warned about.
73+
74+
You may also use the admonitions **caution** or even **danger** if the
75+
severity of the warning must be stressed.
76+
77+
Attention
78+
~~~~~~~~~
79+
80+
.. code-block:: rest
81+
82+
.. attention::
83+
A attention
84+
85+
.. attention::
86+
A attention
87+
88+
You can find further information about Admonitions here: https://pradyunsg.me/furo/reference/admonitions/
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
=================
2+
Adding Docstrings
3+
=================
4+
5+
A docstring is a string literal that is used right after the definition
6+
of a module, function, class, or method. They are used to document our code.
7+
This page will give you a set of guidelines to write efficient and correct docstrings.
8+
9+
10+
Formatting the Docstrings
11+
-------------------------
12+
13+
Please begin the description of the class/function in the same line as
14+
the 3 quotes:
15+
16+
.. code:: py
17+
18+
def do_this():
19+
"""This is correct.
20+
(...)
21+
"""
22+
23+
24+
def dont_do_this():
25+
"""
26+
This is incorrect.
27+
(...)
28+
"""
29+
30+
NumPy Format
31+
------------
32+
The Manim Community uses numpy format for the documentation.
33+
34+
Use the numpy format for sections and formatting - see
35+
https://numpydoc.readthedocs.io/en/latest/format.html.
36+
37+
This includes:
38+
39+
1. The usage of ``Attributes`` to specify ALL ATTRIBUTES that a
40+
class can have and a brief (or long, if
41+
needed) description.
42+
43+
Also, ``__init__`` parameters should be specified as ``Parameters`` **on
44+
the class docstring**, *rather than under* ``__init__``. Note that this
45+
can be omitted if the parameters and the attributes are the same
46+
(i.e., dataclass) - priority should be given to the ``Attributes``
47+
section, in this case, which must **always be present**, unless the
48+
class specifies no attributes at all. (See more on Parameters in number
49+
2 of this list.)
50+
51+
Example:
52+
53+
.. code:: py
54+
55+
class MyClass:
56+
"""My cool class. Long or short (whatever is more appropriate) description here.
57+
58+
Parameters
59+
----------
60+
name
61+
The class's name.
62+
id
63+
The class's id.
64+
mobj
65+
The mobject linked to this instance. Defaults to `Mobject()` \
66+
(is set to that if `None` is specified).
67+
68+
Attributes
69+
----------
70+
name
71+
The user's name.
72+
id
73+
The user's id.
74+
singleton
75+
Something.
76+
mobj
77+
The mobject linked to this instance.
78+
"""
79+
80+
def __init__(name: str, id: int, singleton: MyClass, mobj: Mobject = None):
81+
...
82+
83+
2. The usage of ``Parameters`` on functions to specify how
84+
every parameter works and what it does. This should be excluded if
85+
the function has no parameters. Note that you **should not** specify
86+
the default value of the parameter on the type. On the documentation
87+
render, this is already specified on the function's signature. If you
88+
need to indicate a further consequence of value omission or simply
89+
want to specify it on the docs, make sure to **specify it in the
90+
parameter's DESCRIPTION**.
91+
92+
See an example on list item 4.
93+
94+
.. note::
95+
96+
When documenting varargs (args and kwargs), make sure to
97+
document them by listing the possible types of each value specified,
98+
like this:
99+
100+
::
101+
102+
Parameters
103+
----------
104+
args
105+
The args specified can be either an int or a float.
106+
kwargs
107+
The kwargs specified can only be a float.
108+
109+
Note that, if the kwargs expect specific values, those can be specified
110+
in a section such as ``Other Parameters``:
111+
112+
::
113+
114+
Other Parameters
115+
----------------
116+
kwarg_param_1
117+
Parameter documentation here
118+
(etc)
119+
120+
3. The usage of ``Returns`` to indicate what is the type of this
121+
function's return value and what exactly it returns (i.e., a brief -
122+
or long, if needed - description of what this function returns). Can
123+
be omitted if the function does not explicitly return (i.e., always
124+
returns ``None`` because ``return`` is never specified, and it is
125+
very clear why this function does not return at all). In all other
126+
cases, it should be specified.
127+
128+
See an example on list item 4.
129+
130+
4. The usage of ``Examples`` in order to specify an example of usage of
131+
a function **is highly encouraged** and, in general, should be
132+
specified for *every function* unless its usage is **extremely
133+
obvious**, which can be debatable. Even if it is, it's always a good
134+
idea to add an example in order to give a better orientation to the
135+
documentation user. Use the following format for Python code:
136+
137+
.. code:: rst
138+
139+
::
140+
141+
# python code here
142+
143+
.. note::
144+
Also, if this is a video- or animation-related change, please
145+
try to add an example GIF or video if possible for demonstration
146+
purposes.
147+
148+
Make sure to be as explicit as possible in your documentation. We all
149+
want the users to have an easier time using this library.
150+
151+
Example:
152+
153+
.. code:: py
154+
155+
def my_function(
156+
thing: int,
157+
other: np.ndarray,
158+
name: str,
159+
*,
160+
d: "SomeClassFromFarAway",
161+
test: Optional[int] = 45
162+
) -> "EpicClassInThisFile": # typings are optional for now
163+
"""My cool function. Builds and modifies an :class:`EpicClassInThisFile` instance with the given
164+
parameters.
165+
166+
Parameters
167+
----------
168+
thing
169+
Specifies the index of life.
170+
other
171+
Specifies something cool.
172+
name
173+
Specifies my name.
174+
d
175+
Sets thing D to this value.
176+
test
177+
Defines the number of times things should be tested. \
178+
Defaults to 45, because that is almost the meaning of life.
179+
180+
Returns
181+
-------
182+
:class:`EpicClassInThisFile`
183+
The generated EpicClass with the specified attributes and modifications.
184+
185+
Examples
186+
--------
187+
Normal usage::
188+
189+
my_function(5, np.array([1, 2, 3]), "Chelovek", d=SomeClassFromFarAway(cool=True), test=5)
190+
"""
191+
# code...
192+
pass

0 commit comments

Comments
 (0)