Make autodoc documentation template string for a module Parameters ---------- uri : string python location of module - e.g 'sphinx.builder' Returns ------- S : string Contents of API doc
(self, uri)
| 238 | return self._parse_module(uri) |
| 239 | |
| 240 | def generate_api_doc(self, uri): |
| 241 | '''Make autodoc documentation template string for a module |
| 242 | |
| 243 | Parameters |
| 244 | ---------- |
| 245 | uri : string |
| 246 | python location of module - e.g 'sphinx.builder' |
| 247 | |
| 248 | Returns |
| 249 | ------- |
| 250 | S : string |
| 251 | Contents of API doc |
| 252 | ''' |
| 253 | # get the names of all classes and functions |
| 254 | functions, classes = self.find_funcs_classes(uri) |
| 255 | if not len(functions) and not len(classes): |
| 256 | #print ('WARNING: Empty -', uri) # dbg |
| 257 | return '' |
| 258 | |
| 259 | # Make a shorter version of the uri that omits the package name for |
| 260 | # titles |
| 261 | uri_short = re.sub(r'^%s\.' % self.package_name,'',uri) |
| 262 | |
| 263 | ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n' |
| 264 | |
| 265 | # Set the chapter title to read 'Module:' for all modules except for the |
| 266 | # main packages |
| 267 | if '.' in uri: |
| 268 | chap_title = 'Module: :mod:`' + uri_short + '`' |
| 269 | else: |
| 270 | chap_title = ':mod:`' + uri_short + '`' |
| 271 | ad += chap_title + '\n' + self.rst_section_levels[1] * len(chap_title) |
| 272 | |
| 273 | ad += '\n.. automodule:: ' + uri + '\n' |
| 274 | ad += '\n.. currentmodule:: ' + uri + '\n' |
| 275 | |
| 276 | if classes: |
| 277 | subhead = str(len(classes)) + (' Classes' if len(classes) > 1 else ' Class') |
| 278 | ad += '\n'+ subhead + '\n' + \ |
| 279 | self.rst_section_levels[2] * len(subhead) + '\n' |
| 280 | |
| 281 | for c in classes: |
| 282 | ad += '\n.. autoclass:: ' + c.name + '\n' |
| 283 | # must NOT exclude from index to keep cross-refs working |
| 284 | ad += ' :members:\n' \ |
| 285 | ' :show-inheritance:\n' |
| 286 | if c.has_init: |
| 287 | ad += '\n .. automethod:: __init__\n' |
| 288 | |
| 289 | if functions: |
| 290 | subhead = str(len(functions)) + (' Functions' if len(functions) > 1 else ' Function') |
| 291 | ad += '\n'+ subhead + '\n' + \ |
| 292 | self.rst_section_levels[2] * len(subhead) + '\n' |
| 293 | for f in functions: |
| 294 | # must NOT exclude from index to keep cross-refs working |
| 295 | ad += '\n.. autofunction:: ' + uri + '.' + f + '\n\n' |
| 296 | return ad |
| 297 |
no test coverage detected