Show More
@@ -1,963 +1,1085 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | Pdb debugger class. |
|
4 | 4 | |
|
5 | ||
|
6 | This is an extension to PDB which adds a number of new features. | |
|
7 | Note that there is also the `IPython.terminal.debugger` class which provides UI | |
|
8 | improvements. | |
|
9 | ||
|
10 | We also strongly recommend to use this via the `ipdb` package, which provides | |
|
11 | extra configuration options. | |
|
12 | ||
|
13 | Among other things, this subclass of PDB: | |
|
14 | - supports many IPython magics like pdef/psource | |
|
15 | - hide frames in tracebacks based on `__tracebackhide__` | |
|
16 | - allows to skip frames based on `__debuggerskip__` | |
|
17 | ||
|
18 | The skipping and hiding frames are configurable via the `skip_predicates` | |
|
19 | command. | |
|
20 | ||
|
21 | By default, frames from readonly files will be hidden, frames containing | |
|
22 | ``__tracebackhide__=True`` will be hidden. | |
|
23 | ||
|
24 | Frames containing ``__debuggerskip__`` will be stepped over, frames who's parent | |
|
25 | frames value of ``__debuggerskip__`` is ``True`` will be skipped. | |
|
26 | ||
|
27 | >>> def helper_1(): | |
|
28 | ... print("don't step in me") | |
|
29 | ... | |
|
30 | ... | |
|
31 | ... def helper_2(): | |
|
32 | ... print("in me neither") | |
|
33 | ... | |
|
34 | ||
|
35 | One can define a decorator that wraps a function between the two helpers: | |
|
36 | ||
|
37 | >>> def pdb_skipped_decorator(function): | |
|
38 | ... | |
|
39 | ... | |
|
40 | ... def wrapped_fn(*args, **kwargs): | |
|
41 | ... __debuggerskip__ = True | |
|
42 | ... helper_1() | |
|
43 | ... __debuggerskip__ = False | |
|
44 | ... result = function(*args, **kwargs) | |
|
45 | ... __debuggerskip__ = True | |
|
46 | ... helper_2() | |
|
47 | ... return result | |
|
48 | ... | |
|
49 | ... return wrapped_fn | |
|
50 | ||
|
51 | When decorating a function, ipdb will directly step into ``bar()`` by | |
|
52 | default: | |
|
53 | ||
|
54 | >>> @foo_decorator | |
|
55 | ... def bar(x, y): | |
|
56 | ... return x * y | |
|
57 | ||
|
58 | ||
|
59 | You can toggle the behavior with | |
|
60 | ||
|
61 | ipdb> skip_predicates debuggerskip false | |
|
62 | ||
|
63 | or configure it in your ``.pdbrc`` | |
|
64 | ||
|
65 | ||
|
66 | ||
|
67 | Licencse | |
|
68 | -------- | |
|
69 | ||
|
5 | 70 | Modified from the standard pdb.Pdb class to avoid including readline, so that |
|
6 | 71 | the command line completion of other programs which include this isn't |
|
7 | 72 | damaged. |
|
8 | 73 | |
|
9 | 74 | In the future, this class will be expanded with improvements over the standard |
|
10 | 75 | pdb. |
|
11 | 76 | |
|
12 |
The code in this file is mainly lifted out of cmd.py in Python 2.2, |
|
|
13 |
changes. Licensing should therefore be under the standard Python |
|
|
14 |
details on the PSF (Python Software Foundation) standard license, |
|
|
77 | The original code in this file is mainly lifted out of cmd.py in Python 2.2, | |
|
78 | with minor changes. Licensing should therefore be under the standard Python | |
|
79 | terms. For details on the PSF (Python Software Foundation) standard license, | |
|
80 | see: | |
|
15 | 81 | |
|
16 | 82 | https://docs.python.org/2/license.html |
|
83 | ||
|
84 | ||
|
85 | All the changes since then are under the same license as IPython. | |
|
86 | ||
|
17 | 87 | """ |
|
18 | 88 | |
|
19 | 89 | #***************************************************************************** |
|
20 | 90 | # |
|
21 | 91 | # This file is licensed under the PSF license. |
|
22 | 92 | # |
|
23 | 93 | # Copyright (C) 2001 Python Software Foundation, www.python.org |
|
24 | 94 | # Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu> |
|
25 | 95 | # |
|
26 | 96 | # |
|
27 | 97 | #***************************************************************************** |
|
28 | 98 | |
|
29 | 99 | import bdb |
|
30 | 100 | import functools |
|
31 | 101 | import inspect |
|
32 | 102 | import linecache |
|
33 | 103 | import sys |
|
34 | 104 | import warnings |
|
35 | 105 | import re |
|
36 | 106 | import os |
|
37 | 107 | |
|
38 | 108 | from IPython import get_ipython |
|
39 | 109 | from IPython.utils import PyColorize |
|
40 | 110 | from IPython.utils import coloransi, py3compat |
|
41 | 111 | from IPython.core.excolors import exception_colors |
|
42 | 112 | from IPython.testing.skipdoctest import skip_doctest |
|
43 | 113 | |
|
44 | 114 | |
|
45 | 115 | prompt = 'ipdb> ' |
|
46 | 116 | |
|
47 | 117 | #We have to check this directly from sys.argv, config struct not yet available |
|
48 | 118 | from pdb import Pdb as OldPdb |
|
49 | 119 | |
|
50 | 120 | # Allow the set_trace code to operate outside of an ipython instance, even if |
|
51 | 121 | # it does so with some limitations. The rest of this support is implemented in |
|
52 | 122 | # the Tracer constructor. |
|
53 | 123 | |
|
124 | DEBUGGERSKIP = "__debuggerskip__" | |
|
125 | ||
|
126 | ||
|
54 | 127 | def make_arrow(pad): |
|
55 | 128 | """generate the leading arrow in front of traceback or debugger""" |
|
56 | 129 | if pad >= 2: |
|
57 | 130 | return '-'*(pad-2) + '> ' |
|
58 | 131 | elif pad == 1: |
|
59 | 132 | return '>' |
|
60 | 133 | return '' |
|
61 | 134 | |
|
62 | 135 | |
|
63 | 136 | def BdbQuit_excepthook(et, ev, tb, excepthook=None): |
|
64 | 137 | """Exception hook which handles `BdbQuit` exceptions. |
|
65 | 138 | |
|
66 | 139 | All other exceptions are processed using the `excepthook` |
|
67 | 140 | parameter. |
|
68 | 141 | """ |
|
69 | 142 | warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1", |
|
70 | 143 | DeprecationWarning, stacklevel=2) |
|
71 | 144 | if et==bdb.BdbQuit: |
|
72 | 145 | print('Exiting Debugger.') |
|
73 | 146 | elif excepthook is not None: |
|
74 | 147 | excepthook(et, ev, tb) |
|
75 | 148 | else: |
|
76 | 149 | # Backwards compatibility. Raise deprecation warning? |
|
77 | 150 | BdbQuit_excepthook.excepthook_ori(et,ev,tb) |
|
78 | 151 | |
|
79 | 152 | |
|
80 | 153 | def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None): |
|
81 | 154 | warnings.warn( |
|
82 | 155 | "`BdbQuit_IPython_excepthook` is deprecated since version 5.1", |
|
83 | 156 | DeprecationWarning, stacklevel=2) |
|
84 | 157 | print('Exiting Debugger.') |
|
85 | 158 | |
|
86 | 159 | |
|
87 | 160 | class Tracer(object): |
|
88 | 161 | """ |
|
89 | 162 | DEPRECATED |
|
90 | 163 | |
|
91 | 164 | Class for local debugging, similar to pdb.set_trace. |
|
92 | 165 | |
|
93 | 166 | Instances of this class, when called, behave like pdb.set_trace, but |
|
94 | 167 | providing IPython's enhanced capabilities. |
|
95 | 168 | |
|
96 | 169 | This is implemented as a class which must be initialized in your own code |
|
97 | 170 | and not as a standalone function because we need to detect at runtime |
|
98 | 171 | whether IPython is already active or not. That detection is done in the |
|
99 | 172 | constructor, ensuring that this code plays nicely with a running IPython, |
|
100 | 173 | while functioning acceptably (though with limitations) if outside of it. |
|
101 | 174 | """ |
|
102 | 175 | |
|
103 | 176 | @skip_doctest |
|
104 | 177 | def __init__(self, colors=None): |
|
105 | 178 | """ |
|
106 | 179 | DEPRECATED |
|
107 | 180 | |
|
108 | 181 | Create a local debugger instance. |
|
109 | 182 | |
|
110 | 183 | Parameters |
|
111 | 184 | ---------- |
|
112 | 185 | |
|
113 | 186 | colors : str, optional |
|
114 | 187 | The name of the color scheme to use, it must be one of IPython's |
|
115 | 188 | valid color schemes. If not given, the function will default to |
|
116 | 189 | the current IPython scheme when running inside IPython, and to |
|
117 | 190 | 'NoColor' otherwise. |
|
118 | 191 | |
|
119 | 192 | Examples |
|
120 | 193 | -------- |
|
121 | 194 | :: |
|
122 | 195 | |
|
123 | 196 | from IPython.core.debugger import Tracer; debug_here = Tracer() |
|
124 | 197 | |
|
125 | 198 | Later in your code:: |
|
126 | 199 | |
|
127 | 200 | debug_here() # -> will open up the debugger at that point. |
|
128 | 201 | |
|
129 | 202 | Once the debugger activates, you can use all of its regular commands to |
|
130 | 203 | step through code, set breakpoints, etc. See the pdb documentation |
|
131 | 204 | from the Python standard library for usage details. |
|
132 | 205 | """ |
|
133 | 206 | warnings.warn("`Tracer` is deprecated since version 5.1, directly use " |
|
134 | 207 | "`IPython.core.debugger.Pdb.set_trace()`", |
|
135 | 208 | DeprecationWarning, stacklevel=2) |
|
136 | 209 | |
|
137 | 210 | ip = get_ipython() |
|
138 | 211 | if ip is None: |
|
139 | 212 | # Outside of ipython, we set our own exception hook manually |
|
140 | 213 | sys.excepthook = functools.partial(BdbQuit_excepthook, |
|
141 | 214 | excepthook=sys.excepthook) |
|
142 | 215 | def_colors = 'NoColor' |
|
143 | 216 | else: |
|
144 | 217 | # In ipython, we use its custom exception handler mechanism |
|
145 | 218 | def_colors = ip.colors |
|
146 | 219 | ip.set_custom_exc((bdb.BdbQuit,), BdbQuit_IPython_excepthook) |
|
147 | 220 | |
|
148 | 221 | if colors is None: |
|
149 | 222 | colors = def_colors |
|
150 | 223 | |
|
151 | 224 | # The stdlib debugger internally uses a modified repr from the `repr` |
|
152 | 225 | # module, that limits the length of printed strings to a hardcoded |
|
153 | 226 | # limit of 30 characters. That much trimming is too aggressive, let's |
|
154 | 227 | # at least raise that limit to 80 chars, which should be enough for |
|
155 | 228 | # most interactive uses. |
|
156 | 229 | try: |
|
157 | 230 | from reprlib import aRepr |
|
158 | 231 | aRepr.maxstring = 80 |
|
159 | 232 | except: |
|
160 | 233 | # This is only a user-facing convenience, so any error we encounter |
|
161 | 234 | # here can be warned about but can be otherwise ignored. These |
|
162 | 235 | # printouts will tell us about problems if this API changes |
|
163 | 236 | import traceback |
|
164 | 237 | traceback.print_exc() |
|
165 | 238 | |
|
166 | 239 | self.debugger = Pdb(colors) |
|
167 | 240 | |
|
168 | 241 | def __call__(self): |
|
169 | 242 | """Starts an interactive debugger at the point where called. |
|
170 | 243 | |
|
171 | 244 | This is similar to the pdb.set_trace() function from the std lib, but |
|
172 | 245 | using IPython's enhanced debugger.""" |
|
173 | 246 | |
|
174 | 247 | self.debugger.set_trace(sys._getframe().f_back) |
|
175 | 248 | |
|
176 | 249 | |
|
177 | 250 | RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+') |
|
178 | 251 | |
|
179 | 252 | |
|
180 | 253 | def strip_indentation(multiline_string): |
|
181 | 254 | return RGX_EXTRA_INDENT.sub('', multiline_string) |
|
182 | 255 | |
|
183 | 256 | |
|
184 | 257 | def decorate_fn_with_doc(new_fn, old_fn, additional_text=""): |
|
185 | 258 | """Make new_fn have old_fn's doc string. This is particularly useful |
|
186 | 259 | for the ``do_...`` commands that hook into the help system. |
|
187 | 260 | Adapted from from a comp.lang.python posting |
|
188 | 261 | by Duncan Booth.""" |
|
189 | 262 | def wrapper(*args, **kw): |
|
190 | 263 | return new_fn(*args, **kw) |
|
191 | 264 | if old_fn.__doc__: |
|
192 | 265 | wrapper.__doc__ = strip_indentation(old_fn.__doc__) + additional_text |
|
193 | 266 | return wrapper |
|
194 | 267 | |
|
195 | 268 | |
|
196 | 269 | class Pdb(OldPdb): |
|
197 | 270 | """Modified Pdb class, does not load readline. |
|
198 | 271 | |
|
199 | 272 | for a standalone version that uses prompt_toolkit, see |
|
200 | 273 | `IPython.terminal.debugger.TerminalPdb` and |
|
201 | 274 | `IPython.terminal.debugger.set_trace()` |
|
202 | 275 | |
|
203 | 276 | |
|
204 | 277 | This debugger can hide and skip frames that are tagged according to some predicates. |
|
205 | 278 | See the `skip_predicates` commands. |
|
206 | 279 | |
|
207 | 280 | """ |
|
208 | 281 | |
|
209 | default_predicates = {"tbhide": True, "readonly": False, "ipython_internal": True} | |
|
282 | default_predicates = { | |
|
283 | "tbhide": True, | |
|
284 | "readonly": False, | |
|
285 | "ipython_internal": True, | |
|
286 | "debuggerskip": True, | |
|
287 | } | |
|
210 | 288 | |
|
211 | 289 | def __init__(self, color_scheme=None, completekey=None, |
|
212 | 290 | stdin=None, stdout=None, context=5, **kwargs): |
|
213 | 291 | """Create a new IPython debugger. |
|
214 | 292 | |
|
215 | 293 | Parameters |
|
216 | 294 | ---------- |
|
217 | 295 | color_scheme : default None |
|
218 | 296 | Deprecated, do not use. |
|
219 | 297 | completekey : default None |
|
220 | 298 | Passed to pdb.Pdb. |
|
221 | 299 | stdin : default None |
|
222 | 300 | Passed to pdb.Pdb. |
|
223 | 301 | stdout : default None |
|
224 | 302 | Passed to pdb.Pdb. |
|
225 | 303 | context : int |
|
226 | 304 | Number of lines of source code context to show when |
|
227 | 305 | displaying stacktrace information. |
|
228 | 306 | **kwargs |
|
229 | 307 | Passed to pdb.Pdb. |
|
230 | 308 | |
|
231 | 309 | Notes |
|
232 | 310 | ----- |
|
233 | 311 | The possibilities are python version dependent, see the python |
|
234 | 312 | docs for more info. |
|
235 | 313 | """ |
|
236 | 314 | |
|
237 | 315 | # Parent constructor: |
|
238 | 316 | try: |
|
239 | 317 | self.context = int(context) |
|
240 | 318 | if self.context <= 0: |
|
241 | 319 | raise ValueError("Context must be a positive integer") |
|
242 | 320 | except (TypeError, ValueError): |
|
243 | 321 | raise ValueError("Context must be a positive integer") |
|
244 | 322 | |
|
245 | 323 | # `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`. |
|
246 | 324 | OldPdb.__init__(self, completekey, stdin, stdout, **kwargs) |
|
247 | 325 | |
|
248 | 326 | # IPython changes... |
|
249 | 327 | self.shell = get_ipython() |
|
250 | 328 | |
|
251 | 329 | if self.shell is None: |
|
252 | 330 | save_main = sys.modules['__main__'] |
|
253 | 331 | # No IPython instance running, we must create one |
|
254 | 332 | from IPython.terminal.interactiveshell import \ |
|
255 | 333 | TerminalInteractiveShell |
|
256 | 334 | self.shell = TerminalInteractiveShell.instance() |
|
257 | 335 | # needed by any code which calls __import__("__main__") after |
|
258 | 336 | # the debugger was entered. See also #9941. |
|
259 | 337 | sys.modules['__main__'] = save_main |
|
260 | 338 | |
|
261 | 339 | if color_scheme is not None: |
|
262 | 340 | warnings.warn( |
|
263 | 341 | "The `color_scheme` argument is deprecated since version 5.1", |
|
264 | 342 | DeprecationWarning, stacklevel=2) |
|
265 | 343 | else: |
|
266 | 344 | color_scheme = self.shell.colors |
|
267 | 345 | |
|
268 | 346 | self.aliases = {} |
|
269 | 347 | |
|
270 | 348 | # Create color table: we copy the default one from the traceback |
|
271 | 349 | # module and add a few attributes needed for debugging |
|
272 | 350 | self.color_scheme_table = exception_colors() |
|
273 | 351 | |
|
274 | 352 | # shorthands |
|
275 | 353 | C = coloransi.TermColors |
|
276 | 354 | cst = self.color_scheme_table |
|
277 | 355 | |
|
278 | 356 | cst['NoColor'].colors.prompt = C.NoColor |
|
279 | 357 | cst['NoColor'].colors.breakpoint_enabled = C.NoColor |
|
280 | 358 | cst['NoColor'].colors.breakpoint_disabled = C.NoColor |
|
281 | 359 | |
|
282 | 360 | cst['Linux'].colors.prompt = C.Green |
|
283 | 361 | cst['Linux'].colors.breakpoint_enabled = C.LightRed |
|
284 | 362 | cst['Linux'].colors.breakpoint_disabled = C.Red |
|
285 | 363 | |
|
286 | 364 | cst['LightBG'].colors.prompt = C.Blue |
|
287 | 365 | cst['LightBG'].colors.breakpoint_enabled = C.LightRed |
|
288 | 366 | cst['LightBG'].colors.breakpoint_disabled = C.Red |
|
289 | 367 | |
|
290 | 368 | cst['Neutral'].colors.prompt = C.Blue |
|
291 | 369 | cst['Neutral'].colors.breakpoint_enabled = C.LightRed |
|
292 | 370 | cst['Neutral'].colors.breakpoint_disabled = C.Red |
|
293 | 371 | |
|
294 | 372 | |
|
295 | 373 | # Add a python parser so we can syntax highlight source while |
|
296 | 374 | # debugging. |
|
297 | 375 | self.parser = PyColorize.Parser(style=color_scheme) |
|
298 | 376 | self.set_colors(color_scheme) |
|
299 | 377 | |
|
300 | 378 | # Set the prompt - the default prompt is '(Pdb)' |
|
301 | 379 | self.prompt = prompt |
|
302 | 380 | self.skip_hidden = True |
|
303 | 381 | self.report_skipped = True |
|
304 | 382 | |
|
305 | 383 | # list of predicates we use to skip frames |
|
306 | 384 | self._predicates = self.default_predicates |
|
307 | 385 | |
|
386 | # | |
|
308 | 387 | def set_colors(self, scheme): |
|
309 | 388 | """Shorthand access to the color table scheme selector method.""" |
|
310 | 389 | self.color_scheme_table.set_active_scheme(scheme) |
|
311 | 390 | self.parser.style = scheme |
|
312 | 391 | |
|
313 | 392 | def set_trace(self, frame=None): |
|
314 | 393 | if frame is None: |
|
315 | 394 | frame = sys._getframe().f_back |
|
316 | 395 | self.initial_frame = frame |
|
317 | 396 | return super().set_trace(frame) |
|
318 | 397 | |
|
319 | 398 | def _hidden_predicate(self, frame): |
|
320 | 399 | """ |
|
321 | 400 | Given a frame return whether it it should be hidden or not by IPython. |
|
322 | 401 | """ |
|
323 | 402 | |
|
324 | 403 | if self._predicates["readonly"]: |
|
325 | 404 | fname = frame.f_code.co_filename |
|
326 | 405 | # we need to check for file existence and interactively define |
|
327 | 406 | # function would otherwise appear as RO. |
|
328 | 407 | if os.path.isfile(fname) and not os.access(fname, os.W_OK): |
|
329 | 408 | return True |
|
330 | 409 | |
|
331 | 410 | if self._predicates["tbhide"]: |
|
332 | 411 | if frame in (self.curframe, getattr(self, "initial_frame", None)): |
|
333 | 412 | return False |
|
334 | 413 | else: |
|
335 | 414 | return self._get_frame_locals(frame).get("__tracebackhide__", False) |
|
336 | 415 | |
|
337 | 416 | return False |
|
338 | 417 | |
|
339 | 418 | def hidden_frames(self, stack): |
|
340 | 419 | """ |
|
341 | 420 | Given an index in the stack return wether it should be skipped. |
|
342 | 421 | |
|
343 | 422 | This is used in up/down and where to skip frames. |
|
344 | 423 | """ |
|
345 | 424 | # The f_locals dictionary is updated from the actual frame |
|
346 | 425 | # locals whenever the .f_locals accessor is called, so we |
|
347 | 426 | # avoid calling it here to preserve self.curframe_locals. |
|
348 | 427 | # Futhermore, there is no good reason to hide the current frame. |
|
349 | 428 | ip_hide = [self._hidden_predicate(s[0]) for s in stack] |
|
350 | 429 | ip_start = [i for i, s in enumerate(ip_hide) if s == "__ipython_bottom__"] |
|
351 | 430 | if ip_start and self._predicates["ipython_internal"]: |
|
352 | 431 | ip_hide = [h if i > ip_start[0] else True for (i, h) in enumerate(ip_hide)] |
|
353 | 432 | return ip_hide |
|
354 | 433 | |
|
355 | 434 | def interaction(self, frame, traceback): |
|
356 | 435 | try: |
|
357 | 436 | OldPdb.interaction(self, frame, traceback) |
|
358 | 437 | except KeyboardInterrupt: |
|
359 | 438 | self.stdout.write("\n" + self.shell.get_exception_only()) |
|
360 | 439 | |
|
361 | 440 | def new_do_frame(self, arg): |
|
362 | 441 | OldPdb.do_frame(self, arg) |
|
363 | 442 | |
|
364 | 443 | def new_do_quit(self, arg): |
|
365 | 444 | |
|
366 | 445 | if hasattr(self, 'old_all_completions'): |
|
367 | 446 | self.shell.Completer.all_completions=self.old_all_completions |
|
368 | 447 | |
|
369 | 448 | return OldPdb.do_quit(self, arg) |
|
370 | 449 | |
|
371 | 450 | do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit) |
|
372 | 451 | |
|
373 | 452 | def new_do_restart(self, arg): |
|
374 | 453 | """Restart command. In the context of ipython this is exactly the same |
|
375 | 454 | thing as 'quit'.""" |
|
376 | 455 | self.msg("Restart doesn't make sense here. Using 'quit' instead.") |
|
377 | 456 | return self.do_quit(arg) |
|
378 | 457 | |
|
379 | 458 | def print_stack_trace(self, context=None): |
|
380 | 459 | Colors = self.color_scheme_table.active_colors |
|
381 | 460 | ColorsNormal = Colors.Normal |
|
382 | 461 | if context is None: |
|
383 | 462 | context = self.context |
|
384 | 463 | try: |
|
385 | 464 | context=int(context) |
|
386 | 465 | if context <= 0: |
|
387 | 466 | raise ValueError("Context must be a positive integer") |
|
388 | 467 | except (TypeError, ValueError): |
|
389 | 468 | raise ValueError("Context must be a positive integer") |
|
390 | 469 | try: |
|
391 | 470 | skipped = 0 |
|
392 | 471 | for hidden, frame_lineno in zip(self.hidden_frames(self.stack), self.stack): |
|
393 | 472 | if hidden and self.skip_hidden: |
|
394 | 473 | skipped += 1 |
|
395 | 474 | continue |
|
396 | 475 | if skipped: |
|
397 | 476 | print( |
|
398 | 477 | f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n" |
|
399 | 478 | ) |
|
400 | 479 | skipped = 0 |
|
401 | 480 | self.print_stack_entry(frame_lineno, context=context) |
|
402 | 481 | if skipped: |
|
403 | 482 | print( |
|
404 | 483 | f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n" |
|
405 | 484 | ) |
|
406 | 485 | except KeyboardInterrupt: |
|
407 | 486 | pass |
|
408 | 487 | |
|
409 | 488 | def print_stack_entry(self, frame_lineno, prompt_prefix='\n-> ', |
|
410 | 489 | context=None): |
|
411 | 490 | if context is None: |
|
412 | 491 | context = self.context |
|
413 | 492 | try: |
|
414 | 493 | context=int(context) |
|
415 | 494 | if context <= 0: |
|
416 | 495 | raise ValueError("Context must be a positive integer") |
|
417 | 496 | except (TypeError, ValueError): |
|
418 | 497 | raise ValueError("Context must be a positive integer") |
|
419 | 498 | print(self.format_stack_entry(frame_lineno, '', context), file=self.stdout) |
|
420 | 499 | |
|
421 | 500 | # vds: >> |
|
422 | 501 | frame, lineno = frame_lineno |
|
423 | 502 | filename = frame.f_code.co_filename |
|
424 | 503 | self.shell.hooks.synchronize_with_editor(filename, lineno, 0) |
|
425 | 504 | # vds: << |
|
426 | 505 | |
|
427 | 506 | def _get_frame_locals(self, frame): |
|
428 | 507 | """ " |
|
429 | 508 | Acessing f_local of current frame reset the namespace, so we want to avoid |
|
430 | 509 | that or the following can happend |
|
431 | 510 | |
|
432 | 511 | ipdb> foo |
|
433 | 512 | "old" |
|
434 | 513 | ipdb> foo = "new" |
|
435 | 514 | ipdb> foo |
|
436 | 515 | "new" |
|
437 | 516 | ipdb> where |
|
438 | 517 | ipdb> foo |
|
439 | 518 | "old" |
|
440 | 519 | |
|
441 | 520 | So if frame is self.current_frame we instead return self.curframe_locals |
|
442 | 521 | |
|
443 | 522 | """ |
|
444 | 523 | if frame is self.curframe: |
|
445 | 524 | return self.curframe_locals |
|
446 | 525 | else: |
|
447 | 526 | return frame.f_locals |
|
448 | 527 | |
|
449 | 528 | def format_stack_entry(self, frame_lineno, lprefix=': ', context=None): |
|
450 | 529 | if context is None: |
|
451 | 530 | context = self.context |
|
452 | 531 | try: |
|
453 | 532 | context=int(context) |
|
454 | 533 | if context <= 0: |
|
455 | 534 | print("Context must be a positive integer", file=self.stdout) |
|
456 | 535 | except (TypeError, ValueError): |
|
457 | 536 | print("Context must be a positive integer", file=self.stdout) |
|
458 | 537 | try: |
|
459 | 538 | import reprlib # Py 3 |
|
460 | 539 | except ImportError: |
|
461 | 540 | import repr as reprlib # Py 2 |
|
462 | 541 | |
|
463 | 542 | ret = [] |
|
464 | 543 | |
|
465 | 544 | Colors = self.color_scheme_table.active_colors |
|
466 | 545 | ColorsNormal = Colors.Normal |
|
467 | 546 | tpl_link = u'%s%%s%s' % (Colors.filenameEm, ColorsNormal) |
|
468 | 547 | tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal) |
|
469 | 548 | tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) |
|
470 | 549 | tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, |
|
471 | 550 | ColorsNormal) |
|
472 | 551 | |
|
473 | 552 | frame, lineno = frame_lineno |
|
474 | 553 | |
|
475 | 554 | return_value = '' |
|
476 | 555 | loc_frame = self._get_frame_locals(frame) |
|
477 | 556 | if "__return__" in loc_frame: |
|
478 | 557 | rv = loc_frame["__return__"] |
|
479 | 558 | # return_value += '->' |
|
480 | 559 | return_value += reprlib.repr(rv) + "\n" |
|
481 | 560 | ret.append(return_value) |
|
482 | 561 | |
|
483 | 562 | #s = filename + '(' + `lineno` + ')' |
|
484 | 563 | filename = self.canonic(frame.f_code.co_filename) |
|
485 | 564 | link = tpl_link % py3compat.cast_unicode(filename) |
|
486 | 565 | |
|
487 | 566 | if frame.f_code.co_name: |
|
488 | 567 | func = frame.f_code.co_name |
|
489 | 568 | else: |
|
490 | 569 | func = "<lambda>" |
|
491 | 570 | |
|
492 | 571 | call = "" |
|
493 | 572 | if func != "?": |
|
494 | 573 | if "__args__" in loc_frame: |
|
495 | 574 | args = reprlib.repr(loc_frame["__args__"]) |
|
496 | 575 | else: |
|
497 | 576 | args = '()' |
|
498 | 577 | call = tpl_call % (func, args) |
|
499 | 578 | |
|
500 | 579 | # The level info should be generated in the same format pdb uses, to |
|
501 | 580 | # avoid breaking the pdbtrack functionality of python-mode in *emacs. |
|
502 | 581 | if frame is self.curframe: |
|
503 | 582 | ret.append('> ') |
|
504 | 583 | else: |
|
505 | 584 | ret.append(' ') |
|
506 | 585 | ret.append(u'%s(%s)%s\n' % (link,lineno,call)) |
|
507 | 586 | |
|
508 | 587 | start = lineno - 1 - context//2 |
|
509 | 588 | lines = linecache.getlines(filename) |
|
510 | 589 | start = min(start, len(lines) - context) |
|
511 | 590 | start = max(start, 0) |
|
512 | 591 | lines = lines[start : start + context] |
|
513 | 592 | |
|
514 | 593 | for i,line in enumerate(lines): |
|
515 | 594 | show_arrow = (start + 1 + i == lineno) |
|
516 | 595 | linetpl = (frame is self.curframe or show_arrow) \ |
|
517 | 596 | and tpl_line_em \ |
|
518 | 597 | or tpl_line |
|
519 | 598 | ret.append(self.__format_line(linetpl, filename, |
|
520 | 599 | start + 1 + i, line, |
|
521 | 600 | arrow = show_arrow) ) |
|
522 | 601 | return ''.join(ret) |
|
523 | 602 | |
|
524 | 603 | def __format_line(self, tpl_line, filename, lineno, line, arrow = False): |
|
525 | 604 | bp_mark = "" |
|
526 | 605 | bp_mark_color = "" |
|
527 | 606 | |
|
528 | 607 | new_line, err = self.parser.format2(line, 'str') |
|
529 | 608 | if not err: |
|
530 | 609 | line = new_line |
|
531 | 610 | |
|
532 | 611 | bp = None |
|
533 | 612 | if lineno in self.get_file_breaks(filename): |
|
534 | 613 | bps = self.get_breaks(filename, lineno) |
|
535 | 614 | bp = bps[-1] |
|
536 | 615 | |
|
537 | 616 | if bp: |
|
538 | 617 | Colors = self.color_scheme_table.active_colors |
|
539 | 618 | bp_mark = str(bp.number) |
|
540 | 619 | bp_mark_color = Colors.breakpoint_enabled |
|
541 | 620 | if not bp.enabled: |
|
542 | 621 | bp_mark_color = Colors.breakpoint_disabled |
|
543 | 622 | |
|
544 | 623 | numbers_width = 7 |
|
545 | 624 | if arrow: |
|
546 | 625 | # This is the line with the error |
|
547 | 626 | pad = numbers_width - len(str(lineno)) - len(bp_mark) |
|
548 | 627 | num = '%s%s' % (make_arrow(pad), str(lineno)) |
|
549 | 628 | else: |
|
550 | 629 | num = '%*s' % (numbers_width - len(bp_mark), str(lineno)) |
|
551 | 630 | |
|
552 | 631 | return tpl_line % (bp_mark_color + bp_mark, num, line) |
|
553 | 632 | |
|
554 | 633 | |
|
555 | 634 | def print_list_lines(self, filename, first, last): |
|
556 | 635 | """The printing (as opposed to the parsing part of a 'list' |
|
557 | 636 | command.""" |
|
558 | 637 | try: |
|
559 | 638 | Colors = self.color_scheme_table.active_colors |
|
560 | 639 | ColorsNormal = Colors.Normal |
|
561 | 640 | tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) |
|
562 | 641 | tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal) |
|
563 | 642 | src = [] |
|
564 | 643 | if filename == "<string>" and hasattr(self, "_exec_filename"): |
|
565 | 644 | filename = self._exec_filename |
|
566 | 645 | |
|
567 | 646 | for lineno in range(first, last+1): |
|
568 | 647 | line = linecache.getline(filename, lineno) |
|
569 | 648 | if not line: |
|
570 | 649 | break |
|
571 | 650 | |
|
572 | 651 | if lineno == self.curframe.f_lineno: |
|
573 | 652 | line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True) |
|
574 | 653 | else: |
|
575 | 654 | line = self.__format_line(tpl_line, filename, lineno, line, arrow = False) |
|
576 | 655 | |
|
577 | 656 | src.append(line) |
|
578 | 657 | self.lineno = lineno |
|
579 | 658 | |
|
580 | 659 | print(''.join(src), file=self.stdout) |
|
581 | 660 | |
|
582 | 661 | except KeyboardInterrupt: |
|
583 | 662 | pass |
|
584 | 663 | |
|
585 | 664 | def do_skip_predicates(self, args): |
|
586 | 665 | """ |
|
587 | 666 | Turn on/off individual predicates as to whether a frame should be hidden/skip. |
|
588 | 667 | |
|
589 | 668 | The global option to skip (or not) hidden frames is set with skip_hidden |
|
590 | 669 | |
|
591 | 670 | To change the value of a predicate |
|
592 | 671 | |
|
593 | 672 | skip_predicates key [true|false] |
|
594 | 673 | |
|
595 | 674 | Call without arguments to see the current values. |
|
596 | 675 | |
|
597 | 676 | To permanently change the value of an option add the corresponding |
|
598 | 677 | command to your ``~/.pdbrc`` file. If you are programmatically using the |
|
599 | 678 | Pdb instance you can also change the ``default_predicates`` class |
|
600 | 679 | attribute. |
|
601 | 680 | """ |
|
602 | 681 | if not args.strip(): |
|
603 | 682 | print("current predicates:") |
|
604 | 683 | for (p, v) in self._predicates.items(): |
|
605 | 684 | print(" ", p, ":", v) |
|
606 | 685 | return |
|
607 | 686 | type_value = args.strip().split(" ") |
|
608 | 687 | if len(type_value) != 2: |
|
609 | 688 | print( |
|
610 | 689 | f"Usage: skip_predicates <type> <value>, with <type> one of {set(self._predicates.keys())}" |
|
611 | 690 | ) |
|
612 | 691 | return |
|
613 | 692 | |
|
614 | 693 | type_, value = type_value |
|
615 | 694 | if type_ not in self._predicates: |
|
616 | 695 | print(f"{type_!r} not in {set(self._predicates.keys())}") |
|
617 | 696 | return |
|
618 | 697 | if value.lower() not in ("true", "yes", "1", "no", "false", "0"): |
|
619 | 698 | print( |
|
620 | 699 | f"{value!r} is invalid - use one of ('true', 'yes', '1', 'no', 'false', '0')" |
|
621 | 700 | ) |
|
622 | 701 | return |
|
623 | 702 | |
|
624 | 703 | self._predicates[type_] = value.lower() in ("true", "yes", "1") |
|
625 | 704 | if not any(self._predicates.values()): |
|
626 | 705 | print( |
|
627 | 706 | "Warning, all predicates set to False, skip_hidden may not have any effects." |
|
628 | 707 | ) |
|
629 | 708 | |
|
630 | 709 | def do_skip_hidden(self, arg): |
|
631 | 710 | """ |
|
632 | 711 | Change whether or not we should skip frames with the |
|
633 | 712 | __tracebackhide__ attribute. |
|
634 | 713 | """ |
|
635 | 714 | if not arg.strip(): |
|
636 | 715 | print( |
|
637 | 716 | f"skip_hidden = {self.skip_hidden}, use 'yes','no', 'true', or 'false' to change." |
|
638 | 717 | ) |
|
639 | 718 | elif arg.strip().lower() in ("true", "yes"): |
|
640 | 719 | self.skip_hidden = True |
|
641 | 720 | elif arg.strip().lower() in ("false", "no"): |
|
642 | 721 | self.skip_hidden = False |
|
643 | 722 | if not any(self._predicates.values()): |
|
644 | 723 | print( |
|
645 | 724 | "Warning, all predicates set to False, skip_hidden may not have any effects." |
|
646 | 725 | ) |
|
647 | 726 | |
|
648 | 727 | def do_list(self, arg): |
|
649 | 728 | """Print lines of code from the current stack frame |
|
650 | 729 | """ |
|
651 | 730 | self.lastcmd = 'list' |
|
652 | 731 | last = None |
|
653 | 732 | if arg: |
|
654 | 733 | try: |
|
655 | 734 | x = eval(arg, {}, {}) |
|
656 | 735 | if type(x) == type(()): |
|
657 | 736 | first, last = x |
|
658 | 737 | first = int(first) |
|
659 | 738 | last = int(last) |
|
660 | 739 | if last < first: |
|
661 | 740 | # Assume it's a count |
|
662 | 741 | last = first + last |
|
663 | 742 | else: |
|
664 | 743 | first = max(1, int(x) - 5) |
|
665 | 744 | except: |
|
666 | 745 | print('*** Error in argument:', repr(arg), file=self.stdout) |
|
667 | 746 | return |
|
668 | 747 | elif self.lineno is None: |
|
669 | 748 | first = max(1, self.curframe.f_lineno - 5) |
|
670 | 749 | else: |
|
671 | 750 | first = self.lineno + 1 |
|
672 | 751 | if last is None: |
|
673 | 752 | last = first + 10 |
|
674 | 753 | self.print_list_lines(self.curframe.f_code.co_filename, first, last) |
|
675 | 754 | |
|
676 | 755 | # vds: >> |
|
677 | 756 | lineno = first |
|
678 | 757 | filename = self.curframe.f_code.co_filename |
|
679 | 758 | self.shell.hooks.synchronize_with_editor(filename, lineno, 0) |
|
680 | 759 | # vds: << |
|
681 | 760 | |
|
682 | 761 | do_l = do_list |
|
683 | 762 | |
|
684 | 763 | def getsourcelines(self, obj): |
|
685 | 764 | lines, lineno = inspect.findsource(obj) |
|
686 | 765 | if inspect.isframe(obj) and obj.f_globals is self._get_frame_locals(obj): |
|
687 | 766 | # must be a module frame: do not try to cut a block out of it |
|
688 | 767 | return lines, 1 |
|
689 | 768 | elif inspect.ismodule(obj): |
|
690 | 769 | return lines, 1 |
|
691 | 770 | return inspect.getblock(lines[lineno:]), lineno+1 |
|
692 | 771 | |
|
693 | 772 | def do_longlist(self, arg): |
|
694 | 773 | """Print lines of code from the current stack frame. |
|
695 | 774 | |
|
696 | 775 | Shows more lines than 'list' does. |
|
697 | 776 | """ |
|
698 | 777 | self.lastcmd = 'longlist' |
|
699 | 778 | try: |
|
700 | 779 | lines, lineno = self.getsourcelines(self.curframe) |
|
701 | 780 | except OSError as err: |
|
702 | 781 | self.error(err) |
|
703 | 782 | return |
|
704 | 783 | last = lineno + len(lines) |
|
705 | 784 | self.print_list_lines(self.curframe.f_code.co_filename, lineno, last) |
|
706 | 785 | do_ll = do_longlist |
|
707 | 786 | |
|
708 | 787 | def do_debug(self, arg): |
|
709 | 788 | """debug code |
|
710 | 789 | Enter a recursive debugger that steps through the code |
|
711 | 790 | argument (which is an arbitrary expression or statement to be |
|
712 | 791 | executed in the current environment). |
|
713 | 792 | """ |
|
714 | 793 | trace_function = sys.gettrace() |
|
715 | 794 | sys.settrace(None) |
|
716 | 795 | globals = self.curframe.f_globals |
|
717 | 796 | locals = self.curframe_locals |
|
718 | 797 | p = self.__class__(completekey=self.completekey, |
|
719 | 798 | stdin=self.stdin, stdout=self.stdout) |
|
720 | 799 | p.use_rawinput = self.use_rawinput |
|
721 | 800 | p.prompt = "(%s) " % self.prompt.strip() |
|
722 | 801 | self.message("ENTERING RECURSIVE DEBUGGER") |
|
723 | 802 | sys.call_tracing(p.run, (arg, globals, locals)) |
|
724 | 803 | self.message("LEAVING RECURSIVE DEBUGGER") |
|
725 | 804 | sys.settrace(trace_function) |
|
726 | 805 | self.lastcmd = p.lastcmd |
|
727 | 806 | |
|
728 | 807 | def do_pdef(self, arg): |
|
729 | 808 | """Print the call signature for any callable object. |
|
730 | 809 | |
|
731 | 810 | The debugger interface to %pdef""" |
|
732 | 811 | namespaces = [ |
|
733 | 812 | ("Locals", self.curframe_locals), |
|
734 | 813 | ("Globals", self.curframe.f_globals), |
|
735 | 814 | ] |
|
736 | 815 | self.shell.find_line_magic("pdef")(arg, namespaces=namespaces) |
|
737 | 816 | |
|
738 | 817 | def do_pdoc(self, arg): |
|
739 | 818 | """Print the docstring for an object. |
|
740 | 819 | |
|
741 | 820 | The debugger interface to %pdoc.""" |
|
742 | 821 | namespaces = [ |
|
743 | 822 | ("Locals", self.curframe_locals), |
|
744 | 823 | ("Globals", self.curframe.f_globals), |
|
745 | 824 | ] |
|
746 | 825 | self.shell.find_line_magic("pdoc")(arg, namespaces=namespaces) |
|
747 | 826 | |
|
748 | 827 | def do_pfile(self, arg): |
|
749 | 828 | """Print (or run through pager) the file where an object is defined. |
|
750 | 829 | |
|
751 | 830 | The debugger interface to %pfile. |
|
752 | 831 | """ |
|
753 | 832 | namespaces = [ |
|
754 | 833 | ("Locals", self.curframe_locals), |
|
755 | 834 | ("Globals", self.curframe.f_globals), |
|
756 | 835 | ] |
|
757 | 836 | self.shell.find_line_magic("pfile")(arg, namespaces=namespaces) |
|
758 | 837 | |
|
759 | 838 | def do_pinfo(self, arg): |
|
760 | 839 | """Provide detailed information about an object. |
|
761 | 840 | |
|
762 | 841 | The debugger interface to %pinfo, i.e., obj?.""" |
|
763 | 842 | namespaces = [ |
|
764 | 843 | ("Locals", self.curframe_locals), |
|
765 | 844 | ("Globals", self.curframe.f_globals), |
|
766 | 845 | ] |
|
767 | 846 | self.shell.find_line_magic("pinfo")(arg, namespaces=namespaces) |
|
768 | 847 | |
|
769 | 848 | def do_pinfo2(self, arg): |
|
770 | 849 | """Provide extra detailed information about an object. |
|
771 | 850 | |
|
772 | 851 | The debugger interface to %pinfo2, i.e., obj??.""" |
|
773 | 852 | namespaces = [ |
|
774 | 853 | ("Locals", self.curframe_locals), |
|
775 | 854 | ("Globals", self.curframe.f_globals), |
|
776 | 855 | ] |
|
777 | 856 | self.shell.find_line_magic("pinfo2")(arg, namespaces=namespaces) |
|
778 | 857 | |
|
779 | 858 | def do_psource(self, arg): |
|
780 | 859 | """Print (or run through pager) the source code for an object.""" |
|
781 | 860 | namespaces = [ |
|
782 | 861 | ("Locals", self.curframe_locals), |
|
783 | 862 | ("Globals", self.curframe.f_globals), |
|
784 | 863 | ] |
|
785 | 864 | self.shell.find_line_magic("psource")(arg, namespaces=namespaces) |
|
786 | 865 | |
|
787 | 866 | def do_where(self, arg): |
|
788 | 867 | """w(here) |
|
789 | 868 | Print a stack trace, with the most recent frame at the bottom. |
|
790 | 869 | An arrow indicates the "current frame", which determines the |
|
791 | 870 | context of most commands. 'bt' is an alias for this command. |
|
792 | 871 | |
|
793 | 872 | Take a number as argument as an (optional) number of context line to |
|
794 | 873 | print""" |
|
795 | 874 | if arg: |
|
796 | 875 | try: |
|
797 | 876 | context = int(arg) |
|
798 | 877 | except ValueError as err: |
|
799 | 878 | self.error(err) |
|
800 | 879 | return |
|
801 | 880 | self.print_stack_trace(context) |
|
802 | 881 | else: |
|
803 | 882 | self.print_stack_trace() |
|
804 | 883 | |
|
805 | 884 | do_w = do_where |
|
806 | 885 | |
|
886 | def break_anywhere(self, frame): | |
|
887 | """ | |
|
888 | ||
|
889 | _stop_in_decorator_internals is overly restrictive, as we may still want | |
|
890 | to trace function calls, so we need to also update break_anywhere so | |
|
891 | that is we don't `stop_here`, because of debugger skip, we may still | |
|
892 | stop at any point inside the function | |
|
893 | ||
|
894 | """ | |
|
895 | if self._predicates["debuggerskip"]: | |
|
896 | if DEBUGGERSKIP in frame.f_code.co_varnames: | |
|
897 | return True | |
|
898 | if frame.f_back and self._get_frame_locals(frame.f_back).get(DEBUGGERSKIP): | |
|
899 | return True | |
|
900 | return super().break_anywhere(frame) | |
|
901 | ||
|
902 | @skip_doctest | |
|
903 | def _is_in_decorator_internal_and_should_skip(self, frame): | |
|
904 | """ | |
|
905 | Utility to tell us whether we are in a decorator internal and should stop. | |
|
906 | ||
|
907 | ||
|
908 | ||
|
909 | """ | |
|
910 | ||
|
911 | # if we are disabled don't skip | |
|
912 | if not self._predicates["debuggerskip"]: | |
|
913 | return False | |
|
914 | ||
|
915 | # if frame is tagged, skip by default. | |
|
916 | if DEBUGGERSKIP in frame.f_code.co_varnames: | |
|
917 | return True | |
|
918 | ||
|
919 | # if parent frame value set to True skip as well. | |
|
920 | if frame.f_back and self._get_frame_locals(frame.f_back).get(DEBUGGERSKIP): | |
|
921 | return True | |
|
922 | ||
|
923 | return False | |
|
924 | ||
|
807 | 925 | def stop_here(self, frame): |
|
808 | 926 | """Check if pdb should stop here""" |
|
809 | 927 | if not super().stop_here(frame): |
|
810 | 928 | return False |
|
929 | ||
|
930 | if self._is_in_decorator_internal_and_should_skip(frame) is True: | |
|
931 | return False | |
|
932 | ||
|
811 | 933 | hidden = False |
|
812 | 934 | if self.skip_hidden: |
|
813 | 935 | hidden = self._hidden_predicate(frame) |
|
814 | 936 | if hidden: |
|
815 | 937 | if self.report_skipped: |
|
816 | 938 | Colors = self.color_scheme_table.active_colors |
|
817 | 939 | ColorsNormal = Colors.Normal |
|
818 | 940 | print(f"{Colors.excName} [... skipped 1 hidden frame]{ColorsNormal}\n") |
|
819 | 941 | return False |
|
820 | 942 | return True |
|
821 | 943 | |
|
822 | 944 | def do_up(self, arg): |
|
823 | 945 | """u(p) [count] |
|
824 | 946 | Move the current frame count (default one) levels up in the |
|
825 | 947 | stack trace (to an older frame). |
|
826 | 948 | |
|
827 | 949 | Will skip hidden frames. |
|
828 | 950 | """ |
|
829 | 951 | # modified version of upstream that skips |
|
830 | 952 | # frames with __tracebackhide__ |
|
831 | 953 | if self.curindex == 0: |
|
832 | 954 | self.error("Oldest frame") |
|
833 | 955 | return |
|
834 | 956 | try: |
|
835 | 957 | count = int(arg or 1) |
|
836 | 958 | except ValueError: |
|
837 | 959 | self.error("Invalid frame count (%s)" % arg) |
|
838 | 960 | return |
|
839 | 961 | skipped = 0 |
|
840 | 962 | if count < 0: |
|
841 | 963 | _newframe = 0 |
|
842 | 964 | else: |
|
843 | 965 | _newindex = self.curindex |
|
844 | 966 | counter = 0 |
|
845 | 967 | hidden_frames = self.hidden_frames(self.stack) |
|
846 | 968 | for i in range(self.curindex - 1, -1, -1): |
|
847 | 969 | frame = self.stack[i][0] |
|
848 | 970 | if hidden_frames[i] and self.skip_hidden: |
|
849 | 971 | skipped += 1 |
|
850 | 972 | continue |
|
851 | 973 | counter += 1 |
|
852 | 974 | if counter >= count: |
|
853 | 975 | break |
|
854 | 976 | else: |
|
855 | 977 | # if no break occured. |
|
856 | 978 | self.error("all frames above hidden") |
|
857 | 979 | return |
|
858 | 980 | |
|
859 | 981 | Colors = self.color_scheme_table.active_colors |
|
860 | 982 | ColorsNormal = Colors.Normal |
|
861 | 983 | _newframe = i |
|
862 | 984 | self._select_frame(_newframe) |
|
863 | 985 | if skipped: |
|
864 | 986 | print( |
|
865 | 987 | f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n" |
|
866 | 988 | ) |
|
867 | 989 | |
|
868 | 990 | def do_down(self, arg): |
|
869 | 991 | """d(own) [count] |
|
870 | 992 | Move the current frame count (default one) levels down in the |
|
871 | 993 | stack trace (to a newer frame). |
|
872 | 994 | |
|
873 | 995 | Will skip hidden frames. |
|
874 | 996 | """ |
|
875 | 997 | if self.curindex + 1 == len(self.stack): |
|
876 | 998 | self.error("Newest frame") |
|
877 | 999 | return |
|
878 | 1000 | try: |
|
879 | 1001 | count = int(arg or 1) |
|
880 | 1002 | except ValueError: |
|
881 | 1003 | self.error("Invalid frame count (%s)" % arg) |
|
882 | 1004 | return |
|
883 | 1005 | if count < 0: |
|
884 | 1006 | _newframe = len(self.stack) - 1 |
|
885 | 1007 | else: |
|
886 | 1008 | _newindex = self.curindex |
|
887 | 1009 | counter = 0 |
|
888 | 1010 | skipped = 0 |
|
889 | 1011 | hidden_frames = self.hidden_frames(self.stack) |
|
890 | 1012 | for i in range(self.curindex + 1, len(self.stack)): |
|
891 | 1013 | frame = self.stack[i][0] |
|
892 | 1014 | if hidden_frames[i] and self.skip_hidden: |
|
893 | 1015 | skipped += 1 |
|
894 | 1016 | continue |
|
895 | 1017 | counter += 1 |
|
896 | 1018 | if counter >= count: |
|
897 | 1019 | break |
|
898 | 1020 | else: |
|
899 | 1021 | self.error("all frames bellow hidden") |
|
900 | 1022 | return |
|
901 | 1023 | |
|
902 | 1024 | Colors = self.color_scheme_table.active_colors |
|
903 | 1025 | ColorsNormal = Colors.Normal |
|
904 | 1026 | if skipped: |
|
905 | 1027 | print( |
|
906 | 1028 | f"{Colors.excName} [... skipped {skipped} hidden frame(s)]{ColorsNormal}\n" |
|
907 | 1029 | ) |
|
908 | 1030 | _newframe = i |
|
909 | 1031 | |
|
910 | 1032 | self._select_frame(_newframe) |
|
911 | 1033 | |
|
912 | 1034 | do_d = do_down |
|
913 | 1035 | do_u = do_up |
|
914 | 1036 | |
|
915 | 1037 | def do_context(self, context): |
|
916 | 1038 | """context number_of_lines |
|
917 | 1039 | Set the number of lines of source code to show when displaying |
|
918 | 1040 | stacktrace information. |
|
919 | 1041 | """ |
|
920 | 1042 | try: |
|
921 | 1043 | new_context = int(context) |
|
922 | 1044 | if new_context <= 0: |
|
923 | 1045 | raise ValueError() |
|
924 | 1046 | self.context = new_context |
|
925 | 1047 | except ValueError: |
|
926 | 1048 | self.error("The 'context' command requires a positive integer argument.") |
|
927 | 1049 | |
|
928 | 1050 | |
|
929 | 1051 | class InterruptiblePdb(Pdb): |
|
930 | 1052 | """Version of debugger where KeyboardInterrupt exits the debugger altogether.""" |
|
931 | 1053 | |
|
932 | def cmdloop(self): | |
|
1054 | def cmdloop(self, intro=None): | |
|
933 | 1055 | """Wrap cmdloop() such that KeyboardInterrupt stops the debugger.""" |
|
934 | 1056 | try: |
|
935 | return OldPdb.cmdloop(self) | |
|
1057 | return OldPdb.cmdloop(self, intro=intro) | |
|
936 | 1058 | except KeyboardInterrupt: |
|
937 | 1059 | self.stop_here = lambda frame: False |
|
938 | 1060 | self.do_quit("") |
|
939 | 1061 | sys.settrace(None) |
|
940 | 1062 | self.quitting = False |
|
941 | 1063 | raise |
|
942 | 1064 | |
|
943 | 1065 | def _cmdloop(self): |
|
944 | 1066 | while True: |
|
945 | 1067 | try: |
|
946 | 1068 | # keyboard interrupts allow for an easy way to cancel |
|
947 | 1069 | # the current command, so allow them during interactive input |
|
948 | 1070 | self.allow_kbdint = True |
|
949 | 1071 | self.cmdloop() |
|
950 | 1072 | self.allow_kbdint = False |
|
951 | 1073 | break |
|
952 | 1074 | except KeyboardInterrupt: |
|
953 | 1075 | self.message('--KeyboardInterrupt--') |
|
954 | 1076 | raise |
|
955 | 1077 | |
|
956 | 1078 | |
|
957 | 1079 | def set_trace(frame=None): |
|
958 | 1080 | """ |
|
959 | 1081 | Start debugging from `frame`. |
|
960 | 1082 | |
|
961 | 1083 | If frame is not specified, debugging starts from caller's frame. |
|
962 | 1084 | """ |
|
963 | 1085 | Pdb().set_trace(frame or sys._getframe().f_back) |
@@ -1,393 +1,505 b'' | |||
|
1 | 1 | """Tests for debugging machinery. |
|
2 | 2 | """ |
|
3 | 3 | |
|
4 | 4 | # Copyright (c) IPython Development Team. |
|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
|
6 | 6 | |
|
7 | 7 | import bdb |
|
8 | 8 | import builtins |
|
9 | 9 | import os |
|
10 | 10 | import signal |
|
11 | 11 | import subprocess |
|
12 | 12 | import sys |
|
13 | 13 | import time |
|
14 | 14 | import warnings |
|
15 | 15 | from subprocess import PIPE, CalledProcessError, check_output |
|
16 | 16 | from tempfile import NamedTemporaryFile |
|
17 | 17 | from textwrap import dedent |
|
18 | 18 | from unittest.mock import patch |
|
19 | 19 | |
|
20 | 20 | import nose.tools as nt |
|
21 | 21 | |
|
22 | 22 | from IPython.core import debugger |
|
23 | 23 | from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE |
|
24 | 24 | from IPython.testing.decorators import skip_win32 |
|
25 | 25 | |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | # Helper classes, from CPython's Pdb test suite |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | 29 | |
|
30 | 30 | class _FakeInput(object): |
|
31 | 31 | """ |
|
32 | 32 | A fake input stream for pdb's interactive debugger. Whenever a |
|
33 | 33 | line is read, print it (to simulate the user typing it), and then |
|
34 | 34 | return it. The set of lines to return is specified in the |
|
35 | 35 | constructor; they should not have trailing newlines. |
|
36 | 36 | """ |
|
37 | 37 | def __init__(self, lines): |
|
38 | 38 | self.lines = iter(lines) |
|
39 | 39 | |
|
40 | 40 | def readline(self): |
|
41 | 41 | line = next(self.lines) |
|
42 | 42 | print(line) |
|
43 | 43 | return line+'\n' |
|
44 | 44 | |
|
45 | 45 | class PdbTestInput(object): |
|
46 | 46 | """Context manager that makes testing Pdb in doctests easier.""" |
|
47 | 47 | |
|
48 | 48 | def __init__(self, input): |
|
49 | 49 | self.input = input |
|
50 | 50 | |
|
51 | 51 | def __enter__(self): |
|
52 | 52 | self.real_stdin = sys.stdin |
|
53 | 53 | sys.stdin = _FakeInput(self.input) |
|
54 | 54 | |
|
55 | 55 | def __exit__(self, *exc): |
|
56 | 56 | sys.stdin = self.real_stdin |
|
57 | 57 | |
|
58 | 58 | #----------------------------------------------------------------------------- |
|
59 | 59 | # Tests |
|
60 | 60 | #----------------------------------------------------------------------------- |
|
61 | 61 | |
|
62 | 62 | def test_longer_repr(): |
|
63 | 63 | try: |
|
64 | 64 | from reprlib import repr as trepr # Py 3 |
|
65 | 65 | except ImportError: |
|
66 | 66 | from repr import repr as trepr # Py 2 |
|
67 | 67 | |
|
68 | 68 | a = '1234567890'* 7 |
|
69 | 69 | ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'" |
|
70 | 70 | a_trunc = "'123456789012...8901234567890'" |
|
71 | 71 | nt.assert_equal(trepr(a), a_trunc) |
|
72 | 72 | # The creation of our tracer modifies the repr module's repr function |
|
73 | 73 | # in-place, since that global is used directly by the stdlib's pdb module. |
|
74 | 74 | with warnings.catch_warnings(): |
|
75 | 75 | warnings.simplefilter('ignore', DeprecationWarning) |
|
76 | 76 | debugger.Tracer() |
|
77 | 77 | nt.assert_equal(trepr(a), ar) |
|
78 | 78 | |
|
79 | 79 | def test_ipdb_magics(): |
|
80 | 80 | '''Test calling some IPython magics from ipdb. |
|
81 | 81 | |
|
82 | 82 | First, set up some test functions and classes which we can inspect. |
|
83 | 83 | |
|
84 | 84 | >>> class ExampleClass(object): |
|
85 | 85 | ... """Docstring for ExampleClass.""" |
|
86 | 86 | ... def __init__(self): |
|
87 | 87 | ... """Docstring for ExampleClass.__init__""" |
|
88 | 88 | ... pass |
|
89 | 89 | ... def __str__(self): |
|
90 | 90 | ... return "ExampleClass()" |
|
91 | 91 | |
|
92 | 92 | >>> def example_function(x, y, z="hello"): |
|
93 | 93 | ... """Docstring for example_function.""" |
|
94 | 94 | ... pass |
|
95 | 95 | |
|
96 | 96 | >>> old_trace = sys.gettrace() |
|
97 | 97 | |
|
98 | 98 | Create a function which triggers ipdb. |
|
99 | 99 | |
|
100 | 100 | >>> def trigger_ipdb(): |
|
101 | 101 | ... a = ExampleClass() |
|
102 | 102 | ... debugger.Pdb().set_trace() |
|
103 | 103 | |
|
104 | 104 | >>> with PdbTestInput([ |
|
105 | 105 | ... 'pdef example_function', |
|
106 | 106 | ... 'pdoc ExampleClass', |
|
107 | 107 | ... 'up', |
|
108 | 108 | ... 'down', |
|
109 | 109 | ... 'list', |
|
110 | 110 | ... 'pinfo a', |
|
111 | 111 | ... 'll', |
|
112 | 112 | ... 'continue', |
|
113 | 113 | ... ]): |
|
114 | 114 | ... trigger_ipdb() |
|
115 | 115 | --Return-- |
|
116 | 116 | None |
|
117 | 117 | > <doctest ...>(3)trigger_ipdb() |
|
118 | 118 | 1 def trigger_ipdb(): |
|
119 | 119 | 2 a = ExampleClass() |
|
120 | 120 | ----> 3 debugger.Pdb().set_trace() |
|
121 | 121 | <BLANKLINE> |
|
122 | 122 | ipdb> pdef example_function |
|
123 | 123 | example_function(x, y, z='hello') |
|
124 | 124 | ipdb> pdoc ExampleClass |
|
125 | 125 | Class docstring: |
|
126 | 126 | Docstring for ExampleClass. |
|
127 | 127 | Init docstring: |
|
128 | 128 | Docstring for ExampleClass.__init__ |
|
129 | 129 | ipdb> up |
|
130 | 130 | > <doctest ...>(11)<module>() |
|
131 | 131 | 7 'pinfo a', |
|
132 | 132 | 8 'll', |
|
133 | 133 | 9 'continue', |
|
134 | 134 | 10 ]): |
|
135 | 135 | ---> 11 trigger_ipdb() |
|
136 | 136 | <BLANKLINE> |
|
137 | 137 | ipdb> down |
|
138 | 138 | None |
|
139 | 139 | > <doctest ...>(3)trigger_ipdb() |
|
140 | 140 | 1 def trigger_ipdb(): |
|
141 | 141 | 2 a = ExampleClass() |
|
142 | 142 | ----> 3 debugger.Pdb().set_trace() |
|
143 | 143 | <BLANKLINE> |
|
144 | 144 | ipdb> list |
|
145 | 145 | 1 def trigger_ipdb(): |
|
146 | 146 | 2 a = ExampleClass() |
|
147 | 147 | ----> 3 debugger.Pdb().set_trace() |
|
148 | 148 | <BLANKLINE> |
|
149 | 149 | ipdb> pinfo a |
|
150 | 150 | Type: ExampleClass |
|
151 | 151 | String form: ExampleClass() |
|
152 | 152 | Namespace: Local... |
|
153 | 153 | Docstring: Docstring for ExampleClass. |
|
154 | 154 | Init docstring: Docstring for ExampleClass.__init__ |
|
155 | 155 | ipdb> ll |
|
156 | 156 | 1 def trigger_ipdb(): |
|
157 | 157 | 2 a = ExampleClass() |
|
158 | 158 | ----> 3 debugger.Pdb().set_trace() |
|
159 | 159 | <BLANKLINE> |
|
160 | 160 | ipdb> continue |
|
161 | 161 | |
|
162 | 162 | Restore previous trace function, e.g. for coverage.py |
|
163 | 163 | |
|
164 | 164 | >>> sys.settrace(old_trace) |
|
165 | 165 | ''' |
|
166 | 166 | |
|
167 | 167 | def test_ipdb_magics2(): |
|
168 | 168 | '''Test ipdb with a very short function. |
|
169 | 169 | |
|
170 | 170 | >>> old_trace = sys.gettrace() |
|
171 | 171 | |
|
172 | 172 | >>> def bar(): |
|
173 | 173 | ... pass |
|
174 | 174 | |
|
175 | 175 | Run ipdb. |
|
176 | 176 | |
|
177 | 177 | >>> with PdbTestInput([ |
|
178 | 178 | ... 'continue', |
|
179 | 179 | ... ]): |
|
180 | 180 | ... debugger.Pdb().runcall(bar) |
|
181 | 181 | > <doctest ...>(2)bar() |
|
182 | 182 | 1 def bar(): |
|
183 | 183 | ----> 2 pass |
|
184 | 184 | <BLANKLINE> |
|
185 | 185 | ipdb> continue |
|
186 | 186 | |
|
187 | 187 | Restore previous trace function, e.g. for coverage.py |
|
188 | 188 | |
|
189 | 189 | >>> sys.settrace(old_trace) |
|
190 | 190 | ''' |
|
191 | 191 | |
|
192 | 192 | def can_quit(): |
|
193 | 193 | '''Test that quit work in ipydb |
|
194 | 194 | |
|
195 | 195 | >>> old_trace = sys.gettrace() |
|
196 | 196 | |
|
197 | 197 | >>> def bar(): |
|
198 | 198 | ... pass |
|
199 | 199 | |
|
200 | 200 | >>> with PdbTestInput([ |
|
201 | 201 | ... 'quit', |
|
202 | 202 | ... ]): |
|
203 | 203 | ... debugger.Pdb().runcall(bar) |
|
204 | 204 | > <doctest ...>(2)bar() |
|
205 | 205 | 1 def bar(): |
|
206 | 206 | ----> 2 pass |
|
207 | 207 | <BLANKLINE> |
|
208 | 208 | ipdb> quit |
|
209 | 209 | |
|
210 | 210 | Restore previous trace function, e.g. for coverage.py |
|
211 | 211 | |
|
212 | 212 | >>> sys.settrace(old_trace) |
|
213 | 213 | ''' |
|
214 | 214 | |
|
215 | 215 | |
|
216 | 216 | def can_exit(): |
|
217 | 217 | '''Test that quit work in ipydb |
|
218 | 218 | |
|
219 | 219 | >>> old_trace = sys.gettrace() |
|
220 | 220 | |
|
221 | 221 | >>> def bar(): |
|
222 | 222 | ... pass |
|
223 | 223 | |
|
224 | 224 | >>> with PdbTestInput([ |
|
225 | 225 | ... 'exit', |
|
226 | 226 | ... ]): |
|
227 | 227 | ... debugger.Pdb().runcall(bar) |
|
228 | 228 | > <doctest ...>(2)bar() |
|
229 | 229 | 1 def bar(): |
|
230 | 230 | ----> 2 pass |
|
231 | 231 | <BLANKLINE> |
|
232 | 232 | ipdb> exit |
|
233 | 233 | |
|
234 | 234 | Restore previous trace function, e.g. for coverage.py |
|
235 | 235 | |
|
236 | 236 | >>> sys.settrace(old_trace) |
|
237 | 237 | ''' |
|
238 | 238 | |
|
239 | 239 | |
|
240 | 240 | def test_interruptible_core_debugger(): |
|
241 | 241 | """The debugger can be interrupted. |
|
242 | 242 | |
|
243 | 243 | The presumption is there is some mechanism that causes a KeyboardInterrupt |
|
244 | 244 | (this is implemented in ipykernel). We want to ensure the |
|
245 | 245 | KeyboardInterrupt cause debugging to cease. |
|
246 | 246 | """ |
|
247 | 247 | def raising_input(msg="", called=[0]): |
|
248 | 248 | called[0] += 1 |
|
249 | 249 | if called[0] == 1: |
|
250 | 250 | raise KeyboardInterrupt() |
|
251 | 251 | else: |
|
252 | 252 | raise AssertionError("input() should only be called once!") |
|
253 | 253 | |
|
254 | 254 | with patch.object(builtins, "input", raising_input): |
|
255 | 255 | debugger.InterruptiblePdb().set_trace() |
|
256 | 256 | # The way this test will fail is by set_trace() never exiting, |
|
257 | 257 | # resulting in a timeout by the test runner. The alternative |
|
258 | 258 | # implementation would involve a subprocess, but that adds issues with |
|
259 | 259 | # interrupting subprocesses that are rather complex, so it's simpler |
|
260 | 260 | # just to do it this way. |
|
261 | 261 | |
|
262 | 262 | @skip_win32 |
|
263 | 263 | def test_xmode_skip(): |
|
264 | 264 | """that xmode skip frames |
|
265 | 265 | |
|
266 | 266 | Not as a doctest as pytest does not run doctests. |
|
267 | 267 | """ |
|
268 | 268 | import pexpect |
|
269 | 269 | env = os.environ.copy() |
|
270 | 270 | env["IPY_TEST_SIMPLE_PROMPT"] = "1" |
|
271 | 271 | |
|
272 | 272 | child = pexpect.spawn( |
|
273 | 273 | sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env |
|
274 | 274 | ) |
|
275 | 275 | child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE |
|
276 | 276 | |
|
277 | 277 | child.expect("IPython") |
|
278 | 278 | child.expect("\n") |
|
279 | 279 | child.expect_exact("In [1]") |
|
280 | 280 | |
|
281 | 281 | block = dedent( |
|
282 | 282 | """ |
|
283 | 283 | def f(): |
|
284 | 284 | __tracebackhide__ = True |
|
285 | 285 | g() |
|
286 | 286 | |
|
287 | 287 | def g(): |
|
288 | 288 | raise ValueError |
|
289 | 289 | |
|
290 | 290 | f() |
|
291 | 291 | """ |
|
292 | 292 | ) |
|
293 | 293 | |
|
294 | 294 | for line in block.splitlines(): |
|
295 | 295 | child.sendline(line) |
|
296 | 296 | child.expect_exact(line) |
|
297 | 297 | child.expect_exact("skipping") |
|
298 | 298 | |
|
299 | 299 | block = dedent( |
|
300 | 300 | """ |
|
301 | 301 | def f(): |
|
302 | 302 | __tracebackhide__ = True |
|
303 | 303 | g() |
|
304 | 304 | |
|
305 | 305 | def g(): |
|
306 | 306 | from IPython.core.debugger import set_trace |
|
307 | 307 | set_trace() |
|
308 | 308 | |
|
309 | 309 | f() |
|
310 | 310 | """ |
|
311 | 311 | ) |
|
312 | 312 | |
|
313 | 313 | for line in block.splitlines(): |
|
314 | 314 | child.sendline(line) |
|
315 | 315 | child.expect_exact(line) |
|
316 | 316 | |
|
317 | 317 | child.expect("ipdb>") |
|
318 | 318 | child.sendline("w") |
|
319 | 319 | child.expect("hidden") |
|
320 | 320 | child.expect("ipdb>") |
|
321 | 321 | child.sendline("skip_hidden false") |
|
322 | 322 | child.sendline("w") |
|
323 | 323 | child.expect("__traceba") |
|
324 | 324 | child.expect("ipdb>") |
|
325 | 325 | |
|
326 | 326 | child.close() |
|
327 | 327 | |
|
328 | 328 | |
|
329 | skip_decorators_blocks = ( | |
|
330 | """ | |
|
331 | def helper_1(): | |
|
332 | pass # should not stop here | |
|
333 | """, | |
|
334 | """ | |
|
335 | def helper_2(): | |
|
336 | pass # should not stop here | |
|
337 | """, | |
|
338 | """ | |
|
339 | def pdb_skipped_decorator(function): | |
|
340 | def wrapped_fn(*args, **kwargs): | |
|
341 | __debuggerskip__ = True | |
|
342 | helper_1() | |
|
343 | __debuggerskip__ = False | |
|
344 | result = function(*args, **kwargs) | |
|
345 | __debuggerskip__ = True | |
|
346 | helper_2() | |
|
347 | return result | |
|
348 | return wrapped_fn | |
|
349 | """, | |
|
350 | """ | |
|
351 | @pdb_skipped_decorator | |
|
352 | def bar(x, y): | |
|
353 | return x * y | |
|
354 | """, | |
|
355 | """import IPython.terminal.debugger as ipdb""", | |
|
356 | """ | |
|
357 | def f(): | |
|
358 | ipdb.set_trace() | |
|
359 | bar(3, 4) | |
|
360 | """, | |
|
361 | """ | |
|
362 | f() | |
|
363 | """, | |
|
364 | ) | |
|
365 | ||
|
366 | ||
|
367 | def _decorator_skip_setup(): | |
|
368 | import pexpect | |
|
369 | ||
|
370 | env = os.environ.copy() | |
|
371 | env["IPY_TEST_SIMPLE_PROMPT"] = "1" | |
|
372 | ||
|
373 | child = pexpect.spawn( | |
|
374 | sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env | |
|
375 | ) | |
|
376 | child.timeout = 5 * IPYTHON_TESTING_TIMEOUT_SCALE | |
|
377 | ||
|
378 | child.expect("IPython") | |
|
379 | child.expect("\n") | |
|
380 | ||
|
381 | dedented_blocks = [dedent(b).strip() for b in skip_decorators_blocks] | |
|
382 | in_prompt_number = 1 | |
|
383 | for cblock in dedented_blocks: | |
|
384 | child.expect_exact(f"In [{in_prompt_number}]:") | |
|
385 | in_prompt_number += 1 | |
|
386 | for line in cblock.splitlines(): | |
|
387 | child.sendline(line) | |
|
388 | child.expect_exact(line) | |
|
389 | child.sendline("") | |
|
390 | return child | |
|
391 | ||
|
392 | ||
|
393 | @skip_win32 | |
|
394 | def test_decorator_skip(): | |
|
395 | """test that decorator frames can be skipped.""" | |
|
396 | ||
|
397 | child = _decorator_skip_setup() | |
|
398 | ||
|
399 | child.expect_exact("3 bar(3, 4)") | |
|
400 | child.expect("ipdb>") | |
|
401 | ||
|
402 | child.expect("ipdb>") | |
|
403 | child.sendline("step") | |
|
404 | child.expect_exact("step") | |
|
405 | ||
|
406 | child.expect_exact("1 @pdb_skipped_decorator") | |
|
407 | ||
|
408 | child.sendline("s") | |
|
409 | child.expect_exact("return x * y") | |
|
410 | ||
|
411 | child.close() | |
|
412 | ||
|
413 | ||
|
414 | @skip_win32 | |
|
415 | def test_decorator_skip_disabled(): | |
|
416 | """test that decorator frame skipping can be disabled""" | |
|
417 | ||
|
418 | child = _decorator_skip_setup() | |
|
419 | ||
|
420 | child.expect_exact("3 bar(3, 4)") | |
|
421 | ||
|
422 | for input_, expected in [ | |
|
423 | ("skip_predicates debuggerskip False", ""), | |
|
424 | ("skip_predicates", "debuggerskip : False"), | |
|
425 | ("step", "---> 2 def wrapped_fn"), | |
|
426 | ("step", "----> 3 __debuggerskip__"), | |
|
427 | ("step", "----> 4 helper_1()"), | |
|
428 | ("step", "---> 1 def helper_1():"), | |
|
429 | ("next", "----> 2 pass"), | |
|
430 | ("next", "--Return--"), | |
|
431 | ("next", "----> 5 __debuggerskip__ = False"), | |
|
432 | ]: | |
|
433 | child.expect("ipdb>") | |
|
434 | child.sendline(input_) | |
|
435 | child.expect_exact(input_) | |
|
436 | child.expect_exact(expected) | |
|
437 | ||
|
438 | child.close() | |
|
439 | ||
|
440 | ||
|
329 | 441 | @skip_win32 |
|
330 | 442 | def test_where_erase_value(): |
|
331 | 443 | """Test that `where` does not access f_locals and erase values.""" |
|
332 | 444 | import pexpect |
|
333 | 445 | |
|
334 | 446 | env = os.environ.copy() |
|
335 | 447 | env["IPY_TEST_SIMPLE_PROMPT"] = "1" |
|
336 | 448 | |
|
337 | 449 | child = pexpect.spawn( |
|
338 | 450 | sys.executable, ["-m", "IPython", "--colors=nocolor"], env=env |
|
339 | 451 | ) |
|
340 | 452 | child.timeout = 15 * IPYTHON_TESTING_TIMEOUT_SCALE |
|
341 | 453 | |
|
342 | 454 | child.expect("IPython") |
|
343 | 455 | child.expect("\n") |
|
344 | 456 | child.expect_exact("In [1]") |
|
345 | 457 | |
|
346 | 458 | block = dedent( |
|
347 | 459 | """ |
|
348 | 460 | def simple_f(): |
|
349 | 461 | myvar = 1 |
|
350 | 462 | print(myvar) |
|
351 | 463 | 1/0 |
|
352 | 464 | print(myvar) |
|
353 | 465 | simple_f() """ |
|
354 | 466 | ) |
|
355 | 467 | |
|
356 | 468 | for line in block.splitlines(): |
|
357 | 469 | child.sendline(line) |
|
358 | 470 | child.expect_exact(line) |
|
359 | 471 | child.expect_exact("ZeroDivisionError") |
|
360 | 472 | child.expect_exact("In [2]:") |
|
361 | 473 | |
|
362 | 474 | child.sendline("%debug") |
|
363 | 475 | |
|
364 | 476 | ## |
|
365 | 477 | child.expect("ipdb>") |
|
366 | 478 | |
|
367 | 479 | child.sendline("myvar") |
|
368 | 480 | child.expect("1") |
|
369 | 481 | |
|
370 | 482 | ## |
|
371 | 483 | child.expect("ipdb>") |
|
372 | 484 | |
|
373 | 485 | child.sendline("myvar = 2") |
|
374 | 486 | |
|
375 | 487 | ## |
|
376 | 488 | child.expect_exact("ipdb>") |
|
377 | 489 | |
|
378 | 490 | child.sendline("myvar") |
|
379 | 491 | |
|
380 | 492 | child.expect_exact("2") |
|
381 | 493 | |
|
382 | 494 | ## |
|
383 | 495 | child.expect("ipdb>") |
|
384 | 496 | child.sendline("where") |
|
385 | 497 | |
|
386 | 498 | ## |
|
387 | 499 | child.expect("ipdb>") |
|
388 | 500 | child.sendline("myvar") |
|
389 | 501 | |
|
390 | 502 | child.expect_exact("2") |
|
391 | 503 | child.expect("ipdb>") |
|
392 | 504 | |
|
393 | 505 | child.close() |
@@ -1,161 +1,159 b'' | |||
|
1 | 1 | import asyncio |
|
2 | 2 | import signal |
|
3 | 3 | import sys |
|
4 | 4 | import threading |
|
5 | 5 | |
|
6 | 6 | from IPython.core.debugger import Pdb |
|
7 | 7 | |
|
8 | 8 | from IPython.core.completer import IPCompleter |
|
9 | 9 | from .ptutils import IPythonPTCompleter |
|
10 | 10 | from .shortcuts import create_ipython_shortcuts, suspend_to_bg, cursor_in_leading_ws |
|
11 | 11 | |
|
12 | 12 | from prompt_toolkit.enums import DEFAULT_BUFFER |
|
13 | 13 | from prompt_toolkit.filters import (Condition, has_focus, has_selection, |
|
14 | 14 | vi_insert_mode, emacs_insert_mode) |
|
15 | 15 | from prompt_toolkit.key_binding import KeyBindings |
|
16 | 16 | from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline |
|
17 | 17 | from pygments.token import Token |
|
18 | 18 | from prompt_toolkit.shortcuts.prompt import PromptSession |
|
19 | 19 | from prompt_toolkit.enums import EditingMode |
|
20 | 20 | from prompt_toolkit.formatted_text import PygmentsTokens |
|
21 | 21 | |
|
22 | 22 | from prompt_toolkit import __version__ as ptk_version |
|
23 | 23 | PTK3 = ptk_version.startswith('3.') |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class TerminalPdb(Pdb): |
|
27 | 27 | """Standalone IPython debugger.""" |
|
28 | 28 | |
|
29 | 29 | def __init__(self, *args, pt_session_options=None, **kwargs): |
|
30 | 30 | Pdb.__init__(self, *args, **kwargs) |
|
31 | 31 | self._ptcomp = None |
|
32 | 32 | self.pt_init(pt_session_options) |
|
33 | 33 | |
|
34 | 34 | def pt_init(self, pt_session_options=None): |
|
35 | 35 | """Initialize the prompt session and the prompt loop |
|
36 | 36 | and store them in self.pt_app and self.pt_loop. |
|
37 | 37 | |
|
38 | 38 | Additional keyword arguments for the PromptSession class |
|
39 | 39 | can be specified in pt_session_options. |
|
40 | 40 | """ |
|
41 | 41 | if pt_session_options is None: |
|
42 | 42 | pt_session_options = {} |
|
43 | 43 | |
|
44 | 44 | def get_prompt_tokens(): |
|
45 | 45 | return [(Token.Prompt, self.prompt)] |
|
46 | 46 | |
|
47 | 47 | if self._ptcomp is None: |
|
48 | 48 | compl = IPCompleter(shell=self.shell, |
|
49 | 49 | namespace={}, |
|
50 | 50 | global_namespace={}, |
|
51 | 51 | parent=self.shell, |
|
52 | 52 | ) |
|
53 | 53 | # add a completer for all the do_ methods |
|
54 | 54 | methods_names = [m[3:] for m in dir(self) if m.startswith("do_")] |
|
55 | 55 | |
|
56 | 56 | def gen_comp(self, text): |
|
57 | 57 | return [m for m in methods_names if m.startswith(text)] |
|
58 | 58 | import types |
|
59 | 59 | newcomp = types.MethodType(gen_comp, compl) |
|
60 | 60 | compl.custom_matchers.insert(0, newcomp) |
|
61 | 61 | # end add completer. |
|
62 | 62 | |
|
63 | 63 | self._ptcomp = IPythonPTCompleter(compl) |
|
64 | 64 | |
|
65 | 65 | options = dict( |
|
66 | 66 | message=(lambda: PygmentsTokens(get_prompt_tokens())), |
|
67 | 67 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
|
68 | 68 | key_bindings=create_ipython_shortcuts(self.shell), |
|
69 | 69 | history=self.shell.debugger_history, |
|
70 | 70 | completer=self._ptcomp, |
|
71 | 71 | enable_history_search=True, |
|
72 | 72 | mouse_support=self.shell.mouse_support, |
|
73 | 73 | complete_style=self.shell.pt_complete_style, |
|
74 |
style=self.shell |
|
|
74 | style=getattr(self.shell, "style", None), | |
|
75 | 75 | color_depth=self.shell.color_depth, |
|
76 | 76 | ) |
|
77 | 77 | |
|
78 | 78 | if not PTK3: |
|
79 | 79 | options['inputhook'] = self.shell.inputhook |
|
80 | 80 | options.update(pt_session_options) |
|
81 | 81 | self.pt_loop = asyncio.new_event_loop() |
|
82 | 82 | self.pt_app = PromptSession(**options) |
|
83 | 83 | |
|
84 | 84 | def cmdloop(self, intro=None): |
|
85 | 85 | """Repeatedly issue a prompt, accept input, parse an initial prefix |
|
86 | 86 | off the received input, and dispatch to action methods, passing them |
|
87 | 87 | the remainder of the line as argument. |
|
88 | 88 | |
|
89 | 89 | override the same methods from cmd.Cmd to provide prompt toolkit replacement. |
|
90 | 90 | """ |
|
91 | 91 | if not self.use_rawinput: |
|
92 | 92 | raise ValueError('Sorry ipdb does not support use_rawinput=False') |
|
93 | 93 | |
|
94 | 94 | # In order to make sure that prompt, which uses asyncio doesn't |
|
95 | 95 | # interfere with applications in which it's used, we always run the |
|
96 | 96 | # prompt itself in a different thread (we can't start an event loop |
|
97 | 97 | # within an event loop). This new thread won't have any event loop |
|
98 | 98 | # running, and here we run our prompt-loop. |
|
99 | ||
|
100 | 99 | self.preloop() |
|
101 | 100 | |
|
102 | 101 | try: |
|
103 | 102 | if intro is not None: |
|
104 | 103 | self.intro = intro |
|
105 | 104 | if self.intro: |
|
106 | 105 | self.stdout.write(str(self.intro)+"\n") |
|
107 | 106 | stop = None |
|
108 | 107 | while not stop: |
|
109 | 108 | if self.cmdqueue: |
|
110 | 109 | line = self.cmdqueue.pop(0) |
|
111 | 110 | else: |
|
112 | 111 | self._ptcomp.ipy_completer.namespace = self.curframe_locals |
|
113 | 112 | self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals |
|
114 | 113 | |
|
115 | 114 | # Run the prompt in a different thread. |
|
116 | 115 | line = '' |
|
117 | 116 | keyboard_interrupt = False |
|
118 | 117 | |
|
119 | 118 | def in_thread(): |
|
120 | 119 | nonlocal line, keyboard_interrupt |
|
121 | 120 | try: |
|
122 | 121 | line = self.pt_app.prompt() |
|
123 | 122 | except EOFError: |
|
124 | 123 | line = 'EOF' |
|
125 | 124 | except KeyboardInterrupt: |
|
126 | 125 | keyboard_interrupt = True |
|
127 | 126 | |
|
128 | 127 | th = threading.Thread(target=in_thread) |
|
129 | 128 | th.start() |
|
130 | 129 | th.join() |
|
131 | 130 | |
|
132 | 131 | if keyboard_interrupt: |
|
133 | 132 | raise KeyboardInterrupt |
|
134 | ||
|
135 | 133 | line = self.precmd(line) |
|
136 | 134 | stop = self.onecmd(line) |
|
137 | 135 | stop = self.postcmd(stop, line) |
|
138 | 136 | self.postloop() |
|
139 | 137 | except Exception: |
|
140 | 138 | raise |
|
141 | 139 | |
|
142 | 140 | |
|
143 | 141 | def set_trace(frame=None): |
|
144 | 142 | """ |
|
145 | 143 | Start debugging from `frame`. |
|
146 | 144 | |
|
147 | 145 | If frame is not specified, debugging starts from caller's frame. |
|
148 | 146 | """ |
|
149 | 147 | TerminalPdb().set_trace(frame or sys._getframe().f_back) |
|
150 | 148 | |
|
151 | 149 | |
|
152 | 150 | if __name__ == '__main__': |
|
153 | 151 | import pdb |
|
154 | 152 | # IPython.core.debugger.Pdb.trace_dispatch shall not catch |
|
155 | 153 | # bdb.BdbQuit. When started through __main__ and an exception |
|
156 | 154 | # happened after hitting "c", this is needed in order to |
|
157 | 155 | # be able to quit the debugging session (see #9950). |
|
158 | 156 | old_trace_dispatch = pdb.Pdb.trace_dispatch |
|
159 | 157 | pdb.Pdb = TerminalPdb |
|
160 | 158 | pdb.Pdb.trace_dispatch = old_trace_dispatch |
|
161 | 159 | pdb.main() |
@@ -1,1563 +1,1564 b'' | |||
|
1 | 1 | ============ |
|
2 | 2 | 7.x Series |
|
3 | 3 | ============ |
|
4 | 4 | |
|
5 | ||
|
5 | 6 | .. _version 7.28: |
|
6 | 7 | |
|
7 | 8 | IPython 7.28 |
|
8 | 9 | ============ |
|
9 | 10 | |
|
10 | 11 | |
|
11 | 12 | IPython 7.28 is again a minor release that mostly bring bugfixes, and couple of |
|
12 | 13 | improvement. Many thanks to MrMino, who again did all the work this month, and |
|
13 | 14 | made a number of documentation improvements. |
|
14 | 15 | |
|
15 | 16 | Here is a non-exhaustive list of changes, |
|
16 | 17 | |
|
17 | 18 | Fixes: |
|
18 | 19 | |
|
19 | 20 | - async with doesn't allow newlines :ghpull:`13090` |
|
20 | 21 | - Dynamically changing to vi mode via %config magic) :ghpull:`13091` |
|
21 | 22 | |
|
22 | 23 | Virtualenv handling fixes: |
|
23 | 24 | |
|
24 | 25 | - init_virtualenv now uses Pathlib :ghpull:`12548` |
|
25 | 26 | - Fix Improper path comparison of virtualenv directories :ghpull:`13140` |
|
26 | 27 | - Fix virtual environment user warning for lower case pathes :ghpull:`13094` |
|
27 | 28 | - Adapt to all sorts of drive names for cygwin :ghpull:`13153` |
|
28 | 29 | |
|
29 | 30 | New Features: |
|
30 | 31 | |
|
31 | 32 | - enable autoplay in embed YouTube player :ghpull:`13133` |
|
32 | 33 | |
|
33 | 34 | Documentation: |
|
34 | 35 | |
|
35 | 36 | - Fix formatting for the core.interactiveshell documentation :ghpull:`13118` |
|
36 | 37 | - Fix broken ipyparallel's refs :ghpull:`13138` |
|
37 | 38 | - Improve formatting of %time documentation :ghpull:`13125` |
|
38 | 39 | - Reword the YouTubeVideo autoplay WN :ghpull:`13147` |
|
39 | 40 | |
|
40 | 41 | |
|
41 | 42 | Thanks |
|
42 | 43 | ------ |
|
43 | 44 | |
|
44 | 45 | Many thanks to all the contributors to this release. You can find all individual |
|
45 | 46 | contributions to this milestone `on github |
|
46 | 47 | <https://github.com/ipython/ipython/milestone/92>`__. |
|
47 | 48 | |
|
48 | 49 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
49 | 50 | work on IPython and related libraries. |
|
50 | 51 | |
|
51 | 52 | |
|
52 | 53 | .. _version 7.27: |
|
53 | 54 | |
|
54 | 55 | IPython 7.27 |
|
55 | 56 | ============ |
|
56 | 57 | |
|
57 | 58 | IPython 7.27 is a minor release that fixes a couple of issues and compatibility. |
|
58 | 59 | |
|
59 | 60 | - Add support for GTK4 :ghpull:`131011` |
|
60 | 61 | - Add support for Qt6 :ghpull:`13085` |
|
61 | 62 | - Fix an issue with pip magic on windows :ghpull:`13093` |
|
62 | 63 | |
|
63 | 64 | Thanks |
|
64 | 65 | ------ |
|
65 | 66 | |
|
66 | 67 | Many thanks to all the contributors to this release. You can find all individual |
|
67 | 68 | contributions to this milestone `on github |
|
68 | 69 | <https://github.com/ipython/ipython/milestone/91>`__. |
|
69 | 70 | |
|
70 | 71 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
71 | 72 | work on IPython and related libraries. |
|
72 | 73 | |
|
73 | 74 | .. _version 7.26: |
|
74 | 75 | |
|
75 | 76 | IPython 7.26 |
|
76 | 77 | ============ |
|
77 | 78 | |
|
78 | 79 | IPython 7.26 is a minor release that fixes a couple of issues, updates in API |
|
79 | 80 | and Copyright/Licenses issues around various part of the codebase. |
|
80 | 81 | |
|
81 | 82 | We'll highlight `this issue <https://github.com/ipython/ipython/issues/13039>` |
|
82 | 83 | pointing out we were including and refereeing to code from Stack Overflow which |
|
83 | 84 | was CC-BY-SA, hence incompatible with the BSD license of IPython. This lead us |
|
84 | 85 | to a rewriting of the corresponding logic which in our case was done in a more |
|
85 | 86 | efficient way (in our case we were searching string prefixes instead of full |
|
86 | 87 | strings). |
|
87 | 88 | |
|
88 | 89 | You will notice also a number of documentation improvements and cleanup. |
|
89 | 90 | |
|
90 | 91 | Of particular interest are the following Pull-requests: |
|
91 | 92 | |
|
92 | 93 | |
|
93 | 94 | - The IPython directive now uses Sphinx logging for warnings. :ghpull:`13030`. |
|
94 | 95 | - Add expiry days option to pastebin magic and change http protocol to https. |
|
95 | 96 | :ghpull:`13056` |
|
96 | 97 | - Make Ipython.utils.timing work with jupyterlite :ghpull:`13050`. |
|
97 | 98 | |
|
98 | 99 | |
|
99 | 100 | |
|
100 | 101 | Thanks |
|
101 | 102 | ------ |
|
102 | 103 | |
|
103 | 104 | Many thanks to all the contributors to this release and in particular MrMino who |
|
104 | 105 | is doing most of the work those days. You can find all individual contributions |
|
105 | 106 | to this milestone `on github <https://github.com/ipython/ipython/milestone/90>`__. |
|
106 | 107 | |
|
107 | 108 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
108 | 109 | work on IPython and related libraries. |
|
109 | 110 | |
|
110 | 111 | |
|
111 | 112 | .. _version 7.25: |
|
112 | 113 | |
|
113 | 114 | IPython 7.25 |
|
114 | 115 | ============ |
|
115 | 116 | |
|
116 | 117 | IPython 7.25 is a minor release that contains a single bugfix, which is highly |
|
117 | 118 | recommended for all users of ipdb, ipython debugger %debug magic and similar. |
|
118 | 119 | |
|
119 | 120 | Issuing commands like ``where`` from within the debugger would reset the |
|
120 | 121 | local variables changes made by the user. It is interesting to look at the root |
|
121 | 122 | cause of the issue as accessing an attribute (``frame.f_locals``) would trigger |
|
122 | 123 | this side effects. |
|
123 | 124 | |
|
124 | 125 | Thanks in particular to the patience from the reporters at D.E. Shaw for their |
|
125 | 126 | initial bug report that was due to a similar coding oversight in an extension, |
|
126 | 127 | and who took time to debug and narrow down the problem. |
|
127 | 128 | |
|
128 | 129 | Thanks |
|
129 | 130 | ------ |
|
130 | 131 | |
|
131 | 132 | Many thanks to all the contributors to this release you can find all individual |
|
132 | 133 | contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/89>`__. |
|
133 | 134 | |
|
134 | 135 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
135 | 136 | work on IPython and related libraries. |
|
136 | 137 | |
|
137 | 138 | |
|
138 | 139 | .. _version 7.24: |
|
139 | 140 | |
|
140 | 141 | IPython 7.24 |
|
141 | 142 | ============ |
|
142 | 143 | |
|
143 | 144 | Third release of IPython for 2021, mostly containing bug fixes. A couple of not |
|
144 | 145 | typical updates: |
|
145 | 146 | |
|
146 | 147 | Misc |
|
147 | 148 | ---- |
|
148 | 149 | |
|
149 | 150 | |
|
150 | 151 | - Fix an issue where ``%recall`` would both succeeded and print an error message |
|
151 | 152 | it failed. :ghpull:`12952` |
|
152 | 153 | - Drop support for NumPy 1.16 β practically has no effect beyond indicating in |
|
153 | 154 | package metadata that we do not support it. :ghpull:`12937` |
|
154 | 155 | |
|
155 | 156 | Debugger improvements |
|
156 | 157 | --------------------- |
|
157 | 158 | |
|
158 | 159 | The debugger (and ``%debug`` magic) have been improved and can skip or hide frames |
|
159 | 160 | originating from files that are not writable to the user, as these are less |
|
160 | 161 | likely to be the source of errors, or be part of system files this can be a useful |
|
161 | 162 | addition when debugging long errors. |
|
162 | 163 | |
|
163 | 164 | In addition to the global ``skip_hidden True|False`` command, the debugger has |
|
164 | 165 | gained finer grained control of predicates as to whether to a frame should be |
|
165 | 166 | considered hidden. So far 3 predicates are available : |
|
166 | 167 | |
|
167 | 168 | - ``tbhide``: frames containing the local variable ``__tracebackhide__`` set to |
|
168 | 169 | True. |
|
169 | 170 | - ``readonly``: frames originating from readonly files, set to False. |
|
170 | 171 | - ``ipython_internal``: frames that are likely to be from IPython internal |
|
171 | 172 | code, set to True. |
|
172 | 173 | |
|
173 | 174 | You can toggle individual predicates during a session with |
|
174 | 175 | |
|
175 | 176 | .. code-block:: |
|
176 | 177 | |
|
177 | 178 | ipdb> skip_predicates readonly True |
|
178 | 179 | |
|
179 | 180 | Read-only files will now be considered hidden frames. |
|
180 | 181 | |
|
181 | 182 | |
|
182 | 183 | You can call ``skip_predicates`` without arguments to see the states of current |
|
183 | 184 | predicates: |
|
184 | 185 | |
|
185 | 186 | .. code-block:: |
|
186 | 187 | |
|
187 | 188 | ipdb> skip_predicates |
|
188 | 189 | current predicates: |
|
189 | 190 | tbhide : True |
|
190 | 191 | readonly : False |
|
191 | 192 | ipython_internal : True |
|
192 | 193 | |
|
193 | 194 | If all predicates are set to ``False``, ``skip_hidden`` will practically have |
|
194 | 195 | no effect. We attempt to warn you when all predicates are False. |
|
195 | 196 | |
|
196 | 197 | Note that the ``readonly`` predicate may increase disk access as we check for |
|
197 | 198 | file access permission for all frames on many command invocation, but is usually |
|
198 | 199 | cached by operating systems. Let us know if you encounter any issues. |
|
199 | 200 | |
|
200 | 201 | As the IPython debugger does not use the traitlets infrastructure for |
|
201 | 202 | configuration, by editing your ``.pdbrc`` files and appending commands you would |
|
202 | 203 | like to be executed just before entering the interactive prompt. For example: |
|
203 | 204 | |
|
204 | 205 | |
|
205 | 206 | .. code:: |
|
206 | 207 | |
|
207 | 208 | # file : ~/.pdbrc |
|
208 | 209 | skip_predicates readonly True |
|
209 | 210 | skip_predicates tbhide False |
|
210 | 211 | |
|
211 | 212 | Will hide read only frames by default and show frames marked with |
|
212 | 213 | ``__tracebackhide__``. |
|
213 | 214 | |
|
214 | 215 | |
|
215 | 216 | |
|
216 | 217 | |
|
217 | 218 | Thanks |
|
218 | 219 | ------ |
|
219 | 220 | |
|
220 | 221 | Many thanks to all the contributors to this release you can find all individual |
|
221 | 222 | contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/87>`__. |
|
222 | 223 | |
|
223 | 224 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
224 | 225 | work on IPython and related libraries, in particular above mentioned |
|
225 | 226 | improvements to the debugger. |
|
226 | 227 | |
|
227 | 228 | |
|
228 | 229 | |
|
229 | 230 | |
|
230 | 231 | .. _version 7.23: |
|
231 | 232 | |
|
232 | 233 | IPython 7.23 and 7.23.1 |
|
233 | 234 | ======================= |
|
234 | 235 | |
|
235 | 236 | |
|
236 | 237 | Third release of IPython for 2021, mostly containing bug fixes. A couple of not |
|
237 | 238 | typical updates: |
|
238 | 239 | |
|
239 | 240 | - We moved to GitHub actions away from Travis-CI, the transition may not be |
|
240 | 241 | 100% complete (not testing on nightly anymore), but as we ran out of |
|
241 | 242 | Travis-Ci hours on the IPython organisation that was a necessary step. |
|
242 | 243 | :ghpull:`12900`. |
|
243 | 244 | |
|
244 | 245 | - We have a new dependency: ``matplotlib-inline``, which try to extract |
|
245 | 246 | matplotlib inline backend specific behavior. It is available on PyPI and |
|
246 | 247 | conda-forge thus should not be a problem to upgrade to this version. If you |
|
247 | 248 | are a package maintainer that might be an extra dependency to package first. |
|
248 | 249 | :ghpull:`12817` (IPython 7.23.1 fix a typo that made this change fail) |
|
249 | 250 | |
|
250 | 251 | In the addition/new feature category, ``display()`` now have a ``clear=True`` |
|
251 | 252 | option to clear the display if any further outputs arrives, allowing users to |
|
252 | 253 | avoid having to use ``clear_output()`` directly. :ghpull:`12823`. |
|
253 | 254 | |
|
254 | 255 | In bug fixes category, this release fix an issue when printing tracebacks |
|
255 | 256 | containing Unicode characters :ghpull:`12758`. |
|
256 | 257 | |
|
257 | 258 | In code cleanup category :ghpull:`12932` remove usage of some deprecated |
|
258 | 259 | functionality for compatibility with Python 3.10. |
|
259 | 260 | |
|
260 | 261 | |
|
261 | 262 | |
|
262 | 263 | Thanks |
|
263 | 264 | ------ |
|
264 | 265 | |
|
265 | 266 | Many thanks to all the contributors to this release you can find all individual |
|
266 | 267 | contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/86>`__. |
|
267 | 268 | In particular MrMino for responding to almost all new issues, and triaging many |
|
268 | 269 | of the old ones, as well as takluyver, minrk, willingc for reacting quikly when |
|
269 | 270 | we ran out of CI Hours. |
|
270 | 271 | |
|
271 | 272 | Thanks as well to organisations, QuantStack (martinRenou and SylvainCorlay) for |
|
272 | 273 | extracting matplotlib inline backend into its own package, and the `D. E. Shaw group |
|
273 | 274 | <https://deshaw.com/>`__ for sponsoring work on IPython and related libraries. |
|
274 | 275 | |
|
275 | 276 | |
|
276 | 277 | .. _version 7.22: |
|
277 | 278 | |
|
278 | 279 | IPython 7.22 |
|
279 | 280 | ============ |
|
280 | 281 | |
|
281 | 282 | Second release of IPython for 2021, mostly containing bug fixes. Here is a quick |
|
282 | 283 | rundown of the few changes. |
|
283 | 284 | |
|
284 | 285 | - Fix some ``sys.excepthook`` shenanigan when embedding with qt, recommended if |
|
285 | 286 | you β for example β use `napari <https://napari.org>`__. :ghpull:`12842`. |
|
286 | 287 | - Fix bug when using the new ipdb ``%context`` magic :ghpull:`12844` |
|
287 | 288 | - Couples of deprecation cleanup :ghpull:`12868` |
|
288 | 289 | - Update for new dpast.com api if you use the ``%pastbin`` magic. :ghpull:`12712` |
|
289 | 290 | - Remove support for numpy before 1.16. :ghpull:`12836` |
|
290 | 291 | |
|
291 | 292 | |
|
292 | 293 | Thanks |
|
293 | 294 | ------ |
|
294 | 295 | |
|
295 | 296 | We have a new team member that you should see more often on the IPython |
|
296 | 297 | repository, BΕaΕΌej Michalik (@MrMino) have been doing regular contributions to |
|
297 | 298 | IPython, and spent time replying to many issues and guiding new users to the |
|
298 | 299 | codebase; they now have triage permissions to the IPython repository and we'll |
|
299 | 300 | work toward giving them more permission in the future. |
|
300 | 301 | |
|
301 | 302 | Many thanks to all the contributors to this release you can find all individual |
|
302 | 303 | contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/84>`__. |
|
303 | 304 | |
|
304 | 305 | Thanks as well to organisations, QuantStack for working on debugger |
|
305 | 306 | compatibility for Xeus_python, and the `D. E. Shaw group |
|
306 | 307 | <https://deshaw.com/>`__ for sponsoring work on IPython and related libraries. |
|
307 | 308 | |
|
308 | 309 | .. _version 721: |
|
309 | 310 | |
|
310 | 311 | IPython 7.21 |
|
311 | 312 | ============ |
|
312 | 313 | |
|
313 | 314 | IPython 7.21 is the first release we have back on schedule of one release every |
|
314 | 315 | month; it contains a number of minor fixes and improvements, notably, the new |
|
315 | 316 | context command for ipdb |
|
316 | 317 | |
|
317 | 318 | |
|
318 | 319 | New "context" command in ipdb |
|
319 | 320 | ----------------------------- |
|
320 | 321 | |
|
321 | 322 | It is now possible to change the number of lines shown in the backtrace |
|
322 | 323 | information in ipdb using "context" command. :ghpull:`12826` |
|
323 | 324 | |
|
324 | 325 | (thanks @MrMino, there are other improvement from them on master). |
|
325 | 326 | |
|
326 | 327 | Other notable changes in IPython 7.21 |
|
327 | 328 | ------------------------------------- |
|
328 | 329 | |
|
329 | 330 | - Fix some issues on new osx-arm64 :ghpull:`12804`, :ghpull:`12807`. |
|
330 | 331 | - Compatibility with Xeus-Python for debugger protocol, :ghpull:`12809` |
|
331 | 332 | - Misc docs fixes for compatibility and uniformity with Numpydoc. |
|
332 | 333 | :ghpull:`12824` |
|
333 | 334 | |
|
334 | 335 | |
|
335 | 336 | Thanks |
|
336 | 337 | ------ |
|
337 | 338 | |
|
338 | 339 | Many thanks to all the contributors to this release you can find all individual |
|
339 | 340 | contribution to this milestone `on github <https://github.com/ipython/ipython/milestone/83>`__. |
|
340 | 341 | |
|
341 | 342 | |
|
342 | 343 | .. _version 720: |
|
343 | 344 | |
|
344 | 345 | IPython 7.20 |
|
345 | 346 | ============ |
|
346 | 347 | |
|
347 | 348 | IPython 7.20 is the accumulation of 3 month of work on IPython, spacing between |
|
348 | 349 | IPython release have been increased from the usual once a month for various |
|
349 | 350 | reason. |
|
350 | 351 | |
|
351 | 352 | - Mainly as I'm too busy and the effectively sole maintainer, and |
|
352 | 353 | - Second because not much changes happened before mid December. |
|
353 | 354 | |
|
354 | 355 | The main driver for this release was the new version of Jedi 0.18 breaking API; |
|
355 | 356 | which was taken care of in the master branch early in 2020 but not in 7.x as I |
|
356 | 357 | though that by now 8.0 would be out. |
|
357 | 358 | |
|
358 | 359 | The inclusion of a resolver in pip did not help and actually made things worse. |
|
359 | 360 | If usually I would have simply pinned Jedi to ``<0.18``; this is not a solution |
|
360 | 361 | anymore as now pip is free to install Jedi 0.18, and downgrade IPython. |
|
361 | 362 | |
|
362 | 363 | I'll do my best to keep the regular release, but as the 8.0-dev branch and 7.x |
|
363 | 364 | are starting to diverge this is becoming difficult in particular with my limited |
|
364 | 365 | time, so if you have any cycles to spare I'll appreciate your help to respond to |
|
365 | 366 | issues and pushing 8.0 forward. |
|
366 | 367 | |
|
367 | 368 | Here are thus some of the changes for IPython 7.20. |
|
368 | 369 | |
|
369 | 370 | - Support for PyQt5 >= 5.11 :ghpull:`12715` |
|
370 | 371 | - ``%reset`` remove imports more agressively :ghpull:`12718` |
|
371 | 372 | - fix the ``%conda`` magic :ghpull:`12739` |
|
372 | 373 | - compatibility with Jedi 0.18, and bump minimum Jedi version. :ghpull:`12793` |
|
373 | 374 | |
|
374 | 375 | |
|
375 | 376 | .. _version 719: |
|
376 | 377 | |
|
377 | 378 | IPython 7.19 |
|
378 | 379 | ============ |
|
379 | 380 | |
|
380 | 381 | IPython 7.19 accumulative two month of works, bug fixes and improvements, there |
|
381 | 382 | was exceptionally no release last month. |
|
382 | 383 | |
|
383 | 384 | - Fix to restore the ability to specify more than one extension using command |
|
384 | 385 | line flags when using traitlets 5.0 :ghpull:`12543` |
|
385 | 386 | - Docs docs formatting that make the install commands work on zsh |
|
386 | 387 | :ghpull:`12587` |
|
387 | 388 | - Always display the last frame in tracebacks even if hidden with |
|
388 | 389 | ``__tracebackhide__`` :ghpull:`12601` |
|
389 | 390 | - Avoid an issue where a callback can be registered multiple times. |
|
390 | 391 | :ghpull:`12625` |
|
391 | 392 | - Avoid an issue in debugger mode where frames changes could be lost. |
|
392 | 393 | :ghpull:`12627` |
|
393 | 394 | |
|
394 | 395 | - Never hide the frames that invoke a debugger, even if marked as hidden by |
|
395 | 396 | ``__tracebackhide__`` :ghpull:`12631` |
|
396 | 397 | - Fix calling the debugger in a recursive manner :ghpull:`12659` |
|
397 | 398 | |
|
398 | 399 | |
|
399 | 400 | A number of code changes have landed on master and we are getting close to |
|
400 | 401 | enough new features and codebase improvement that a 8.0 start to make sens. |
|
401 | 402 | For downstream packages, please start working on migrating downstream testing |
|
402 | 403 | away from iptest and using pytest, as nose will not work on Python 3.10 and we |
|
403 | 404 | will likely start removing it as a dependency for testing. |
|
404 | 405 | |
|
405 | 406 | .. _version 718: |
|
406 | 407 | |
|
407 | 408 | IPython 7.18 |
|
408 | 409 | ============ |
|
409 | 410 | |
|
410 | 411 | IPython 7.18 is a minor release that mostly contains bugfixes. |
|
411 | 412 | |
|
412 | 413 | - ``CRLF`` is now handled by magics my default; solving some issues due to copy |
|
413 | 414 | pasting on windows. :ghpull:`12475` |
|
414 | 415 | |
|
415 | 416 | - Requiring pexpect ``>=4.3`` as we are Python 3.7+ only and earlier version of |
|
416 | 417 | pexpect will be incompatible. :ghpull:`12510` |
|
417 | 418 | |
|
418 | 419 | - Minimum jedi version is now 0.16. :ghpull:`12488` |
|
419 | 420 | |
|
420 | 421 | |
|
421 | 422 | |
|
422 | 423 | .. _version 717: |
|
423 | 424 | |
|
424 | 425 | IPython 7.17 |
|
425 | 426 | ============ |
|
426 | 427 | |
|
427 | 428 | IPython 7.17 brings a couple of new improvements to API and a couple of user |
|
428 | 429 | facing changes to make the terminal experience more user friendly. |
|
429 | 430 | |
|
430 | 431 | :ghpull:`12407` introduces the ability to pass extra argument to the IPython |
|
431 | 432 | debugger class; this is to help a new project from ``kmaork`` |
|
432 | 433 | (https://github.com/kmaork/madbg) to feature a fully remote debugger. |
|
433 | 434 | |
|
434 | 435 | :ghpull:`12410` finally remove support for 3.6, while the codebase is still |
|
435 | 436 | technically compatible; IPython will not install on Python 3.6. |
|
436 | 437 | |
|
437 | 438 | lots of work on the debugger and hidden frames from ``@impact27`` in |
|
438 | 439 | :ghpull:`12437`, :ghpull:`12445`, :ghpull:`12460` and in particular |
|
439 | 440 | :ghpull:`12453` which make the debug magic more robust at handling spaces. |
|
440 | 441 | |
|
441 | 442 | Biggest API addition is code transformation which is done before code execution; |
|
442 | 443 | IPython allows a number of hooks to catch non-valid Python syntax (magic, prompt |
|
443 | 444 | stripping...etc). Transformers are usually called many time; typically: |
|
444 | 445 | |
|
445 | 446 | - When trying to figure out whether the code is complete and valid (should we |
|
446 | 447 | insert a new line or execute ?) |
|
447 | 448 | - During actual code execution pass before giving the code to Python's |
|
448 | 449 | ``exec``. |
|
449 | 450 | |
|
450 | 451 | This lead to issues when transformer might have had side effects; or do external |
|
451 | 452 | queries. Starting with IPython 7.17 you can expect your transformer to be called |
|
452 | 453 | less time. |
|
453 | 454 | |
|
454 | 455 | Input transformers are now called only once in the execution path of |
|
455 | 456 | `InteractiveShell`, allowing to register transformer that potentially have side |
|
456 | 457 | effects (note that this is not recommended). Internal methods `should_run_async`, and |
|
457 | 458 | `run_cell_async` now take a recommended optional `transformed_cell`, and |
|
458 | 459 | `preprocessing_exc_tuple` parameters that will become mandatory at some point in |
|
459 | 460 | the future; that is to say cells need to be explicitly transformed to be valid |
|
460 | 461 | Python syntax ahead of trying to run them. :ghpull:`12440`; |
|
461 | 462 | |
|
462 | 463 | ``input_transformers`` can now also have an attribute ``has_side_effects`` set |
|
463 | 464 | to `True`, when this attribute is present; this will prevent the transformers |
|
464 | 465 | from being ran when IPython is trying to guess whether the user input is |
|
465 | 466 | complete. Note that this may means you will need to explicitly execute in some |
|
466 | 467 | case where your transformations are now not ran; but will not affect users with |
|
467 | 468 | no custom extensions. |
|
468 | 469 | |
|
469 | 470 | |
|
470 | 471 | API Changes |
|
471 | 472 | ----------- |
|
472 | 473 | |
|
473 | 474 | Change of API and exposed objects automatically detected using `frappuccino |
|
474 | 475 | <https://pypi.org/project/frappuccino/>`_ |
|
475 | 476 | |
|
476 | 477 | |
|
477 | 478 | The following items are new since 7.16.0:: |
|
478 | 479 | |
|
479 | 480 | + IPython.core.interactiveshell.InteractiveShell.get_local_scope(self, stack_depth) |
|
480 | 481 | |
|
481 | 482 | The following signatures differ since 7.16.0:: |
|
482 | 483 | |
|
483 | 484 | - IPython.core.interactiveshell.InteractiveShell.run_cell_async(self, raw_cell, store_history=False, silent=False, shell_futures=True) |
|
484 | 485 | + IPython.core.interactiveshell.InteractiveShell.run_cell_async(self, raw_cell, store_history=False, silent=False, shell_futures=True, *, transformed_cell=None, preprocessing_exc_tuple=None) |
|
485 | 486 | |
|
486 | 487 | - IPython.core.interactiveshell.InteractiveShell.should_run_async(self, raw_cell) |
|
487 | 488 | + IPython.core.interactiveshell.InteractiveShell.should_run_async(self, raw_cell, *, transformed_cell=None, preprocessing_exc_tuple=None) |
|
488 | 489 | |
|
489 | 490 | - IPython.terminal.debugger.TerminalPdb.pt_init(self) |
|
490 | 491 | + IPython.terminal.debugger.TerminalPdb.pt_init(self, pt_session_options=None) |
|
491 | 492 | |
|
492 | 493 | This method was added:: |
|
493 | 494 | |
|
494 | 495 | + IPython.core.interactiveshell.InteractiveShell.get_local_scope |
|
495 | 496 | |
|
496 | 497 | Which is now also present on subclasses:: |
|
497 | 498 | |
|
498 | 499 | + IPython.terminal.embed.InteractiveShellEmbed.get_local_scope |
|
499 | 500 | + IPython.terminal.interactiveshell.TerminalInteractiveShell.get_local_scope |
|
500 | 501 | |
|
501 | 502 | |
|
502 | 503 | .. _version 716: |
|
503 | 504 | |
|
504 | 505 | IPython 7.16 |
|
505 | 506 | ============ |
|
506 | 507 | |
|
507 | 508 | |
|
508 | 509 | The default traceback mode will now skip frames that are marked with |
|
509 | 510 | ``__tracebackhide__ = True`` and show how many traceback frames have been |
|
510 | 511 | skipped. This can be toggled by using :magic:`xmode` with the ``--show`` or |
|
511 | 512 | ``--hide`` attribute. It will have no effect on non verbose traceback modes. |
|
512 | 513 | |
|
513 | 514 | The ipython debugger also now understands ``__tracebackhide__`` as well and will |
|
514 | 515 | skip hidden frames when displaying. Movement up and down the stack will skip the |
|
515 | 516 | hidden frames and will show how many frames were hidden. Internal IPython frames |
|
516 | 517 | are also now hidden by default. The behavior can be changed with the |
|
517 | 518 | ``skip_hidden`` while in the debugger, command and accepts "yes", "no", "true" |
|
518 | 519 | and "false" case insensitive parameters. |
|
519 | 520 | |
|
520 | 521 | |
|
521 | 522 | Misc Noticeable changes: |
|
522 | 523 | ------------------------ |
|
523 | 524 | |
|
524 | 525 | - Exceptions are now (re)raised when running notebooks via the :magic:`%run`, helping to catch issues in workflows and |
|
525 | 526 | pipelines. :ghpull:`12301` |
|
526 | 527 | - Fix inputhook for qt 5.15.0 :ghpull:`12355` |
|
527 | 528 | - Fix wx inputhook :ghpull:`12375` |
|
528 | 529 | - Add handling for malformed pathext env var (Windows) :ghpull:`12367` |
|
529 | 530 | - use $SHELL in system_piped :ghpull:`12360` for uniform behavior with |
|
530 | 531 | ipykernel. |
|
531 | 532 | |
|
532 | 533 | Reproducible Build |
|
533 | 534 | ------------------ |
|
534 | 535 | |
|
535 | 536 | IPython 7.15 reproducible build did not work, so we try again this month |
|
536 | 537 | :ghpull:`12358`. |
|
537 | 538 | |
|
538 | 539 | |
|
539 | 540 | API Changes |
|
540 | 541 | ----------- |
|
541 | 542 | |
|
542 | 543 | Change of API and exposed objects automatically detected using `frappuccino |
|
543 | 544 | <https://pypi.org/project/frappuccino/>`_ (still in beta): |
|
544 | 545 | |
|
545 | 546 | |
|
546 |
The following items are new and mostly related to understanding ``__traceback |
|
|
547 | The following items are new and mostly related to understanding ``__tracebackhide__``:: | |
|
547 | 548 | |
|
548 | 549 | + IPython.core.debugger.Pdb.do_down(self, arg) |
|
549 | 550 | + IPython.core.debugger.Pdb.do_skip_hidden(self, arg) |
|
550 | 551 | + IPython.core.debugger.Pdb.do_up(self, arg) |
|
551 | 552 | + IPython.core.debugger.Pdb.hidden_frames(self, stack) |
|
552 | 553 | + IPython.core.debugger.Pdb.stop_here(self, frame) |
|
553 | 554 | |
|
554 | 555 | |
|
555 | 556 | The following items have been removed:: |
|
556 | 557 | |
|
557 | 558 | - IPython.core.debugger.Pdb.new_do_down |
|
558 | 559 | - IPython.core.debugger.Pdb.new_do_up |
|
559 | 560 | |
|
560 | 561 | Those were implementation details. |
|
561 | 562 | |
|
562 | 563 | |
|
563 | 564 | .. _version 715: |
|
564 | 565 | |
|
565 | 566 | IPython 7.15 |
|
566 | 567 | ============ |
|
567 | 568 | |
|
568 | 569 | IPython 7.15 brings a number of bug fixes and user facing improvements. |
|
569 | 570 | |
|
570 | 571 | Misc Noticeable changes: |
|
571 | 572 | ------------------------ |
|
572 | 573 | |
|
573 | 574 | - Long completion name have better elision in terminal :ghpull:`12284` |
|
574 | 575 | - I've started to test on Python 3.9 :ghpull:`12307` and fix some errors. |
|
575 | 576 | - Hi DPI scaling of figures when using qt eventloop :ghpull:`12314` |
|
576 | 577 | - Document the ability to have systemwide configuration for IPython. |
|
577 | 578 | :ghpull:`12328` |
|
578 | 579 | - Fix issues with input autoformatting :ghpull:`12336` |
|
579 | 580 | - ``IPython.core.debugger.Pdb`` is now interruptible (:ghpull:`12168`, in 7.14 |
|
580 | 581 | but forgotten in release notes) |
|
581 | 582 | - Video HTML attributes (:ghpull:`12212`, in 7.14 but forgotten in release |
|
582 | 583 | notes) |
|
583 | 584 | |
|
584 | 585 | Reproducible Build |
|
585 | 586 | ------------------ |
|
586 | 587 | |
|
587 | 588 | Starting with IPython 7.15, I am attempting to provide reproducible builds, |
|
588 | 589 | that is to say you should be able from the source tree to generate an sdist |
|
589 | 590 | and wheel that are identical byte for byte with the publish version on PyPI. |
|
590 | 591 | |
|
591 | 592 | I've only tested on a couple of machines so far and the process is relatively |
|
592 | 593 | straightforward, so this mean that IPython not only have a deterministic build |
|
593 | 594 | process, but also I have either removed, or put under control all effects of |
|
594 | 595 | the build environments on the final artifact. I encourage you to attempt the |
|
595 | 596 | build process on your machine as documented in :ref:`core_developer_guide` |
|
596 | 597 | and let me know if you do not obtain an identical artifact. |
|
597 | 598 | |
|
598 | 599 | While reproducible builds is critical to check that the supply chain of (open |
|
599 | 600 | source) software has not been compromised, it can also help to speedup many |
|
600 | 601 | of the build processes in large environment (conda, apt...) by allowing |
|
601 | 602 | better caching of intermediate build steps. |
|
602 | 603 | |
|
603 | 604 | Learn more on `<https://reproducible-builds.org/>`_. `Reflections on trusting |
|
604 | 605 | trust <https://dl.acm.org/doi/10.1145/358198.358210>`_ is also one of the |
|
605 | 606 | cornerstone and recommended reads on this subject. |
|
606 | 607 | |
|
607 | 608 | .. note:: |
|
608 | 609 | |
|
609 | 610 | The build commit from which the sdist is generated is also `signed |
|
610 | 611 | <https://en.wikipedia.org/wiki/Digital_signature>`_, so you should be able to |
|
611 | 612 | check it has not been compromised, and the git repository is a `merkle-tree |
|
612 | 613 | <https://en.wikipedia.org/wiki/Merkle_tree>`_, you can check the consistency |
|
613 | 614 | with `git-fsck <https://git-scm.com/docs/git-fsck>`_ which you likely `want |
|
614 | 615 | to enable by default |
|
615 | 616 | <https://gist.github.com/mbbx6spp/14b86437e794bffb4120>`_. |
|
616 | 617 | |
|
617 | 618 | NEP29: Last version to support Python 3.6 |
|
618 | 619 | ----------------------------------------- |
|
619 | 620 | |
|
620 | 621 | IPython 7.15 will be the Last IPython version to officially support Python |
|
621 | 622 | 3.6, as stated by `NumPy Enhancement Proposal 29 |
|
622 | 623 | <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_. Starting with |
|
623 | 624 | next minor version of IPython I may stop testing on Python 3.6 and may stop |
|
624 | 625 | publishing release artifacts that install on Python 3.6 |
|
625 | 626 | |
|
626 | 627 | Highlighted features |
|
627 | 628 | -------------------- |
|
628 | 629 | |
|
629 | 630 | Highlighted features are not new, but seem to not be widely known, this |
|
630 | 631 | section will help you discover in more narrative form what you can do with |
|
631 | 632 | IPython. |
|
632 | 633 | |
|
633 | 634 | Increase Tab Completion Menu Height |
|
634 | 635 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
635 | 636 | |
|
636 | 637 | In terminal IPython it is possible to increase the hight of the tab-completion |
|
637 | 638 | menu. To do so set the value of |
|
638 | 639 | :configtrait:`TerminalInteractiveShell.space_for_menu`, this will reserve more |
|
639 | 640 | space at the bottom of the screen for various kind of menus in IPython including |
|
640 | 641 | tab completion and searching in history. |
|
641 | 642 | |
|
642 | 643 | Autoformat Code in the terminal |
|
643 | 644 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
644 | 645 | |
|
645 | 646 | If you have a preferred code formatter, you can configure IPython to |
|
646 | 647 | reformat your code. Set the value of |
|
647 | 648 | :configtrait:`TerminalInteractiveShell.autoformatter` to for example ``'black'`` |
|
648 | 649 | and IPython will auto format your code when possible. |
|
649 | 650 | |
|
650 | 651 | |
|
651 | 652 | .. _version 714: |
|
652 | 653 | |
|
653 | 654 | IPython 7.14 |
|
654 | 655 | ============ |
|
655 | 656 | |
|
656 | 657 | IPython 7.14 is a minor release that fix a couple of bugs and prepare |
|
657 | 658 | compatibility with new or future versions of some libraries. |
|
658 | 659 | |
|
659 | 660 | Important changes: |
|
660 | 661 | ------------------ |
|
661 | 662 | |
|
662 | 663 | - Fix compatibility with Sphinx 3+ :ghpull:`12235` |
|
663 | 664 | - Remove deprecated matplotlib parameter usage, compatibility with matplotlib |
|
664 | 665 | 3.3+ :`122250` |
|
665 | 666 | |
|
666 | 667 | Misc Changes |
|
667 | 668 | ------------ |
|
668 | 669 | |
|
669 | 670 | - set ``.py`` extension when editing current buffer in vi/emacs. :ghpull:`12167` |
|
670 | 671 | - support for unicode identifiers in ``?``/``??`` :ghpull:`12208` |
|
671 | 672 | - add extra options to the ``Video`` Rich objects :ghpull:`12212` |
|
672 | 673 | - add pretty-printing to ``SimpleNamespace`` :ghpull:`12230` |
|
673 | 674 | |
|
674 | 675 | IPython.core.debugger.Pdb is now interruptible |
|
675 | 676 | ---------------------------------------------- |
|
676 | 677 | |
|
677 | 678 | A ``KeyboardInterrupt`` will now interrupt IPython's extended debugger, in order to make Jupyter able to interrupt it. (:ghpull:`12168`) |
|
678 | 679 | |
|
679 | 680 | Video HTML attributes |
|
680 | 681 | --------------------- |
|
681 | 682 | |
|
682 | 683 | Add an option to `IPython.display.Video` to change the attributes of the HTML display of the video (:ghpull:`12212`) |
|
683 | 684 | |
|
684 | 685 | |
|
685 | 686 | Pending deprecated imports |
|
686 | 687 | -------------------------- |
|
687 | 688 | |
|
688 | 689 | Many object present in ``IPython.core.display`` are there for internal use only, |
|
689 | 690 | and should already been imported from ``IPython.display`` by users and external |
|
690 | 691 | libraries. Trying to import those from ``IPython.core.display`` is still possible |
|
691 | 692 | but will trigger a |
|
692 | 693 | deprecation warning in later versions of IPython and will become errors in the |
|
693 | 694 | future. |
|
694 | 695 | |
|
695 | 696 | This will simplify compatibility with other Python kernels (like Xeus-Python), |
|
696 | 697 | and simplify code base. |
|
697 | 698 | |
|
698 | 699 | |
|
699 | 700 | |
|
700 | 701 | |
|
701 | 702 | .. _version 713: |
|
702 | 703 | |
|
703 | 704 | IPython 7.13 |
|
704 | 705 | ============ |
|
705 | 706 | |
|
706 | 707 | IPython 7.13 is the final release of the 7.x branch since master is diverging |
|
707 | 708 | toward an 8.0. Exiting new features have already been merged in 8.0 and will |
|
708 | 709 | not be available on the 7.x branch. All the changes below have been backported |
|
709 | 710 | from the master branch. |
|
710 | 711 | |
|
711 | 712 | |
|
712 | 713 | - Fix inability to run PDB when inside an event loop :ghpull:`12141` |
|
713 | 714 | - Fix ability to interrupt some processes on windows :ghpull:`12137` |
|
714 | 715 | - Fix debugger shortcuts :ghpull:`12132` |
|
715 | 716 | - improve tab completion when inside a string by removing irrelevant elements :ghpull:`12128` |
|
716 | 717 | - Fix display of filename tab completion when the path is long :ghpull:`12122` |
|
717 | 718 | - Many removal of Python 2 specific code path :ghpull:`12110` |
|
718 | 719 | - displaying wav files do not require NumPy anymore, and is 5x to 30x faster :ghpull:`12113` |
|
719 | 720 | |
|
720 | 721 | See the list of all closed issues and pull request on `github |
|
721 | 722 | <https://github.com/ipython/ipython/pulls?q=is%3Aclosed+milestone%3A7.13>`_. |
|
722 | 723 | |
|
723 | 724 | .. _version 712: |
|
724 | 725 | |
|
725 | 726 | IPython 7.12 |
|
726 | 727 | ============ |
|
727 | 728 | |
|
728 | 729 | IPython 7.12 is a minor update that mostly brings code cleanup, removal of |
|
729 | 730 | longtime deprecated function and a couple update to documentation cleanup as well. |
|
730 | 731 | |
|
731 | 732 | Notable changes are the following: |
|
732 | 733 | |
|
733 | 734 | - Exit non-zero when ipython is given a file path to run that doesn't exist :ghpull:`12074` |
|
734 | 735 | - Test PR on ARM64 with Travis-CI :ghpull:`12073` |
|
735 | 736 | - Update CI to work with latest Pytest :ghpull:`12086` |
|
736 | 737 | - Add infrastructure to run ipykernel eventloop via trio :ghpull:`12097` |
|
737 | 738 | - Support git blame ignore revs :ghpull:`12091` |
|
738 | 739 | - Start multi-line ``__repr__`` s on their own line :ghpull:`12099` |
|
739 | 740 | |
|
740 | 741 | .. _version 7111: |
|
741 | 742 | |
|
742 | 743 | IPython 7.11.1 |
|
743 | 744 | ============== |
|
744 | 745 | |
|
745 | 746 | A couple of deprecated functions (no-op) have been reintroduces in py3compat as |
|
746 | 747 | Cython was still relying on them, and will be removed in a couple of versions. |
|
747 | 748 | |
|
748 | 749 | .. _version 711: |
|
749 | 750 | |
|
750 | 751 | IPython 7.11 |
|
751 | 752 | ============ |
|
752 | 753 | |
|
753 | 754 | IPython 7.11 received a couple of compatibility fixes and code cleanup. |
|
754 | 755 | |
|
755 | 756 | A number of function in the ``py3compat`` have been removed; a number of types |
|
756 | 757 | in the IPython code base are now non-ambiguous and now always ``unicode`` |
|
757 | 758 | instead of ``Union[Unicode,bytes]``; many of the relevant code path have thus |
|
758 | 759 | been simplified/cleaned and types annotation added. |
|
759 | 760 | |
|
760 | 761 | IPython support several verbosity level from exceptions. ``xmode plain`` now |
|
761 | 762 | support chained exceptions. :ghpull:`11999` |
|
762 | 763 | |
|
763 | 764 | We are starting to remove ``shell=True`` in some usages of subprocess. While not directly |
|
764 | 765 | a security issue (as IPython is made to run arbitrary code anyway) it is not good |
|
765 | 766 | practice and we'd like to show the example. :ghissue:`12023`. This discussion |
|
766 | 767 | was started by ``@mschwager`` thanks to a new auditing tool they are working on |
|
767 | 768 | with duo-labs (`dlint <https://github.com/duo-labs/dlint>`_). |
|
768 | 769 | |
|
769 | 770 | Work around some bugs in Python 3.9 tokenizer :ghpull:`12057` |
|
770 | 771 | |
|
771 | 772 | IPython will now print its version after a crash. :ghpull:`11986` |
|
772 | 773 | |
|
773 | 774 | This is likely the last release from the 7.x series that will see new feature. |
|
774 | 775 | The master branch will soon accept large code changes and thrilling new |
|
775 | 776 | features; the 7.x branch will only start to accept critical bug fixes, and |
|
776 | 777 | update dependencies. |
|
777 | 778 | |
|
778 | 779 | .. _version 7102: |
|
779 | 780 | |
|
780 | 781 | IPython 7.10.2 |
|
781 | 782 | ============== |
|
782 | 783 | |
|
783 | 784 | IPython 7.10.2 fix a couple of extra incompatibility between IPython, ipdb, |
|
784 | 785 | asyncio and Prompt Toolkit 3. |
|
785 | 786 | |
|
786 | 787 | .. _version 7101: |
|
787 | 788 | |
|
788 | 789 | IPython 7.10.1 |
|
789 | 790 | ============== |
|
790 | 791 | |
|
791 | 792 | IPython 7.10.1 fix a couple of incompatibilities with Prompt toolkit 3 (please |
|
792 | 793 | update Prompt toolkit to 3.0.2 at least), and fixes some interaction with |
|
793 | 794 | headless IPython. |
|
794 | 795 | |
|
795 | 796 | .. _version 7100: |
|
796 | 797 | |
|
797 | 798 | IPython 7.10.0 |
|
798 | 799 | ============== |
|
799 | 800 | |
|
800 | 801 | IPython 7.10 is the first double digit minor release in the last decade, and |
|
801 | 802 | first since the release of IPython 1.0, previous double digit minor release was |
|
802 | 803 | in August 2009. |
|
803 | 804 | |
|
804 | 805 | We've been trying to give you regular release on the last Friday of every month |
|
805 | 806 | for a guaranty of rapid access to bug fixes and new features. |
|
806 | 807 | |
|
807 | 808 | Unlike the previous first few releases that have seen only a couple of code |
|
808 | 809 | changes, 7.10 bring a number of changes, new features and bugfixes. |
|
809 | 810 | |
|
810 | 811 | Stop Support for Python 3.5 β Adopt NEP 29 |
|
811 | 812 | ------------------------------------------ |
|
812 | 813 | |
|
813 | 814 | IPython has decided to follow the informational `NEP 29 |
|
814 | 815 | <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_ which layout a clear |
|
815 | 816 | policy as to which version of (C)Python and NumPy are supported. |
|
816 | 817 | |
|
817 | 818 | We thus dropped support for Python 3.5, and cleaned up a number of code path |
|
818 | 819 | that were Python-version dependant. If you are on 3.5 or earlier pip should |
|
819 | 820 | automatically give you the latest compatible version of IPython so you do not |
|
820 | 821 | need to pin to a given version. |
|
821 | 822 | |
|
822 | 823 | Support for Prompt Toolkit 3.0 |
|
823 | 824 | ------------------------------ |
|
824 | 825 | |
|
825 | 826 | Prompt Toolkit 3.0 was release a week before IPython 7.10 and introduces a few |
|
826 | 827 | breaking changes. We believe IPython 7.10 should be compatible with both Prompt |
|
827 | 828 | Toolkit 2.x and 3.x, though it has not been extensively tested with 3.x so |
|
828 | 829 | please report any issues. |
|
829 | 830 | |
|
830 | 831 | |
|
831 | 832 | Prompt Rendering Performance improvements |
|
832 | 833 | ----------------------------------------- |
|
833 | 834 | |
|
834 | 835 | Pull Request :ghpull:`11933` introduced an optimisation in the prompt rendering |
|
835 | 836 | logic that should decrease the resource usage of IPython when using the |
|
836 | 837 | _default_ configuration but could potentially introduce a regression of |
|
837 | 838 | functionalities if you are using a custom prompt. |
|
838 | 839 | |
|
839 | 840 | We know assume if you haven't changed the default keybindings that the prompt |
|
840 | 841 | **will not change** during the duration of your input β which is for example |
|
841 | 842 | not true when using vi insert mode that switches between `[ins]` and `[nor]` |
|
842 | 843 | for the current mode. |
|
843 | 844 | |
|
844 | 845 | If you are experiencing any issue let us know. |
|
845 | 846 | |
|
846 | 847 | Code autoformatting |
|
847 | 848 | ------------------- |
|
848 | 849 | |
|
849 | 850 | The IPython terminal can now auto format your code just before entering a new |
|
850 | 851 | line or executing a command. To do so use the |
|
851 | 852 | ``--TerminalInteractiveShell.autoformatter`` option and set it to ``'black'``; |
|
852 | 853 | if black is installed IPython will use black to format your code when possible. |
|
853 | 854 | |
|
854 | 855 | IPython cannot always properly format your code; in particular it will |
|
855 | 856 | auto formatting with *black* will only work if: |
|
856 | 857 | |
|
857 | 858 | - Your code does not contains magics or special python syntax. |
|
858 | 859 | |
|
859 | 860 | - There is no code after your cursor. |
|
860 | 861 | |
|
861 | 862 | The Black API is also still in motion; so this may not work with all versions of |
|
862 | 863 | black. |
|
863 | 864 | |
|
864 | 865 | It should be possible to register custom formatter, though the API is till in |
|
865 | 866 | flux. |
|
866 | 867 | |
|
867 | 868 | Arbitrary Mimetypes Handing in Terminal (Aka inline images in terminal) |
|
868 | 869 | ----------------------------------------------------------------------- |
|
869 | 870 | |
|
870 | 871 | When using IPython terminal it is now possible to register function to handle |
|
871 | 872 | arbitrary mimetypes. While rendering non-text based representation was possible in |
|
872 | 873 | many jupyter frontend; it was not possible in terminal IPython, as usually |
|
873 | 874 | terminal are limited to displaying text. As many terminal these days provide |
|
874 | 875 | escape sequences to display non-text; bringing this loved feature to IPython CLI |
|
875 | 876 | made a lot of sens. This functionality will not only allow inline images; but |
|
876 | 877 | allow opening of external program; for example ``mplayer`` to "display" sound |
|
877 | 878 | files. |
|
878 | 879 | |
|
879 | 880 | So far only the hooks necessary for this are in place, but no default mime |
|
880 | 881 | renderers added; so inline images will only be available via extensions. We will |
|
881 | 882 | progressively enable these features by default in the next few releases, and |
|
882 | 883 | contribution is welcomed. |
|
883 | 884 | |
|
884 | 885 | We welcome any feedback on the API. See :ref:`shell_mimerenderer` for more |
|
885 | 886 | informations. |
|
886 | 887 | |
|
887 | 888 | This is originally based on work form in :ghpull:`10610` from @stephanh42 |
|
888 | 889 | started over two years ago, and still a lot need to be done. |
|
889 | 890 | |
|
890 | 891 | MISC |
|
891 | 892 | ---- |
|
892 | 893 | |
|
893 | 894 | - Completions can define their own ordering :ghpull:`11855` |
|
894 | 895 | - Enable Plotting in the same cell than the one that import matplotlib |
|
895 | 896 | :ghpull:`11916` |
|
896 | 897 | - Allow to store and restore multiple variables at once :ghpull:`11930` |
|
897 | 898 | |
|
898 | 899 | You can see `all pull-requests <https://github.com/ipython/ipython/pulls?q=is%3Apr+milestone%3A7.10+is%3Aclosed>`_ for this release. |
|
899 | 900 | |
|
900 | 901 | API Changes |
|
901 | 902 | ----------- |
|
902 | 903 | |
|
903 | 904 | Change of API and exposed objects automatically detected using `frappuccino <https://pypi.org/project/frappuccino/>`_ (still in beta): |
|
904 | 905 | |
|
905 | 906 | The following items are new in IPython 7.10:: |
|
906 | 907 | |
|
907 | 908 | + IPython.terminal.shortcuts.reformat_text_before_cursor(buffer, document, shell) |
|
908 | 909 | + IPython.terminal.interactiveshell.PTK3 |
|
909 | 910 | + IPython.terminal.interactiveshell.black_reformat_handler(text_before_cursor) |
|
910 | 911 | + IPython.terminal.prompts.RichPromptDisplayHook.write_format_data(self, format_dict, md_dict='None') |
|
911 | 912 | |
|
912 | 913 | The following items have been removed in 7.10:: |
|
913 | 914 | |
|
914 | 915 | - IPython.lib.pretty.DICT_IS_ORDERED |
|
915 | 916 | |
|
916 | 917 | The following signatures differ between versions:: |
|
917 | 918 | |
|
918 | 919 | - IPython.extensions.storemagic.restore_aliases(ip) |
|
919 | 920 | + IPython.extensions.storemagic.restore_aliases(ip, alias='None') |
|
920 | 921 | |
|
921 | 922 | Special Thanks |
|
922 | 923 | -------------- |
|
923 | 924 | |
|
924 | 925 | - @stephanh42 who started the work on inline images in terminal 2 years ago |
|
925 | 926 | - @augustogoulart who spent a lot of time triaging issues and responding to |
|
926 | 927 | users. |
|
927 | 928 | - @con-f-use who is my (@Carreau) first sponsor on GitHub, as a reminder if you |
|
928 | 929 | like IPython, Jupyter and many other library of the SciPy stack you can |
|
929 | 930 | donate to numfocus.org non profit |
|
930 | 931 | |
|
931 | 932 | .. _version 790: |
|
932 | 933 | |
|
933 | 934 | IPython 7.9.0 |
|
934 | 935 | ============= |
|
935 | 936 | |
|
936 | 937 | IPython 7.9 is a small release with a couple of improvement and bug fixes. |
|
937 | 938 | |
|
938 | 939 | - Xterm terminal title should be restored on exit :ghpull:`11910` |
|
939 | 940 | - special variables ``_``,``__``, ``___`` are not set anymore when cache size |
|
940 | 941 | is 0 or less. :ghpull:`11877` |
|
941 | 942 | - Autoreload should have regained some speed by using a new heuristic logic to |
|
942 | 943 | find all objects needing reload. This should avoid large objects traversal |
|
943 | 944 | like pandas dataframes. :ghpull:`11876` |
|
944 | 945 | - Get ready for Python 4. :ghpull:`11874` |
|
945 | 946 | - `%env` Magic now has heuristic to hide potentially sensitive values :ghpull:`11896` |
|
946 | 947 | |
|
947 | 948 | This is a small release despite a number of Pull Request Pending that need to |
|
948 | 949 | be reviewed/worked on. Many of the core developers have been busy outside of |
|
949 | 950 | IPython/Jupyter and we thanks all contributor for their patience; we'll work on |
|
950 | 951 | these as soon as we have time. |
|
951 | 952 | |
|
952 | 953 | |
|
953 | 954 | .. _version780: |
|
954 | 955 | |
|
955 | 956 | IPython 7.8.0 |
|
956 | 957 | ============= |
|
957 | 958 | |
|
958 | 959 | IPython 7.8.0 contain a few bugfix and 2 new APIs: |
|
959 | 960 | |
|
960 | 961 | - Enable changing the font color for LaTeX rendering :ghpull:`11840` |
|
961 | 962 | - and Re-Expose some PDB API (see below) |
|
962 | 963 | |
|
963 | 964 | Expose Pdb API |
|
964 | 965 | -------------- |
|
965 | 966 | |
|
966 | 967 | Expose the built-in ``pdb.Pdb`` API. ``Pdb`` constructor arguments are generically |
|
967 | 968 | exposed, regardless of python version. |
|
968 | 969 | Newly exposed arguments: |
|
969 | 970 | |
|
970 | 971 | - ``skip`` - Python 3.1+ |
|
971 | 972 | - ``nosiginnt`` - Python 3.2+ |
|
972 | 973 | - ``readrc`` - Python 3.6+ |
|
973 | 974 | |
|
974 | 975 | Try it out:: |
|
975 | 976 | |
|
976 | 977 | from IPython.terminal.debugger import TerminalPdb |
|
977 | 978 | pdb = TerminalPdb(skip=["skipthismodule"]) |
|
978 | 979 | |
|
979 | 980 | |
|
980 | 981 | See :ghpull:`11840` |
|
981 | 982 | |
|
982 | 983 | .. _version770: |
|
983 | 984 | |
|
984 | 985 | IPython 7.7.0 |
|
985 | 986 | ============= |
|
986 | 987 | |
|
987 | 988 | IPython 7.7.0 contain multiple bug fixes and documentation updates; Here are a |
|
988 | 989 | few of the outstanding issue fixed: |
|
989 | 990 | |
|
990 | 991 | - Fix a bug introduced in 7.6 where the ``%matplotlib`` magic would fail on |
|
991 | 992 | previously acceptable arguments :ghpull:`11814`. |
|
992 | 993 | - Fix the manage location on freebsd :ghpull:`11808`. |
|
993 | 994 | - Fix error message about aliases after ``%reset`` call in ipykernel |
|
994 | 995 | :ghpull:`11806` |
|
995 | 996 | - Fix Duplication completions in emacs :ghpull:`11803` |
|
996 | 997 | |
|
997 | 998 | We are planning to adopt `NEP29 <https://github.com/numpy/numpy/pull/14086>`_ |
|
998 | 999 | (still currently in draft) which may make this minor version of IPython the |
|
999 | 1000 | last one to support Python 3.5 and will make the code base more aggressive |
|
1000 | 1001 | toward removing compatibility with older versions of Python. |
|
1001 | 1002 | |
|
1002 | 1003 | GitHub now support to give only "Triage" permissions to users; if you'd like to |
|
1003 | 1004 | help close stale issues and labels issues please reach to us with your GitHub |
|
1004 | 1005 | Username and we'll add you to the triage team. It is a great way to start |
|
1005 | 1006 | contributing and a path toward getting commit rights. |
|
1006 | 1007 | |
|
1007 | 1008 | .. _version761: |
|
1008 | 1009 | |
|
1009 | 1010 | IPython 7.6.1 |
|
1010 | 1011 | ============= |
|
1011 | 1012 | |
|
1012 | 1013 | IPython 7.6.1 contain a critical bugfix in the ``%timeit`` magic, which would |
|
1013 | 1014 | crash on some inputs as a side effect of :ghpull:`11716`. See :ghpull:`11812` |
|
1014 | 1015 | |
|
1015 | 1016 | |
|
1016 | 1017 | .. _whatsnew760: |
|
1017 | 1018 | |
|
1018 | 1019 | IPython 7.6.0 |
|
1019 | 1020 | ============= |
|
1020 | 1021 | |
|
1021 | 1022 | IPython 7.6.0 contains a couple of bug fixes and number of small features |
|
1022 | 1023 | additions as well as some compatibility with the current development version of |
|
1023 | 1024 | Python 3.8. |
|
1024 | 1025 | |
|
1025 | 1026 | - Add a ``-l`` option to :magic:`psearch` to list the available search |
|
1026 | 1027 | types. :ghpull:`11672` |
|
1027 | 1028 | - Support ``PathLike`` for ``DisplayObject`` and ``Image``. :ghpull:`11764` |
|
1028 | 1029 | - Configurability of timeout in the test suite for slow platforms. |
|
1029 | 1030 | :ghpull:`11756` |
|
1030 | 1031 | - Accept any casing for matplotlib backend. :ghpull:`121748` |
|
1031 | 1032 | - Properly skip test that requires numpy to be installed :ghpull:`11723` |
|
1032 | 1033 | - More support for Python 3.8 and positional only arguments (pep570) |
|
1033 | 1034 | :ghpull:`11720` |
|
1034 | 1035 | - Unicode names for the completion are loaded lazily on first use which |
|
1035 | 1036 | should decrease startup time. :ghpull:`11693` |
|
1036 | 1037 | - Autoreload now update the types of reloaded objects; this for example allow |
|
1037 | 1038 | pickling of reloaded objects. :ghpull:`11644` |
|
1038 | 1039 | - Fix a bug where ``%%time`` magic would suppress cell output. :ghpull:`11716` |
|
1039 | 1040 | |
|
1040 | 1041 | |
|
1041 | 1042 | Prepare migration to pytest (instead of nose) for testing |
|
1042 | 1043 | --------------------------------------------------------- |
|
1043 | 1044 | |
|
1044 | 1045 | Most of the work between 7.5 and 7.6 was to prepare the migration from our |
|
1045 | 1046 | testing framework to pytest. Most of the test suite should now work by simply |
|
1046 | 1047 | issuing ``pytest`` from the root of the repository. |
|
1047 | 1048 | |
|
1048 | 1049 | The migration to pytest is just at its beginning. Many of our test still rely |
|
1049 | 1050 | on IPython-specific plugins for nose using pytest (doctest using IPython syntax |
|
1050 | 1051 | is one example of this where test appear as "passing", while no code has been |
|
1051 | 1052 | ran). Many test also need to be updated like ``yield-test`` to be properly |
|
1052 | 1053 | parametrized tests. |
|
1053 | 1054 | |
|
1054 | 1055 | Migration to pytest allowed me to discover a number of issues in our test |
|
1055 | 1056 | suite; which was hiding a number of subtle issues βΒ or not actually running |
|
1056 | 1057 | some of the tests in our test suite β I have thus corrected many of those; like |
|
1057 | 1058 | improperly closed resources; or used of deprecated features. I also made use of |
|
1058 | 1059 | the ``pytest --durations=...`` to find some of our slowest test and speed them |
|
1059 | 1060 | up (our test suite can now be up to 10% faster). Pytest as also a variety of |
|
1060 | 1061 | plugins and flags which will make the code quality of IPython and the testing |
|
1061 | 1062 | experience better. |
|
1062 | 1063 | |
|
1063 | 1064 | Misc |
|
1064 | 1065 | ---- |
|
1065 | 1066 | |
|
1066 | 1067 | We skipped the release of 7.6 at the end of May, but will attempt to get back |
|
1067 | 1068 | on schedule. We are starting to think about making introducing backward |
|
1068 | 1069 | incompatible change and start the 8.0 series. |
|
1069 | 1070 | |
|
1070 | 1071 | Special Thanks to Gabriel (@gpotter2 on GitHub), who among other took care many |
|
1071 | 1072 | of the remaining task for 7.4 and 7.5, like updating the website. |
|
1072 | 1073 | |
|
1073 | 1074 | .. _whatsnew750: |
|
1074 | 1075 | |
|
1075 | 1076 | IPython 7.5.0 |
|
1076 | 1077 | ============= |
|
1077 | 1078 | |
|
1078 | 1079 | IPython 7.5.0 consist mostly of bug-fixes, and documentation updates, with one |
|
1079 | 1080 | minor new feature. The `Audio` display element can now be assigned an element |
|
1080 | 1081 | id when displayed in browser. See :ghpull:`11670` |
|
1081 | 1082 | |
|
1082 | 1083 | The major outstanding bug fix correct a change of behavior that was introduce |
|
1083 | 1084 | in 7.4.0 where some cell magics would not be able to access or modify global |
|
1084 | 1085 | scope when using the ``@needs_local_scope`` decorator. This was typically |
|
1085 | 1086 | encountered with the ``%%time`` and ``%%timeit`` magics. See :ghissue:`11659` |
|
1086 | 1087 | and :ghpull:`11698`. |
|
1087 | 1088 | |
|
1088 | 1089 | .. _whatsnew740: |
|
1089 | 1090 | |
|
1090 | 1091 | IPython 7.4.0 |
|
1091 | 1092 | ============= |
|
1092 | 1093 | |
|
1093 | 1094 | Unicode name completions |
|
1094 | 1095 | ------------------------ |
|
1095 | 1096 | |
|
1096 | 1097 | Previously, we provided completion for a unicode name with its relative symbol. |
|
1097 | 1098 | With this, now IPython provides complete suggestions to unicode name symbols. |
|
1098 | 1099 | |
|
1099 | 1100 | As on the PR, if user types ``\LAT<tab>``, IPython provides a list of |
|
1100 | 1101 | possible completions. In this case, it would be something like:: |
|
1101 | 1102 | |
|
1102 | 1103 | 'LATIN CAPITAL LETTER A', |
|
1103 | 1104 | 'LATIN CAPITAL LETTER B', |
|
1104 | 1105 | 'LATIN CAPITAL LETTER C', |
|
1105 | 1106 | 'LATIN CAPITAL LETTER D', |
|
1106 | 1107 | .... |
|
1107 | 1108 | |
|
1108 | 1109 | This help to type unicode character that do not have short latex aliases, and |
|
1109 | 1110 | have long unicode names. for example ``Ν°``, ``\GREEK CAPITAL LETTER HETA``. |
|
1110 | 1111 | |
|
1111 | 1112 | This feature was contributed by Luciana Marques :ghpull:`11583`. |
|
1112 | 1113 | |
|
1113 | 1114 | Make audio normalization optional |
|
1114 | 1115 | --------------------------------- |
|
1115 | 1116 | |
|
1116 | 1117 | Added 'normalize' argument to `IPython.display.Audio`. This argument applies |
|
1117 | 1118 | when audio data is given as an array of samples. The default of `normalize=True` |
|
1118 | 1119 | preserves prior behavior of normalizing the audio to the maximum possible range. |
|
1119 | 1120 | Setting to `False` disables normalization. |
|
1120 | 1121 | |
|
1121 | 1122 | |
|
1122 | 1123 | Miscellaneous |
|
1123 | 1124 | ------------- |
|
1124 | 1125 | |
|
1125 | 1126 | - Fix improper acceptation of ``return`` outside of functions. :ghpull:`11641`. |
|
1126 | 1127 | - Fixed PyQt 5.11 backwards incompatibility causing sip import failure. |
|
1127 | 1128 | :ghpull:`11613`. |
|
1128 | 1129 | - Fix Bug where ``type?`` would crash IPython. :ghpull:`1608`. |
|
1129 | 1130 | - Allow to apply ``@needs_local_scope`` to cell magics for convenience. |
|
1130 | 1131 | :ghpull:`11542`. |
|
1131 | 1132 | |
|
1132 | 1133 | .. _whatsnew730: |
|
1133 | 1134 | |
|
1134 | 1135 | IPython 7.3.0 |
|
1135 | 1136 | ============= |
|
1136 | 1137 | |
|
1137 | 1138 | .. _whatsnew720: |
|
1138 | 1139 | |
|
1139 | 1140 | IPython 7.3.0 bring several bug fixes and small improvements that you will |
|
1140 | 1141 | described bellow. |
|
1141 | 1142 | |
|
1142 | 1143 | The biggest change to this release is the implementation of the ``%conda`` and |
|
1143 | 1144 | ``%pip`` magics, that will attempt to install packages in the **current |
|
1144 | 1145 | environment**. You may still need to restart your interpreter or kernel for the |
|
1145 | 1146 | change to be taken into account, but it should simplify installation of packages |
|
1146 | 1147 | into remote environment. Installing using pip/conda from the command line is |
|
1147 | 1148 | still the prefer method. |
|
1148 | 1149 | |
|
1149 | 1150 | The ``%pip`` magic was already present, but was only printing a warning; now it |
|
1150 | 1151 | will actually forward commands to pip. |
|
1151 | 1152 | |
|
1152 | 1153 | Misc bug fixes and improvements: |
|
1153 | 1154 | |
|
1154 | 1155 | - Compatibility with Python 3.8. |
|
1155 | 1156 | - Do not expand shell variable in execution magics, and added the |
|
1156 | 1157 | ``no_var_expand`` decorator for magic requiring a similar functionality |
|
1157 | 1158 | :ghpull:`11516` |
|
1158 | 1159 | - Add ``%pip`` and ``%conda`` magic :ghpull:`11524` |
|
1159 | 1160 | - Re-initialize posix aliases after a ``%reset`` :ghpull:`11528` |
|
1160 | 1161 | - Allow the IPython command line to run ``*.ipynb`` files :ghpull:`11529` |
|
1161 | 1162 | |
|
1162 | 1163 | IPython 7.2.0 |
|
1163 | 1164 | ============= |
|
1164 | 1165 | |
|
1165 | 1166 | IPython 7.2.0 brings minor bugfixes, improvements, and new configuration options: |
|
1166 | 1167 | |
|
1167 | 1168 | - Fix a bug preventing PySide2 GUI integration from working :ghpull:`11464` |
|
1168 | 1169 | - Run CI on Mac OS ! :ghpull:`11471` |
|
1169 | 1170 | - Fix IPython "Demo" mode. :ghpull:`11498` |
|
1170 | 1171 | - Fix ``%run`` magic with path in name :ghpull:`11499` |
|
1171 | 1172 | - Fix: add CWD to sys.path *after* stdlib :ghpull:`11502` |
|
1172 | 1173 | - Better rendering of signatures, especially long ones. :ghpull:`11505` |
|
1173 | 1174 | - Re-enable jedi by default if it's installed :ghpull:`11506` |
|
1174 | 1175 | - Add New ``minimal`` exception reporting mode (useful for educational purpose). See :ghpull:`11509` |
|
1175 | 1176 | |
|
1176 | 1177 | |
|
1177 | 1178 | Added ability to show subclasses when using pinfo and other utilities |
|
1178 | 1179 | --------------------------------------------------------------------- |
|
1179 | 1180 | |
|
1180 | 1181 | When using ``?``/``??`` on a class, IPython will now list the first 10 subclasses. |
|
1181 | 1182 | |
|
1182 | 1183 | Special Thanks to Chris Mentzel of the Moore Foundation for this feature. Chris |
|
1183 | 1184 | is one of the people who played a critical role in IPython/Jupyter getting |
|
1184 | 1185 | funding. |
|
1185 | 1186 | |
|
1186 | 1187 | We are grateful for all the help Chris has given us over the years, |
|
1187 | 1188 | and we're now proud to have code contributed by Chris in IPython. |
|
1188 | 1189 | |
|
1189 | 1190 | OSMagics.cd_force_quiet configuration option |
|
1190 | 1191 | -------------------------------------------- |
|
1191 | 1192 | |
|
1192 | 1193 | You can set this option to force the %cd magic to behave as if ``-q`` was passed: |
|
1193 | 1194 | :: |
|
1194 | 1195 | |
|
1195 | 1196 | In [1]: cd / |
|
1196 | 1197 | / |
|
1197 | 1198 | |
|
1198 | 1199 | In [2]: %config OSMagics.cd_force_quiet = True |
|
1199 | 1200 | |
|
1200 | 1201 | In [3]: cd /tmp |
|
1201 | 1202 | |
|
1202 | 1203 | In [4]: |
|
1203 | 1204 | |
|
1204 | 1205 | See :ghpull:`11491` |
|
1205 | 1206 | |
|
1206 | 1207 | In vi editing mode, whether the prompt includes the current vi mode can now be configured |
|
1207 | 1208 | ----------------------------------------------------------------------------------------- |
|
1208 | 1209 | |
|
1209 | 1210 | Set the ``TerminalInteractiveShell.prompt_includes_vi_mode`` to a boolean value |
|
1210 | 1211 | (default: True) to control this feature. See :ghpull:`11492` |
|
1211 | 1212 | |
|
1212 | 1213 | .. _whatsnew710: |
|
1213 | 1214 | |
|
1214 | 1215 | IPython 7.1.0 |
|
1215 | 1216 | ============= |
|
1216 | 1217 | |
|
1217 | 1218 | IPython 7.1.0 is the first minor release after 7.0.0 and mostly brings fixes to |
|
1218 | 1219 | new features, internal refactoring, and fixes for regressions that happened during the 6.x->7.x |
|
1219 | 1220 | transition. It also brings **Compatibility with Python 3.7.1**, as we're |
|
1220 | 1221 | unwillingly relying on a bug in CPython. |
|
1221 | 1222 | |
|
1222 | 1223 | New Core Dev: |
|
1223 | 1224 | |
|
1224 | 1225 | - We welcome Jonathan Slenders to the commiters. Jonathan has done a fantastic |
|
1225 | 1226 | work on prompt_toolkit, and we'd like to recognise his impact by giving him |
|
1226 | 1227 | commit rights. :ghissue:`11397` |
|
1227 | 1228 | |
|
1228 | 1229 | Notable Changes |
|
1229 | 1230 | |
|
1230 | 1231 | - Major update of "latex to unicode" tab completion map (see below) |
|
1231 | 1232 | |
|
1232 | 1233 | Notable New Features: |
|
1233 | 1234 | |
|
1234 | 1235 | - Restore functionality and documentation of the **sphinx directive**, which |
|
1235 | 1236 | is now stricter (fail on error by daefault), has new configuration options, |
|
1236 | 1237 | has a brand new documentation page :ref:`ipython_directive` (which needs |
|
1237 | 1238 | some cleanup). It is also now *tested* so we hope to have less regressions. |
|
1238 | 1239 | :ghpull:`11402` |
|
1239 | 1240 | |
|
1240 | 1241 | - ``IPython.display.Video`` now supports ``width`` and ``height`` arguments, |
|
1241 | 1242 | allowing a custom width and height to be set instead of using the video's |
|
1242 | 1243 | width and height. :ghpull:`11353` |
|
1243 | 1244 | |
|
1244 | 1245 | - Warn when using ``HTML('<iframe>')`` instead of ``IFrame`` :ghpull:`11350` |
|
1245 | 1246 | |
|
1246 | 1247 | - Allow Dynamic switching of editing mode between vi/emacs and show |
|
1247 | 1248 | normal/input mode in prompt when using vi. :ghpull:`11390`. Use ``%config |
|
1248 | 1249 | TerminalInteractiveShell.editing_mode = 'vi'`` or ``%config |
|
1249 | 1250 | TerminalInteractiveShell.editing_mode = 'emacs'`` to dynamically switch |
|
1250 | 1251 | between modes. |
|
1251 | 1252 | |
|
1252 | 1253 | |
|
1253 | 1254 | Notable Fixes: |
|
1254 | 1255 | |
|
1255 | 1256 | - Fix entering of **multi-line blocks in terminal** IPython, and various |
|
1256 | 1257 | crashes in the new input transformation machinery :ghpull:`11354`, |
|
1257 | 1258 | :ghpull:`11356`, :ghpull:`11358`. These also fix a **Compatibility bug |
|
1258 | 1259 | with Python 3.7.1**. |
|
1259 | 1260 | |
|
1260 | 1261 | - Fix moving through generator stack in ipdb :ghpull:`11266` |
|
1261 | 1262 | |
|
1262 | 1263 | - %Magic command arguments now support quoting. :ghpull:`11330` |
|
1263 | 1264 | |
|
1264 | 1265 | - Re-add ``rprint`` and ``rprinte`` aliases. :ghpull:`11331` |
|
1265 | 1266 | |
|
1266 | 1267 | - Remove implicit dependency on ``ipython_genutils`` :ghpull:`11317` |
|
1267 | 1268 | |
|
1268 | 1269 | - Make ``nonlocal`` raise ``SyntaxError`` instead of silently failing in async |
|
1269 | 1270 | mode. :ghpull:`11382` |
|
1270 | 1271 | |
|
1271 | 1272 | - Fix mishandling of magics and ``= !`` assignment just after a dedent in |
|
1272 | 1273 | nested code blocks :ghpull:`11418` |
|
1273 | 1274 | |
|
1274 | 1275 | - Fix instructions for custom shortcuts :ghpull:`11426` |
|
1275 | 1276 | |
|
1276 | 1277 | |
|
1277 | 1278 | Notable Internals improvements: |
|
1278 | 1279 | |
|
1279 | 1280 | - Use of ``os.scandir`` (Python 3 only) to speed up some file system operations. |
|
1280 | 1281 | :ghpull:`11365` |
|
1281 | 1282 | |
|
1282 | 1283 | - use ``perf_counter`` instead of ``clock`` for more precise |
|
1283 | 1284 | timing results with ``%time`` :ghpull:`11376` |
|
1284 | 1285 | |
|
1285 | 1286 | Many thanks to all the contributors and in particular to ``bartskowron`` and |
|
1286 | 1287 | ``tonyfast`` who handled some pretty complicated bugs in the input machinery. We |
|
1287 | 1288 | had a number of first time contributors and maybe hacktoberfest participants that |
|
1288 | 1289 | made significant contributions and helped us free some time to focus on more |
|
1289 | 1290 | complicated bugs. |
|
1290 | 1291 | |
|
1291 | 1292 | You |
|
1292 | 1293 | can see all the closed issues and Merged PR, new features and fixes `here |
|
1293 | 1294 | <https://github.com/ipython/ipython/issues?utf8=%E2%9C%93&q=+is%3Aclosed+milestone%3A7.1+>`_. |
|
1294 | 1295 | |
|
1295 | 1296 | Unicode Completion update |
|
1296 | 1297 | ------------------------- |
|
1297 | 1298 | |
|
1298 | 1299 | In IPython 7.1 the Unicode completion map has been updated and synchronized with |
|
1299 | 1300 | the Julia language. |
|
1300 | 1301 | |
|
1301 | 1302 | Added and removed character characters: |
|
1302 | 1303 | |
|
1303 | 1304 | ``\jmath`` (``Θ·``), ``\\underleftrightarrow`` (U+034D, combining) have been |
|
1304 | 1305 | added, while ``\\textasciicaron`` have been removed |
|
1305 | 1306 | |
|
1306 | 1307 | Some sequences have seen their prefix removed: |
|
1307 | 1308 | |
|
1308 | 1309 | - 6 characters ``\text...<tab>`` should now be inputed with ``\...<tab>`` directly, |
|
1309 | 1310 | - 45 characters ``\Elz...<tab>`` should now be inputed with ``\...<tab>`` directly, |
|
1310 | 1311 | - 65 characters ``\B...<tab>`` should now be inputed with ``\...<tab>`` directly, |
|
1311 | 1312 | - 450 characters ``\m...<tab>`` should now be inputed with ``\...<tab>`` directly, |
|
1312 | 1313 | |
|
1313 | 1314 | Some sequences have seen their prefix shortened: |
|
1314 | 1315 | |
|
1315 | 1316 | - 5 characters ``\mitBbb...<tab>`` should now be inputed with ``\bbi...<tab>`` directly, |
|
1316 | 1317 | - 52 characters ``\mit...<tab>`` should now be inputed with ``\i...<tab>`` directly, |
|
1317 | 1318 | - 216 characters ``\mbfit...<tab>`` should now be inputed with ``\bi...<tab>`` directly, |
|
1318 | 1319 | - 222 characters ``\mbf...<tab>`` should now be inputed with ``\b...<tab>`` directly, |
|
1319 | 1320 | |
|
1320 | 1321 | A couple of characters had their sequence simplified: |
|
1321 | 1322 | |
|
1322 | 1323 | - ``Γ°``, type ``\dh<tab>``, instead of ``\eth<tab>`` |
|
1323 | 1324 | - ``Δ§``, type ``\hbar<tab>``, instead of ``\Elzxh<tab>`` |
|
1324 | 1325 | - ``ΙΈ``, type ``\ltphi<tab>``, instead of ``\textphi<tab>`` |
|
1325 | 1326 | - ``Ο΄``, type ``\varTheta<tab>``, instead of ``\textTheta<tab>`` |
|
1326 | 1327 | - ``β``, type ``\eulermascheroni<tab>``, instead of ``\Eulerconst<tab>`` |
|
1327 | 1328 | - ``β``, type ``\planck<tab>``, instead of ``\Planckconst<tab>`` |
|
1328 | 1329 | |
|
1329 | 1330 | - U+0336 (COMBINING LONG STROKE OVERLAY), type ``\strike<tab>``, instead of ``\Elzbar<tab>``. |
|
1330 | 1331 | |
|
1331 | 1332 | A couple of sequences have been updated: |
|
1332 | 1333 | |
|
1333 | 1334 | - ``\varepsilon`` now gives ``Ι`` (GREEK SMALL LETTER EPSILON) instead of ``Ξ΅`` (GREEK LUNATE EPSILON SYMBOL), |
|
1334 | 1335 | - ``\underbar`` now gives U+0331 (COMBINING MACRON BELOW) instead of U+0332 (COMBINING LOW LINE). |
|
1335 | 1336 | |
|
1336 | 1337 | |
|
1337 | 1338 | .. _whatsnew700: |
|
1338 | 1339 | |
|
1339 | 1340 | IPython 7.0.0 |
|
1340 | 1341 | ============= |
|
1341 | 1342 | |
|
1342 | 1343 | Released Thursday September 27th, 2018 |
|
1343 | 1344 | |
|
1344 | 1345 | IPython 7 includes major feature improvements. |
|
1345 | 1346 | This is also the second major version of IPython to support only |
|
1346 | 1347 | Python 3 βΒ starting at Python 3.4. Python 2 is still community-supported |
|
1347 | 1348 | on the bugfix only 5.x branch, but we remind you that Python 2 "end of life" |
|
1348 | 1349 | is on Jan 1st 2020. |
|
1349 | 1350 | |
|
1350 | 1351 | We were able to backport bug fixes to the 5.x branch thanks to our backport bot which |
|
1351 | 1352 | backported more than `70 Pull-Requests |
|
1352 | 1353 | <https://github.com/ipython/ipython/pulls?page=3&q=is%3Apr+sort%3Aupdated-desc+author%3Aapp%2Fmeeseeksdev++5.x&utf8=%E2%9C%93>`_, but there are still many PRs that required manual work. This is an area of the project where you can easily contribute by looking for `PRs that still need manual backport <https://github.com/ipython/ipython/issues?q=label%3A%22Still+Needs+Manual+Backport%22+is%3Aclosed+sort%3Aupdated-desc>`_ |
|
1353 | 1354 | |
|
1354 | 1355 | The IPython 6.x branch will likely not see any further release unless critical |
|
1355 | 1356 | bugs are found. |
|
1356 | 1357 | |
|
1357 | 1358 | Make sure you have pip > 9.0 before upgrading. You should be able to update by running: |
|
1358 | 1359 | |
|
1359 | 1360 | .. code:: |
|
1360 | 1361 | |
|
1361 | 1362 | pip install ipython --upgrade |
|
1362 | 1363 | |
|
1363 | 1364 | .. only:: ipydev |
|
1364 | 1365 | |
|
1365 | 1366 | If you are trying to install or update an ``alpha``, ``beta``, or ``rc`` |
|
1366 | 1367 | version, use pip ``--pre`` flag. |
|
1367 | 1368 | |
|
1368 | 1369 | .. code:: |
|
1369 | 1370 | |
|
1370 | 1371 | pip install ipython --upgrade --pre |
|
1371 | 1372 | |
|
1372 | 1373 | |
|
1373 | 1374 | Or, if you have conda installed: |
|
1374 | 1375 | |
|
1375 | 1376 | .. code:: |
|
1376 | 1377 | |
|
1377 | 1378 | conda install ipython |
|
1378 | 1379 | |
|
1379 | 1380 | |
|
1380 | 1381 | |
|
1381 | 1382 | Prompt Toolkit 2.0 |
|
1382 | 1383 | ------------------ |
|
1383 | 1384 | |
|
1384 | 1385 | IPython 7.0+ now uses ``prompt_toolkit 2.0``. If you still need to use an earlier |
|
1385 | 1386 | ``prompt_toolkit`` version, you may need to pin IPython to ``<7.0``. |
|
1386 | 1387 | |
|
1387 | 1388 | Autowait: Asynchronous REPL |
|
1388 | 1389 | --------------------------- |
|
1389 | 1390 | |
|
1390 | 1391 | Staring with IPython 7.0 on Python 3.6+, IPython can automatically ``await`` |
|
1391 | 1392 | top level code. You should not need to access an event loop or runner |
|
1392 | 1393 | yourself. To learn more, read the :ref:`autoawait` section of our docs, see |
|
1393 | 1394 | :ghpull:`11265`, or try the following code:: |
|
1394 | 1395 | |
|
1395 | 1396 | Python 3.6.0 |
|
1396 | 1397 | Type 'copyright', 'credits' or 'license' for more information |
|
1397 | 1398 | IPython 7.0.0 -- An enhanced Interactive Python. Type '?' for help. |
|
1398 | 1399 | |
|
1399 | 1400 | In [1]: import aiohttp |
|
1400 | 1401 | ...: result = aiohttp.get('https://api.github.com') |
|
1401 | 1402 | |
|
1402 | 1403 | In [2]: response = await result |
|
1403 | 1404 | <pause for a few 100s ms> |
|
1404 | 1405 | |
|
1405 | 1406 | In [3]: await response.json() |
|
1406 | 1407 | Out[3]: |
|
1407 | 1408 | {'authorizations_url': 'https://api.github.com/authorizations', |
|
1408 | 1409 | 'code_search_url': 'https://api.github.com/search/code?q={query}{&page,per_page,sort,order}', |
|
1409 | 1410 | ... |
|
1410 | 1411 | } |
|
1411 | 1412 | |
|
1412 | 1413 | .. note:: |
|
1413 | 1414 | |
|
1414 | 1415 | Async integration is experimental code, behavior may change or be removed |
|
1415 | 1416 | between Python and IPython versions without warnings. |
|
1416 | 1417 | |
|
1417 | 1418 | Integration is by default with `asyncio`, but other libraries can be configured -- |
|
1418 | 1419 | like ``curio`` or ``trio`` -- to improve concurrency in the REPL:: |
|
1419 | 1420 | |
|
1420 | 1421 | In [1]: %autoawait trio |
|
1421 | 1422 | |
|
1422 | 1423 | In [2]: import trio |
|
1423 | 1424 | |
|
1424 | 1425 | In [3]: async def child(i): |
|
1425 | 1426 | ...: print(" child %s goes to sleep"%i) |
|
1426 | 1427 | ...: await trio.sleep(2) |
|
1427 | 1428 | ...: print(" child %s wakes up"%i) |
|
1428 | 1429 | |
|
1429 | 1430 | In [4]: print('parent start') |
|
1430 | 1431 | ...: async with trio.open_nursery() as n: |
|
1431 | 1432 | ...: for i in range(3): |
|
1432 | 1433 | ...: n.spawn(child, i) |
|
1433 | 1434 | ...: print('parent end') |
|
1434 | 1435 | parent start |
|
1435 | 1436 | child 2 goes to sleep |
|
1436 | 1437 | child 0 goes to sleep |
|
1437 | 1438 | child 1 goes to sleep |
|
1438 | 1439 | <about 2 seconds pause> |
|
1439 | 1440 | child 2 wakes up |
|
1440 | 1441 | child 1 wakes up |
|
1441 | 1442 | child 0 wakes up |
|
1442 | 1443 | parent end |
|
1443 | 1444 | |
|
1444 | 1445 | See :ref:`autoawait` for more information. |
|
1445 | 1446 | |
|
1446 | 1447 | |
|
1447 | 1448 | Asynchronous code in a Notebook interface or any other frontend using the |
|
1448 | 1449 | Jupyter Protocol will require further updates to the IPykernel package. |
|
1449 | 1450 | |
|
1450 | 1451 | Non-Asynchronous code |
|
1451 | 1452 | ~~~~~~~~~~~~~~~~~~~~~ |
|
1452 | 1453 | |
|
1453 | 1454 | As the internal API of IPython is now asynchronous, IPython needs to run under |
|
1454 | 1455 | an event loop. In order to allow many workflows, (like using the :magic:`%run` |
|
1455 | 1456 | magic, or copy-pasting code that explicitly starts/stop event loop), when |
|
1456 | 1457 | top-level code is detected as not being asynchronous, IPython code is advanced |
|
1457 | 1458 | via a pseudo-synchronous runner, and may not advance pending tasks. |
|
1458 | 1459 | |
|
1459 | 1460 | Change to Nested Embed |
|
1460 | 1461 | ~~~~~~~~~~~~~~~~~~~~~~ |
|
1461 | 1462 | |
|
1462 | 1463 | The introduction of the ability to run async code had some effect on the |
|
1463 | 1464 | ``IPython.embed()`` API. By default, embed will not allow you to run asynchronous |
|
1464 | 1465 | code unless an event loop is specified. |
|
1465 | 1466 | |
|
1466 | 1467 | Effects on Magics |
|
1467 | 1468 | ~~~~~~~~~~~~~~~~~ |
|
1468 | 1469 | |
|
1469 | 1470 | Some magics will not work with async until they're updated. |
|
1470 | 1471 | Contributions welcome. |
|
1471 | 1472 | |
|
1472 | 1473 | Expected Future changes |
|
1473 | 1474 | ~~~~~~~~~~~~~~~~~~~~~~~ |
|
1474 | 1475 | |
|
1475 | 1476 | We expect more internal but public IPython functions to become ``async``, and |
|
1476 | 1477 | will likely end up having a persistent event loop while IPython is running. |
|
1477 | 1478 | |
|
1478 | 1479 | Thanks |
|
1479 | 1480 | ~~~~~~ |
|
1480 | 1481 | |
|
1481 | 1482 | This release took more than a year in the making. |
|
1482 | 1483 | The code was rebased a number of |
|
1483 | 1484 | times; leading to commit authorship that may have been lost in the final |
|
1484 | 1485 | Pull-Request. Huge thanks to many people for contribution, discussion, code, |
|
1485 | 1486 | documentation, use-cases: dalejung, danielballan, ellisonbg, fperez, gnestor, |
|
1486 | 1487 | minrk, njsmith, pganssle, tacaswell, takluyver , vidartf ... And many others. |
|
1487 | 1488 | |
|
1488 | 1489 | |
|
1489 | 1490 | Autoreload Improvement |
|
1490 | 1491 | ---------------------- |
|
1491 | 1492 | |
|
1492 | 1493 | The magic :magic:`%autoreload 2 <autoreload>` now captures new methods added to |
|
1493 | 1494 | classes. Earlier, only methods existing as of the initial import were being |
|
1494 | 1495 | tracked and updated. |
|
1495 | 1496 | |
|
1496 | 1497 | This new feature helps dual environment development - Jupyter+IDE - where the |
|
1497 | 1498 | code gradually moves from notebook cells to package files as it gets |
|
1498 | 1499 | structured. |
|
1499 | 1500 | |
|
1500 | 1501 | **Example**: An instance of the class ``MyClass`` will be able to access the |
|
1501 | 1502 | method ``cube()`` after it is uncommented and the file ``file1.py`` is saved on |
|
1502 | 1503 | disk. |
|
1503 | 1504 | |
|
1504 | 1505 | |
|
1505 | 1506 | .. code:: |
|
1506 | 1507 | |
|
1507 | 1508 | # notebook |
|
1508 | 1509 | |
|
1509 | 1510 | from mymodule import MyClass |
|
1510 | 1511 | first = MyClass(5) |
|
1511 | 1512 | |
|
1512 | 1513 | .. code:: |
|
1513 | 1514 | |
|
1514 | 1515 | # mymodule/file1.py |
|
1515 | 1516 | |
|
1516 | 1517 | class MyClass: |
|
1517 | 1518 | |
|
1518 | 1519 | def __init__(self, a=10): |
|
1519 | 1520 | self.a = a |
|
1520 | 1521 | |
|
1521 | 1522 | def square(self): |
|
1522 | 1523 | print('compute square') |
|
1523 | 1524 | return self.a*self.a |
|
1524 | 1525 | |
|
1525 | 1526 | # def cube(self): |
|
1526 | 1527 | # print('compute cube') |
|
1527 | 1528 | # return self.a*self.a*self.a |
|
1528 | 1529 | |
|
1529 | 1530 | |
|
1530 | 1531 | |
|
1531 | 1532 | |
|
1532 | 1533 | Misc |
|
1533 | 1534 | ---- |
|
1534 | 1535 | |
|
1535 | 1536 | The autoindent feature that was deprecated in 5.x was re-enabled and |
|
1536 | 1537 | un-deprecated in :ghpull:`11257` |
|
1537 | 1538 | |
|
1538 | 1539 | Make :magic:`%run -n -i ... <run>` work correctly. Earlier, if :magic:`%run` was |
|
1539 | 1540 | passed both arguments, ``-n`` would be silently ignored. See :ghpull:`10308` |
|
1540 | 1541 | |
|
1541 | 1542 | |
|
1542 | 1543 | The :cellmagic:`%%script` (as well as :cellmagic:`%%bash`, |
|
1543 | 1544 | :cellmagic:`%%ruby`... ) cell magics now raise by default if the return code of |
|
1544 | 1545 | the given code is non-zero (thus halting execution of further cells in a |
|
1545 | 1546 | notebook). The behavior can be disable by passing the ``--no-raise-error`` flag. |
|
1546 | 1547 | |
|
1547 | 1548 | |
|
1548 | 1549 | Deprecations |
|
1549 | 1550 | ------------ |
|
1550 | 1551 | |
|
1551 | 1552 | A couple of unused functions and methods have been deprecated and will be removed |
|
1552 | 1553 | in future versions: |
|
1553 | 1554 | |
|
1554 | 1555 | - ``IPython.utils.io.raw_print_err`` |
|
1555 | 1556 | - ``IPython.utils.io.raw_print`` |
|
1556 | 1557 | |
|
1557 | 1558 | |
|
1558 | 1559 | Backwards incompatible changes |
|
1559 | 1560 | ------------------------------ |
|
1560 | 1561 | |
|
1561 | 1562 | * The API for transforming input before it is parsed as Python code has been |
|
1562 | 1563 | completely redesigned: any custom input transformations will need to be |
|
1563 | 1564 | rewritten. See :doc:`/config/inputtransforms` for details of the new API. |
General Comments 0
You need to be logged in to leave comments.
Login now