/
styles.py
106 lines (74 loc) · 2.25 KB
/
styles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Example showing supported docstring styles in defopt.
You need to enable the `sphinx.ext.napoleon` extension
to generate documentation for this module.
Code usage::
>>> sphinx(2, farewell='goodbye!')
Command line usage::
$ python styles.py sphinx 2 --farewell goodbye!
"""
import defopt
def sphinx(integer, *, farewell=None):
"""
Example function with a Sphinx-style docstring.
Squares a given integer.
.. This is a comment; it won't show up anywhere but here.
Below is a literal block which will be displayed with a
4-space indent in the help string and as a code block
in the documentation.
::
$ python styles.py sphinx 2 --farewell goodbye!
4
goodbye!
:param int integer: Number to square
:keyword str farewell: Parting message
"""
print(integer ** 2)
if farewell is not None:
print(farewell)
def google(integer, *, farewell=None):
"""
Example function with a Google-style docstring.
Squares a given integer.
.. This is a comment; it won't show up anywhere but here.
Below is a literal block which will be displayed with a
4-space indent in the help string and as a code block
in the documentation.
::
$ python styles.py google 2 --farewell goodbye!
4
goodbye!
Args:
integer(int): Number to square
Keyword Arguments:
farewell(str): Parting message
"""
print(integer ** 2)
if farewell is not None:
print(farewell)
def numpy(integer, *, farewell=None):
"""
Example function with a Numpy-style docstring.
Squares a given integer.
.. This is a comment; it won't show up anywhere but here.
Below is a literal block which will be displayed with a
4-space indent in the help string and as a code block
in the documentation.
::
$ python styles.py numpy 2 --farewell goodbye!
4
goodbye!
Parameters
----------
integer : int
Number to square
Keyword Arguments
-----------------
farewell : str
Parting message
"""
print(integer ** 2)
if farewell is not None:
print(farewell)
if __name__ == '__main__':
defopt.run([sphinx, google, numpy])