10
10
- Convert Parameters etc. sections to field lists.
11
11
- Convert See Also section to a See also entry.
12
12
- Renumber references.
13
- - Extract the signature from the docstring, if it can't be determined otherwise.
13
+ - Extract the signature from the docstring, if it can't be determined
14
+ otherwise.
14
15
15
16
.. [1] https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
16
17
39
40
def mangle_docstrings (app , what , name , obj , options , lines ,
40
41
reference_offset = [0 ]):
41
42
42
- cfg = dict (
43
- use_plots = app .config .numpydoc_use_plots ,
44
- show_class_members = app .config .numpydoc_show_class_members ,
45
- show_inherited_class_members = app .config .numpydoc_show_inherited_class_members ,
46
- class_members_toctree = app .config .numpydoc_class_members_toctree ,
47
- )
43
+ cfg = {'use_plots' : app .config .numpydoc_use_plots ,
44
+ 'show_class_members' : app .config .numpydoc_show_class_members ,
45
+ 'show_inherited_class_members' :
46
+ app .config .numpydoc_show_inherited_class_members ,
47
+ 'class_members_toctree' : app .config .numpydoc_class_members_toctree }
48
48
49
+ u_NL = sixu ('\n ' )
49
50
if what == 'module' :
50
51
# Strip top title
51
- title_re = re . compile ( sixu ( '^\\ s*[#*=]{4,}\\ n[a-z0-9 -]+\\ n[#*=]{4,}\\ s*' ),
52
- re .I | re .S )
53
- lines [:] = title_re .sub (sixu ('' ), sixu ( " \n " ) .join (lines )).split (sixu ( " \n " ) )
52
+ pattern = '^\\ s*[#*=]{4,}\\ n[a-z0-9 -]+\\ n[#*=]{4,}\\ s*'
53
+ title_re = re . compile ( sixu ( pattern ), re .I | re .S )
54
+ lines [:] = title_re .sub (sixu ('' ), u_NL .join (lines )).split (u_NL )
54
55
else :
55
- doc = get_doc_object (obj , what , sixu ( " \n " ) .join (lines ), config = cfg )
56
+ doc = get_doc_object (obj , what , u_NL .join (lines ), config = cfg )
56
57
if sys .version_info [0 ] >= 3 :
57
58
doc = str (doc )
58
59
else :
59
60
doc = unicode (doc )
60
- lines [:] = doc .split (sixu ( " \n " ) )
61
+ lines [:] = doc .split (u_NL )
61
62
62
- if app .config .numpydoc_edit_link and hasattr (obj , '__name__' ) and \
63
- obj .__name__ :
63
+ if ( app .config .numpydoc_edit_link and hasattr (obj , '__name__' ) and
64
+ obj .__name__ ) :
64
65
if hasattr (obj , '__module__' ):
65
66
v = dict (full_name = sixu ("%s.%s" ) % (obj .__module__ , obj .__name__ ))
66
67
else :
@@ -93,24 +94,30 @@ def mangle_docstrings(app, what, name, obj, options, lines,
93
94
94
95
reference_offset [0 ] += len (references )
95
96
97
+
96
98
def mangle_signature (app , what , name , obj , options , sig , retann ):
97
99
# Do not try to inspect classes that don't define `__init__`
98
100
if (inspect .isclass (obj ) and
99
101
(not hasattr (obj , '__init__' ) or
100
- 'initializes x; see ' in pydoc .getdoc (obj .__init__ ))):
102
+ 'initializes x; see ' in pydoc .getdoc (obj .__init__ ))):
101
103
return '' , ''
102
104
103
- if not (isinstance (obj , collections .Callable ) or hasattr (obj , '__argspec_is_invalid_' )): return
104
- if not hasattr (obj , '__doc__' ): return
105
+ if not (isinstance (obj , collections .Callable ) or
106
+ hasattr (obj , '__argspec_is_invalid_' )):
107
+ return
108
+
109
+ if not hasattr (obj , '__doc__' ):
110
+ return
105
111
106
112
doc = SphinxDocString (pydoc .getdoc (obj ))
107
113
if doc ['Signature' ]:
108
114
sig = re .sub (sixu ("^[^(]*" ), sixu ("" ), doc ['Signature' ])
109
115
return sig , sixu ('' )
110
116
117
+
111
118
def setup (app , get_doc_object_ = get_doc_object ):
112
119
if not hasattr (app , 'add_config_value' ):
113
- return # probably called by nose, better bail out
120
+ return # probably called by nose, better bail out
114
121
115
122
global get_doc_object
116
123
get_doc_object = get_doc_object_
@@ -127,14 +134,15 @@ def setup(app, get_doc_object_=get_doc_object):
127
134
app .add_domain (NumpyPythonDomain )
128
135
app .add_domain (NumpyCDomain )
129
136
130
- #------------------------------------------------------------------------------
137
+ # ------------------------------------------------------------------------------
131
138
# Docstring-mangling domains
132
- #------------------------------------------------------------------------------
139
+ # ------------------------------------------------------------------------------
133
140
134
141
from docutils .statemachine import ViewList
135
142
from sphinx .domains .c import CDomain
136
143
from sphinx .domains .python import PythonDomain
137
144
145
+
138
146
class ManglingDomainBase (object ):
139
147
directive_mangling_map = {}
140
148
@@ -147,6 +155,7 @@ def wrap_mangling_directives(self):
147
155
self .directives [name ] = wrap_mangling_directive (
148
156
self .directives [name ], objtype )
149
157
158
+
150
159
class NumpyPythonDomain (ManglingDomainBase , PythonDomain ):
151
160
name = 'np'
152
161
directive_mangling_map = {
@@ -160,6 +169,7 @@ class NumpyPythonDomain(ManglingDomainBase, PythonDomain):
160
169
}
161
170
indices = []
162
171
172
+
163
173
class NumpyCDomain (ManglingDomainBase , CDomain ):
164
174
name = 'np-c'
165
175
directive_mangling_map = {
@@ -170,6 +180,7 @@ class NumpyCDomain(ManglingDomainBase, CDomain):
170
180
'var' : 'object' ,
171
181
}
172
182
183
+
173
184
def wrap_mangling_directive (base_directive , objtype ):
174
185
class directive (base_directive ):
175
186
def run (self ):
0 commit comments