|
4 | 4 | import os |
5 | 5 | import sphinx_compas_theme |
6 | 6 |
|
| 7 | +from sphinx.ext.napoleon.docstring import NumpyDocstring |
| 8 | + |
7 | 9 | extensions = [ |
8 | 10 | 'sphinx.ext.autodoc', |
9 | 11 | 'sphinx.ext.autosummary', |
|
46 | 48 | # autodoc options |
47 | 49 | autodoc_default_options = { |
48 | 50 | 'member-order': 'bysource', |
49 | | - 'special-members': '__init__', |
50 | 51 | 'exclude-members': '__weakref__', |
51 | 52 | 'undoc-members': True, |
52 | 53 | 'private-members': True, |
|
93 | 94 | napoleon_use_param = False |
94 | 95 | napoleon_use_rtype = False |
95 | 96 |
|
| 97 | +# Parse Attributes and Class Attributes on Class docs same as parameters. |
| 98 | +# first, we define new methods for any new sections and add them to the class |
| 99 | + |
| 100 | + |
| 101 | +def parse_keys_section(self, section): |
| 102 | + return self._format_fields('Keys', self._consume_fields()) |
| 103 | + |
| 104 | + |
| 105 | +NumpyDocstring._parse_keys_section = parse_keys_section |
| 106 | + |
| 107 | + |
| 108 | +def parse_attributes_section(self, section): |
| 109 | + return self._format_fields('Attributes', self._consume_fields()) |
| 110 | + |
| 111 | + |
| 112 | +NumpyDocstring._parse_attributes_section = parse_attributes_section |
| 113 | + |
| 114 | + |
| 115 | +def parse_class_attributes_section(self, section): |
| 116 | + return self._format_fields('Class Attributes', self._consume_fields()) |
| 117 | + |
| 118 | + |
| 119 | +NumpyDocstring._parse_class_attributes_section = parse_class_attributes_section |
| 120 | + |
| 121 | + |
| 122 | +# we now patch the parse method to guarantee that the the above methods are |
| 123 | +# assigned to the _section dict |
| 124 | +def patched_parse(self): |
| 125 | + self._sections['keys'] = self._parse_keys_section |
| 126 | + self._sections['class attributes'] = self._parse_class_attributes_section |
| 127 | + self._unpatched_parse() |
| 128 | + |
| 129 | + |
| 130 | +NumpyDocstring._unpatched_parse = NumpyDocstring._parse |
| 131 | +NumpyDocstring._parse = patched_parse |
0 commit comments