Mon, 07 Nov 2022 17:19:58 +0100
Corrected/acknowledged some bad import style and removed some obsolete code.
7998 | 1 | # -*- coding: utf-8 -*- |
2 | ||
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
3 | # Copyright (c) 2021 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
7998 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing the docstring generator for the 'sphinxdoc' style. | |
8 | """ | |
9 | ||
10 | ||
11 | def generateGoogleDoc(functionInfo, editor): | |
12 | """ | |
13 | Function to generate the docstring line list iaw. Sphinx documentation | |
14 | style. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
15 | |
7998 | 16 | Note: Text is created with DESCRIPTION placeholders for descriptions and |
17 | TYPE placeholders for type information | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
18 | |
7998 | 19 | @param functionInfo object containing the function information to base |
20 | the docstring on | |
21 | @type FunctionInfo | |
22 | @param editor reference to the editor | |
23 | @type Editor | |
24 | @return list of docstring lines | |
25 | @rtype str | |
26 | """ | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
27 | # __IGNORE_WARNING_D202__ |
7998 | 28 | lines = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
29 | |
7998 | 30 | # function description |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
31 | lines.append("") |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
32 | |
7998 | 33 | # remove 'self', 'this' or 'cls' from arguments list |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
34 | if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | "self", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
36 | "cls", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | "this", |
7998 | 38 | ): |
39 | del functionInfo.argumentsList[0] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | |
7998 | 41 | # determine additional indentation string |
42 | indentWidth = editor.indentationWidth() | |
43 | if indentWidth == 0: | |
44 | indentWidth = editor.tabWidth() | |
45 | indent = indentWidth * " " | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | |
7998 | 47 | # add the parameters section |
48 | if functionInfo.argumentsList: | |
49 | lines.append("") | |
50 | lines.append("Args:") | |
51 | for argName, argType, argValue in functionInfo.argumentsList: | |
52 | argLine = "{0}{1} ".format(indent, argName) | |
53 | argLine += "(" | |
54 | if argType: | |
55 | argLine += "{0}".format(argType) | |
56 | else: | |
57 | argLine += "TYPE" | |
58 | argLine += "):" | |
59 | lines.append(argLine) | |
60 | argLine = "{0}".format(2 * indent) | |
61 | if argValue: | |
62 | argLine += "Optional; " | |
63 | argLine += "DESCRIPTION" | |
64 | if argValue: | |
65 | argLine += " Defaults to {0}.".format(argValue) | |
66 | lines.append(argLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
7998 | 68 | # add return section |
69 | lines.append("") | |
70 | if functionInfo.hasYield: | |
71 | lines.append("Yields:") | |
72 | else: | |
73 | lines.append("Returns:") | |
74 | if functionInfo.returnTypeAnnotated: | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
75 | lines.append( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | "{0}{1}: DESCRIPTION".format(indent, functionInfo.returnTypeAnnotated) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | ) |
7998 | 78 | elif functionInfo.returnValueInBody: |
79 | lines.append("{0}TYPE: DESCRIPTION") | |
80 | else: | |
81 | lines.append("{0}None".format(indent)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
82 | |
7998 | 83 | # add an exceptions section, if function raises something |
84 | if functionInfo.raiseList: | |
85 | lines.append("") | |
86 | lines.append("Raises:") | |
87 | for exc in sorted(functionInfo.raiseList): | |
88 | lines.append("{0}{1}: DESCRIPTION".format(indent, exc)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | |
7998 | 90 | return lines |