##// END OF EJS Templates
strip indentation from imported docstrings
Corey McCandless -
Show More
@@ -32,6 +32,7 b' import inspect'
32 import linecache
32 import linecache
33 import sys
33 import sys
34 import warnings
34 import warnings
35 import re
35
36
36 from IPython import get_ipython
37 from IPython import get_ipython
37 from IPython.utils import PyColorize
38 from IPython.utils import PyColorize
@@ -40,6 +41,9 b' from IPython.core.excolors import exception_colors'
40 from IPython.testing.skipdoctest import skip_doctest
41 from IPython.testing.skipdoctest import skip_doctest
41
42
42
43
44 RGX_EXTRA_INDENT = re.compile('(?<=\n)\s+')
45
46
43 prompt = 'ipdb> '
47 prompt = 'ipdb> '
44
48
45 #We have to check this directly from sys.argv, config struct not yet available
49 #We have to check this directly from sys.argv, config struct not yet available
@@ -175,6 +179,10 b' class Tracer(object):'
175 self.debugger.set_trace(sys._getframe().f_back)
179 self.debugger.set_trace(sys._getframe().f_back)
176
180
177
181
182 def strip_indentation(multiline_string):
183 return RGX_EXTRA_INDENT.sub('', multiline_string)
184
185
178 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
186 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
179 """Make new_fn have old_fn's doc string. This is particularly useful
187 """Make new_fn have old_fn's doc string. This is particularly useful
180 for the ``do_...`` commands that hook into the help system.
188 for the ``do_...`` commands that hook into the help system.
@@ -183,7 +191,7 b' def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):'
183 def wrapper(*args, **kw):
191 def wrapper(*args, **kw):
184 return new_fn(*args, **kw)
192 return new_fn(*args, **kw)
185 if old_fn.__doc__:
193 if old_fn.__doc__:
186 wrapper.__doc__ = old_fn.__doc__ + additional_text
194 wrapper.__doc__ = strip_indentation(old_fn.__doc__) + additional_text
187 return wrapper
195 return wrapper
188
196
189
197
General Comments 0
You need to be logged in to leave comments. Login now