##// END OF EJS Templates
print the version on crash
Matthias Bussonnier -
Show More
@@ -1,226 +1,228 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """sys.excepthook for IPython itself, leaves a detailed report on disk.
2 """sys.excepthook for IPython itself, leaves a detailed report on disk.
3
3
4 Authors:
4 Authors:
5
5
6 * Fernando Perez
6 * Fernando Perez
7 * Brian E. Granger
7 * Brian E. Granger
8 """
8 """
9
9
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11 # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
12 # Copyright (C) 2008-2011 The IPython Development Team
12 # Copyright (C) 2008-2011 The IPython Development Team
13 #
13 #
14 # Distributed under the terms of the BSD License. The full license is in
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
15 # the file COPYING, distributed as part of this software.
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 #-----------------------------------------------------------------------------
18 #-----------------------------------------------------------------------------
19 # Imports
19 # Imports
20 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
21
21
22 import os
22 import os
23 import sys
23 import sys
24 import traceback
24 import traceback
25 from pprint import pformat
25 from pprint import pformat
26
26
27 from IPython.core import ultratb
27 from IPython.core import ultratb
28 from IPython.core.release import author_email
28 from IPython.core.release import author_email
29 from IPython.utils.sysinfo import sys_info
29 from IPython.utils.sysinfo import sys_info
30 from IPython.utils.py3compat import input
30 from IPython.utils.py3compat import input
31
31
32 from IPython.core.release import __version__ as version
33
32 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
33 # Code
35 # Code
34 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
35
37
36 # Template for the user message.
38 # Template for the user message.
37 _default_message_template = """\
39 _default_message_template = """\
38 Oops, {app_name} crashed. We do our best to make it stable, but...
40 Oops, {app_name} crashed. We do our best to make it stable, but...
39
41
40 A crash report was automatically generated with the following information:
42 A crash report was automatically generated with the following information:
41 - A verbatim copy of the crash traceback.
43 - A verbatim copy of the crash traceback.
42 - A copy of your input history during this session.
44 - A copy of your input history during this session.
43 - Data on your current {app_name} configuration.
45 - Data on your current {app_name} configuration.
44
46
45 It was left in the file named:
47 It was left in the file named:
46 \t'{crash_report_fname}'
48 \t'{crash_report_fname}'
47 If you can email this file to the developers, the information in it will help
49 If you can email this file to the developers, the information in it will help
48 them in understanding and correcting the problem.
50 them in understanding and correcting the problem.
49
51
50 You can mail it to: {contact_name} at {contact_email}
52 You can mail it to: {contact_name} at {contact_email}
51 with the subject '{app_name} Crash Report'.
53 with the subject '{app_name} Crash Report'.
52
54
53 If you want to do it now, the following command will work (under Unix):
55 If you want to do it now, the following command will work (under Unix):
54 mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}
56 mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}
55
57
56 In your email, please also include information about:
58 In your email, please also include information about:
57 - The operating system under which the crash happened: Linux, macOS, Windows,
59 - The operating system under which the crash happened: Linux, macOS, Windows,
58 other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2,
60 other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2,
59 Windows 10 Pro), and whether it is 32-bit or 64-bit;
61 Windows 10 Pro), and whether it is 32-bit or 64-bit;
60 - How {app_name} was installed: using pip or conda, from GitHub, as part of
62 - How {app_name} was installed: using pip or conda, from GitHub, as part of
61 a Docker container, or other, providing more detail if possible;
63 a Docker container, or other, providing more detail if possible;
62 - How to reproduce the crash: what exact sequence of instructions can one
64 - How to reproduce the crash: what exact sequence of instructions can one
63 input to get the same crash? Ideally, find a minimal yet complete sequence
65 input to get the same crash? Ideally, find a minimal yet complete sequence
64 of instructions that yields the crash.
66 of instructions that yields the crash.
65
67
66 To ensure accurate tracking of this issue, please file a report about it at:
68 To ensure accurate tracking of this issue, please file a report about it at:
67 {bug_tracker}
69 {bug_tracker}
68 """
70 """
69
71
70 _lite_message_template = """
72 _lite_message_template = """
71 If you suspect this is an IPython bug, please report it at:
73 If you suspect this is an IPython {version} bug, please report it at:
72 https://github.com/ipython/ipython/issues
74 https://github.com/ipython/ipython/issues
73 or send an email to the mailing list at {email}
75 or send an email to the mailing list at {email}
74
76
75 You can print a more detailed traceback right now with "%tb", or use "%debug"
77 You can print a more detailed traceback right now with "%tb", or use "%debug"
76 to interactively debug it.
78 to interactively debug it.
77
79
78 Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
80 Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
79 {config}Application.verbose_crash=True
81 {config}Application.verbose_crash=True
80 """
82 """
81
83
82
84
83 class CrashHandler(object):
85 class CrashHandler(object):
84 """Customizable crash handlers for IPython applications.
86 """Customizable crash handlers for IPython applications.
85
87
86 Instances of this class provide a :meth:`__call__` method which can be
88 Instances of this class provide a :meth:`__call__` method which can be
87 used as a ``sys.excepthook``. The :meth:`__call__` signature is::
89 used as a ``sys.excepthook``. The :meth:`__call__` signature is::
88
90
89 def __call__(self, etype, evalue, etb)
91 def __call__(self, etype, evalue, etb)
90 """
92 """
91
93
92 message_template = _default_message_template
94 message_template = _default_message_template
93 section_sep = '\n\n'+'*'*75+'\n\n'
95 section_sep = '\n\n'+'*'*75+'\n\n'
94
96
95 def __init__(self, app, contact_name=None, contact_email=None,
97 def __init__(self, app, contact_name=None, contact_email=None,
96 bug_tracker=None, show_crash_traceback=True, call_pdb=False):
98 bug_tracker=None, show_crash_traceback=True, call_pdb=False):
97 """Create a new crash handler
99 """Create a new crash handler
98
100
99 Parameters
101 Parameters
100 ----------
102 ----------
101 app : Application
103 app : Application
102 A running :class:`Application` instance, which will be queried at
104 A running :class:`Application` instance, which will be queried at
103 crash time for internal information.
105 crash time for internal information.
104
106
105 contact_name : str
107 contact_name : str
106 A string with the name of the person to contact.
108 A string with the name of the person to contact.
107
109
108 contact_email : str
110 contact_email : str
109 A string with the email address of the contact.
111 A string with the email address of the contact.
110
112
111 bug_tracker : str
113 bug_tracker : str
112 A string with the URL for your project's bug tracker.
114 A string with the URL for your project's bug tracker.
113
115
114 show_crash_traceback : bool
116 show_crash_traceback : bool
115 If false, don't print the crash traceback on stderr, only generate
117 If false, don't print the crash traceback on stderr, only generate
116 the on-disk report
118 the on-disk report
117
119
118 Non-argument instance attributes:
120 Non-argument instance attributes:
119
121
120 These instances contain some non-argument attributes which allow for
122 These instances contain some non-argument attributes which allow for
121 further customization of the crash handler's behavior. Please see the
123 further customization of the crash handler's behavior. Please see the
122 source for further details.
124 source for further details.
123 """
125 """
124 self.crash_report_fname = "Crash_report_%s.txt" % app.name
126 self.crash_report_fname = "Crash_report_%s.txt" % app.name
125 self.app = app
127 self.app = app
126 self.call_pdb = call_pdb
128 self.call_pdb = call_pdb
127 #self.call_pdb = True # dbg
129 #self.call_pdb = True # dbg
128 self.show_crash_traceback = show_crash_traceback
130 self.show_crash_traceback = show_crash_traceback
129 self.info = dict(app_name = app.name,
131 self.info = dict(app_name = app.name,
130 contact_name = contact_name,
132 contact_name = contact_name,
131 contact_email = contact_email,
133 contact_email = contact_email,
132 bug_tracker = bug_tracker,
134 bug_tracker = bug_tracker,
133 crash_report_fname = self.crash_report_fname)
135 crash_report_fname = self.crash_report_fname)
134
136
135
137
136 def __call__(self, etype, evalue, etb):
138 def __call__(self, etype, evalue, etb):
137 """Handle an exception, call for compatible with sys.excepthook"""
139 """Handle an exception, call for compatible with sys.excepthook"""
138
140
139 # do not allow the crash handler to be called twice without reinstalling it
141 # do not allow the crash handler to be called twice without reinstalling it
140 # this prevents unlikely errors in the crash handling from entering an
142 # this prevents unlikely errors in the crash handling from entering an
141 # infinite loop.
143 # infinite loop.
142 sys.excepthook = sys.__excepthook__
144 sys.excepthook = sys.__excepthook__
143
145
144 # Report tracebacks shouldn't use color in general (safer for users)
146 # Report tracebacks shouldn't use color in general (safer for users)
145 color_scheme = 'NoColor'
147 color_scheme = 'NoColor'
146
148
147 # Use this ONLY for developer debugging (keep commented out for release)
149 # Use this ONLY for developer debugging (keep commented out for release)
148 #color_scheme = 'Linux' # dbg
150 #color_scheme = 'Linux' # dbg
149 try:
151 try:
150 rptdir = self.app.ipython_dir
152 rptdir = self.app.ipython_dir
151 except:
153 except:
152 rptdir = os.getcwd()
154 rptdir = os.getcwd()
153 if rptdir is None or not os.path.isdir(rptdir):
155 if rptdir is None or not os.path.isdir(rptdir):
154 rptdir = os.getcwd()
156 rptdir = os.getcwd()
155 report_name = os.path.join(rptdir,self.crash_report_fname)
157 report_name = os.path.join(rptdir,self.crash_report_fname)
156 # write the report filename into the instance dict so it can get
158 # write the report filename into the instance dict so it can get
157 # properly expanded out in the user message template
159 # properly expanded out in the user message template
158 self.crash_report_fname = report_name
160 self.crash_report_fname = report_name
159 self.info['crash_report_fname'] = report_name
161 self.info['crash_report_fname'] = report_name
160 TBhandler = ultratb.VerboseTB(
162 TBhandler = ultratb.VerboseTB(
161 color_scheme=color_scheme,
163 color_scheme=color_scheme,
162 long_header=1,
164 long_header=1,
163 call_pdb=self.call_pdb,
165 call_pdb=self.call_pdb,
164 )
166 )
165 if self.call_pdb:
167 if self.call_pdb:
166 TBhandler(etype,evalue,etb)
168 TBhandler(etype,evalue,etb)
167 return
169 return
168 else:
170 else:
169 traceback = TBhandler.text(etype,evalue,etb,context=31)
171 traceback = TBhandler.text(etype,evalue,etb,context=31)
170
172
171 # print traceback to screen
173 # print traceback to screen
172 if self.show_crash_traceback:
174 if self.show_crash_traceback:
173 print(traceback, file=sys.stderr)
175 print(traceback, file=sys.stderr)
174
176
175 # and generate a complete report on disk
177 # and generate a complete report on disk
176 try:
178 try:
177 report = open(report_name,'w')
179 report = open(report_name,'w')
178 except:
180 except:
179 print('Could not create crash report on disk.', file=sys.stderr)
181 print('Could not create crash report on disk.', file=sys.stderr)
180 return
182 return
181
183
182 with report:
184 with report:
183 # Inform user on stderr of what happened
185 # Inform user on stderr of what happened
184 print('\n'+'*'*70+'\n', file=sys.stderr)
186 print('\n'+'*'*70+'\n', file=sys.stderr)
185 print(self.message_template.format(**self.info), file=sys.stderr)
187 print(self.message_template.format(**self.info), file=sys.stderr)
186
188
187 # Construct report on disk
189 # Construct report on disk
188 report.write(self.make_report(traceback))
190 report.write(self.make_report(traceback))
189
191
190 input("Hit <Enter> to quit (your terminal may close):")
192 input("Hit <Enter> to quit (your terminal may close):")
191
193
192 def make_report(self,traceback):
194 def make_report(self,traceback):
193 """Return a string containing a crash report."""
195 """Return a string containing a crash report."""
194
196
195 sec_sep = self.section_sep
197 sec_sep = self.section_sep
196
198
197 report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n']
199 report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n']
198 rpt_add = report.append
200 rpt_add = report.append
199 rpt_add(sys_info())
201 rpt_add(sys_info())
200
202
201 try:
203 try:
202 config = pformat(self.app.config)
204 config = pformat(self.app.config)
203 rpt_add(sec_sep)
205 rpt_add(sec_sep)
204 rpt_add('Application name: %s\n\n' % self.app_name)
206 rpt_add('Application name: %s\n\n' % self.app_name)
205 rpt_add('Current user configuration structure:\n\n')
207 rpt_add('Current user configuration structure:\n\n')
206 rpt_add(config)
208 rpt_add(config)
207 except:
209 except:
208 pass
210 pass
209 rpt_add(sec_sep+'Crash traceback:\n\n' + traceback)
211 rpt_add(sec_sep+'Crash traceback:\n\n' + traceback)
210
212
211 return ''.join(report)
213 return ''.join(report)
212
214
213
215
214 def crash_handler_lite(etype, evalue, tb):
216 def crash_handler_lite(etype, evalue, tb):
215 """a light excepthook, adding a small message to the usual traceback"""
217 """a light excepthook, adding a small message to the usual traceback"""
216 traceback.print_exception(etype, evalue, tb)
218 traceback.print_exception(etype, evalue, tb)
217
219
218 from IPython.core.interactiveshell import InteractiveShell
220 from IPython.core.interactiveshell import InteractiveShell
219 if InteractiveShell.initialized():
221 if InteractiveShell.initialized():
220 # we are in a Shell environment, give %magic example
222 # we are in a Shell environment, give %magic example
221 config = "%config "
223 config = "%config "
222 else:
224 else:
223 # we are not in a shell, show generic config
225 # we are not in a shell, show generic config
224 config = "c."
226 config = "c."
225 print(_lite_message_template.format(email=author_email, config=config), file=sys.stderr)
227 print(_lite_message_template.format(email=author_email, config=config, version=version), file=sys.stderr)
226
228
@@ -1,108 +1,112 b''
1 # Simple tool to help for release
1 # Simple tool to help for release
2 # when releasing with bash, simplei source it to get asked questions.
2 # when releasing with bash, simplei source it to get asked questions.
3
3
4 # misc check before starting
4 # misc check before starting
5
5
6 python -c 'import keyring'
6 python -c 'import keyring'
7 python -c 'import twine'
7 python -c 'import twine'
8 python -c 'import sphinx'
8 python -c 'import sphinx'
9 python -c 'import sphinx_rtd_theme'
9 python -c 'import sphinx_rtd_theme'
10 python -c 'import nose'
10 python -c 'import nose'
11
11
12 echo -n 'PREV_RELEASE (X.y.z):'
12 echo -n 'PREV_RELEASE (X.y.z):'
13 read PREV_RELEASE
13 read PREV_RELEASE
14 echo -n 'MILESTONE (X.y):'
14 echo -n 'MILESTONE (X.y):'
15 read MILESTONE
15 read MILESTONE
16 echo -n 'VERSION (X.y.z):'
16 echo -n 'VERSION (X.y.z):'
17 read VERSION
17 read VERSION
18 echo -n 'branch (master|X.y):'
18 echo -n 'branch (master|X.y):'
19 read branch
19 read branch
20
20
21 BLACK=$(tput setaf 1)
21 BLACK=$(tput setaf 1)
22 RED=$(tput setaf 1)
22 RED=$(tput setaf 1)
23 GREEN=$(tput setaf 2)
23 GREEN=$(tput setaf 2)
24 YELLOW=$(tput setaf 3)
24 YELLOW=$(tput setaf 3)
25 BLUE=$(tput setaf 4)
25 BLUE=$(tput setaf 4)
26 MAGENTA=$(tput setaf 5)
26 MAGENTA=$(tput setaf 5)
27 CYAN=$(tput setaf 6)
27 CYAN=$(tput setaf 6)
28 WHITE=$(tput setaf 7)
28 WHITE=$(tput setaf 7)
29 NOR=$(tput sgr0)
29 NOR=$(tput sgr0)
30
30
31 echo
31 echo
32 echo $BLUE"Updating what's new with informations from docs/source/whatsnew/pr"$NOR
32 echo $BLUE"Updating what's new with informations from docs/source/whatsnew/pr"$NOR
33 python tools/update_whatsnew.py
33 python tools/update_whatsnew.py
34
34
35 echo
35 echo
36 echo $BLUE"please move the contents of "docs/source/whatsnew/development.rst" to version-X.rst"$NOR
36 echo $BLUE"please move the contents of "docs/source/whatsnew/development.rst" to version-X.rst"$NOR
37 echo $GREEN"Press enter to continue"$NOR
37 echo $GREEN"Press enter to continue"$NOR
38 read
38 read
39
39
40 echo
40 echo
41 echo $BLUE"here are all the authors that contributed to this release:"$NOR
41 echo $BLUE"here are all the authors that contributed to this release:"$NOR
42 git log --format="%aN <%aE>" $PREV_RELEASE... | sort -u -f
42 git log --format="%aN <%aE>" $PREV_RELEASE... | sort -u -f
43
43
44 echo
44 echo
45 echo $BLUE"If you see any duplicates cancel (Ctrl-C), then edit .mailmap.\n"$GREEN"Press enter to continue:"$NOR
45 echo $BLUE"If you see any duplicates cancel (Ctrl-C), then edit .mailmap.\n"$GREEN"Press enter to continue:"$NOR
46 read
46 read
47
47
48 echo $BLUE"generating stats"$NOR
48 echo $BLUE"generating stats"$NOR
49 python tools/github_stats.py --milestone $MILESTONE > stats.rst
49 python tools/github_stats.py --milestone $MILESTONE > stats.rst
50
50
51 echo $BLUE"stats.rst files generated."$NOR
51 echo $BLUE"stats.rst files generated."$NOR
52 echo $GREEN"Please merge it with the right file (github-stats-X.rst) and commit."$NOR
52 echo $GREEN"Please merge it with the right file (github-stats-X.rst) and commit."$NOR
53 echo $GREEN"press enter to continue."$NOR
53 echo $GREEN"press enter to continue."$NOR
54 read
54 read
55
55
56 echo "Cleaning repository"
56 echo "Cleaning repository"
57 git clean -xfdi
57 git clean -xfdi
58
58
59 echo $GREEN"please update version number in ${RED}IPython/core/release.py${NOR} , Do not commit yet – we'll do it later."$NOR
59 echo $GREEN"please update version number in ${RED}IPython/core/release.py${NOR} , Do not commit yet – we'll do it later."$NOR
60
60
61 echo $GREEN"Press enter to continue"$NOR
61 echo $GREEN"Press enter to continue"$NOR
62 read
62 read
63
63
64 echo
64 echo
65 echo "Attempting to build the docs.."
65 echo "Attempting to build the docs.."
66 make html -C docs
66 make html -C docs
67
67
68 echo
68 echo
69 echo $GREEN"Check the docs, press enter to continue"$NOR
69 echo $GREEN"Check the docs, press enter to continue"$NOR
70 read
70 read
71
71
72 echo
72 echo
73 echo $BLUE"Attempting to build package..."$NOR
73 echo $BLUE"Attempting to build package..."$NOR
74
74
75 tools/build_release
75 tools/build_release
76
76
77 echo
77 echo
78 echo "Let's commit : git commit -am \"release $VERSION\" -S"
78 echo "Let's commit : git commit -am \"release $VERSION\" -S"
79 echo $GREEN"Press enter to commit"$NOR
79 echo $GREEN"Press enter to commit"$NOR
80 read
80 read
81 git commit -am "release $VERSION" -S
81 git commit -am "release $VERSION" -S
82
82
83 echo
83 echo
84 echo $BLUE"git push origin \$BRANCH ($BRANCH)?"$NOR
84 echo $BLUE"git push origin \$BRANCH ($BRANCH)?"$NOR
85 echo $GREEN"Make sure you can push"$NOR
85 echo $GREEN"Make sure you can push"$NOR
86 echo $GREEN"Press enter to continue"$NOR
86 echo $GREEN"Press enter to continue"$NOR
87 read
87 read
88 git push origin $BRANCH
88 git push origin $BRANCH
89
89
90 echo
90 echo
91 echo "Let's tag : git tag -am \"release $VERSION\" \"$VERSION\" -s"
91 echo "Let's tag : git tag -am \"release $VERSION\" \"$VERSION\" -s"
92 echo $GREEN"Press enter to wtagcommit"$NOR
92 echo $GREEN"Press enter to wtagcommit"$NOR
93 read
93 read
94 git tag -am "release $VERSION" "$VERSION" -s
94 git tag -am "release $VERSION" "$VERSION" -s
95
95
96 echo
96 echo
97 echo $BLUE"And push the tag: git push origin \$VERSION ?"$NOR
97 echo $BLUE"And push the tag: git push origin \$VERSION ?"$NOR
98 echo $GREEN"Press enter to continue"$NOR
98 echo $GREEN"Press enter to continue"$NOR
99 read
99 read
100 git push origin $VERSION
100 git push origin $VERSION
101
101
102 echo
102 echo
103 echo $BLUE"let's : git checkout $VERSION"$NOR
103 echo $BLUE"let's : git checkout $VERSION"$NOR
104 echo $GREEN"Press enter to continue"$NOR
104 echo $GREEN"Press enter to continue"$NOR
105 read
105 read
106 git checkout $VERSION
106 git checkout $VERSION
107
107
108 # ./tools/release
109 # ls ./dist
110 # shasum -a 256 dist/*
111
108
112
General Comments 0
You need to be logged in to leave comments. Login now