##// END OF EJS Templates
Typo Manger -> Manager
Matthias Bussonnier -
Show More
@@ -1,746 +1,746 b''
1 1 # encoding: utf-8
2 2 """Magic functions for InteractiveShell.
3 3 """
4 4
5 5 #-----------------------------------------------------------------------------
6 6 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 7 # Copyright (C) 2001 Fernando Perez <fperez@colorado.edu>
8 8 # Copyright (C) 2008 The IPython Development Team
9 9
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #-----------------------------------------------------------------------------
13 13
14 14 import os
15 15 import re
16 16 import sys
17 17 from getopt import getopt, GetoptError
18 18
19 19 from traitlets.config.configurable import Configurable
20 20 from . import oinspect
21 21 from .error import UsageError
22 22 from .inputtransformer2 import ESC_MAGIC, ESC_MAGIC2
23 23 from ..utils.ipstruct import Struct
24 24 from ..utils.process import arg_split
25 25 from ..utils.text import dedent
26 26 from traitlets import Bool, Dict, Instance, observe
27 27 from logging import error
28 28
29 29 #-----------------------------------------------------------------------------
30 30 # Globals
31 31 #-----------------------------------------------------------------------------
32 32
33 33 # A dict we'll use for each class that has magics, used as temporary storage to
34 34 # pass information between the @line/cell_magic method decorators and the
35 35 # @magics_class class decorator, because the method decorators have no
36 36 # access to the class when they run. See for more details:
37 37 # http://stackoverflow.com/questions/2366713/can-a-python-decorator-of-an-instance-method-access-the-class
38 38
39 39 magics = dict(line={}, cell={})
40 40
41 41 magic_kinds = ('line', 'cell')
42 42 magic_spec = ('line', 'cell', 'line_cell')
43 43 magic_escapes = dict(line=ESC_MAGIC, cell=ESC_MAGIC2)
44 44
45 45 #-----------------------------------------------------------------------------
46 46 # Utility classes and functions
47 47 #-----------------------------------------------------------------------------
48 48
49 49 class Bunch: pass
50 50
51 51
52 52 def on_off(tag):
53 53 """Return an ON/OFF string for a 1/0 input. Simple utility function."""
54 54 return ['OFF','ON'][tag]
55 55
56 56
57 57 def compress_dhist(dh):
58 58 """Compress a directory history into a new one with at most 20 entries.
59 59
60 60 Return a new list made from the first and last 10 elements of dhist after
61 61 removal of duplicates.
62 62 """
63 63 head, tail = dh[:-10], dh[-10:]
64 64
65 65 newhead = []
66 66 done = set()
67 67 for h in head:
68 68 if h in done:
69 69 continue
70 70 newhead.append(h)
71 71 done.add(h)
72 72
73 73 return newhead + tail
74 74
75 75
76 76 def needs_local_scope(func):
77 77 """Decorator to mark magic functions which need to local scope to run."""
78 78 func.needs_local_scope = True
79 79 return func
80 80
81 81 #-----------------------------------------------------------------------------
82 82 # Class and method decorators for registering magics
83 83 #-----------------------------------------------------------------------------
84 84
85 85 def magics_class(cls):
86 86 """Class decorator for all subclasses of the main Magics class.
87 87
88 88 Any class that subclasses Magics *must* also apply this decorator, to
89 89 ensure that all the methods that have been decorated as line/cell magics
90 90 get correctly registered in the class instance. This is necessary because
91 91 when method decorators run, the class does not exist yet, so they
92 92 temporarily store their information into a module global. Application of
93 93 this class decorator copies that global data to the class instance and
94 94 clears the global.
95 95
96 96 Obviously, this mechanism is not thread-safe, which means that the
97 97 *creation* of subclasses of Magic should only be done in a single-thread
98 98 context. Instantiation of the classes has no restrictions. Given that
99 99 these classes are typically created at IPython startup time and before user
100 100 application code becomes active, in practice this should not pose any
101 101 problems.
102 102 """
103 103 cls.registered = True
104 104 cls.magics = dict(line = magics['line'],
105 105 cell = magics['cell'])
106 106 magics['line'] = {}
107 107 magics['cell'] = {}
108 108 return cls
109 109
110 110
111 111 def record_magic(dct, magic_kind, magic_name, func):
112 112 """Utility function to store a function as a magic of a specific kind.
113 113
114 114 Parameters
115 115 ----------
116 116 dct : dict
117 117 A dictionary with 'line' and 'cell' subdicts.
118 118 magic_kind : str
119 119 Kind of magic to be stored.
120 120 magic_name : str
121 121 Key to store the magic as.
122 122 func : function
123 123 Callable object to store.
124 124 """
125 125 if magic_kind == 'line_cell':
126 126 dct['line'][magic_name] = dct['cell'][magic_name] = func
127 127 else:
128 128 dct[magic_kind][magic_name] = func
129 129
130 130
131 131 def validate_type(magic_kind):
132 132 """Ensure that the given magic_kind is valid.
133 133
134 134 Check that the given magic_kind is one of the accepted spec types (stored
135 135 in the global `magic_spec`), raise ValueError otherwise.
136 136 """
137 137 if magic_kind not in magic_spec:
138 138 raise ValueError('magic_kind must be one of %s, %s given' %
139 139 magic_kinds, magic_kind)
140 140
141 141
142 142 # The docstrings for the decorator below will be fairly similar for the two
143 143 # types (method and function), so we generate them here once and reuse the
144 144 # templates below.
145 145 _docstring_template = \
146 146 """Decorate the given {0} as {1} magic.
147 147
148 148 The decorator can be used with or without arguments, as follows.
149 149
150 150 i) without arguments: it will create a {1} magic named as the {0} being
151 151 decorated::
152 152
153 153 @deco
154 154 def foo(...)
155 155
156 156 will create a {1} magic named `foo`.
157 157
158 158 ii) with one string argument: which will be used as the actual name of the
159 159 resulting magic::
160 160
161 161 @deco('bar')
162 162 def foo(...)
163 163
164 164 will create a {1} magic named `bar`.
165 165
166 166 To register a class magic use ``Interactiveshell.register_magic(class or instance)``.
167 167 """
168 168
169 169 # These two are decorator factories. While they are conceptually very similar,
170 170 # there are enough differences in the details that it's simpler to have them
171 171 # written as completely standalone functions rather than trying to share code
172 172 # and make a single one with convoluted logic.
173 173
174 174 def _method_magic_marker(magic_kind):
175 175 """Decorator factory for methods in Magics subclasses.
176 176 """
177 177
178 178 validate_type(magic_kind)
179 179
180 180 # This is a closure to capture the magic_kind. We could also use a class,
181 181 # but it's overkill for just that one bit of state.
182 182 def magic_deco(arg):
183 183 if callable(arg):
184 184 # "Naked" decorator call (just @foo, no args)
185 185 func = arg
186 186 name = func.__name__
187 187 retval = arg
188 188 record_magic(magics, magic_kind, name, name)
189 189 elif isinstance(arg, str):
190 190 # Decorator called with arguments (@foo('bar'))
191 191 name = arg
192 192 def mark(func, *a, **kw):
193 193 record_magic(magics, magic_kind, name, func.__name__)
194 194 return func
195 195 retval = mark
196 196 else:
197 197 raise TypeError("Decorator can only be called with "
198 198 "string or function")
199 199 return retval
200 200
201 201 # Ensure the resulting decorator has a usable docstring
202 202 magic_deco.__doc__ = _docstring_template.format('method', magic_kind)
203 203 return magic_deco
204 204
205 205
206 206 def _function_magic_marker(magic_kind):
207 207 """Decorator factory for standalone functions.
208 208 """
209 209 validate_type(magic_kind)
210 210
211 211 # This is a closure to capture the magic_kind. We could also use a class,
212 212 # but it's overkill for just that one bit of state.
213 213 def magic_deco(arg):
214 214 # Find get_ipython() in the caller's namespace
215 215 caller = sys._getframe(1)
216 216 for ns in ['f_locals', 'f_globals', 'f_builtins']:
217 217 get_ipython = getattr(caller, ns).get('get_ipython')
218 218 if get_ipython is not None:
219 219 break
220 220 else:
221 221 raise NameError('Decorator can only run in context where '
222 222 '`get_ipython` exists')
223 223
224 224 ip = get_ipython()
225 225
226 226 if callable(arg):
227 227 # "Naked" decorator call (just @foo, no args)
228 228 func = arg
229 229 name = func.__name__
230 230 ip.register_magic_function(func, magic_kind, name)
231 231 retval = arg
232 232 elif isinstance(arg, str):
233 233 # Decorator called with arguments (@foo('bar'))
234 234 name = arg
235 235 def mark(func, *a, **kw):
236 236 ip.register_magic_function(func, magic_kind, name)
237 237 return func
238 238 retval = mark
239 239 else:
240 240 raise TypeError("Decorator can only be called with "
241 241 "string or function")
242 242 return retval
243 243
244 244 # Ensure the resulting decorator has a usable docstring
245 245 ds = _docstring_template.format('function', magic_kind)
246 246
247 247 ds += dedent("""
248 248 Note: this decorator can only be used in a context where IPython is already
249 249 active, so that the `get_ipython()` call succeeds. You can therefore use
250 250 it in your startup files loaded after IPython initializes, but *not* in the
251 251 IPython configuration file itself, which is executed before IPython is
252 252 fully up and running. Any file located in the `startup` subdirectory of
253 253 your configuration profile will be OK in this sense.
254 254 """)
255 255
256 256 magic_deco.__doc__ = ds
257 257 return magic_deco
258 258
259 259
260 260 MAGIC_NO_VAR_EXPAND_ATTR = '_ipython_magic_no_var_expand'
261 261
262 262
263 263 def no_var_expand(magic_func):
264 264 """Mark a magic function as not needing variable expansion
265 265
266 266 By default, IPython interprets `{a}` or `$a` in the line passed to magics
267 267 as variables that should be interpolated from the interactive namespace
268 268 before passing the line to the magic function.
269 269 This is not always desirable, e.g. when the magic executes Python code
270 270 (%timeit, %time, etc.).
271 271 Decorate magics with `@no_var_expand` to opt-out of variable expansion.
272 272
273 273 .. versionadded:: 7.3
274 274 """
275 275 setattr(magic_func, MAGIC_NO_VAR_EXPAND_ATTR, True)
276 276 return magic_func
277 277
278 278
279 279 # Create the actual decorators for public use
280 280
281 281 # These three are used to decorate methods in class definitions
282 282 line_magic = _method_magic_marker('line')
283 283 cell_magic = _method_magic_marker('cell')
284 284 line_cell_magic = _method_magic_marker('line_cell')
285 285
286 286 # These three decorate standalone functions and perform the decoration
287 287 # immediately. They can only run where get_ipython() works
288 288 register_line_magic = _function_magic_marker('line')
289 289 register_cell_magic = _function_magic_marker('cell')
290 290 register_line_cell_magic = _function_magic_marker('line_cell')
291 291
292 292 #-----------------------------------------------------------------------------
293 293 # Core Magic classes
294 294 #-----------------------------------------------------------------------------
295 295
296 296 class MagicsManager(Configurable):
297 297 """Object that handles all magic-related functionality for IPython.
298 298 """
299 299 # Non-configurable class attributes
300 300
301 301 # A two-level dict, first keyed by magic type, then by magic function, and
302 302 # holding the actual callable object as value. This is the dict used for
303 303 # magic function dispatch
304 304 magics = Dict()
305 305 lazy_magics = Dict(
306 306 help="""
307 307 Mapping from magic names to modules to load.
308 308
309 309 This can be used in IPython/IPykernel configuration to declare lazy magics
310 310 that will only be imported/registered on first use.
311 311
312 312 For example::
313 313
314 c.MagicsManger.lazy_magics = {
314 c.MagicsManager.lazy_magics = {
315 315 "my_magic": "slow.to.import",
316 316 "my_other_magic": "also.slow",
317 317 }
318 318
319 319 On first invocation of `%my_magic`, `%%my_magic`, `%%my_other_magic` or
320 320 `%%my_other_magic`, the corresponding module will be loaded as an ipython
321 321 extensions as if you had previously done `%load_ext ipython`.
322 322
323 323 Magics names should be without percent(s) as magics can be both cell
324 324 and line magics.
325 325
326 326 Lazy loading happen relatively late in execution process, and
327 327 complex extensions that manipulate Python/IPython internal state or global state
328 328 might not support lazy loading.
329 329 """
330 330 ).tag(
331 331 config=True,
332 332 )
333 333
334 334 # A registry of the original objects that we've been given holding magics.
335 335 registry = Dict()
336 336
337 337 shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', allow_none=True)
338 338
339 339 auto_magic = Bool(True, help=
340 340 "Automatically call line magics without requiring explicit % prefix"
341 341 ).tag(config=True)
342 342 @observe('auto_magic')
343 343 def _auto_magic_changed(self, change):
344 344 self.shell.automagic = change['new']
345 345
346 346 _auto_status = [
347 347 'Automagic is OFF, % prefix IS needed for line magics.',
348 348 'Automagic is ON, % prefix IS NOT needed for line magics.']
349 349
350 350 user_magics = Instance('IPython.core.magics.UserMagics', allow_none=True)
351 351
352 352 def __init__(self, shell=None, config=None, user_magics=None, **traits):
353 353
354 354 super(MagicsManager, self).__init__(shell=shell, config=config,
355 355 user_magics=user_magics, **traits)
356 356 self.magics = dict(line={}, cell={})
357 357 # Let's add the user_magics to the registry for uniformity, so *all*
358 358 # registered magic containers can be found there.
359 359 self.registry[user_magics.__class__.__name__] = user_magics
360 360
361 361 def auto_status(self):
362 362 """Return descriptive string with automagic status."""
363 363 return self._auto_status[self.auto_magic]
364 364
365 365 def lsmagic(self):
366 366 """Return a dict of currently available magic functions.
367 367
368 368 The return dict has the keys 'line' and 'cell', corresponding to the
369 369 two types of magics we support. Each value is a list of names.
370 370 """
371 371 return self.magics
372 372
373 373 def lsmagic_docs(self, brief=False, missing=''):
374 374 """Return dict of documentation of magic functions.
375 375
376 376 The return dict has the keys 'line' and 'cell', corresponding to the
377 377 two types of magics we support. Each value is a dict keyed by magic
378 378 name whose value is the function docstring. If a docstring is
379 379 unavailable, the value of `missing` is used instead.
380 380
381 381 If brief is True, only the first line of each docstring will be returned.
382 382 """
383 383 docs = {}
384 384 for m_type in self.magics:
385 385 m_docs = {}
386 386 for m_name, m_func in self.magics[m_type].items():
387 387 if m_func.__doc__:
388 388 if brief:
389 389 m_docs[m_name] = m_func.__doc__.split('\n', 1)[0]
390 390 else:
391 391 m_docs[m_name] = m_func.__doc__.rstrip()
392 392 else:
393 393 m_docs[m_name] = missing
394 394 docs[m_type] = m_docs
395 395 return docs
396 396
397 397 def register_lazy(self, name: str, fully_qualified_name: str):
398 398 """
399 399 Lazily register a magic via an extension.
400 400
401 401
402 402 Parameters
403 403 ----------
404 404 name : str
405 405 Name of the magic you wish to register.
406 406 fully_qualified_name :
407 407 Fully qualified name of the module/submodule that should be loaded
408 408 as an extensions when the magic is first called.
409 409 It is assumed that loading this extensions will register the given
410 410 magic.
411 411 """
412 412
413 413 self.lazy_magics[name] = fully_qualified_name
414 414
415 415 def register(self, *magic_objects):
416 416 """Register one or more instances of Magics.
417 417
418 418 Take one or more classes or instances of classes that subclass the main
419 419 `core.Magic` class, and register them with IPython to use the magic
420 420 functions they provide. The registration process will then ensure that
421 421 any methods that have decorated to provide line and/or cell magics will
422 422 be recognized with the `%x`/`%%x` syntax as a line/cell magic
423 423 respectively.
424 424
425 425 If classes are given, they will be instantiated with the default
426 426 constructor. If your classes need a custom constructor, you should
427 427 instanitate them first and pass the instance.
428 428
429 429 The provided arguments can be an arbitrary mix of classes and instances.
430 430
431 431 Parameters
432 432 ----------
433 433 *magic_objects : one or more classes or instances
434 434 """
435 435 # Start by validating them to ensure they have all had their magic
436 436 # methods registered at the instance level
437 437 for m in magic_objects:
438 438 if not m.registered:
439 439 raise ValueError("Class of magics %r was constructed without "
440 440 "the @register_magics class decorator")
441 441 if isinstance(m, type):
442 442 # If we're given an uninstantiated class
443 443 m = m(shell=self.shell)
444 444
445 445 # Now that we have an instance, we can register it and update the
446 446 # table of callables
447 447 self.registry[m.__class__.__name__] = m
448 448 for mtype in magic_kinds:
449 449 self.magics[mtype].update(m.magics[mtype])
450 450
451 451 def register_function(self, func, magic_kind='line', magic_name=None):
452 452 """Expose a standalone function as magic function for IPython.
453 453
454 454 This will create an IPython magic (line, cell or both) from a
455 455 standalone function. The functions should have the following
456 456 signatures:
457 457
458 458 * For line magics: `def f(line)`
459 459 * For cell magics: `def f(line, cell)`
460 460 * For a function that does both: `def f(line, cell=None)`
461 461
462 462 In the latter case, the function will be called with `cell==None` when
463 463 invoked as `%f`, and with cell as a string when invoked as `%%f`.
464 464
465 465 Parameters
466 466 ----------
467 467 func : callable
468 468 Function to be registered as a magic.
469 469 magic_kind : str
470 470 Kind of magic, one of 'line', 'cell' or 'line_cell'
471 471 magic_name : optional str
472 472 If given, the name the magic will have in the IPython namespace. By
473 473 default, the name of the function itself is used.
474 474 """
475 475
476 476 # Create the new method in the user_magics and register it in the
477 477 # global table
478 478 validate_type(magic_kind)
479 479 magic_name = func.__name__ if magic_name is None else magic_name
480 480 setattr(self.user_magics, magic_name, func)
481 481 record_magic(self.magics, magic_kind, magic_name, func)
482 482
483 483 def register_alias(self, alias_name, magic_name, magic_kind='line', magic_params=None):
484 484 """Register an alias to a magic function.
485 485
486 486 The alias is an instance of :class:`MagicAlias`, which holds the
487 487 name and kind of the magic it should call. Binding is done at
488 488 call time, so if the underlying magic function is changed the alias
489 489 will call the new function.
490 490
491 491 Parameters
492 492 ----------
493 493 alias_name : str
494 494 The name of the magic to be registered.
495 495 magic_name : str
496 496 The name of an existing magic.
497 497 magic_kind : str
498 498 Kind of magic, one of 'line' or 'cell'
499 499 """
500 500
501 501 # `validate_type` is too permissive, as it allows 'line_cell'
502 502 # which we do not handle.
503 503 if magic_kind not in magic_kinds:
504 504 raise ValueError('magic_kind must be one of %s, %s given' %
505 505 magic_kinds, magic_kind)
506 506
507 507 alias = MagicAlias(self.shell, magic_name, magic_kind, magic_params)
508 508 setattr(self.user_magics, alias_name, alias)
509 509 record_magic(self.magics, magic_kind, alias_name, alias)
510 510
511 511 # Key base class that provides the central functionality for magics.
512 512
513 513
514 514 class Magics(Configurable):
515 515 """Base class for implementing magic functions.
516 516
517 517 Shell functions which can be reached as %function_name. All magic
518 518 functions should accept a string, which they can parse for their own
519 519 needs. This can make some functions easier to type, eg `%cd ../`
520 520 vs. `%cd("../")`
521 521
522 522 Classes providing magic functions need to subclass this class, and they
523 523 MUST:
524 524
525 525 - Use the method decorators `@line_magic` and `@cell_magic` to decorate
526 526 individual methods as magic functions, AND
527 527
528 528 - Use the class decorator `@magics_class` to ensure that the magic
529 529 methods are properly registered at the instance level upon instance
530 530 initialization.
531 531
532 532 See :mod:`magic_functions` for examples of actual implementation classes.
533 533 """
534 534 # Dict holding all command-line options for each magic.
535 535 options_table = None
536 536 # Dict for the mapping of magic names to methods, set by class decorator
537 537 magics = None
538 538 # Flag to check that the class decorator was properly applied
539 539 registered = False
540 540 # Instance of IPython shell
541 541 shell = None
542 542
543 543 def __init__(self, shell=None, **kwargs):
544 544 if not(self.__class__.registered):
545 545 raise ValueError('Magics subclass without registration - '
546 546 'did you forget to apply @magics_class?')
547 547 if shell is not None:
548 548 if hasattr(shell, 'configurables'):
549 549 shell.configurables.append(self)
550 550 if hasattr(shell, 'config'):
551 551 kwargs.setdefault('parent', shell)
552 552
553 553 self.shell = shell
554 554 self.options_table = {}
555 555 # The method decorators are run when the instance doesn't exist yet, so
556 556 # they can only record the names of the methods they are supposed to
557 557 # grab. Only now, that the instance exists, can we create the proper
558 558 # mapping to bound methods. So we read the info off the original names
559 559 # table and replace each method name by the actual bound method.
560 560 # But we mustn't clobber the *class* mapping, in case of multiple instances.
561 561 class_magics = self.magics
562 562 self.magics = {}
563 563 for mtype in magic_kinds:
564 564 tab = self.magics[mtype] = {}
565 565 cls_tab = class_magics[mtype]
566 566 for magic_name, meth_name in cls_tab.items():
567 567 if isinstance(meth_name, str):
568 568 # it's a method name, grab it
569 569 tab[magic_name] = getattr(self, meth_name)
570 570 else:
571 571 # it's the real thing
572 572 tab[magic_name] = meth_name
573 573 # Configurable **needs** to be initiated at the end or the config
574 574 # magics get screwed up.
575 575 super(Magics, self).__init__(**kwargs)
576 576
577 577 def arg_err(self,func):
578 578 """Print docstring if incorrect arguments were passed"""
579 579 print('Error in arguments:')
580 580 print(oinspect.getdoc(func))
581 581
582 582 def format_latex(self, strng):
583 583 """Format a string for latex inclusion."""
584 584
585 585 # Characters that need to be escaped for latex:
586 586 escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE)
587 587 # Magic command names as headers:
588 588 cmd_name_re = re.compile(r'^(%s.*?):' % ESC_MAGIC,
589 589 re.MULTILINE)
590 590 # Magic commands
591 591 cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % ESC_MAGIC,
592 592 re.MULTILINE)
593 593 # Paragraph continue
594 594 par_re = re.compile(r'\\$',re.MULTILINE)
595 595
596 596 # The "\n" symbol
597 597 newline_re = re.compile(r'\\n')
598 598
599 599 # Now build the string for output:
600 600 #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng)
601 601 strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:',
602 602 strng)
603 603 strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng)
604 604 strng = par_re.sub(r'\\\\',strng)
605 605 strng = escape_re.sub(r'\\\1',strng)
606 606 strng = newline_re.sub(r'\\textbackslash{}n',strng)
607 607 return strng
608 608
609 609 def parse_options(self, arg_str, opt_str, *long_opts, **kw):
610 610 """Parse options passed to an argument string.
611 611
612 612 The interface is similar to that of :func:`getopt.getopt`, but it
613 613 returns a :class:`~IPython.utils.struct.Struct` with the options as keys
614 614 and the stripped argument string still as a string.
615 615
616 616 arg_str is quoted as a true sys.argv vector by using shlex.split.
617 617 This allows us to easily expand variables, glob files, quote
618 618 arguments, etc.
619 619
620 620 Parameters
621 621 ----------
622 622 arg_str : str
623 623 The arguments to parse.
624 624 opt_str : str
625 625 The options specification.
626 626 mode : str, default 'string'
627 627 If given as 'list', the argument string is returned as a list (split
628 628 on whitespace) instead of a string.
629 629 list_all : bool, default False
630 630 Put all option values in lists. Normally only options
631 631 appearing more than once are put in a list.
632 632 posix : bool, default True
633 633 Whether to split the input line in POSIX mode or not, as per the
634 634 conventions outlined in the :mod:`shlex` module from the standard
635 635 library.
636 636 """
637 637
638 638 # inject default options at the beginning of the input line
639 639 caller = sys._getframe(1).f_code.co_name
640 640 arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str)
641 641
642 642 mode = kw.get('mode','string')
643 643 if mode not in ['string','list']:
644 644 raise ValueError('incorrect mode given: %s' % mode)
645 645 # Get options
646 646 list_all = kw.get('list_all',0)
647 647 posix = kw.get('posix', os.name == 'posix')
648 648 strict = kw.get('strict', True)
649 649
650 650 preserve_non_opts = kw.get("preserve_non_opts", False)
651 651 remainder_arg_str = arg_str
652 652
653 653 # Check if we have more than one argument to warrant extra processing:
654 654 odict = {} # Dictionary with options
655 655 args = arg_str.split()
656 656 if len(args) >= 1:
657 657 # If the list of inputs only has 0 or 1 thing in it, there's no
658 658 # need to look for options
659 659 argv = arg_split(arg_str, posix, strict)
660 660 # Do regular option processing
661 661 try:
662 662 opts,args = getopt(argv, opt_str, long_opts)
663 663 except GetoptError as e:
664 664 raise UsageError(
665 665 '%s ( allowed: "%s" %s)' % (e.msg, opt_str, " ".join(long_opts))
666 666 ) from e
667 667 for o, a in opts:
668 668 if mode == "string" and preserve_non_opts:
669 669 # remove option-parts from the original args-string and preserve remaining-part.
670 670 # This relies on the arg_split(...) and getopt(...)'s impl spec, that the parsed options are
671 671 # returned in the original order.
672 672 remainder_arg_str = remainder_arg_str.replace(o, "", 1).replace(
673 673 a, "", 1
674 674 )
675 675 if o.startswith("--"):
676 676 o = o[2:]
677 677 else:
678 678 o = o[1:]
679 679 try:
680 680 odict[o].append(a)
681 681 except AttributeError:
682 682 odict[o] = [odict[o],a]
683 683 except KeyError:
684 684 if list_all:
685 685 odict[o] = [a]
686 686 else:
687 687 odict[o] = a
688 688
689 689 # Prepare opts,args for return
690 690 opts = Struct(odict)
691 691 if mode == 'string':
692 692 if preserve_non_opts:
693 693 args = remainder_arg_str.lstrip()
694 694 else:
695 695 args = " ".join(args)
696 696
697 697 return opts,args
698 698
699 699 def default_option(self, fn, optstr):
700 700 """Make an entry in the options_table for fn, with value optstr"""
701 701
702 702 if fn not in self.lsmagic():
703 703 error("%s is not a magic function" % fn)
704 704 self.options_table[fn] = optstr
705 705
706 706
707 707 class MagicAlias(object):
708 708 """An alias to another magic function.
709 709
710 710 An alias is determined by its magic name and magic kind. Lookup
711 711 is done at call time, so if the underlying magic changes the alias
712 712 will call the new function.
713 713
714 714 Use the :meth:`MagicsManager.register_alias` method or the
715 715 `%alias_magic` magic function to create and register a new alias.
716 716 """
717 717 def __init__(self, shell, magic_name, magic_kind, magic_params=None):
718 718 self.shell = shell
719 719 self.magic_name = magic_name
720 720 self.magic_params = magic_params
721 721 self.magic_kind = magic_kind
722 722
723 723 self.pretty_target = '%s%s' % (magic_escapes[self.magic_kind], self.magic_name)
724 724 self.__doc__ = "Alias for `%s`." % self.pretty_target
725 725
726 726 self._in_call = False
727 727
728 728 def __call__(self, *args, **kwargs):
729 729 """Call the magic alias."""
730 730 fn = self.shell.find_magic(self.magic_name, self.magic_kind)
731 731 if fn is None:
732 732 raise UsageError("Magic `%s` not found." % self.pretty_target)
733 733
734 734 # Protect against infinite recursion.
735 735 if self._in_call:
736 736 raise UsageError("Infinite recursion detected; "
737 737 "magic aliases cannot call themselves.")
738 738 self._in_call = True
739 739 try:
740 740 if self.magic_params:
741 741 args_list = list(args)
742 742 args_list[0] = self.magic_params + " " + args[0]
743 743 args = tuple(args_list)
744 744 return fn(*args, **kwargs)
745 745 finally:
746 746 self._in_call = False
@@ -1,1777 +1,1777 b''
1 1 ============
2 2 7.x Series
3 3 ============
4 4
5 5
6 6 .. _version 7.32:
7 7
8 8 IPython 7.32
9 9 ============
10 10
11 11
12 12
13 13 Autoload magic lazily
14 14 ---------------------
15 15
16 16 The ability to configure magics to be lazily loaded has been added to IPython.
17 17 See the ``ipython --help-all`` section on ``MagicsManager.lazy_magic``.
18 18 One can now use::
19 19
20 c.MagicsManger.lazy_magics = {
20 c.MagicsManager.lazy_magics = {
21 21 "my_magic": "slow.to.import",
22 22 "my_other_magic": "also.slow",
23 23 }
24 24
25 25 And on first use of ``%my_magic``, or corresponding cell magic, or other line magic,
26 26 the corresponding ``load_ext`` will be called just before trying to invoke the magic.
27 27
28 28 Misc
29 29 ----
30 30
31 31 - Update sphinxify for Docrepr 0.2.0 :ghpull:`13503`.
32 32 - Set co_name for cells run line by line (to fix debugging with Python 3.10)
33 33 :ghpull:`13535`
34 34
35 35
36 36 Many thanks to all the contributors to this release. You can find all individual
37 37 contributions to this milestone `on github
38 38 <https://github.com/ipython/ipython/milestone/99>`__.
39 39
40 40 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
41 41 work on IPython and related libraries.
42 42
43 43 .. _version 7.31:
44 44
45 45 IPython 7.31
46 46 ============
47 47
48 48 IPython 7.31 brings a couple of backports and fixes from the 8.0 branches,
49 49 it is likely one of the last releases of the 7.x series, as 8.0 will probably be released
50 50 between this release and what would have been 7.32.
51 51
52 52 Please test 8.0 beta/rc releases in addition to this release.
53 53
54 54 This Releases:
55 55 - Backport some fixes for Python 3.10 (:ghpull:`13412`)
56 56 - use full-alpha transparency on dvipng rendered LaTeX (:ghpull:`13372`)
57 57
58 58 Many thanks to all the contributors to this release. You can find all individual
59 59 contributions to this milestone `on github
60 60 <https://github.com/ipython/ipython/milestone/95>`__.
61 61
62 62 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
63 63 work on IPython and related libraries.
64 64
65 65
66 66 .. _version 7.30:
67 67
68 68 IPython 7.30
69 69 ============
70 70
71 71 IPython 7.30 fixes a couple of bugs introduce in previous releases (in
72 72 particular with respect to path handling), and introduce a few features and
73 73 improvements:
74 74
75 75 Notably we will highlight :ghpull:`13267` "Document that ``%run`` can execute
76 76 notebooks and ipy scripts.", which is the first commit of Fernando PΓ©rez since
77 77 mid 2016 (IPython 5.1). If you are new to IPython, Fernando created IPython in
78 78 2001. The other most recent contribution of Fernando to IPython itself was
79 79 May 2018, by reviewing and merging PRs. I want to note that Fernando is still
80 80 active but mostly as a mentor and leader of the whole Jupyter organisation, but
81 81 we're still happy to see him contribute code !
82 82
83 83 :ghpull:`13290` "Use sphinxify (if available) in object_inspect_mime path"
84 84 should allow richer Repr of docstrings when using jupyterlab inspector.
85 85
86 86 :ghpull:`13311` make the debugger use ``ThreadPoolExecutor`` for debugger cmdloop.
87 87 This should fix some issues/infinite loop, but let us know if you come across
88 88 any regressions. In particular this fixes issues with `kmaork/madbg <https://github.com/kmaork/madbg>`_,
89 89 a remote debugger for IPython.
90 90
91 91 Note that this is likely the ante-penultimate release of IPython 7.x as a stable
92 92 branch, as I hope to release IPython 8.0 as well as IPython 7.31 next
93 93 month/early 2022.
94 94
95 95 IPython 8.0 will drop support for Python 3.7, removed nose as a dependency, and
96 96 7.x will only get critical bug fixes with 8.x becoming the new stable. This will
97 97 not be possible without `NumFOCUS Small Development Grants
98 98 <https://numfocus.org/programs/small-development-grants>`_ Which allowed us to
99 99 hire `Nikita Kniazev <https://github.com/Kojoley>`_ who provide Python and C++
100 100 help and contracting work.
101 101
102 102
103 103 Many thanks to all the contributors to this release. You can find all individual
104 104 contributions to this milestone `on github
105 105 <https://github.com/ipython/ipython/milestone/94?closed=1>`__.
106 106
107 107 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
108 108 work on IPython and related libraries.
109 109
110 110
111 111 .. _version 7.29:
112 112
113 113 IPython 7.29
114 114 ============
115 115
116 116
117 117 IPython 7.29 brings a couple of new functionalities to IPython and a number of bugfixes.
118 118 It is one of the largest recent release, relatively speaking, with close to 15 Pull Requests.
119 119
120 120
121 121 - fix an issue where base64 was returned instead of bytes when showing figures :ghpull:`13162`
122 122 - fix compatibility with PyQt6, PySide 6 :ghpull:`13172`. This may be of
123 123 interest if you are running on Apple Silicon as only qt6.2+ is natively
124 124 compatible.
125 125 - fix matplotlib qtagg eventloop :ghpull:`13179`
126 126 - Multiple docs fixes, typos, ... etc.
127 127 - Debugger will now exit by default on SigInt :ghpull:`13218`, this will be
128 128 useful in notebook/lab if you forgot to exit the debugger. "Interrupt Kernel"
129 129 will now exist the debugger.
130 130
131 131 It give Pdb the ability to skip code in decorators. If functions contain a
132 132 special value names ``__debuggerskip__ = True|False``, the function will not be
133 133 stepped into, and Pdb will step into lower frames only if the value is set to
134 134 ``False``. The exact behavior is still likely to have corner cases and will be
135 135 refined in subsequent releases. Feedback welcome. See the debugger module
136 136 documentation for more info. Thanks to the `D. E. Shaw
137 137 group <https://deshaw.com/>`__ for funding this feature.
138 138
139 139 The main branch of IPython is receiving a number of changes as we received a
140 140 `NumFOCUS SDG <https://numfocus.org/programs/small-development-grants>`__
141 141 ($4800), to help us finish replacing ``nose`` by ``pytest``, and make IPython
142 142 future proof with an 8.0 release.
143 143
144 144
145 145 Many thanks to all the contributors to this release. You can find all individual
146 146 contributions to this milestone `on github
147 147 <https://github.com/ipython/ipython/milestone/93>`__.
148 148
149 149 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
150 150 work on IPython and related libraries.
151 151
152 152
153 153 .. _version 7.28:
154 154
155 155 IPython 7.28
156 156 ============
157 157
158 158
159 159 IPython 7.28 is again a minor release that mostly bring bugfixes, and couple of
160 160 improvement. Many thanks to MrMino, who again did all the work this month, and
161 161 made a number of documentation improvements.
162 162
163 163 Here is a non-exhaustive list of changes,
164 164
165 165 Fixes:
166 166
167 167 - async with doesn't allow newlines :ghpull:`13090`
168 168 - Dynamically changing to vi mode via %config magic) :ghpull:`13091`
169 169
170 170 Virtualenv handling fixes:
171 171
172 172 - init_virtualenv now uses Pathlib :ghpull:`12548`
173 173 - Fix Improper path comparison of virtualenv directories :ghpull:`13140`
174 174 - Fix virtual environment user warning for lower case pathes :ghpull:`13094`
175 175 - Adapt to all sorts of drive names for cygwin :ghpull:`13153`
176 176
177 177 New Features:
178 178
179 179 - enable autoplay in embed YouTube player :ghpull:`13133`
180 180
181 181 Documentation:
182 182
183 183 - Fix formatting for the core.interactiveshell documentation :ghpull:`13118`
184 184 - Fix broken ipyparallel's refs :ghpull:`13138`
185 185 - Improve formatting of %time documentation :ghpull:`13125`
186 186 - Reword the YouTubeVideo autoplay WN :ghpull:`13147`
187 187
188 188
189 189 Highlighted features
190 190 --------------------
191 191
192 192
193 193 ``YouTubeVideo`` autoplay and the ability to add extra attributes to ``IFrame``
194 194 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195 195
196 196 You can add any extra attributes to the ``<iframe>`` tag using the new
197 197 ``extras`` argument in the ``IFrame`` class. For example::
198 198
199 199 In [1]: from IPython.display import IFrame
200 200
201 201 In [2]: IFrame(src="src", width=300, height=300, extras=['loading="eager"'])
202 202
203 203 The above cells will result in the following HTML code being displayed in a
204 204 notebook::
205 205
206 206 <iframe
207 207 width="300"
208 208 height="300"
209 209 src="src"
210 210 frameborder="0"
211 211 allowfullscreen
212 212 loading="eager"
213 213 ></iframe>
214 214
215 215 Related to the above, the ``YouTubeVideo`` class now takes an
216 216 ``allow_autoplay`` flag, which sets up the iframe of the embedded YouTube video
217 217 such that it allows autoplay.
218 218
219 219 .. note::
220 220 Whether this works depends on the autoplay policy of the browser rendering
221 221 the HTML allowing it. It also could get blocked by some browser extensions.
222 222
223 223 Try it out!
224 224 ::
225 225
226 226 In [1]: from IPython.display import YouTubeVideo
227 227
228 228 In [2]: YouTubeVideo("dQw4w9WgXcQ", allow_autoplay=True)
229 229
230 230
231 231
232 232 Thanks
233 233 ------
234 234
235 235 Many thanks to all the contributors to this release. You can find all individual
236 236 contributions to this milestone `on github
237 237 <https://github.com/ipython/ipython/milestone/92>`__.
238 238
239 239 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
240 240 work on IPython and related libraries.
241 241
242 242
243 243 .. _version 7.27:
244 244
245 245 IPython 7.27
246 246 ============
247 247
248 248 IPython 7.27 is a minor release that fixes a couple of issues and compatibility.
249 249
250 250 - Add support for GTK4 :ghpull:`131011`
251 251 - Add support for Qt6 :ghpull:`13085`
252 252 - Fix an issue with pip magic on windows :ghpull:`13093`
253 253
254 254 Thanks
255 255 ------
256 256
257 257 Many thanks to all the contributors to this release. You can find all individual
258 258 contributions to this milestone `on github
259 259 <https://github.com/ipython/ipython/milestone/91>`__.
260 260
261 261 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
262 262 work on IPython and related libraries.
263 263
264 264 .. _version 7.26:
265 265
266 266 IPython 7.26
267 267 ============
268 268
269 269 IPython 7.26 is a minor release that fixes a couple of issues, updates in API
270 270 and Copyright/Licenses issues around various part of the codebase.
271 271
272 272 We'll highlight `this issue <https://github.com/ipython/ipython/issues/13039>`
273 273 pointing out we were including and refereeing to code from Stack Overflow which
274 274 was CC-BY-SA, hence incompatible with the BSD license of IPython. This lead us
275 275 to a rewriting of the corresponding logic which in our case was done in a more
276 276 efficient way (in our case we were searching string prefixes instead of full
277 277 strings).
278 278
279 279 You will notice also a number of documentation improvements and cleanup.
280 280
281 281 Of particular interest are the following Pull-requests:
282 282
283 283
284 284 - The IPython directive now uses Sphinx logging for warnings. :ghpull:`13030`.
285 285 - Add expiry days option to pastebin magic and change http protocol to https.
286 286 :ghpull:`13056`
287 287 - Make Ipython.utils.timing work with jupyterlite :ghpull:`13050`.
288 288
289 289 Pastebin magic expiry days option
290 290 ---------------------------------
291 291
292 292 The Pastebin magic now has ``-e`` option to determine
293 293 the number of days for paste expiration. For example
294 294 the paste that created with ``%pastebin -e 20 1`` magic will
295 295 be available for next 20 days.
296 296
297 297
298 298
299 299
300 300
301 301 Thanks
302 302 ------
303 303
304 304 Many thanks to all the contributors to this release and in particular MrMino who
305 305 is doing most of the work those days. You can find all individual contributions
306 306 to this milestone `on github <https://github.com/ipython/ipython/milestone/90>`__.
307 307
308 308 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
309 309 work on IPython and related libraries.
310 310
311 311
312 312 .. _version 7.25:
313 313
314 314 IPython 7.25
315 315 ============
316 316
317 317 IPython 7.25 is a minor release that contains a single bugfix, which is highly
318 318 recommended for all users of ipdb, ipython debugger %debug magic and similar.
319 319
320 320 Issuing commands like ``where`` from within the debugger would reset the
321 321 local variables changes made by the user. It is interesting to look at the root
322 322 cause of the issue as accessing an attribute (``frame.f_locals``) would trigger
323 323 this side effects.
324 324
325 325 Thanks in particular to the patience from the reporters at D.E. Shaw for their
326 326 initial bug report that was due to a similar coding oversight in an extension,
327 327 and who took time to debug and narrow down the problem.
328 328
329 329 Thanks
330 330 ------
331 331
332 332 Many thanks to all the contributors to this release you can find all individual
333 333 contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/89>`__.
334 334
335 335 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
336 336 work on IPython and related libraries.
337 337
338 338
339 339 .. _version 7.24:
340 340
341 341 IPython 7.24
342 342 ============
343 343
344 344 Third release of IPython for 2021, mostly containing bug fixes. A couple of not
345 345 typical updates:
346 346
347 347 Misc
348 348 ----
349 349
350 350
351 351 - Fix an issue where ``%recall`` would both succeeded and print an error message
352 352 it failed. :ghpull:`12952`
353 353 - Drop support for NumPy 1.16 – practically has no effect beyond indicating in
354 354 package metadata that we do not support it. :ghpull:`12937`
355 355
356 356 Debugger improvements
357 357 ---------------------
358 358
359 359 The debugger (and ``%debug`` magic) have been improved and can skip or hide frames
360 360 originating from files that are not writable to the user, as these are less
361 361 likely to be the source of errors, or be part of system files this can be a useful
362 362 addition when debugging long errors.
363 363
364 364 In addition to the global ``skip_hidden True|False`` command, the debugger has
365 365 gained finer grained control of predicates as to whether to a frame should be
366 366 considered hidden. So far 3 predicates are available :
367 367
368 368 - ``tbhide``: frames containing the local variable ``__tracebackhide__`` set to
369 369 True.
370 370 - ``readonly``: frames originating from readonly files, set to False.
371 371 - ``ipython_internal``: frames that are likely to be from IPython internal
372 372 code, set to True.
373 373
374 374 You can toggle individual predicates during a session with
375 375
376 376 .. code-block::
377 377
378 378 ipdb> skip_predicates readonly True
379 379
380 380 Read-only files will now be considered hidden frames.
381 381
382 382
383 383 You can call ``skip_predicates`` without arguments to see the states of current
384 384 predicates:
385 385
386 386 .. code-block::
387 387
388 388 ipdb> skip_predicates
389 389 current predicates:
390 390 tbhide : True
391 391 readonly : False
392 392 ipython_internal : True
393 393
394 394 If all predicates are set to ``False``, ``skip_hidden`` will practically have
395 395 no effect. We attempt to warn you when all predicates are False.
396 396
397 397 Note that the ``readonly`` predicate may increase disk access as we check for
398 398 file access permission for all frames on many command invocation, but is usually
399 399 cached by operating systems. Let us know if you encounter any issues.
400 400
401 401 As the IPython debugger does not use the traitlets infrastructure for
402 402 configuration, by editing your ``.pdbrc`` files and appending commands you would
403 403 like to be executed just before entering the interactive prompt. For example:
404 404
405 405
406 406 .. code::
407 407
408 408 # file : ~/.pdbrc
409 409 skip_predicates readonly True
410 410 skip_predicates tbhide False
411 411
412 412 Will hide read only frames by default and show frames marked with
413 413 ``__tracebackhide__``.
414 414
415 415
416 416
417 417
418 418 Thanks
419 419 ------
420 420
421 421 Many thanks to all the contributors to this release you can find all individual
422 422 contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/87>`__.
423 423
424 424 Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring
425 425 work on IPython and related libraries, in particular above mentioned
426 426 improvements to the debugger.
427 427
428 428
429 429
430 430
431 431 .. _version 7.23:
432 432
433 433 IPython 7.23 and 7.23.1
434 434 =======================
435 435
436 436
437 437 Third release of IPython for 2021, mostly containing bug fixes. A couple of not
438 438 typical updates:
439 439
440 440 - We moved to GitHub actions away from Travis-CI, the transition may not be
441 441 100% complete (not testing on nightly anymore), but as we ran out of
442 442 Travis-Ci hours on the IPython organisation that was a necessary step.
443 443 :ghpull:`12900`.
444 444
445 445 - We have a new dependency: ``matplotlib-inline``, which try to extract
446 446 matplotlib inline backend specific behavior. It is available on PyPI and
447 447 conda-forge thus should not be a problem to upgrade to this version. If you
448 448 are a package maintainer that might be an extra dependency to package first.
449 449 :ghpull:`12817` (IPython 7.23.1 fix a typo that made this change fail)
450 450
451 451 In the addition/new feature category, ``display()`` now have a ``clear=True``
452 452 option to clear the display if any further outputs arrives, allowing users to
453 453 avoid having to use ``clear_output()`` directly. :ghpull:`12823`.
454 454
455 455 In bug fixes category, this release fix an issue when printing tracebacks
456 456 containing Unicode characters :ghpull:`12758`.
457 457
458 458 In code cleanup category :ghpull:`12932` remove usage of some deprecated
459 459 functionality for compatibility with Python 3.10.
460 460
461 461
462 462
463 463 Thanks
464 464 ------
465 465
466 466 Many thanks to all the contributors to this release you can find all individual
467 467 contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/86>`__.
468 468 In particular MrMino for responding to almost all new issues, and triaging many
469 469 of the old ones, as well as takluyver, minrk, willingc for reacting quikly when
470 470 we ran out of CI Hours.
471 471
472 472 Thanks as well to organisations, QuantStack (martinRenou and SylvainCorlay) for
473 473 extracting matplotlib inline backend into its own package, and the `D. E. Shaw group
474 474 <https://deshaw.com/>`__ for sponsoring work on IPython and related libraries.
475 475
476 476
477 477 .. _version 7.22:
478 478
479 479 IPython 7.22
480 480 ============
481 481
482 482 Second release of IPython for 2021, mostly containing bug fixes. Here is a quick
483 483 rundown of the few changes.
484 484
485 485 - Fix some ``sys.excepthook`` shenanigan when embedding with qt, recommended if
486 486 you – for example – use `napari <https://napari.org>`__. :ghpull:`12842`.
487 487 - Fix bug when using the new ipdb ``%context`` magic :ghpull:`12844`
488 488 - Couples of deprecation cleanup :ghpull:`12868`
489 489 - Update for new dpast.com api if you use the ``%pastbin`` magic. :ghpull:`12712`
490 490 - Remove support for numpy before 1.16. :ghpull:`12836`
491 491
492 492
493 493 Thanks
494 494 ------
495 495
496 496 We have a new team member that you should see more often on the IPython
497 497 repository, BΕ‚aΕΌej Michalik (@MrMino) have been doing regular contributions to
498 498 IPython, and spent time replying to many issues and guiding new users to the
499 499 codebase; they now have triage permissions to the IPython repository and we'll
500 500 work toward giving them more permission in the future.
501 501
502 502 Many thanks to all the contributors to this release you can find all individual
503 503 contributions to this milestone `on github <https://github.com/ipython/ipython/milestone/84>`__.
504 504
505 505 Thanks as well to organisations, QuantStack for working on debugger
506 506 compatibility for Xeus_python, and the `D. E. Shaw group
507 507 <https://deshaw.com/>`__ for sponsoring work on IPython and related libraries.
508 508
509 509 .. _version 721:
510 510
511 511 IPython 7.21
512 512 ============
513 513
514 514 IPython 7.21 is the first release we have back on schedule of one release every
515 515 month; it contains a number of minor fixes and improvements, notably, the new
516 516 context command for ipdb
517 517
518 518
519 519 New "context" command in ipdb
520 520 -----------------------------
521 521
522 522 It is now possible to change the number of lines shown in the backtrace
523 523 information in ipdb using "context" command. :ghpull:`12826`
524 524
525 525 (thanks @MrMino, there are other improvement from them on master).
526 526
527 527 Other notable changes in IPython 7.21
528 528 -------------------------------------
529 529
530 530 - Fix some issues on new osx-arm64 :ghpull:`12804`, :ghpull:`12807`.
531 531 - Compatibility with Xeus-Python for debugger protocol, :ghpull:`12809`
532 532 - Misc docs fixes for compatibility and uniformity with Numpydoc.
533 533 :ghpull:`12824`
534 534
535 535
536 536 Thanks
537 537 ------
538 538
539 539 Many thanks to all the contributors to this release you can find all individual
540 540 contribution to this milestone `on github <https://github.com/ipython/ipython/milestone/83>`__.
541 541
542 542
543 543 .. _version 720:
544 544
545 545 IPython 7.20
546 546 ============
547 547
548 548 IPython 7.20 is the accumulation of 3 month of work on IPython, spacing between
549 549 IPython release have been increased from the usual once a month for various
550 550 reason.
551 551
552 552 - Mainly as I'm too busy and the effectively sole maintainer, and
553 553 - Second because not much changes happened before mid December.
554 554
555 555 The main driver for this release was the new version of Jedi 0.18 breaking API;
556 556 which was taken care of in the master branch early in 2020 but not in 7.x as I
557 557 though that by now 8.0 would be out.
558 558
559 559 The inclusion of a resolver in pip did not help and actually made things worse.
560 560 If usually I would have simply pinned Jedi to ``<0.18``; this is not a solution
561 561 anymore as now pip is free to install Jedi 0.18, and downgrade IPython.
562 562
563 563 I'll do my best to keep the regular release, but as the 8.0-dev branch and 7.x
564 564 are starting to diverge this is becoming difficult in particular with my limited
565 565 time, so if you have any cycles to spare I'll appreciate your help to respond to
566 566 issues and pushing 8.0 forward.
567 567
568 568 Here are thus some of the changes for IPython 7.20.
569 569
570 570 - Support for PyQt5 >= 5.11 :ghpull:`12715`
571 571 - ``%reset`` remove imports more agressively :ghpull:`12718`
572 572 - fix the ``%conda`` magic :ghpull:`12739`
573 573 - compatibility with Jedi 0.18, and bump minimum Jedi version. :ghpull:`12793`
574 574
575 575
576 576 .. _version 719:
577 577
578 578 IPython 7.19
579 579 ============
580 580
581 581 IPython 7.19 accumulative two month of works, bug fixes and improvements, there
582 582 was exceptionally no release last month.
583 583
584 584 - Fix to restore the ability to specify more than one extension using command
585 585 line flags when using traitlets 5.0 :ghpull:`12543`
586 586 - Docs docs formatting that make the install commands work on zsh
587 587 :ghpull:`12587`
588 588 - Always display the last frame in tracebacks even if hidden with
589 589 ``__tracebackhide__`` :ghpull:`12601`
590 590 - Avoid an issue where a callback can be registered multiple times.
591 591 :ghpull:`12625`
592 592 - Avoid an issue in debugger mode where frames changes could be lost.
593 593 :ghpull:`12627`
594 594
595 595 - Never hide the frames that invoke a debugger, even if marked as hidden by
596 596 ``__tracebackhide__`` :ghpull:`12631`
597 597 - Fix calling the debugger in a recursive manner :ghpull:`12659`
598 598
599 599
600 600 A number of code changes have landed on master and we are getting close to
601 601 enough new features and codebase improvement that a 8.0 start to make sens.
602 602 For downstream packages, please start working on migrating downstream testing
603 603 away from iptest and using pytest, as nose will not work on Python 3.10 and we
604 604 will likely start removing it as a dependency for testing.
605 605
606 606 .. _version 718:
607 607
608 608 IPython 7.18
609 609 ============
610 610
611 611 IPython 7.18 is a minor release that mostly contains bugfixes.
612 612
613 613 - ``CRLF`` is now handled by magics my default; solving some issues due to copy
614 614 pasting on windows. :ghpull:`12475`
615 615
616 616 - Requiring pexpect ``>=4.3`` as we are Python 3.7+ only and earlier version of
617 617 pexpect will be incompatible. :ghpull:`12510`
618 618
619 619 - Minimum jedi version is now 0.16. :ghpull:`12488`
620 620
621 621
622 622
623 623 .. _version 717:
624 624
625 625 IPython 7.17
626 626 ============
627 627
628 628 IPython 7.17 brings a couple of new improvements to API and a couple of user
629 629 facing changes to make the terminal experience more user friendly.
630 630
631 631 :ghpull:`12407` introduces the ability to pass extra argument to the IPython
632 632 debugger class; this is to help a new project from ``kmaork``
633 633 (https://github.com/kmaork/madbg) to feature a fully remote debugger.
634 634
635 635 :ghpull:`12410` finally remove support for 3.6, while the codebase is still
636 636 technically compatible; IPython will not install on Python 3.6.
637 637
638 638 lots of work on the debugger and hidden frames from ``@impact27`` in
639 639 :ghpull:`12437`, :ghpull:`12445`, :ghpull:`12460` and in particular
640 640 :ghpull:`12453` which make the debug magic more robust at handling spaces.
641 641
642 642 Biggest API addition is code transformation which is done before code execution;
643 643 IPython allows a number of hooks to catch non-valid Python syntax (magic, prompt
644 644 stripping...etc). Transformers are usually called many time; typically:
645 645
646 646 - When trying to figure out whether the code is complete and valid (should we
647 647 insert a new line or execute ?)
648 648 - During actual code execution pass before giving the code to Python's
649 649 ``exec``.
650 650
651 651 This lead to issues when transformer might have had side effects; or do external
652 652 queries. Starting with IPython 7.17 you can expect your transformer to be called
653 653 less time.
654 654
655 655 Input transformers are now called only once in the execution path of
656 656 `InteractiveShell`, allowing to register transformer that potentially have side
657 657 effects (note that this is not recommended). Internal methods `should_run_async`, and
658 658 `run_cell_async` now take a recommended optional `transformed_cell`, and
659 659 `preprocessing_exc_tuple` parameters that will become mandatory at some point in
660 660 the future; that is to say cells need to be explicitly transformed to be valid
661 661 Python syntax ahead of trying to run them. :ghpull:`12440`;
662 662
663 663 ``input_transformers`` can now also have an attribute ``has_side_effects`` set
664 664 to `True`, when this attribute is present; this will prevent the transformers
665 665 from being ran when IPython is trying to guess whether the user input is
666 666 complete. Note that this may means you will need to explicitly execute in some
667 667 case where your transformations are now not ran; but will not affect users with
668 668 no custom extensions.
669 669
670 670
671 671 API Changes
672 672 -----------
673 673
674 674 Change of API and exposed objects automatically detected using `frappuccino
675 675 <https://pypi.org/project/frappuccino/>`_
676 676
677 677
678 678 The following items are new since 7.16.0::
679 679
680 680 + IPython.core.interactiveshell.InteractiveShell.get_local_scope(self, stack_depth)
681 681
682 682 The following signatures differ since 7.16.0::
683 683
684 684 - IPython.core.interactiveshell.InteractiveShell.run_cell_async(self, raw_cell, store_history=False, silent=False, shell_futures=True)
685 685 + 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)
686 686
687 687 - IPython.core.interactiveshell.InteractiveShell.should_run_async(self, raw_cell)
688 688 + IPython.core.interactiveshell.InteractiveShell.should_run_async(self, raw_cell, *, transformed_cell=None, preprocessing_exc_tuple=None)
689 689
690 690 - IPython.terminal.debugger.TerminalPdb.pt_init(self)
691 691 + IPython.terminal.debugger.TerminalPdb.pt_init(self, pt_session_options=None)
692 692
693 693 This method was added::
694 694
695 695 + IPython.core.interactiveshell.InteractiveShell.get_local_scope
696 696
697 697 Which is now also present on subclasses::
698 698
699 699 + IPython.terminal.embed.InteractiveShellEmbed.get_local_scope
700 700 + IPython.terminal.interactiveshell.TerminalInteractiveShell.get_local_scope
701 701
702 702
703 703 .. _version 716:
704 704
705 705 IPython 7.16.1, 7.16.2
706 706 ======================
707 707
708 708 IPython 7.16.1 was release immediately after 7.16.0 to fix a conda packaging issue.
709 709 The source is identical to 7.16.0 but the file permissions in the tar are different.
710 710
711 711 IPython 7.16.2 pins jedi dependency to "<=0.17.2" which should prevent some
712 712 issues for users still on python 3.6. This may not be sufficient as pip may
713 713 still allow to downgrade IPython.
714 714
715 715 Compatibility with Jedi > 0.17.2 was not added as this would have meant bumping
716 716 the minimal version to >0.16.
717 717
718 718 IPython 7.16
719 719 ============
720 720
721 721
722 722 The default traceback mode will now skip frames that are marked with
723 723 ``__tracebackhide__ = True`` and show how many traceback frames have been
724 724 skipped. This can be toggled by using :magic:`xmode` with the ``--show`` or
725 725 ``--hide`` attribute. It will have no effect on non verbose traceback modes.
726 726
727 727 The ipython debugger also now understands ``__tracebackhide__`` as well and will
728 728 skip hidden frames when displaying. Movement up and down the stack will skip the
729 729 hidden frames and will show how many frames were hidden. Internal IPython frames
730 730 are also now hidden by default. The behavior can be changed with the
731 731 ``skip_hidden`` while in the debugger, command and accepts "yes", "no", "true"
732 732 and "false" case insensitive parameters.
733 733
734 734
735 735 Misc Noticeable changes:
736 736 ------------------------
737 737
738 738 - Exceptions are now (re)raised when running notebooks via the :magic:`%run`, helping to catch issues in workflows and
739 739 pipelines. :ghpull:`12301`
740 740 - Fix inputhook for qt 5.15.0 :ghpull:`12355`
741 741 - Fix wx inputhook :ghpull:`12375`
742 742 - Add handling for malformed pathext env var (Windows) :ghpull:`12367`
743 743 - use $SHELL in system_piped :ghpull:`12360` for uniform behavior with
744 744 ipykernel.
745 745
746 746 Reproducible Build
747 747 ------------------
748 748
749 749 IPython 7.15 reproducible build did not work, so we try again this month
750 750 :ghpull:`12358`.
751 751
752 752
753 753 API Changes
754 754 -----------
755 755
756 756 Change of API and exposed objects automatically detected using `frappuccino
757 757 <https://pypi.org/project/frappuccino/>`_ (still in beta):
758 758
759 759
760 760 The following items are new and mostly related to understanding ``__tracebackhide__``::
761 761
762 762 + IPython.core.debugger.Pdb.do_down(self, arg)
763 763 + IPython.core.debugger.Pdb.do_skip_hidden(self, arg)
764 764 + IPython.core.debugger.Pdb.do_up(self, arg)
765 765 + IPython.core.debugger.Pdb.hidden_frames(self, stack)
766 766 + IPython.core.debugger.Pdb.stop_here(self, frame)
767 767
768 768
769 769 The following items have been removed::
770 770
771 771 - IPython.core.debugger.Pdb.new_do_down
772 772 - IPython.core.debugger.Pdb.new_do_up
773 773
774 774 Those were implementation details.
775 775
776 776
777 777 .. _version 715:
778 778
779 779 IPython 7.15
780 780 ============
781 781
782 782 IPython 7.15 brings a number of bug fixes and user facing improvements.
783 783
784 784 Misc Noticeable changes:
785 785 ------------------------
786 786
787 787 - Long completion name have better elision in terminal :ghpull:`12284`
788 788 - I've started to test on Python 3.9 :ghpull:`12307` and fix some errors.
789 789 - Hi DPI scaling of figures when using qt eventloop :ghpull:`12314`
790 790 - Document the ability to have systemwide configuration for IPython.
791 791 :ghpull:`12328`
792 792 - Fix issues with input autoformatting :ghpull:`12336`
793 793 - ``IPython.core.debugger.Pdb`` is now interruptible (:ghpull:`12168`, in 7.14
794 794 but forgotten in release notes)
795 795 - Video HTML attributes (:ghpull:`12212`, in 7.14 but forgotten in release
796 796 notes)
797 797
798 798 Reproducible Build
799 799 ------------------
800 800
801 801 Starting with IPython 7.15, I am attempting to provide reproducible builds,
802 802 that is to say you should be able from the source tree to generate an sdist
803 803 and wheel that are identical byte for byte with the publish version on PyPI.
804 804
805 805 I've only tested on a couple of machines so far and the process is relatively
806 806 straightforward, so this mean that IPython not only have a deterministic build
807 807 process, but also I have either removed, or put under control all effects of
808 808 the build environments on the final artifact. I encourage you to attempt the
809 809 build process on your machine as documented in :ref:`core_developer_guide`
810 810 and let me know if you do not obtain an identical artifact.
811 811
812 812 While reproducible builds is critical to check that the supply chain of (open
813 813 source) software has not been compromised, it can also help to speedup many
814 814 of the build processes in large environment (conda, apt...) by allowing
815 815 better caching of intermediate build steps.
816 816
817 817 Learn more on `<https://reproducible-builds.org/>`_. `Reflections on trusting
818 818 trust <https://dl.acm.org/doi/10.1145/358198.358210>`_ is also one of the
819 819 cornerstone and recommended reads on this subject.
820 820
821 821 .. note::
822 822
823 823 The build commit from which the sdist is generated is also `signed
824 824 <https://en.wikipedia.org/wiki/Digital_signature>`_, so you should be able to
825 825 check it has not been compromised, and the git repository is a `merkle-tree
826 826 <https://en.wikipedia.org/wiki/Merkle_tree>`_, you can check the consistency
827 827 with `git-fsck <https://git-scm.com/docs/git-fsck>`_ which you likely `want
828 828 to enable by default
829 829 <https://gist.github.com/mbbx6spp/14b86437e794bffb4120>`_.
830 830
831 831 NEP29: Last version to support Python 3.6
832 832 -----------------------------------------
833 833
834 834 IPython 7.15 will be the Last IPython version to officially support Python
835 835 3.6, as stated by `NumPy Enhancement Proposal 29
836 836 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_. Starting with
837 837 next minor version of IPython I may stop testing on Python 3.6 and may stop
838 838 publishing release artifacts that install on Python 3.6
839 839
840 840 Highlighted features
841 841 --------------------
842 842
843 843 Highlighted features are not new, but seem to not be widely known, this
844 844 section will help you discover in more narrative form what you can do with
845 845 IPython.
846 846
847 847 Increase Tab Completion Menu Height
848 848 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
849 849
850 850 In terminal IPython it is possible to increase the hight of the tab-completion
851 851 menu. To do so set the value of
852 852 :configtrait:`TerminalInteractiveShell.space_for_menu`, this will reserve more
853 853 space at the bottom of the screen for various kind of menus in IPython including
854 854 tab completion and searching in history.
855 855
856 856 Autoformat Code in the terminal
857 857 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
858 858
859 859 If you have a preferred code formatter, you can configure IPython to
860 860 reformat your code. Set the value of
861 861 :configtrait:`TerminalInteractiveShell.autoformatter` to for example ``'black'``
862 862 and IPython will auto format your code when possible.
863 863
864 864
865 865 .. _version 714:
866 866
867 867 IPython 7.14
868 868 ============
869 869
870 870 IPython 7.14 is a minor release that fix a couple of bugs and prepare
871 871 compatibility with new or future versions of some libraries.
872 872
873 873 Important changes:
874 874 ------------------
875 875
876 876 - Fix compatibility with Sphinx 3+ :ghpull:`12235`
877 877 - Remove deprecated matplotlib parameter usage, compatibility with matplotlib
878 878 3.3+ :`122250`
879 879
880 880 Misc Changes
881 881 ------------
882 882
883 883 - set ``.py`` extension when editing current buffer in vi/emacs. :ghpull:`12167`
884 884 - support for unicode identifiers in ``?``/``??`` :ghpull:`12208`
885 885 - add extra options to the ``Video`` Rich objects :ghpull:`12212`
886 886 - add pretty-printing to ``SimpleNamespace`` :ghpull:`12230`
887 887
888 888 IPython.core.debugger.Pdb is now interruptible
889 889 ----------------------------------------------
890 890
891 891 A ``KeyboardInterrupt`` will now interrupt IPython's extended debugger, in order to make Jupyter able to interrupt it. (:ghpull:`12168`)
892 892
893 893 Video HTML attributes
894 894 ---------------------
895 895
896 896 Add an option to `IPython.display.Video` to change the attributes of the HTML display of the video (:ghpull:`12212`)
897 897
898 898
899 899 Pending deprecated imports
900 900 --------------------------
901 901
902 902 Many object present in ``IPython.core.display`` are there for internal use only,
903 903 and should already been imported from ``IPython.display`` by users and external
904 904 libraries. Trying to import those from ``IPython.core.display`` is still possible
905 905 but will trigger a
906 906 deprecation warning in later versions of IPython and will become errors in the
907 907 future.
908 908
909 909 This will simplify compatibility with other Python kernels (like Xeus-Python),
910 910 and simplify code base.
911 911
912 912
913 913
914 914
915 915 .. _version 713:
916 916
917 917 IPython 7.13
918 918 ============
919 919
920 920 IPython 7.13 is the final release of the 7.x branch since master is diverging
921 921 toward an 8.0. Exiting new features have already been merged in 8.0 and will
922 922 not be available on the 7.x branch. All the changes below have been backported
923 923 from the master branch.
924 924
925 925
926 926 - Fix inability to run PDB when inside an event loop :ghpull:`12141`
927 927 - Fix ability to interrupt some processes on windows :ghpull:`12137`
928 928 - Fix debugger shortcuts :ghpull:`12132`
929 929 - improve tab completion when inside a string by removing irrelevant elements :ghpull:`12128`
930 930 - Fix display of filename tab completion when the path is long :ghpull:`12122`
931 931 - Many removal of Python 2 specific code path :ghpull:`12110`
932 932 - displaying wav files do not require NumPy anymore, and is 5x to 30x faster :ghpull:`12113`
933 933
934 934 See the list of all closed issues and pull request on `github
935 935 <https://github.com/ipython/ipython/pulls?q=is%3Aclosed+milestone%3A7.13>`_.
936 936
937 937 .. _version 712:
938 938
939 939 IPython 7.12
940 940 ============
941 941
942 942 IPython 7.12 is a minor update that mostly brings code cleanup, removal of
943 943 longtime deprecated function and a couple update to documentation cleanup as well.
944 944
945 945 Notable changes are the following:
946 946
947 947 - Exit non-zero when ipython is given a file path to run that doesn't exist :ghpull:`12074`
948 948 - Test PR on ARM64 with Travis-CI :ghpull:`12073`
949 949 - Update CI to work with latest Pytest :ghpull:`12086`
950 950 - Add infrastructure to run ipykernel eventloop via trio :ghpull:`12097`
951 951 - Support git blame ignore revs :ghpull:`12091`
952 952 - Start multi-line ``__repr__`` s on their own line :ghpull:`12099`
953 953
954 954 .. _version 7111:
955 955
956 956 IPython 7.11.1
957 957 ==============
958 958
959 959 A couple of deprecated functions (no-op) have been reintroduces in py3compat as
960 960 Cython was still relying on them, and will be removed in a couple of versions.
961 961
962 962 .. _version 711:
963 963
964 964 IPython 7.11
965 965 ============
966 966
967 967 IPython 7.11 received a couple of compatibility fixes and code cleanup.
968 968
969 969 A number of function in the ``py3compat`` have been removed; a number of types
970 970 in the IPython code base are now non-ambiguous and now always ``unicode``
971 971 instead of ``Union[Unicode,bytes]``; many of the relevant code path have thus
972 972 been simplified/cleaned and types annotation added.
973 973
974 974 IPython support several verbosity level from exceptions. ``xmode plain`` now
975 975 support chained exceptions. :ghpull:`11999`
976 976
977 977 We are starting to remove ``shell=True`` in some usages of subprocess. While not directly
978 978 a security issue (as IPython is made to run arbitrary code anyway) it is not good
979 979 practice and we'd like to show the example. :ghissue:`12023`. This discussion
980 980 was started by ``@mschwager`` thanks to a new auditing tool they are working on
981 981 with duo-labs (`dlint <https://github.com/duo-labs/dlint>`_).
982 982
983 983 Work around some bugs in Python 3.9 tokenizer :ghpull:`12057`
984 984
985 985 IPython will now print its version after a crash. :ghpull:`11986`
986 986
987 987 This is likely the last release from the 7.x series that will see new feature.
988 988 The master branch will soon accept large code changes and thrilling new
989 989 features; the 7.x branch will only start to accept critical bug fixes, and
990 990 update dependencies.
991 991
992 992 .. _version 7102:
993 993
994 994 IPython 7.10.2
995 995 ==============
996 996
997 997 IPython 7.10.2 fix a couple of extra incompatibility between IPython, ipdb,
998 998 asyncio and Prompt Toolkit 3.
999 999
1000 1000 .. _version 7101:
1001 1001
1002 1002 IPython 7.10.1
1003 1003 ==============
1004 1004
1005 1005 IPython 7.10.1 fix a couple of incompatibilities with Prompt toolkit 3 (please
1006 1006 update Prompt toolkit to 3.0.2 at least), and fixes some interaction with
1007 1007 headless IPython.
1008 1008
1009 1009 .. _version 7100:
1010 1010
1011 1011 IPython 7.10.0
1012 1012 ==============
1013 1013
1014 1014 IPython 7.10 is the first double digit minor release in the last decade, and
1015 1015 first since the release of IPython 1.0, previous double digit minor release was
1016 1016 in August 2009.
1017 1017
1018 1018 We've been trying to give you regular release on the last Friday of every month
1019 1019 for a guaranty of rapid access to bug fixes and new features.
1020 1020
1021 1021 Unlike the previous first few releases that have seen only a couple of code
1022 1022 changes, 7.10 bring a number of changes, new features and bugfixes.
1023 1023
1024 1024 Stop Support for Python 3.5 – Adopt NEP 29
1025 1025 ------------------------------------------
1026 1026
1027 1027 IPython has decided to follow the informational `NEP 29
1028 1028 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_ which layout a clear
1029 1029 policy as to which version of (C)Python and NumPy are supported.
1030 1030
1031 1031 We thus dropped support for Python 3.5, and cleaned up a number of code path
1032 1032 that were Python-version dependant. If you are on 3.5 or earlier pip should
1033 1033 automatically give you the latest compatible version of IPython so you do not
1034 1034 need to pin to a given version.
1035 1035
1036 1036 Support for Prompt Toolkit 3.0
1037 1037 ------------------------------
1038 1038
1039 1039 Prompt Toolkit 3.0 was release a week before IPython 7.10 and introduces a few
1040 1040 breaking changes. We believe IPython 7.10 should be compatible with both Prompt
1041 1041 Toolkit 2.x and 3.x, though it has not been extensively tested with 3.x so
1042 1042 please report any issues.
1043 1043
1044 1044
1045 1045 Prompt Rendering Performance improvements
1046 1046 -----------------------------------------
1047 1047
1048 1048 Pull Request :ghpull:`11933` introduced an optimisation in the prompt rendering
1049 1049 logic that should decrease the resource usage of IPython when using the
1050 1050 _default_ configuration but could potentially introduce a regression of
1051 1051 functionalities if you are using a custom prompt.
1052 1052
1053 1053 We know assume if you haven't changed the default keybindings that the prompt
1054 1054 **will not change** during the duration of your input – which is for example
1055 1055 not true when using vi insert mode that switches between `[ins]` and `[nor]`
1056 1056 for the current mode.
1057 1057
1058 1058 If you are experiencing any issue let us know.
1059 1059
1060 1060 Code autoformatting
1061 1061 -------------------
1062 1062
1063 1063 The IPython terminal can now auto format your code just before entering a new
1064 1064 line or executing a command. To do so use the
1065 1065 ``--TerminalInteractiveShell.autoformatter`` option and set it to ``'black'``;
1066 1066 if black is installed IPython will use black to format your code when possible.
1067 1067
1068 1068 IPython cannot always properly format your code; in particular it will
1069 1069 auto formatting with *black* will only work if:
1070 1070
1071 1071 - Your code does not contains magics or special python syntax.
1072 1072
1073 1073 - There is no code after your cursor.
1074 1074
1075 1075 The Black API is also still in motion; so this may not work with all versions of
1076 1076 black.
1077 1077
1078 1078 It should be possible to register custom formatter, though the API is till in
1079 1079 flux.
1080 1080
1081 1081 Arbitrary Mimetypes Handing in Terminal (Aka inline images in terminal)
1082 1082 -----------------------------------------------------------------------
1083 1083
1084 1084 When using IPython terminal it is now possible to register function to handle
1085 1085 arbitrary mimetypes. While rendering non-text based representation was possible in
1086 1086 many jupyter frontend; it was not possible in terminal IPython, as usually
1087 1087 terminal are limited to displaying text. As many terminal these days provide
1088 1088 escape sequences to display non-text; bringing this loved feature to IPython CLI
1089 1089 made a lot of sens. This functionality will not only allow inline images; but
1090 1090 allow opening of external program; for example ``mplayer`` to "display" sound
1091 1091 files.
1092 1092
1093 1093 So far only the hooks necessary for this are in place, but no default mime
1094 1094 renderers added; so inline images will only be available via extensions. We will
1095 1095 progressively enable these features by default in the next few releases, and
1096 1096 contribution is welcomed.
1097 1097
1098 1098 We welcome any feedback on the API. See :ref:`shell_mimerenderer` for more
1099 1099 informations.
1100 1100
1101 1101 This is originally based on work form in :ghpull:`10610` from @stephanh42
1102 1102 started over two years ago, and still a lot need to be done.
1103 1103
1104 1104 MISC
1105 1105 ----
1106 1106
1107 1107 - Completions can define their own ordering :ghpull:`11855`
1108 1108 - Enable Plotting in the same cell than the one that import matplotlib
1109 1109 :ghpull:`11916`
1110 1110 - Allow to store and restore multiple variables at once :ghpull:`11930`
1111 1111
1112 1112 You can see `all pull-requests <https://github.com/ipython/ipython/pulls?q=is%3Apr+milestone%3A7.10+is%3Aclosed>`_ for this release.
1113 1113
1114 1114 API Changes
1115 1115 -----------
1116 1116
1117 1117 Change of API and exposed objects automatically detected using `frappuccino <https://pypi.org/project/frappuccino/>`_ (still in beta):
1118 1118
1119 1119 The following items are new in IPython 7.10::
1120 1120
1121 1121 + IPython.terminal.shortcuts.reformat_text_before_cursor(buffer, document, shell)
1122 1122 + IPython.terminal.interactiveshell.PTK3
1123 1123 + IPython.terminal.interactiveshell.black_reformat_handler(text_before_cursor)
1124 1124 + IPython.terminal.prompts.RichPromptDisplayHook.write_format_data(self, format_dict, md_dict='None')
1125 1125
1126 1126 The following items have been removed in 7.10::
1127 1127
1128 1128 - IPython.lib.pretty.DICT_IS_ORDERED
1129 1129
1130 1130 The following signatures differ between versions::
1131 1131
1132 1132 - IPython.extensions.storemagic.restore_aliases(ip)
1133 1133 + IPython.extensions.storemagic.restore_aliases(ip, alias='None')
1134 1134
1135 1135 Special Thanks
1136 1136 --------------
1137 1137
1138 1138 - @stephanh42 who started the work on inline images in terminal 2 years ago
1139 1139 - @augustogoulart who spent a lot of time triaging issues and responding to
1140 1140 users.
1141 1141 - @con-f-use who is my (@Carreau) first sponsor on GitHub, as a reminder if you
1142 1142 like IPython, Jupyter and many other library of the SciPy stack you can
1143 1143 donate to numfocus.org non profit
1144 1144
1145 1145 .. _version 790:
1146 1146
1147 1147 IPython 7.9.0
1148 1148 =============
1149 1149
1150 1150 IPython 7.9 is a small release with a couple of improvement and bug fixes.
1151 1151
1152 1152 - Xterm terminal title should be restored on exit :ghpull:`11910`
1153 1153 - special variables ``_``,``__``, ``___`` are not set anymore when cache size
1154 1154 is 0 or less. :ghpull:`11877`
1155 1155 - Autoreload should have regained some speed by using a new heuristic logic to
1156 1156 find all objects needing reload. This should avoid large objects traversal
1157 1157 like pandas dataframes. :ghpull:`11876`
1158 1158 - Get ready for Python 4. :ghpull:`11874`
1159 1159 - `%env` Magic now has heuristic to hide potentially sensitive values :ghpull:`11896`
1160 1160
1161 1161 This is a small release despite a number of Pull Request Pending that need to
1162 1162 be reviewed/worked on. Many of the core developers have been busy outside of
1163 1163 IPython/Jupyter and we thanks all contributor for their patience; we'll work on
1164 1164 these as soon as we have time.
1165 1165
1166 1166
1167 1167 .. _version780:
1168 1168
1169 1169 IPython 7.8.0
1170 1170 =============
1171 1171
1172 1172 IPython 7.8.0 contain a few bugfix and 2 new APIs:
1173 1173
1174 1174 - Enable changing the font color for LaTeX rendering :ghpull:`11840`
1175 1175 - and Re-Expose some PDB API (see below)
1176 1176
1177 1177 Expose Pdb API
1178 1178 --------------
1179 1179
1180 1180 Expose the built-in ``pdb.Pdb`` API. ``Pdb`` constructor arguments are generically
1181 1181 exposed, regardless of python version.
1182 1182 Newly exposed arguments:
1183 1183
1184 1184 - ``skip`` - Python 3.1+
1185 1185 - ``nosiginnt`` - Python 3.2+
1186 1186 - ``readrc`` - Python 3.6+
1187 1187
1188 1188 Try it out::
1189 1189
1190 1190 from IPython.terminal.debugger import TerminalPdb
1191 1191 pdb = TerminalPdb(skip=["skipthismodule"])
1192 1192
1193 1193
1194 1194 See :ghpull:`11840`
1195 1195
1196 1196 .. _version770:
1197 1197
1198 1198 IPython 7.7.0
1199 1199 =============
1200 1200
1201 1201 IPython 7.7.0 contain multiple bug fixes and documentation updates; Here are a
1202 1202 few of the outstanding issue fixed:
1203 1203
1204 1204 - Fix a bug introduced in 7.6 where the ``%matplotlib`` magic would fail on
1205 1205 previously acceptable arguments :ghpull:`11814`.
1206 1206 - Fix the manage location on freebsd :ghpull:`11808`.
1207 1207 - Fix error message about aliases after ``%reset`` call in ipykernel
1208 1208 :ghpull:`11806`
1209 1209 - Fix Duplication completions in emacs :ghpull:`11803`
1210 1210
1211 1211 We are planning to adopt `NEP29 <https://github.com/numpy/numpy/pull/14086>`_
1212 1212 (still currently in draft) which may make this minor version of IPython the
1213 1213 last one to support Python 3.5 and will make the code base more aggressive
1214 1214 toward removing compatibility with older versions of Python.
1215 1215
1216 1216 GitHub now support to give only "Triage" permissions to users; if you'd like to
1217 1217 help close stale issues and labels issues please reach to us with your GitHub
1218 1218 Username and we'll add you to the triage team. It is a great way to start
1219 1219 contributing and a path toward getting commit rights.
1220 1220
1221 1221 .. _version761:
1222 1222
1223 1223 IPython 7.6.1
1224 1224 =============
1225 1225
1226 1226 IPython 7.6.1 contain a critical bugfix in the ``%timeit`` magic, which would
1227 1227 crash on some inputs as a side effect of :ghpull:`11716`. See :ghpull:`11812`
1228 1228
1229 1229
1230 1230 .. _whatsnew760:
1231 1231
1232 1232 IPython 7.6.0
1233 1233 =============
1234 1234
1235 1235 IPython 7.6.0 contains a couple of bug fixes and number of small features
1236 1236 additions as well as some compatibility with the current development version of
1237 1237 Python 3.8.
1238 1238
1239 1239 - Add a ``-l`` option to :magic:`psearch` to list the available search
1240 1240 types. :ghpull:`11672`
1241 1241 - Support ``PathLike`` for ``DisplayObject`` and ``Image``. :ghpull:`11764`
1242 1242 - Configurability of timeout in the test suite for slow platforms.
1243 1243 :ghpull:`11756`
1244 1244 - Accept any casing for matplotlib backend. :ghpull:`121748`
1245 1245 - Properly skip test that requires numpy to be installed :ghpull:`11723`
1246 1246 - More support for Python 3.8 and positional only arguments (pep570)
1247 1247 :ghpull:`11720`
1248 1248 - Unicode names for the completion are loaded lazily on first use which
1249 1249 should decrease startup time. :ghpull:`11693`
1250 1250 - Autoreload now update the types of reloaded objects; this for example allow
1251 1251 pickling of reloaded objects. :ghpull:`11644`
1252 1252 - Fix a bug where ``%%time`` magic would suppress cell output. :ghpull:`11716`
1253 1253
1254 1254
1255 1255 Prepare migration to pytest (instead of nose) for testing
1256 1256 ---------------------------------------------------------
1257 1257
1258 1258 Most of the work between 7.5 and 7.6 was to prepare the migration from our
1259 1259 testing framework to pytest. Most of the test suite should now work by simply
1260 1260 issuing ``pytest`` from the root of the repository.
1261 1261
1262 1262 The migration to pytest is just at its beginning. Many of our test still rely
1263 1263 on IPython-specific plugins for nose using pytest (doctest using IPython syntax
1264 1264 is one example of this where test appear as "passing", while no code has been
1265 1265 ran). Many test also need to be updated like ``yield-test`` to be properly
1266 1266 parametrized tests.
1267 1267
1268 1268 Migration to pytest allowed me to discover a number of issues in our test
1269 1269 suite; which was hiding a number of subtle issues – or not actually running
1270 1270 some of the tests in our test suite – I have thus corrected many of those; like
1271 1271 improperly closed resources; or used of deprecated features. I also made use of
1272 1272 the ``pytest --durations=...`` to find some of our slowest test and speed them
1273 1273 up (our test suite can now be up to 10% faster). Pytest as also a variety of
1274 1274 plugins and flags which will make the code quality of IPython and the testing
1275 1275 experience better.
1276 1276
1277 1277 Misc
1278 1278 ----
1279 1279
1280 1280 We skipped the release of 7.6 at the end of May, but will attempt to get back
1281 1281 on schedule. We are starting to think about making introducing backward
1282 1282 incompatible change and start the 8.0 series.
1283 1283
1284 1284 Special Thanks to Gabriel (@gpotter2 on GitHub), who among other took care many
1285 1285 of the remaining task for 7.4 and 7.5, like updating the website.
1286 1286
1287 1287 .. _whatsnew750:
1288 1288
1289 1289 IPython 7.5.0
1290 1290 =============
1291 1291
1292 1292 IPython 7.5.0 consist mostly of bug-fixes, and documentation updates, with one
1293 1293 minor new feature. The `Audio` display element can now be assigned an element
1294 1294 id when displayed in browser. See :ghpull:`11670`
1295 1295
1296 1296 The major outstanding bug fix correct a change of behavior that was introduce
1297 1297 in 7.4.0 where some cell magics would not be able to access or modify global
1298 1298 scope when using the ``@needs_local_scope`` decorator. This was typically
1299 1299 encountered with the ``%%time`` and ``%%timeit`` magics. See :ghissue:`11659`
1300 1300 and :ghpull:`11698`.
1301 1301
1302 1302 .. _whatsnew740:
1303 1303
1304 1304 IPython 7.4.0
1305 1305 =============
1306 1306
1307 1307 Unicode name completions
1308 1308 ------------------------
1309 1309
1310 1310 Previously, we provided completion for a unicode name with its relative symbol.
1311 1311 With this, now IPython provides complete suggestions to unicode name symbols.
1312 1312
1313 1313 As on the PR, if user types ``\LAT<tab>``, IPython provides a list of
1314 1314 possible completions. In this case, it would be something like::
1315 1315
1316 1316 'LATIN CAPITAL LETTER A',
1317 1317 'LATIN CAPITAL LETTER B',
1318 1318 'LATIN CAPITAL LETTER C',
1319 1319 'LATIN CAPITAL LETTER D',
1320 1320 ....
1321 1321
1322 1322 This help to type unicode character that do not have short latex aliases, and
1323 1323 have long unicode names. for example ``Ν°``, ``\GREEK CAPITAL LETTER HETA``.
1324 1324
1325 1325 This feature was contributed by Luciana Marques :ghpull:`11583`.
1326 1326
1327 1327 Make audio normalization optional
1328 1328 ---------------------------------
1329 1329
1330 1330 Added 'normalize' argument to `IPython.display.Audio`. This argument applies
1331 1331 when audio data is given as an array of samples. The default of `normalize=True`
1332 1332 preserves prior behavior of normalizing the audio to the maximum possible range.
1333 1333 Setting to `False` disables normalization.
1334 1334
1335 1335
1336 1336 Miscellaneous
1337 1337 -------------
1338 1338
1339 1339 - Fix improper acceptation of ``return`` outside of functions. :ghpull:`11641`.
1340 1340 - Fixed PyQt 5.11 backwards incompatibility causing sip import failure.
1341 1341 :ghpull:`11613`.
1342 1342 - Fix Bug where ``type?`` would crash IPython. :ghpull:`1608`.
1343 1343 - Allow to apply ``@needs_local_scope`` to cell magics for convenience.
1344 1344 :ghpull:`11542`.
1345 1345
1346 1346 .. _whatsnew730:
1347 1347
1348 1348 IPython 7.3.0
1349 1349 =============
1350 1350
1351 1351 .. _whatsnew720:
1352 1352
1353 1353 IPython 7.3.0 bring several bug fixes and small improvements that you will
1354 1354 described bellow.
1355 1355
1356 1356 The biggest change to this release is the implementation of the ``%conda`` and
1357 1357 ``%pip`` magics, that will attempt to install packages in the **current
1358 1358 environment**. You may still need to restart your interpreter or kernel for the
1359 1359 change to be taken into account, but it should simplify installation of packages
1360 1360 into remote environment. Installing using pip/conda from the command line is
1361 1361 still the prefer method.
1362 1362
1363 1363 The ``%pip`` magic was already present, but was only printing a warning; now it
1364 1364 will actually forward commands to pip.
1365 1365
1366 1366 Misc bug fixes and improvements:
1367 1367
1368 1368 - Compatibility with Python 3.8.
1369 1369 - Do not expand shell variable in execution magics, and added the
1370 1370 ``no_var_expand`` decorator for magic requiring a similar functionality
1371 1371 :ghpull:`11516`
1372 1372 - Add ``%pip`` and ``%conda`` magic :ghpull:`11524`
1373 1373 - Re-initialize posix aliases after a ``%reset`` :ghpull:`11528`
1374 1374 - Allow the IPython command line to run ``*.ipynb`` files :ghpull:`11529`
1375 1375
1376 1376 IPython 7.2.0
1377 1377 =============
1378 1378
1379 1379 IPython 7.2.0 brings minor bugfixes, improvements, and new configuration options:
1380 1380
1381 1381 - Fix a bug preventing PySide2 GUI integration from working :ghpull:`11464`
1382 1382 - Run CI on Mac OS ! :ghpull:`11471`
1383 1383 - Fix IPython "Demo" mode. :ghpull:`11498`
1384 1384 - Fix ``%run`` magic with path in name :ghpull:`11499`
1385 1385 - Fix: add CWD to sys.path *after* stdlib :ghpull:`11502`
1386 1386 - Better rendering of signatures, especially long ones. :ghpull:`11505`
1387 1387 - Re-enable jedi by default if it's installed :ghpull:`11506`
1388 1388 - Add New ``minimal`` exception reporting mode (useful for educational purpose). See :ghpull:`11509`
1389 1389
1390 1390
1391 1391 Added ability to show subclasses when using pinfo and other utilities
1392 1392 ---------------------------------------------------------------------
1393 1393
1394 1394 When using ``?``/``??`` on a class, IPython will now list the first 10 subclasses.
1395 1395
1396 1396 Special Thanks to Chris Mentzel of the Moore Foundation for this feature. Chris
1397 1397 is one of the people who played a critical role in IPython/Jupyter getting
1398 1398 funding.
1399 1399
1400 1400 We are grateful for all the help Chris has given us over the years,
1401 1401 and we're now proud to have code contributed by Chris in IPython.
1402 1402
1403 1403 OSMagics.cd_force_quiet configuration option
1404 1404 --------------------------------------------
1405 1405
1406 1406 You can set this option to force the %cd magic to behave as if ``-q`` was passed:
1407 1407 ::
1408 1408
1409 1409 In [1]: cd /
1410 1410 /
1411 1411
1412 1412 In [2]: %config OSMagics.cd_force_quiet = True
1413 1413
1414 1414 In [3]: cd /tmp
1415 1415
1416 1416 In [4]:
1417 1417
1418 1418 See :ghpull:`11491`
1419 1419
1420 1420 In vi editing mode, whether the prompt includes the current vi mode can now be configured
1421 1421 -----------------------------------------------------------------------------------------
1422 1422
1423 1423 Set the ``TerminalInteractiveShell.prompt_includes_vi_mode`` to a boolean value
1424 1424 (default: True) to control this feature. See :ghpull:`11492`
1425 1425
1426 1426 .. _whatsnew710:
1427 1427
1428 1428 IPython 7.1.0
1429 1429 =============
1430 1430
1431 1431 IPython 7.1.0 is the first minor release after 7.0.0 and mostly brings fixes to
1432 1432 new features, internal refactoring, and fixes for regressions that happened during the 6.x->7.x
1433 1433 transition. It also brings **Compatibility with Python 3.7.1**, as we're
1434 1434 unwillingly relying on a bug in CPython.
1435 1435
1436 1436 New Core Dev:
1437 1437
1438 1438 - We welcome Jonathan Slenders to the commiters. Jonathan has done a fantastic
1439 1439 work on prompt_toolkit, and we'd like to recognise his impact by giving him
1440 1440 commit rights. :ghissue:`11397`
1441 1441
1442 1442 Notable Changes
1443 1443
1444 1444 - Major update of "latex to unicode" tab completion map (see below)
1445 1445
1446 1446 Notable New Features:
1447 1447
1448 1448 - Restore functionality and documentation of the **sphinx directive**, which
1449 1449 is now stricter (fail on error by daefault), has new configuration options,
1450 1450 has a brand new documentation page :ref:`ipython_directive` (which needs
1451 1451 some cleanup). It is also now *tested* so we hope to have less regressions.
1452 1452 :ghpull:`11402`
1453 1453
1454 1454 - ``IPython.display.Video`` now supports ``width`` and ``height`` arguments,
1455 1455 allowing a custom width and height to be set instead of using the video's
1456 1456 width and height. :ghpull:`11353`
1457 1457
1458 1458 - Warn when using ``HTML('<iframe>')`` instead of ``IFrame`` :ghpull:`11350`
1459 1459
1460 1460 - Allow Dynamic switching of editing mode between vi/emacs and show
1461 1461 normal/input mode in prompt when using vi. :ghpull:`11390`. Use ``%config
1462 1462 TerminalInteractiveShell.editing_mode = 'vi'`` or ``%config
1463 1463 TerminalInteractiveShell.editing_mode = 'emacs'`` to dynamically switch
1464 1464 between modes.
1465 1465
1466 1466
1467 1467 Notable Fixes:
1468 1468
1469 1469 - Fix entering of **multi-line blocks in terminal** IPython, and various
1470 1470 crashes in the new input transformation machinery :ghpull:`11354`,
1471 1471 :ghpull:`11356`, :ghpull:`11358`. These also fix a **Compatibility bug
1472 1472 with Python 3.7.1**.
1473 1473
1474 1474 - Fix moving through generator stack in ipdb :ghpull:`11266`
1475 1475
1476 1476 - %Magic command arguments now support quoting. :ghpull:`11330`
1477 1477
1478 1478 - Re-add ``rprint`` and ``rprinte`` aliases. :ghpull:`11331`
1479 1479
1480 1480 - Remove implicit dependency on ``ipython_genutils`` :ghpull:`11317`
1481 1481
1482 1482 - Make ``nonlocal`` raise ``SyntaxError`` instead of silently failing in async
1483 1483 mode. :ghpull:`11382`
1484 1484
1485 1485 - Fix mishandling of magics and ``= !`` assignment just after a dedent in
1486 1486 nested code blocks :ghpull:`11418`
1487 1487
1488 1488 - Fix instructions for custom shortcuts :ghpull:`11426`
1489 1489
1490 1490
1491 1491 Notable Internals improvements:
1492 1492
1493 1493 - Use of ``os.scandir`` (Python 3 only) to speed up some file system operations.
1494 1494 :ghpull:`11365`
1495 1495
1496 1496 - use ``perf_counter`` instead of ``clock`` for more precise
1497 1497 timing results with ``%time`` :ghpull:`11376`
1498 1498
1499 1499 Many thanks to all the contributors and in particular to ``bartskowron`` and
1500 1500 ``tonyfast`` who handled some pretty complicated bugs in the input machinery. We
1501 1501 had a number of first time contributors and maybe hacktoberfest participants that
1502 1502 made significant contributions and helped us free some time to focus on more
1503 1503 complicated bugs.
1504 1504
1505 1505 You
1506 1506 can see all the closed issues and Merged PR, new features and fixes `here
1507 1507 <https://github.com/ipython/ipython/issues?utf8=%E2%9C%93&q=+is%3Aclosed+milestone%3A7.1+>`_.
1508 1508
1509 1509 Unicode Completion update
1510 1510 -------------------------
1511 1511
1512 1512 In IPython 7.1 the Unicode completion map has been updated and synchronized with
1513 1513 the Julia language.
1514 1514
1515 1515 Added and removed character characters:
1516 1516
1517 1517 ``\jmath`` (``Θ·``), ``\\underleftrightarrow`` (U+034D, combining) have been
1518 1518 added, while ``\\textasciicaron`` have been removed
1519 1519
1520 1520 Some sequences have seen their prefix removed:
1521 1521
1522 1522 - 6 characters ``\text...<tab>`` should now be inputed with ``\...<tab>`` directly,
1523 1523 - 45 characters ``\Elz...<tab>`` should now be inputed with ``\...<tab>`` directly,
1524 1524 - 65 characters ``\B...<tab>`` should now be inputed with ``\...<tab>`` directly,
1525 1525 - 450 characters ``\m...<tab>`` should now be inputed with ``\...<tab>`` directly,
1526 1526
1527 1527 Some sequences have seen their prefix shortened:
1528 1528
1529 1529 - 5 characters ``\mitBbb...<tab>`` should now be inputed with ``\bbi...<tab>`` directly,
1530 1530 - 52 characters ``\mit...<tab>`` should now be inputed with ``\i...<tab>`` directly,
1531 1531 - 216 characters ``\mbfit...<tab>`` should now be inputed with ``\bi...<tab>`` directly,
1532 1532 - 222 characters ``\mbf...<tab>`` should now be inputed with ``\b...<tab>`` directly,
1533 1533
1534 1534 A couple of characters had their sequence simplified:
1535 1535
1536 1536 - ``Γ°``, type ``\dh<tab>``, instead of ``\eth<tab>``
1537 1537 - ``Δ§``, type ``\hbar<tab>``, instead of ``\Elzxh<tab>``
1538 1538 - ``ΙΈ``, type ``\ltphi<tab>``, instead of ``\textphi<tab>``
1539 1539 - ``Ο΄``, type ``\varTheta<tab>``, instead of ``\textTheta<tab>``
1540 1540 - ``ℇ``, type ``\eulermascheroni<tab>``, instead of ``\Eulerconst<tab>``
1541 1541 - ``β„Ž``, type ``\planck<tab>``, instead of ``\Planckconst<tab>``
1542 1542
1543 1543 - U+0336 (COMBINING LONG STROKE OVERLAY), type ``\strike<tab>``, instead of ``\Elzbar<tab>``.
1544 1544
1545 1545 A couple of sequences have been updated:
1546 1546
1547 1547 - ``\varepsilon`` now gives ``Ι›`` (GREEK SMALL LETTER EPSILON) instead of ``Ξ΅`` (GREEK LUNATE EPSILON SYMBOL),
1548 1548 - ``\underbar`` now gives U+0331 (COMBINING MACRON BELOW) instead of U+0332 (COMBINING LOW LINE).
1549 1549
1550 1550
1551 1551 .. _whatsnew700:
1552 1552
1553 1553 IPython 7.0.0
1554 1554 =============
1555 1555
1556 1556 Released Thursday September 27th, 2018
1557 1557
1558 1558 IPython 7 includes major feature improvements.
1559 1559 This is also the second major version of IPython to support only
1560 1560 Python 3 – starting at Python 3.4. Python 2 is still community-supported
1561 1561 on the bugfix only 5.x branch, but we remind you that Python 2 "end of life"
1562 1562 is on Jan 1st 2020.
1563 1563
1564 1564 We were able to backport bug fixes to the 5.x branch thanks to our backport bot which
1565 1565 backported more than `70 Pull-Requests
1566 1566 <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>`_
1567 1567
1568 1568 The IPython 6.x branch will likely not see any further release unless critical
1569 1569 bugs are found.
1570 1570
1571 1571 Make sure you have pip > 9.0 before upgrading. You should be able to update by running:
1572 1572
1573 1573 .. code::
1574 1574
1575 1575 pip install ipython --upgrade
1576 1576
1577 1577 .. only:: ipydev
1578 1578
1579 1579 If you are trying to install or update an ``alpha``, ``beta``, or ``rc``
1580 1580 version, use pip ``--pre`` flag.
1581 1581
1582 1582 .. code::
1583 1583
1584 1584 pip install ipython --upgrade --pre
1585 1585
1586 1586
1587 1587 Or, if you have conda installed:
1588 1588
1589 1589 .. code::
1590 1590
1591 1591 conda install ipython
1592 1592
1593 1593
1594 1594
1595 1595 Prompt Toolkit 2.0
1596 1596 ------------------
1597 1597
1598 1598 IPython 7.0+ now uses ``prompt_toolkit 2.0``. If you still need to use an earlier
1599 1599 ``prompt_toolkit`` version, you may need to pin IPython to ``<7.0``.
1600 1600
1601 1601 Autowait: Asynchronous REPL
1602 1602 ---------------------------
1603 1603
1604 1604 Staring with IPython 7.0 on Python 3.6+, IPython can automatically ``await``
1605 1605 top level code. You should not need to access an event loop or runner
1606 1606 yourself. To learn more, read the :ref:`autoawait` section of our docs, see
1607 1607 :ghpull:`11265`, or try the following code::
1608 1608
1609 1609 Python 3.6.0
1610 1610 Type 'copyright', 'credits' or 'license' for more information
1611 1611 IPython 7.0.0 -- An enhanced Interactive Python. Type '?' for help.
1612 1612
1613 1613 In [1]: import aiohttp
1614 1614 ...: result = aiohttp.get('https://api.github.com')
1615 1615
1616 1616 In [2]: response = await result
1617 1617 <pause for a few 100s ms>
1618 1618
1619 1619 In [3]: await response.json()
1620 1620 Out[3]:
1621 1621 {'authorizations_url': 'https://api.github.com/authorizations',
1622 1622 'code_search_url': 'https://api.github.com/search/code?q={query}{&page,per_page,sort,order}',
1623 1623 ...
1624 1624 }
1625 1625
1626 1626 .. note::
1627 1627
1628 1628 Async integration is experimental code, behavior may change or be removed
1629 1629 between Python and IPython versions without warnings.
1630 1630
1631 1631 Integration is by default with `asyncio`, but other libraries can be configured --
1632 1632 like ``curio`` or ``trio`` -- to improve concurrency in the REPL::
1633 1633
1634 1634 In [1]: %autoawait trio
1635 1635
1636 1636 In [2]: import trio
1637 1637
1638 1638 In [3]: async def child(i):
1639 1639 ...: print(" child %s goes to sleep"%i)
1640 1640 ...: await trio.sleep(2)
1641 1641 ...: print(" child %s wakes up"%i)
1642 1642
1643 1643 In [4]: print('parent start')
1644 1644 ...: async with trio.open_nursery() as n:
1645 1645 ...: for i in range(3):
1646 1646 ...: n.spawn(child, i)
1647 1647 ...: print('parent end')
1648 1648 parent start
1649 1649 child 2 goes to sleep
1650 1650 child 0 goes to sleep
1651 1651 child 1 goes to sleep
1652 1652 <about 2 seconds pause>
1653 1653 child 2 wakes up
1654 1654 child 1 wakes up
1655 1655 child 0 wakes up
1656 1656 parent end
1657 1657
1658 1658 See :ref:`autoawait` for more information.
1659 1659
1660 1660
1661 1661 Asynchronous code in a Notebook interface or any other frontend using the
1662 1662 Jupyter Protocol will require further updates to the IPykernel package.
1663 1663
1664 1664 Non-Asynchronous code
1665 1665 ~~~~~~~~~~~~~~~~~~~~~
1666 1666
1667 1667 As the internal API of IPython is now asynchronous, IPython needs to run under
1668 1668 an event loop. In order to allow many workflows, (like using the :magic:`%run`
1669 1669 magic, or copy-pasting code that explicitly starts/stop event loop), when
1670 1670 top-level code is detected as not being asynchronous, IPython code is advanced
1671 1671 via a pseudo-synchronous runner, and may not advance pending tasks.
1672 1672
1673 1673 Change to Nested Embed
1674 1674 ~~~~~~~~~~~~~~~~~~~~~~
1675 1675
1676 1676 The introduction of the ability to run async code had some effect on the
1677 1677 ``IPython.embed()`` API. By default, embed will not allow you to run asynchronous
1678 1678 code unless an event loop is specified.
1679 1679
1680 1680 Effects on Magics
1681 1681 ~~~~~~~~~~~~~~~~~
1682 1682
1683 1683 Some magics will not work with async until they're updated.
1684 1684 Contributions welcome.
1685 1685
1686 1686 Expected Future changes
1687 1687 ~~~~~~~~~~~~~~~~~~~~~~~
1688 1688
1689 1689 We expect more internal but public IPython functions to become ``async``, and
1690 1690 will likely end up having a persistent event loop while IPython is running.
1691 1691
1692 1692 Thanks
1693 1693 ~~~~~~
1694 1694
1695 1695 This release took more than a year in the making.
1696 1696 The code was rebased a number of
1697 1697 times; leading to commit authorship that may have been lost in the final
1698 1698 Pull-Request. Huge thanks to many people for contribution, discussion, code,
1699 1699 documentation, use-cases: dalejung, danielballan, ellisonbg, fperez, gnestor,
1700 1700 minrk, njsmith, pganssle, tacaswell, takluyver , vidartf ... And many others.
1701 1701
1702 1702
1703 1703 Autoreload Improvement
1704 1704 ----------------------
1705 1705
1706 1706 The magic :magic:`%autoreload 2 <autoreload>` now captures new methods added to
1707 1707 classes. Earlier, only methods existing as of the initial import were being
1708 1708 tracked and updated.
1709 1709
1710 1710 This new feature helps dual environment development - Jupyter+IDE - where the
1711 1711 code gradually moves from notebook cells to package files as it gets
1712 1712 structured.
1713 1713
1714 1714 **Example**: An instance of the class ``MyClass`` will be able to access the
1715 1715 method ``cube()`` after it is uncommented and the file ``file1.py`` is saved on
1716 1716 disk.
1717 1717
1718 1718
1719 1719 .. code::
1720 1720
1721 1721 # notebook
1722 1722
1723 1723 from mymodule import MyClass
1724 1724 first = MyClass(5)
1725 1725
1726 1726 .. code::
1727 1727
1728 1728 # mymodule/file1.py
1729 1729
1730 1730 class MyClass:
1731 1731
1732 1732 def __init__(self, a=10):
1733 1733 self.a = a
1734 1734
1735 1735 def square(self):
1736 1736 print('compute square')
1737 1737 return self.a*self.a
1738 1738
1739 1739 # def cube(self):
1740 1740 # print('compute cube')
1741 1741 # return self.a*self.a*self.a
1742 1742
1743 1743
1744 1744
1745 1745
1746 1746 Misc
1747 1747 ----
1748 1748
1749 1749 The autoindent feature that was deprecated in 5.x was re-enabled and
1750 1750 un-deprecated in :ghpull:`11257`
1751 1751
1752 1752 Make :magic:`%run -n -i ... <run>` work correctly. Earlier, if :magic:`%run` was
1753 1753 passed both arguments, ``-n`` would be silently ignored. See :ghpull:`10308`
1754 1754
1755 1755
1756 1756 The :cellmagic:`%%script` (as well as :cellmagic:`%%bash`,
1757 1757 :cellmagic:`%%ruby`... ) cell magics now raise by default if the return code of
1758 1758 the given code is non-zero (thus halting execution of further cells in a
1759 1759 notebook). The behavior can be disable by passing the ``--no-raise-error`` flag.
1760 1760
1761 1761
1762 1762 Deprecations
1763 1763 ------------
1764 1764
1765 1765 A couple of unused functions and methods have been deprecated and will be removed
1766 1766 in future versions:
1767 1767
1768 1768 - ``IPython.utils.io.raw_print_err``
1769 1769 - ``IPython.utils.io.raw_print``
1770 1770
1771 1771
1772 1772 Backwards incompatible changes
1773 1773 ------------------------------
1774 1774
1775 1775 * The API for transforming input before it is parsed as Python code has been
1776 1776 completely redesigned: any custom input transformations will need to be
1777 1777 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