##// END OF EJS Templates
Merge branch 'str-format'
Thomas Kluyver -
r4158:25fa43fe merge
parent child Browse files
Show More
@@ -24,7 +24,6 b' import sys'
24 from pprint import pformat
24 from pprint import pformat
25
25
26 from IPython.core import ultratb
26 from IPython.core import ultratb
27 from IPython.external.Itpl import itpl
28 from IPython.utils.sysinfo import sys_info
27 from IPython.utils.sysinfo import sys_info
29
28
30 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
@@ -33,7 +32,7 b' from IPython.utils.sysinfo import sys_info'
33
32
34 # Template for the user message.
33 # Template for the user message.
35 _default_message_template = """\
34 _default_message_template = """\
36 Oops, $self.app_name crashed. We do our best to make it stable, but...
35 Oops, {app_name} crashed. We do our best to make it stable, but...
37
36
38 A crash report was automatically generated with the following information:
37 A crash report was automatically generated with the following information:
39 - A verbatim copy of the crash traceback.
38 - A verbatim copy of the crash traceback.
@@ -41,18 +40,18 b' A crash report was automatically generated with the following information:'
41 - Data on your current $self.app_name configuration.
40 - Data on your current $self.app_name configuration.
42
41
43 It was left in the file named:
42 It was left in the file named:
44 \t'$self.crash_report_fname'
43 \t'{crash_report_fname}'
45 If you can email this file to the developers, the information in it will help
44 If you can email this file to the developers, the information in it will help
46 them in understanding and correcting the problem.
45 them in understanding and correcting the problem.
47
46
48 You can mail it to: $self.contact_name at $self.contact_email
47 You can mail it to: $self.contact_name at {contact_email}
49 with the subject '$self.app_name Crash Report'.
48 with the subject '{app_name} Crash Report'.
50
49
51 If you want to do it now, the following command will work (under Unix):
50 If you want to do it now, the following command will work (under Unix):
52 mail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname
51 mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}
53
52
54 To ensure accurate tracking of this issue, please file a report about it at:
53 To ensure accurate tracking of this issue, please file a report about it at:
55 $self.bug_tracker
54 {bug_tracker}
56 """
55 """
57
56
58
57
@@ -66,6 +65,7 b' class CrashHandler(object):'
66 """
65 """
67
66
68 message_template = _default_message_template
67 message_template = _default_message_template
68 section_sep = '\n\n'+'*'*75+'\n\n'
69
69
70 def __init__(self, app, contact_name=None, contact_email=None,
70 def __init__(self, app, contact_name=None, contact_email=None,
71 bug_tracker=None, show_crash_traceback=True, call_pdb=False):
71 bug_tracker=None, show_crash_traceback=True, call_pdb=False):
@@ -96,16 +96,17 b' class CrashHandler(object):'
96 further customization of the crash handler's behavior. Please see the
96 further customization of the crash handler's behavior. Please see the
97 source for further details.
97 source for further details.
98 """
98 """
99 self.crash_report_fname = "Crash_report_%s.txt" % app.name
99 self.app = app
100 self.app = app
100 self.app_name = self.app.name
101 self.contact_name = contact_name
102 self.contact_email = contact_email
103 self.bug_tracker = bug_tracker
104 self.crash_report_fname = "Crash_report_%s.txt" % self.app_name
105 self.show_crash_traceback = show_crash_traceback
106 self.section_sep = '\n\n'+'*'*75+'\n\n'
107 self.call_pdb = call_pdb
101 self.call_pdb = call_pdb
108 #self.call_pdb = True # dbg
102 #self.call_pdb = True # dbg
103 self.show_crash_traceback = show_crash_traceback
104 self.info = dict(app_name = app.name,
105 contact_name = contact_name,
106 contact_email = contact_email,
107 bug_tracker = bug_tracker,
108 crash_report_fname = self.crash_report_fname)
109
109
110
110 def __call__(self, etype, evalue, etb):
111 def __call__(self, etype, evalue, etb):
111 """Handle an exception, call for compatible with sys.excepthook"""
112 """Handle an exception, call for compatible with sys.excepthook"""
@@ -148,8 +149,8 b' class CrashHandler(object):'
148 return
149 return
149
150
150 # Inform user on stderr of what happened
151 # Inform user on stderr of what happened
151 msg = itpl('\n'+'*'*70+'\n'+self.message_template)
152 print >> sys.stderr, '\n'+'*'*70+'\n'
152 print >> sys.stderr, msg
153 print >> sys.stderr, self.message_template.format(**self.info)
153
154
154 # Construct report on disk
155 # Construct report on disk
155 report.write(self.make_report(traceback))
156 report.write(self.make_report(traceback))
@@ -51,7 +51,6 b' from IPython.core.macro import Macro'
51 from IPython.core import page
51 from IPython.core import page
52 from IPython.core.prefilter import ESC_MAGIC
52 from IPython.core.prefilter import ESC_MAGIC
53 from IPython.lib.pylabtools import mpl_runner
53 from IPython.lib.pylabtools import mpl_runner
54 from IPython.external.Itpl import itpl, printpl
55 from IPython.testing.skipdoctest import skip_doctest
54 from IPython.testing.skipdoctest import skip_doctest
56 from IPython.utils.io import file_read, nlprint
55 from IPython.utils.io import file_read, nlprint
57 from IPython.utils.path import get_py_filename
56 from IPython.utils.path import get_py_filename
@@ -915,8 +914,7 b' Currently the magic system has the following functions:\\n"""'
915 datalabel = 'Data/Info'
914 datalabel = 'Data/Info'
916 colsep = 3
915 colsep = 3
917 # variable format strings
916 # variable format strings
918 vformat = "$vname.ljust(varwidth)$vtype.ljust(typewidth)"
917 vformat = "{0:<{varwidth}}{1:<{typewidth}}"
919 vfmt_short = '$vstr[:25]<...>$vstr[-25:]'
920 aformat = "%s: %s elems, type `%s`, %s bytes"
918 aformat = "%s: %s elems, type `%s`, %s bytes"
921 # find the size of the columns to format the output nicely
919 # find the size of the columns to format the output nicely
922 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
920 varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep
@@ -928,7 +926,7 b' Currently the magic system has the following functions:\\n"""'
928 kb = 1024
926 kb = 1024
929 Mb = 1048576 # kb**2
927 Mb = 1048576 # kb**2
930 for vname,var,vtype in zip(varnames,varlist,typelist):
928 for vname,var,vtype in zip(varnames,varlist,typelist):
931 print itpl(vformat),
929 print vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth),
932 if vtype in seq_types:
930 if vtype in seq_types:
933 print "n="+str(len(var))
931 print "n="+str(len(var))
934 elif vtype in [array_type,ndarray_type]:
932 elif vtype in [array_type,ndarray_type]:
@@ -962,7 +960,7 b' Currently the magic system has the following functions:\\n"""'
962 if len(vstr) < 50:
960 if len(vstr) < 50:
963 print vstr
961 print vstr
964 else:
962 else:
965 printpl(vfmt_short)
963 print vstr[:25] + "<...>" + vstr[-25:]
966
964
967 def magic_reset(self, parameter_s=''):
965 def magic_reset(self, parameter_s=''):
968 """Resets the namespace by removing all names defined by the user.
966 """Resets the namespace by removing all names defined by the user.
@@ -28,7 +28,6 b' from itertools import izip_longest'
28
28
29 # IPython's own
29 # IPython's own
30 from IPython.core import page
30 from IPython.core import page
31 from IPython.external.Itpl import itpl
32 from IPython.utils import PyColorize
31 from IPython.utils import PyColorize
33 from IPython.utils import io
32 from IPython.utils import io
34 from IPython.utils.text import indent
33 from IPython.utils.text import indent
@@ -298,22 +297,24 b' class Inspector:'
298 -formatter: a function to run the docstring through for specially
297 -formatter: a function to run the docstring through for specially
299 formatted docstrings."""
298 formatted docstrings."""
300
299
301 head = self.__head # so that itpl can find it even if private
300 head = self.__head # For convenience
302 ds = getdoc(obj)
301 ds = getdoc(obj)
303 if formatter:
302 if formatter:
304 ds = formatter(ds)
303 ds = formatter(ds)
305 if inspect.isclass(obj):
304 if inspect.isclass(obj):
306 init_ds = getdoc(obj.__init__)
305 init_ds = getdoc(obj.__init__)
307 output = itpl('$head("Class Docstring:")\n'
306 output = "\n".join([head("Class Docstring:"),
308 '$indent(ds)\n'
307 indent(ds),
309 '$head("Constructor Docstring"):\n'
308 head("Constructor Docstring:"),
310 '$indent(init_ds)')
309 indent(init_ds)])
311 elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
310 elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
312 and hasattr(obj,'__call__'):
311 and hasattr(obj,'__call__'):
313 call_ds = getdoc(obj.__call__)
312 call_ds = getdoc(obj.__call__)
314 if call_ds:
313 if call_ds:
315 output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
314 output = "\n".join([head("Class Docstring:"),
316 '$head("Calling Docstring:")\n$indent(call_ds)')
315 indent(ds),
316 head("Calling Docstring:"),
317 indent(call_ds)])
317 else:
318 else:
318 output = ds
319 output = ds
319 else:
320 else:
@@ -63,34 +63,9 b" default_config_file_name = u'ipython_config.py'"
63 # Crash handler for this application
63 # Crash handler for this application
64 #-----------------------------------------------------------------------------
64 #-----------------------------------------------------------------------------
65
65
66 _message_template = """\
67 Oops, $self.app_name crashed. We do our best to make it stable, but...
68
69 A crash report was automatically generated with the following information:
70 - A verbatim copy of the crash traceback.
71 - A copy of your input history during this session.
72 - Data on your current $self.app_name configuration.
73
74 It was left in the file named:
75 \t'$self.crash_report_fname'
76 If you can email this file to the developers, the information in it will help
77 them in understanding and correcting the problem.
78
79 You can mail it to: $self.contact_name at $self.contact_email
80 with the subject '$self.app_name Crash Report'.
81
82 If you want to do it now, the following command will work (under Unix):
83 mail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname
84
85 To ensure accurate tracking of this issue, please file a report about it at:
86 $self.bug_tracker
87 """
88
89 class IPAppCrashHandler(CrashHandler):
66 class IPAppCrashHandler(CrashHandler):
90 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
67 """sys.excepthook for IPython itself, leaves a detailed report on disk."""
91
68
92 message_template = _message_template
93
94 def __init__(self, app):
69 def __init__(self, app):
95 contact_name = release.authors['Fernando'][0]
70 contact_name = release.authors['Fernando'][0]
96 contact_email = release.authors['Fernando'][1]
71 contact_email = release.authors['Fernando'][1]
@@ -17,8 +17,6 b' from __future__ import print_function'
17 import sys
17 import sys
18 import tempfile
18 import tempfile
19
19
20 from IPython.external.Itpl import itpl, printpl
21
22 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
23 # Code
21 # Code
24 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
@@ -268,12 +266,13 b' class NLprinter:'
268
266
269 for idx in range(start,stop):
267 for idx in range(start,stop):
270 elem = lst[idx]
268 elem = lst[idx]
269 newpos = pos + str(idx)
271 if type(elem)==type([]):
270 if type(elem)==type([]):
272 self.depth += 1
271 self.depth += 1
273 self.__call__(elem,itpl('$pos$idx,'),**kw)
272 self.__call__(elem, newpos+",", **kw)
274 self.depth -= 1
273 self.depth -= 1
275 else:
274 else:
276 printpl(kw['indent']*self.depth+'$pos$idx$kw["sep"]$elem')
275 print(kw['indent']*self.depth + newpos + kw["sep"] + repr(elem))
277
276
278 nlprint = NLprinter()
277 nlprint = NLprinter()
279
278
General Comments 0
You need to be logged in to leave comments. Login now