##// END OF EJS Templates
Simplify heading structure, and only document __init__ when present.
Thomas Kluyver -
Show More
@@ -22,6 +22,12 b' import ast'
22 import os
22 import os
23 import re
23 import re
24
24
25 class Obj(object):
26 '''Namespace to hold arbitrary information.'''
27 def __init__(self, **kwargs):
28 for k, v in kwargs.items():
29 setattr(self, k, v)
30
25 # Functions and classes
31 # Functions and classes
26 class ApiDocWriter(object):
32 class ApiDocWriter(object):
27 ''' Class for automatic detection and parsing of API docs
33 ''' Class for automatic detection and parsing of API docs
@@ -173,7 +179,10 b' class ApiDocWriter(object):'
173 elif isinstance(node, ast.ClassDef) and \
179 elif isinstance(node, ast.ClassDef) and \
174 not node.name.startswith('_') and \
180 not node.name.startswith('_') and \
175 not has_undoc_decorator(node):
181 not has_undoc_decorator(node):
176 classes.append(node.name)
182 cls = Obj(name=node.name)
183 cls.has_init = any(isinstance(n, ast.FunctionDef) and \
184 n.name=='__init__' for n in node.body)
185 classes.append(cls)
177
186
178 return functions, classes
187 return functions, classes
179
188
@@ -202,17 +211,13 b' class ApiDocWriter(object):'
202
211
203 ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
212 ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
204
213
205 chap_title = uri_short
214 # Set the chapter title to read 'Module:' for all modules except for the
206 ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
207 + '\n\n')
208
209 # Set the chapter title to read 'module' for all modules except for the
210 # main packages
215 # main packages
211 if '.' in uri:
216 if '.' in uri:
212 title = 'Module: :mod:`' + uri_short + '`'
217 chap_title = 'Module: :mod:`' + uri_short + '`'
213 else:
218 else:
214 title = ':mod:`' + uri_short + '`'
219 chap_title = ':mod:`' + uri_short + '`'
215 ad += title + '\n' + self.rst_section_levels[2] * len(title)
220 ad += chap_title + '\n' + self.rst_section_levels[1] * len(chap_title)
216
221
217 if len(classes):
222 if len(classes):
218 ad += '\nInheritance diagram for ``%s``:\n\n' % uri
223 ad += '\nInheritance diagram for ``%s``:\n\n' % uri
@@ -230,15 +235,15 b' class ApiDocWriter(object):'
230 ad += '\n' + 'Class' + '\n' + \
235 ad += '\n' + 'Class' + '\n' + \
231 self.rst_section_levels[2] * 5 + '\n'
236 self.rst_section_levels[2] * 5 + '\n'
232 for c in classes:
237 for c in classes:
233 ad += '\n:class:`' + c + '`\n' \
238 ad += '\n:class:`' + c.name + '`\n' \
234 + self.rst_section_levels[multi_class + 2 ] * \
239 + self.rst_section_levels[multi_class + 2 ] * \
235 (len(c)+9) + '\n\n'
240 (len(c.name)+9) + '\n\n'
236 ad += '\n.. autoclass:: ' + c + '\n'
241 ad += '\n.. autoclass:: ' + c.name + '\n'
237 # must NOT exclude from index to keep cross-refs working
242 # must NOT exclude from index to keep cross-refs working
238 ad += ' :members:\n' \
243 ad += ' :members:\n' \
239 ' :show-inheritance:\n' \
244 ' :show-inheritance:\n'
240 '\n' \
245 if c.has_init:
241 ' .. automethod:: __init__\n'
246 ad += '\n .. automethod:: __init__\n'
242 if multi_fx:
247 if multi_fx:
243 ad += '\n' + 'Functions' + '\n' + \
248 ad += '\n' + 'Functions' + '\n' + \
244 self.rst_section_levels[2] * 9 + '\n\n'
249 self.rst_section_levels[2] * 9 + '\n\n'
General Comments 0
You need to be logged in to leave comments. Login now