16
16
.. [1] https://github.com/numpy/numpydoc
17
17
18
18
"""
19
- from __future__ import division , absolute_import , print_function
20
-
21
19
from copy import deepcopy
22
- import sys
23
20
import re
24
21
import pydoc
25
22
import inspect
26
- try :
27
- from collections .abc import Callable
28
- except ImportError :
29
- from collections import Callable
23
+ from collections .abc import Callable
30
24
import hashlib
31
25
import itertools
32
26
35
29
from sphinx .addnodes import pending_xref , desc_content
36
30
from sphinx .util import logging
37
31
38
- if sphinx .__version__ < '1.0.1 ' :
39
- raise RuntimeError ("Sphinx 1.0.1 or newer is required" )
32
+ if sphinx .__version__ < '1.6.5 ' :
33
+ raise RuntimeError ("Sphinx 1.6.5 or newer is required" )
40
34
41
35
from .docscrape_sphinx import get_doc_object
42
36
from .xref import DEFAULT_LINKS
43
37
from . import __version__
44
38
45
39
logger = logging .getLogger (__name__ )
46
40
47
- if sys .version_info [0 ] >= 3 :
48
- sixu = lambda s : s
49
- else :
50
- sixu = lambda s : unicode (s , 'unicode_escape' )
51
-
52
-
53
41
HASH_LEN = 12
54
42
55
43
def rename_references (app , what , name , obj , options , lines ):
@@ -58,7 +46,7 @@ def rename_references(app, what, name, obj, options, lines):
58
46
references = set ()
59
47
for line in lines :
60
48
line = line .strip ()
61
- m = re .match (sixu ( r'^\.\. +\[(%s)\]' ) %
49
+ m = re .match (r'^\.\. +\[(%s)\]' %
62
50
app .config .numpydoc_citation_re ,
63
51
line , re .I )
64
52
if m :
@@ -73,10 +61,10 @@ def rename_references(app, what, name, obj, options, lines):
73
61
for r in references :
74
62
new_r = prefix + '-' + r
75
63
for i , line in enumerate (lines ):
76
- lines [i ] = lines [i ].replace (sixu ( '[%s]_' ) % r ,
77
- sixu ( '[%s]_' ) % new_r )
78
- lines [i ] = lines [i ].replace (sixu ( '.. [%s]' ) % r ,
79
- sixu ( '.. [%s]' ) % new_r )
64
+ lines [i ] = lines [i ].replace ('[%s]_' % r ,
65
+ '[%s]_' % new_r )
66
+ lines [i ] = lines [i ].replace ('.. [%s]' % r ,
67
+ '.. [%s]' % new_r )
80
68
81
69
82
70
def _is_cite_in_numpydoc_docstring (citation_node ):
@@ -166,33 +154,29 @@ def mangle_docstrings(app, what, name, obj, options, lines):
166
154
}
167
155
168
156
cfg .update (options or {})
169
- u_NL = sixu ( '\n ' )
157
+ u_NL = '\n '
170
158
if what == 'module' :
171
159
# Strip top title
172
160
pattern = '^\\ s*[#*=]{4,}\\ n[a-z0-9 -]+\\ n[#*=]{4,}\\ s*'
173
- title_re = re .compile (sixu ( pattern ) , re .I | re .S )
174
- lines [:] = title_re .sub (sixu ( '' ) , u_NL .join (lines )).split (u_NL )
161
+ title_re = re .compile (pattern , re .I | re .S )
162
+ lines [:] = title_re .sub ('' , u_NL .join (lines )).split (u_NL )
175
163
else :
176
164
try :
177
165
doc = get_doc_object (obj , what , u_NL .join (lines ), config = cfg ,
178
166
builder = app .builder )
179
- if sys .version_info [0 ] >= 3 :
180
- doc = str (doc )
181
- else :
182
- doc = unicode (doc )
183
- lines [:] = doc .split (u_NL )
167
+ lines [:] = str (doc ).split (u_NL )
184
168
except :
185
169
logger .error ('[numpydoc] While processing docstring for %r' , name )
186
170
raise
187
171
188
172
if (app .config .numpydoc_edit_link and hasattr (obj , '__name__' ) and
189
173
obj .__name__ ):
190
174
if hasattr (obj , '__module__' ):
191
- v = dict (full_name = sixu ( "%s.%s" ) % (obj .__module__ , obj .__name__ ))
175
+ v = dict (full_name = "%s.%s" % (obj .__module__ , obj .__name__ ))
192
176
else :
193
177
v = dict (full_name = obj .__name__ )
194
- lines += [sixu ( '' ), sixu ( '.. htmlonly::' ), sixu ( '' ) ]
195
- lines += [sixu ( ' %s' ) % x for x in
178
+ lines += ['' , '.. htmlonly::' , '' ]
179
+ lines += [' %s' % x for x in
196
180
(app .config .numpydoc_edit_link % v ).split ("\n " )]
197
181
198
182
# call function to replace reference numbers so that there are no
@@ -218,8 +202,8 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
218
202
doc = get_doc_object (obj , config = {'show_class_members' : False })
219
203
sig = doc ['Signature' ] or getattr (obj , '__text_signature__' , None )
220
204
if sig :
221
- sig = re .sub (sixu ( "^[^(]*" ), sixu ( "" ) , sig )
222
- return sig , sixu ( '' )
205
+ sig = re .sub ("^[^(]*" , "" , sig )
206
+ return sig , ''
223
207
224
208
225
209
def setup (app , get_doc_object_ = get_doc_object ):
0 commit comments