(cls, output_dir, class_path, base_path=None, children_paths=None)
| 7 | |
| 8 | |
| 9 | def document_class(cls, output_dir, class_path, base_path=None, children_paths=None): |
| 10 | with open(os.path.join(output_dir, "%s.rst" % class_path), "w") as doc: |
| 11 | class_name = class_path.split(".")[-1] |
| 12 | doc.write("%s\n" % class_name) |
| 13 | doc.write("=" * len(class_name)) |
| 14 | doc.write("\n\n") |
| 15 | doc.write(".. autoclass:: %s\n" % class_path) |
| 16 | doc.write(" :members:\n") |
| 17 | doc.write(" :undoc-members:\n") |
| 18 | doc.write(" :inherited-members:\n") |
| 19 | if base_path: |
| 20 | doc.write("\n **Inherits from:** :class:`%s`\n" % base_path) |
| 21 | if children_paths: |
| 22 | doc.write("\n **Extended by:**\n\n") |
| 23 | for path in children_paths: |
| 24 | doc.write(" - :class:`%s`\n" % path) |
| 25 | |
| 26 | def _list_members(category, predicate): |
| 27 | names = [ |
| 28 | name |
| 29 | for name, _ in inspect.getmembers(cls, predicate=predicate) |
| 30 | if not name.startswith("_") |
| 31 | ] |
| 32 | if names: |
| 33 | doc.write("\n **%s:**\n\n" % category) |
| 34 | for name in names: |
| 35 | doc.write(" - :obj:`~%s.%s`\n" % (class_path, name)) |
| 36 | |
| 37 | _list_members("Attributes", lambda member: isinstance(member, property)) |
| 38 | _list_members("Methods", lambda member: inspect.isroutine(member)) |
| 39 | |
| 40 | |
| 41 | def document_function(output_dir, function_path): |
no test coverage detected