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