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