10 |
10 |
11 def generateGoogleDoc(functionInfo, editor): |
11 def generateGoogleDoc(functionInfo, editor): |
12 """ |
12 """ |
13 Function to generate the docstring line list iaw. Sphinx documentation |
13 Function to generate the docstring line list iaw. Sphinx documentation |
14 style. |
14 style. |
15 |
15 |
16 Note: Text is created with DESCRIPTION placeholders for descriptions and |
16 Note: Text is created with DESCRIPTION placeholders for descriptions and |
17 TYPE placeholders for type information |
17 TYPE placeholders for type information |
18 |
18 |
19 @param functionInfo object containing the function information to base |
19 @param functionInfo object containing the function information to base |
20 the docstring on |
20 the docstring on |
21 @type FunctionInfo |
21 @type FunctionInfo |
22 @param editor reference to the editor |
22 @param editor reference to the editor |
23 @type Editor |
23 @type Editor |
24 @return list of docstring lines |
24 @return list of docstring lines |
25 @rtype str |
25 @rtype str |
26 """ |
26 """ |
27 # __IGNORE_WARNING_D202__ |
27 # __IGNORE_WARNING_D202__ |
28 lines = [] |
28 lines = [] |
29 |
29 |
30 # function description |
30 # function description |
31 lines.append("") |
31 lines.append("") |
32 |
32 |
33 # remove 'self', 'this' or 'cls' from arguments list |
33 # remove 'self', 'this' or 'cls' from arguments list |
34 if ( |
34 if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in ( |
35 len(functionInfo.argumentsList) > 0 and |
35 "self", |
36 functionInfo.argumentsList[0][0] in ("self", "cls", "this") |
36 "cls", |
|
37 "this", |
37 ): |
38 ): |
38 del functionInfo.argumentsList[0] |
39 del functionInfo.argumentsList[0] |
39 |
40 |
40 # determine additional indentation string |
41 # determine additional indentation string |
41 indentWidth = editor.indentationWidth() |
42 indentWidth = editor.indentationWidth() |
42 if indentWidth == 0: |
43 if indentWidth == 0: |
43 indentWidth = editor.tabWidth() |
44 indentWidth = editor.tabWidth() |
44 indent = indentWidth * " " |
45 indent = indentWidth * " " |
45 |
46 |
46 # add the parameters section |
47 # add the parameters section |
47 if functionInfo.argumentsList: |
48 if functionInfo.argumentsList: |
48 lines.append("") |
49 lines.append("") |
49 lines.append("Args:") |
50 lines.append("Args:") |
50 for argName, argType, argValue in functionInfo.argumentsList: |
51 for argName, argType, argValue in functionInfo.argumentsList: |
61 argLine += "Optional; " |
62 argLine += "Optional; " |
62 argLine += "DESCRIPTION" |
63 argLine += "DESCRIPTION" |
63 if argValue: |
64 if argValue: |
64 argLine += " Defaults to {0}.".format(argValue) |
65 argLine += " Defaults to {0}.".format(argValue) |
65 lines.append(argLine) |
66 lines.append(argLine) |
66 |
67 |
67 # add return section |
68 # add return section |
68 lines.append("") |
69 lines.append("") |
69 if functionInfo.hasYield: |
70 if functionInfo.hasYield: |
70 lines.append("Yields:") |
71 lines.append("Yields:") |
71 else: |
72 else: |
72 lines.append("Returns:") |
73 lines.append("Returns:") |
73 if functionInfo.returnTypeAnnotated: |
74 if functionInfo.returnTypeAnnotated: |
74 lines.append("{0}{1}: DESCRIPTION".format( |
75 lines.append( |
75 indent, functionInfo.returnTypeAnnotated)) |
76 "{0}{1}: DESCRIPTION".format(indent, functionInfo.returnTypeAnnotated) |
|
77 ) |
76 elif functionInfo.returnValueInBody: |
78 elif functionInfo.returnValueInBody: |
77 lines.append("{0}TYPE: DESCRIPTION") |
79 lines.append("{0}TYPE: DESCRIPTION") |
78 else: |
80 else: |
79 lines.append("{0}None".format(indent)) |
81 lines.append("{0}None".format(indent)) |
80 |
82 |
81 # add an exceptions section, if function raises something |
83 # add an exceptions section, if function raises something |
82 if functionInfo.raiseList: |
84 if functionInfo.raiseList: |
83 lines.append("") |
85 lines.append("") |
84 lines.append("Raises:") |
86 lines.append("Raises:") |
85 for exc in sorted(functionInfo.raiseList): |
87 for exc in sorted(functionInfo.raiseList): |
86 lines.append("{0}{1}: DESCRIPTION".format(indent, exc)) |
88 lines.append("{0}{1}: DESCRIPTION".format(indent, exc)) |
87 |
89 |
88 return lines |
90 return lines |