MCPcopy Create free account
hub / github.com/bspaans/python-mingus / generate_function_wikidocs

Method generate_function_wikidocs

scripts/api_doc_generator.py:169–209  ·  view source on GitHub ↗
(self, func_string, func, is_class = False)

Source from the content-addressed store, hash-verified

167 pass
168
169 def generate_function_wikidocs(self, func_string, func, is_class = False):
170 directive = '----\n\n.. function' if not is_class else ' .. method'
171 res = '\n{0}:: {1}('.format(directive, func_string)
172 argspec = inspect.getargspec(func)
173 args = argspec[0]
174 defaults = argspec[3]
175 def_values = []
176
177 # Get the arguments
178 for n in range(0, len(args)):
179 try:
180 if defaults != None and len(defaults) >= len(args) - n:
181 res += '{0}={1}, '.format(args[n], defaults[n - (len(args) - len(defaults))])
182
183 def_values.append((args[n], defaults[n - (len(args) - len(defaults))]))
184 else:
185 res += '{0}, '.format(args[n])
186 except:
187 res += '{0}, '.format(args[n])
188 if res[-1] != '(':
189 res = res[:-2]
190 res += ')\n\n'
191
192 # Add docstring
193 if func.__doc__ != None:
194 # Remove indentation
195 doc = inspect.cleandoc(func.__doc__)
196 seen_code = False
197
198 # Add wiki syntax for code
199 l = []
200 for line in doc.splitlines():
201 if line.startswith('>>>') and not seen_code:
202 l.append('\n ' + line)
203 seen_code = True
204 else:
205 l.append(line)
206 doc = '\n '.join(l)
207
208 res += ' {0}\n\n'.format(doc)
209 return res
210
211 def reset(self):
212 self.functions = []

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected