Show More
@@ -1,978 +1,980 | |||
|
1 | 1 | """IPython terminal interface using prompt_toolkit""" |
|
2 | 2 | |
|
3 | 3 | import asyncio |
|
4 | 4 | import os |
|
5 | 5 | import sys |
|
6 | 6 | from warnings import warn |
|
7 | 7 | from typing import Union as UnionType |
|
8 | 8 | |
|
9 | 9 | from IPython.core.async_helpers import get_asyncio_loop |
|
10 | 10 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
11 | 11 | from IPython.utils.py3compat import input |
|
12 | 12 | from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title |
|
13 | 13 | from IPython.utils.process import abbrev_cwd |
|
14 | 14 | from traitlets import ( |
|
15 | 15 | Bool, |
|
16 | 16 | Unicode, |
|
17 | 17 | Dict, |
|
18 | 18 | Integer, |
|
19 | 19 | List, |
|
20 | 20 | observe, |
|
21 | 21 | Instance, |
|
22 | 22 | Type, |
|
23 | 23 | default, |
|
24 | 24 | Enum, |
|
25 | 25 | Union, |
|
26 | 26 | Any, |
|
27 | 27 | validate, |
|
28 | 28 | Float, |
|
29 | 29 | ) |
|
30 | 30 | |
|
31 | 31 | from prompt_toolkit.auto_suggest import AutoSuggestFromHistory |
|
32 | 32 | from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode |
|
33 | 33 | from prompt_toolkit.filters import HasFocus, Condition, IsDone |
|
34 | 34 | from prompt_toolkit.formatted_text import PygmentsTokens |
|
35 | 35 | from prompt_toolkit.history import History |
|
36 | 36 | from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor |
|
37 | 37 | from prompt_toolkit.output import ColorDepth |
|
38 | 38 | from prompt_toolkit.patch_stdout import patch_stdout |
|
39 | 39 | from prompt_toolkit.shortcuts import PromptSession, CompleteStyle, print_formatted_text |
|
40 | 40 | from prompt_toolkit.styles import DynamicStyle, merge_styles |
|
41 | 41 | from prompt_toolkit.styles.pygments import style_from_pygments_cls, style_from_pygments_dict |
|
42 | 42 | from prompt_toolkit import __version__ as ptk_version |
|
43 | 43 | |
|
44 | 44 | from pygments.styles import get_style_by_name |
|
45 | 45 | from pygments.style import Style |
|
46 | 46 | from pygments.token import Token |
|
47 | 47 | |
|
48 | 48 | from .debugger import TerminalPdb, Pdb |
|
49 | 49 | from .magics import TerminalMagics |
|
50 | 50 | from .pt_inputhooks import get_inputhook_name_and_func |
|
51 | 51 | from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook |
|
52 | 52 | from .ptutils import IPythonPTCompleter, IPythonPTLexer |
|
53 | 53 | from .shortcuts import ( |
|
54 | 54 | create_ipython_shortcuts, |
|
55 | 55 | create_identifier, |
|
56 | 56 | RuntimeBinding, |
|
57 | 57 | add_binding, |
|
58 | 58 | ) |
|
59 | 59 | from .shortcuts.filters import KEYBINDING_FILTERS, filter_from_string |
|
60 | 60 | from .shortcuts.auto_suggest import ( |
|
61 | 61 | NavigableAutoSuggestFromHistory, |
|
62 | 62 | AppendAutoSuggestionInAnyLine, |
|
63 | 63 | ) |
|
64 | 64 | |
|
65 | 65 | PTK3 = ptk_version.startswith('3.') |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | class _NoStyle(Style): pass |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | _style_overrides_light_bg = { |
|
73 | 73 | Token.Prompt: '#ansibrightblue', |
|
74 | 74 | Token.PromptNum: '#ansiblue bold', |
|
75 | 75 | Token.OutPrompt: '#ansibrightred', |
|
76 | 76 | Token.OutPromptNum: '#ansired bold', |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | _style_overrides_linux = { |
|
80 | 80 | Token.Prompt: '#ansibrightgreen', |
|
81 | 81 | Token.PromptNum: '#ansigreen bold', |
|
82 | 82 | Token.OutPrompt: '#ansibrightred', |
|
83 | 83 | Token.OutPromptNum: '#ansired bold', |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | def get_default_editor(): |
|
87 | 87 | try: |
|
88 | 88 | return os.environ['EDITOR'] |
|
89 | 89 | except KeyError: |
|
90 | 90 | pass |
|
91 | 91 | except UnicodeError: |
|
92 | 92 | warn("$EDITOR environment variable is not pure ASCII. Using platform " |
|
93 | 93 | "default editor.") |
|
94 | 94 | |
|
95 | 95 | if os.name == 'posix': |
|
96 | 96 | return 'vi' # the only one guaranteed to be there! |
|
97 | 97 | else: |
|
98 | 98 | return 'notepad' # same in Windows! |
|
99 | 99 | |
|
100 | 100 | # conservatively check for tty |
|
101 | 101 | # overridden streams can result in things like: |
|
102 | 102 | # - sys.stdin = None |
|
103 | 103 | # - no isatty method |
|
104 | 104 | for _name in ('stdin', 'stdout', 'stderr'): |
|
105 | 105 | _stream = getattr(sys, _name) |
|
106 | 106 | try: |
|
107 | 107 | if not _stream or not hasattr(_stream, "isatty") or not _stream.isatty(): |
|
108 | 108 | _is_tty = False |
|
109 | 109 | break |
|
110 | 110 | except ValueError: |
|
111 | 111 | # stream is closed |
|
112 | 112 | _is_tty = False |
|
113 | 113 | break |
|
114 | 114 | else: |
|
115 | 115 | _is_tty = True |
|
116 | 116 | |
|
117 | 117 | |
|
118 | 118 | _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty) |
|
119 | 119 | |
|
120 | 120 | def black_reformat_handler(text_before_cursor): |
|
121 | 121 | """ |
|
122 | 122 | We do not need to protect against error, |
|
123 | 123 | this is taken care at a higher level where any reformat error is ignored. |
|
124 | 124 | Indeed we may call reformatting on incomplete code. |
|
125 | 125 | """ |
|
126 | 126 | import black |
|
127 | 127 | |
|
128 | 128 | formatted_text = black.format_str(text_before_cursor, mode=black.FileMode()) |
|
129 | 129 | if not text_before_cursor.endswith("\n") and formatted_text.endswith("\n"): |
|
130 | 130 | formatted_text = formatted_text[:-1] |
|
131 | 131 | return formatted_text |
|
132 | 132 | |
|
133 | 133 | |
|
134 | 134 | def yapf_reformat_handler(text_before_cursor): |
|
135 | 135 | from yapf.yapflib import file_resources |
|
136 | 136 | from yapf.yapflib import yapf_api |
|
137 | 137 | |
|
138 | 138 | style_config = file_resources.GetDefaultStyleForDir(os.getcwd()) |
|
139 | 139 | formatted_text, was_formatted = yapf_api.FormatCode( |
|
140 | 140 | text_before_cursor, style_config=style_config |
|
141 | 141 | ) |
|
142 | 142 | if was_formatted: |
|
143 | 143 | if not text_before_cursor.endswith("\n") and formatted_text.endswith("\n"): |
|
144 | 144 | formatted_text = formatted_text[:-1] |
|
145 | 145 | return formatted_text |
|
146 | 146 | else: |
|
147 | 147 | return text_before_cursor |
|
148 | 148 | |
|
149 | 149 | |
|
150 | 150 | class PtkHistoryAdapter(History): |
|
151 | 151 | """ |
|
152 | 152 | Prompt toolkit has it's own way of handling history, Where it assumes it can |
|
153 | 153 | Push/pull from history. |
|
154 | 154 | |
|
155 | 155 | """ |
|
156 | 156 | |
|
157 | 157 | def __init__(self, shell): |
|
158 | 158 | super().__init__() |
|
159 | 159 | self.shell = shell |
|
160 | 160 | self._refresh() |
|
161 | 161 | |
|
162 | 162 | def append_string(self, string): |
|
163 | 163 | # we rely on sql for that. |
|
164 | 164 | self._loaded = False |
|
165 | 165 | self._refresh() |
|
166 | 166 | |
|
167 | 167 | def _refresh(self): |
|
168 | 168 | if not self._loaded: |
|
169 | 169 | self._loaded_strings = list(self.load_history_strings()) |
|
170 | 170 | |
|
171 | 171 | def load_history_strings(self): |
|
172 | 172 | last_cell = "" |
|
173 | 173 | res = [] |
|
174 | 174 | for __, ___, cell in self.shell.history_manager.get_tail( |
|
175 | 175 | self.shell.history_load_length, include_latest=True |
|
176 | 176 | ): |
|
177 | 177 | # Ignore blank lines and consecutive duplicates |
|
178 | 178 | cell = cell.rstrip() |
|
179 | 179 | if cell and (cell != last_cell): |
|
180 | 180 | res.append(cell) |
|
181 | 181 | last_cell = cell |
|
182 | 182 | yield from res[::-1] |
|
183 | 183 | |
|
184 | 184 | def store_string(self, string: str) -> None: |
|
185 | 185 | pass |
|
186 | 186 | |
|
187 | 187 | class TerminalInteractiveShell(InteractiveShell): |
|
188 | 188 | mime_renderers = Dict().tag(config=True) |
|
189 | 189 | |
|
190 | 190 | space_for_menu = Integer(6, help='Number of line at the bottom of the screen ' |
|
191 | 191 | 'to reserve for the tab completion menu, ' |
|
192 | 192 | 'search history, ...etc, the height of ' |
|
193 | 193 | 'these menus will at most this value. ' |
|
194 | 194 | 'Increase it is you prefer long and skinny ' |
|
195 | 195 | 'menus, decrease for short and wide.' |
|
196 | 196 | ).tag(config=True) |
|
197 | 197 | |
|
198 | 198 | pt_app: UnionType[PromptSession, None] = None |
|
199 | 199 | auto_suggest: UnionType[ |
|
200 | 200 | AutoSuggestFromHistory, NavigableAutoSuggestFromHistory, None |
|
201 | 201 | ] = None |
|
202 | 202 | debugger_history = None |
|
203 | 203 | |
|
204 | 204 | debugger_history_file = Unicode( |
|
205 | 205 | "~/.pdbhistory", help="File in which to store and read history" |
|
206 | 206 | ).tag(config=True) |
|
207 | 207 | |
|
208 | 208 | simple_prompt = Bool(_use_simple_prompt, |
|
209 | 209 | help="""Use `raw_input` for the REPL, without completion and prompt colors. |
|
210 | 210 | |
|
211 | 211 | Useful when controlling IPython as a subprocess, and piping STDIN/OUT/ERR. Known usage are: |
|
212 | 212 | IPython own testing machinery, and emacs inferior-shell integration through elpy. |
|
213 | 213 | |
|
214 | 214 | This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT` |
|
215 | 215 | environment variable is set, or the current terminal is not a tty.""" |
|
216 | 216 | ).tag(config=True) |
|
217 | 217 | |
|
218 | 218 | @property |
|
219 | 219 | def debugger_cls(self): |
|
220 | 220 | return Pdb if self.simple_prompt else TerminalPdb |
|
221 | 221 | |
|
222 | 222 | confirm_exit = Bool(True, |
|
223 | 223 | help=""" |
|
224 | 224 | Set to confirm when you try to exit IPython with an EOF (Control-D |
|
225 | 225 | in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit', |
|
226 | 226 | you can force a direct exit without any confirmation.""", |
|
227 | 227 | ).tag(config=True) |
|
228 | 228 | |
|
229 | 229 | editing_mode = Unicode('emacs', |
|
230 | 230 | help="Shortcut style to use at the prompt. 'vi' or 'emacs'.", |
|
231 | 231 | ).tag(config=True) |
|
232 | 232 | |
|
233 | 233 | emacs_bindings_in_vi_insert_mode = Bool( |
|
234 | 234 | True, |
|
235 | 235 | help="Add shortcuts from 'emacs' insert mode to 'vi' insert mode.", |
|
236 | 236 | ).tag(config=True) |
|
237 | 237 | |
|
238 | 238 | modal_cursor = Bool( |
|
239 | 239 | True, |
|
240 | 240 | help=""" |
|
241 | 241 | Cursor shape changes depending on vi mode: beam in vi insert mode, |
|
242 | 242 | block in nav mode, underscore in replace mode.""", |
|
243 | 243 | ).tag(config=True) |
|
244 | 244 | |
|
245 | 245 | ttimeoutlen = Float( |
|
246 | 246 | 0.01, |
|
247 | 247 | help="""The time in milliseconds that is waited for a key code |
|
248 | 248 | to complete.""", |
|
249 | 249 | ).tag(config=True) |
|
250 | 250 | |
|
251 | 251 | timeoutlen = Float( |
|
252 | 252 | 0.5, |
|
253 | 253 | help="""The time in milliseconds that is waited for a mapped key |
|
254 | 254 | sequence to complete.""", |
|
255 | 255 | ).tag(config=True) |
|
256 | 256 | |
|
257 | 257 | autoformatter = Unicode( |
|
258 | 258 | None, |
|
259 | 259 | help="Autoformatter to reformat Terminal code. Can be `'black'`, `'yapf'` or `None`", |
|
260 | 260 | allow_none=True |
|
261 | 261 | ).tag(config=True) |
|
262 | 262 | |
|
263 | 263 | auto_match = Bool( |
|
264 | 264 | False, |
|
265 | 265 | help=""" |
|
266 | 266 | Automatically add/delete closing bracket or quote when opening bracket or quote is entered/deleted. |
|
267 | 267 | Brackets: (), [], {} |
|
268 | 268 | Quotes: '', \"\" |
|
269 | 269 | """, |
|
270 | 270 | ).tag(config=True) |
|
271 | 271 | |
|
272 | 272 | mouse_support = Bool(False, |
|
273 | 273 | help="Enable mouse support in the prompt\n(Note: prevents selecting text with the mouse)" |
|
274 | 274 | ).tag(config=True) |
|
275 | 275 | |
|
276 | 276 | # We don't load the list of styles for the help string, because loading |
|
277 | 277 | # Pygments plugins takes time and can cause unexpected errors. |
|
278 | 278 | highlighting_style = Union([Unicode('legacy'), Type(klass=Style)], |
|
279 | 279 | help="""The name or class of a Pygments style to use for syntax |
|
280 | 280 | highlighting. To see available styles, run `pygmentize -L styles`.""" |
|
281 | 281 | ).tag(config=True) |
|
282 | 282 | |
|
283 | 283 | @validate('editing_mode') |
|
284 | 284 | def _validate_editing_mode(self, proposal): |
|
285 | 285 | if proposal['value'].lower() == 'vim': |
|
286 | 286 | proposal['value']= 'vi' |
|
287 | 287 | elif proposal['value'].lower() == 'default': |
|
288 | 288 | proposal['value']= 'emacs' |
|
289 | 289 | |
|
290 | 290 | if hasattr(EditingMode, proposal['value'].upper()): |
|
291 | 291 | return proposal['value'].lower() |
|
292 | 292 | |
|
293 | 293 | return self.editing_mode |
|
294 | 294 | |
|
295 | 295 | |
|
296 | 296 | @observe('editing_mode') |
|
297 | 297 | def _editing_mode(self, change): |
|
298 | 298 | if self.pt_app: |
|
299 | 299 | self.pt_app.editing_mode = getattr(EditingMode, change.new.upper()) |
|
300 | 300 | |
|
301 | 301 | def _set_formatter(self, formatter): |
|
302 | 302 | if formatter is None: |
|
303 | 303 | self.reformat_handler = lambda x:x |
|
304 | 304 | elif formatter == 'black': |
|
305 | 305 | self.reformat_handler = black_reformat_handler |
|
306 | 306 | elif formatter == "yapf": |
|
307 | 307 | self.reformat_handler = yapf_reformat_handler |
|
308 | 308 | else: |
|
309 | 309 | raise ValueError |
|
310 | 310 | |
|
311 | 311 | @observe("autoformatter") |
|
312 | 312 | def _autoformatter_changed(self, change): |
|
313 | 313 | formatter = change.new |
|
314 | 314 | self._set_formatter(formatter) |
|
315 | 315 | |
|
316 | 316 | @observe('highlighting_style') |
|
317 | 317 | @observe('colors') |
|
318 | 318 | def _highlighting_style_changed(self, change): |
|
319 | 319 | self.refresh_style() |
|
320 | 320 | |
|
321 | 321 | def refresh_style(self): |
|
322 | 322 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) |
|
323 | 323 | |
|
324 | 324 | |
|
325 | 325 | highlighting_style_overrides = Dict( |
|
326 | 326 | help="Override highlighting format for specific tokens" |
|
327 | 327 | ).tag(config=True) |
|
328 | 328 | |
|
329 | 329 | true_color = Bool(False, |
|
330 | 330 | help="""Use 24bit colors instead of 256 colors in prompt highlighting. |
|
331 | 331 | If your terminal supports true color, the following command should |
|
332 | 332 | print ``TRUECOLOR`` in orange:: |
|
333 | 333 | |
|
334 | 334 | printf \"\\x1b[38;2;255;100;0mTRUECOLOR\\x1b[0m\\n\" |
|
335 | 335 | """, |
|
336 | 336 | ).tag(config=True) |
|
337 | 337 | |
|
338 | 338 | editor = Unicode(get_default_editor(), |
|
339 | 339 | help="Set the editor used by IPython (default to $EDITOR/vi/notepad)." |
|
340 | 340 | ).tag(config=True) |
|
341 | 341 | |
|
342 | 342 | prompts_class = Type(Prompts, help='Class used to generate Prompt token for prompt_toolkit').tag(config=True) |
|
343 | 343 | |
|
344 | 344 | prompts = Instance(Prompts) |
|
345 | 345 | |
|
346 | 346 | @default('prompts') |
|
347 | 347 | def _prompts_default(self): |
|
348 | 348 | return self.prompts_class(self) |
|
349 | 349 | |
|
350 | 350 | # @observe('prompts') |
|
351 | 351 | # def _(self, change): |
|
352 | 352 | # self._update_layout() |
|
353 | 353 | |
|
354 | 354 | @default('displayhook_class') |
|
355 | 355 | def _displayhook_class_default(self): |
|
356 | 356 | return RichPromptDisplayHook |
|
357 | 357 | |
|
358 | 358 | term_title = Bool(True, |
|
359 | 359 | help="Automatically set the terminal title" |
|
360 | 360 | ).tag(config=True) |
|
361 | 361 | |
|
362 | 362 | term_title_format = Unicode("IPython: {cwd}", |
|
363 | 363 | help="Customize the terminal title format. This is a python format string. " + |
|
364 | 364 | "Available substitutions are: {cwd}." |
|
365 | 365 | ).tag(config=True) |
|
366 | 366 | |
|
367 | 367 | display_completions = Enum(('column', 'multicolumn','readlinelike'), |
|
368 | 368 | help= ( "Options for displaying tab completions, 'column', 'multicolumn', and " |
|
369 | 369 | "'readlinelike'. These options are for `prompt_toolkit`, see " |
|
370 | 370 | "`prompt_toolkit` documentation for more information." |
|
371 | 371 | ), |
|
372 | 372 | default_value='multicolumn').tag(config=True) |
|
373 | 373 | |
|
374 | 374 | highlight_matching_brackets = Bool(True, |
|
375 | 375 | help="Highlight matching brackets.", |
|
376 | 376 | ).tag(config=True) |
|
377 | 377 | |
|
378 | 378 | extra_open_editor_shortcuts = Bool(False, |
|
379 | 379 | help="Enable vi (v) or Emacs (C-X C-E) shortcuts to open an external editor. " |
|
380 | 380 | "This is in addition to the F2 binding, which is always enabled." |
|
381 | 381 | ).tag(config=True) |
|
382 | 382 | |
|
383 | 383 | handle_return = Any(None, |
|
384 | 384 | help="Provide an alternative handler to be called when the user presses " |
|
385 | 385 | "Return. This is an advanced option intended for debugging, which " |
|
386 | 386 | "may be changed or removed in later releases." |
|
387 | 387 | ).tag(config=True) |
|
388 | 388 | |
|
389 | 389 | enable_history_search = Bool(True, |
|
390 | 390 | help="Allows to enable/disable the prompt toolkit history search" |
|
391 | 391 | ).tag(config=True) |
|
392 | 392 | |
|
393 | 393 | autosuggestions_provider = Unicode( |
|
394 | 394 | "NavigableAutoSuggestFromHistory", |
|
395 | 395 | help="Specifies from which source automatic suggestions are provided. " |
|
396 | 396 | "Can be set to ``'NavigableAutoSuggestFromHistory'`` (:kbd:`up` and " |
|
397 | 397 | ":kbd:`down` swap suggestions), ``'AutoSuggestFromHistory'``, " |
|
398 | 398 | " or ``None`` to disable automatic suggestions. " |
|
399 | 399 | "Default is `'NavigableAutoSuggestFromHistory`'.", |
|
400 | 400 | allow_none=True, |
|
401 | 401 | ).tag(config=True) |
|
402 | 402 | |
|
403 | 403 | def _set_autosuggestions(self, provider): |
|
404 | 404 | # disconnect old handler |
|
405 | 405 | if self.auto_suggest and isinstance( |
|
406 | 406 | self.auto_suggest, NavigableAutoSuggestFromHistory |
|
407 | 407 | ): |
|
408 | 408 | self.auto_suggest.disconnect() |
|
409 | 409 | if provider is None: |
|
410 | 410 | self.auto_suggest = None |
|
411 | 411 | elif provider == "AutoSuggestFromHistory": |
|
412 | 412 | self.auto_suggest = AutoSuggestFromHistory() |
|
413 | 413 | elif provider == "NavigableAutoSuggestFromHistory": |
|
414 | 414 | self.auto_suggest = NavigableAutoSuggestFromHistory() |
|
415 | 415 | else: |
|
416 | 416 | raise ValueError("No valid provider.") |
|
417 | 417 | if self.pt_app: |
|
418 | 418 | self.pt_app.auto_suggest = self.auto_suggest |
|
419 | 419 | |
|
420 | 420 | @observe("autosuggestions_provider") |
|
421 | 421 | def _autosuggestions_provider_changed(self, change): |
|
422 | 422 | provider = change.new |
|
423 | 423 | self._set_autosuggestions(provider) |
|
424 | 424 | |
|
425 | 425 | shortcuts = List( |
|
426 | 426 | trait=Dict( |
|
427 | 427 | key_trait=Enum( |
|
428 | 428 | [ |
|
429 | 429 | "command", |
|
430 | 430 | "match_keys", |
|
431 | 431 | "match_filter", |
|
432 | 432 | "new_keys", |
|
433 | 433 | "new_filter", |
|
434 | 434 | "create", |
|
435 | 435 | ] |
|
436 | 436 | ), |
|
437 | 437 | per_key_traits={ |
|
438 | 438 | "command": Unicode(), |
|
439 | 439 | "match_keys": List(Unicode()), |
|
440 | 440 | "match_filter": Unicode(), |
|
441 | 441 | "new_keys": List(Unicode()), |
|
442 | 442 | "new_filter": Unicode(), |
|
443 | 443 | "create": Bool(False), |
|
444 | 444 | }, |
|
445 | 445 | ), |
|
446 | 446 | help="""Add, disable or modifying shortcuts. |
|
447 | 447 | |
|
448 | 448 | Each entry on the list should be a dictionary with ``command`` key |
|
449 | 449 | identifying the target function executed by the shortcut and at least |
|
450 | 450 | one of the following: |
|
451 | 451 | |
|
452 | 452 | - ``match_keys``: list of keys used to match an existing shortcut, |
|
453 | 453 | - ``match_filter``: shortcut filter used to match an existing shortcut, |
|
454 | 454 | - ``new_keys``: list of keys to set, |
|
455 | 455 | - ``new_filter``: a new shortcut filter to set |
|
456 | 456 | |
|
457 | 457 | The filters have to be composed of pre-defined verbs and joined by one |
|
458 | 458 | of the following conjunctions: ``&`` (and), ``|`` (or), ``~`` (not). |
|
459 | 459 | The pre-defined verbs are: |
|
460 | 460 | |
|
461 | 461 | {} |
|
462 | 462 | |
|
463 | 463 | |
|
464 | 464 | To disable a shortcut set ``new_keys`` to an empty list. |
|
465 | 465 | To add a shortcut add key ``create`` with value ``True``. |
|
466 | 466 | |
|
467 | 467 | When modifying/disabling shortcuts, ``match_keys``/``match_filter`` can |
|
468 | 468 | be omitted if the provided specification uniquely identifies a shortcut |
|
469 | 469 | to be modified/disabled. When modifying a shortcut ``new_filter`` or |
|
470 | 470 | ``new_keys`` can be omitted which will result in reuse of the existing |
|
471 | 471 | filter/keys. |
|
472 | 472 | |
|
473 | 473 | Only shortcuts defined in IPython (and not default prompt-toolkit |
|
474 | 474 | shortcuts) can be modified or disabled. The full list of shortcuts, |
|
475 | 475 | command identifiers and filters is available under |
|
476 | 476 | :ref:`terminal-shortcuts-list`. |
|
477 | 477 | """.format( |
|
478 | 478 | "\n ".join([f"- `{k}`" for k in KEYBINDING_FILTERS]) |
|
479 | 479 | ), |
|
480 | 480 | ).tag(config=True) |
|
481 | 481 | |
|
482 | 482 | @observe("shortcuts") |
|
483 | 483 | def _shortcuts_changed(self, change): |
|
484 | 484 | if self.pt_app: |
|
485 | 485 | self.pt_app.key_bindings = self._merge_shortcuts(user_shortcuts=change.new) |
|
486 | 486 | |
|
487 | 487 | def _merge_shortcuts(self, user_shortcuts): |
|
488 | 488 | # rebuild the bindings list from scratch |
|
489 | 489 | key_bindings = create_ipython_shortcuts(self) |
|
490 | 490 | |
|
491 | 491 | # for now we only allow adding shortcuts for commands which are already |
|
492 | 492 | # registered; this is a security precaution. |
|
493 | 493 | known_commands = { |
|
494 | 494 | create_identifier(binding.handler): binding.handler |
|
495 | 495 | for binding in key_bindings.bindings |
|
496 | 496 | } |
|
497 | 497 | shortcuts_to_skip = [] |
|
498 | 498 | shortcuts_to_add = [] |
|
499 | 499 | |
|
500 | 500 | for shortcut in user_shortcuts: |
|
501 | 501 | command_id = shortcut["command"] |
|
502 | 502 | if command_id not in known_commands: |
|
503 | 503 | allowed_commands = "\n - ".join(known_commands) |
|
504 | 504 | raise ValueError( |
|
505 | 505 | f"{command_id} is not a known shortcut command." |
|
506 | 506 | f" Allowed commands are: \n - {allowed_commands}" |
|
507 | 507 | ) |
|
508 | 508 | old_keys = shortcut.get("match_keys", None) |
|
509 | 509 | old_filter = ( |
|
510 | 510 | filter_from_string(shortcut["match_filter"]) |
|
511 | 511 | if "match_filter" in shortcut |
|
512 | 512 | else None |
|
513 | 513 | ) |
|
514 | 514 | matching = [ |
|
515 | 515 | binding |
|
516 | 516 | for binding in key_bindings.bindings |
|
517 | 517 | if ( |
|
518 | 518 | (old_filter is None or binding.filter == old_filter) |
|
519 | 519 | and (old_keys is None or [k for k in binding.keys] == old_keys) |
|
520 | 520 | and create_identifier(binding.handler) == command_id |
|
521 | 521 | ) |
|
522 | 522 | ] |
|
523 | 523 | |
|
524 | 524 | new_keys = shortcut.get("new_keys", None) |
|
525 | 525 | new_filter = shortcut.get("new_filter", None) |
|
526 | 526 | |
|
527 | 527 | command = known_commands[command_id] |
|
528 | 528 | |
|
529 | 529 | creating_new = shortcut.get("create", False) |
|
530 | 530 | modifying_existing = not creating_new and ( |
|
531 | 531 | new_keys is not None or new_filter |
|
532 | 532 | ) |
|
533 | 533 | |
|
534 | 534 | if creating_new and new_keys == []: |
|
535 | 535 | raise ValueError("Cannot add a shortcut without keys") |
|
536 | 536 | |
|
537 | 537 | if modifying_existing: |
|
538 | 538 | specification = { |
|
539 | 539 | key: shortcut[key] |
|
540 | 540 | for key in ["command", "filter"] |
|
541 | 541 | if key in shortcut |
|
542 | 542 | } |
|
543 | 543 | if len(matching) == 0: |
|
544 |
raise ValueError( |
|
|
544 | raise ValueError( | |
|
545 | f"No shortcuts matching {specification} found in {key_bindings.bindings}" | |
|
546 | ) | |
|
545 | 547 | elif len(matching) > 1: |
|
546 | 548 | raise ValueError( |
|
547 | 549 | f"Multiple shortcuts matching {specification} found," |
|
548 | 550 | f" please add keys/filter to select one of: {matching}" |
|
549 | 551 | ) |
|
550 | 552 | |
|
551 | 553 | matched = matching[0] |
|
552 | 554 | old_filter = matched.filter |
|
553 | 555 | old_keys = list(matched.keys) |
|
554 | 556 | shortcuts_to_skip.append( |
|
555 | 557 | RuntimeBinding( |
|
556 | 558 | command, |
|
557 | 559 | keys=old_keys, |
|
558 | 560 | filter=old_filter, |
|
559 | 561 | ) |
|
560 | 562 | ) |
|
561 | 563 | |
|
562 | 564 | if new_keys != []: |
|
563 | 565 | shortcuts_to_add.append( |
|
564 | 566 | RuntimeBinding( |
|
565 | 567 | command, |
|
566 | 568 | keys=new_keys or old_keys, |
|
567 | 569 | filter=filter_from_string(new_filter) |
|
568 | 570 | if new_filter is not None |
|
569 | 571 | else ( |
|
570 | 572 | old_filter |
|
571 | 573 | if old_filter is not None |
|
572 | 574 | else filter_from_string("always") |
|
573 | 575 | ), |
|
574 | 576 | ) |
|
575 | 577 | ) |
|
576 | 578 | |
|
577 | 579 | # rebuild the bindings list from scratch |
|
578 | 580 | key_bindings = create_ipython_shortcuts(self, skip=shortcuts_to_skip) |
|
579 | 581 | for binding in shortcuts_to_add: |
|
580 | 582 | add_binding(key_bindings, binding) |
|
581 | 583 | |
|
582 | 584 | return key_bindings |
|
583 | 585 | |
|
584 | 586 | prompt_includes_vi_mode = Bool(True, |
|
585 | 587 | help="Display the current vi mode (when using vi editing mode)." |
|
586 | 588 | ).tag(config=True) |
|
587 | 589 | |
|
588 | 590 | @observe('term_title') |
|
589 | 591 | def init_term_title(self, change=None): |
|
590 | 592 | # Enable or disable the terminal title. |
|
591 | 593 | if self.term_title and _is_tty: |
|
592 | 594 | toggle_set_term_title(True) |
|
593 | 595 | set_term_title(self.term_title_format.format(cwd=abbrev_cwd())) |
|
594 | 596 | else: |
|
595 | 597 | toggle_set_term_title(False) |
|
596 | 598 | |
|
597 | 599 | def restore_term_title(self): |
|
598 | 600 | if self.term_title and _is_tty: |
|
599 | 601 | restore_term_title() |
|
600 | 602 | |
|
601 | 603 | def init_display_formatter(self): |
|
602 | 604 | super(TerminalInteractiveShell, self).init_display_formatter() |
|
603 | 605 | # terminal only supports plain text |
|
604 | 606 | self.display_formatter.active_types = ["text/plain"] |
|
605 | 607 | |
|
606 | 608 | def init_prompt_toolkit_cli(self): |
|
607 | 609 | if self.simple_prompt: |
|
608 | 610 | # Fall back to plain non-interactive output for tests. |
|
609 | 611 | # This is very limited. |
|
610 | 612 | def prompt(): |
|
611 | 613 | prompt_text = "".join(x[1] for x in self.prompts.in_prompt_tokens()) |
|
612 | 614 | lines = [input(prompt_text)] |
|
613 | 615 | prompt_continuation = "".join(x[1] for x in self.prompts.continuation_prompt_tokens()) |
|
614 | 616 | while self.check_complete('\n'.join(lines))[0] == 'incomplete': |
|
615 | 617 | lines.append( input(prompt_continuation) ) |
|
616 | 618 | return '\n'.join(lines) |
|
617 | 619 | self.prompt_for_code = prompt |
|
618 | 620 | return |
|
619 | 621 | |
|
620 | 622 | # Set up keyboard shortcuts |
|
621 | 623 | key_bindings = self._merge_shortcuts(user_shortcuts=self.shortcuts) |
|
622 | 624 | |
|
623 | 625 | # Pre-populate history from IPython's history database |
|
624 | 626 | history = PtkHistoryAdapter(self) |
|
625 | 627 | |
|
626 | 628 | self._style = self._make_style_from_name_or_cls(self.highlighting_style) |
|
627 | 629 | self.style = DynamicStyle(lambda: self._style) |
|
628 | 630 | |
|
629 | 631 | editing_mode = getattr(EditingMode, self.editing_mode.upper()) |
|
630 | 632 | |
|
631 | 633 | self.pt_loop = asyncio.new_event_loop() |
|
632 | 634 | self.pt_app = PromptSession( |
|
633 | 635 | auto_suggest=self.auto_suggest, |
|
634 | 636 | editing_mode=editing_mode, |
|
635 | 637 | key_bindings=key_bindings, |
|
636 | 638 | history=history, |
|
637 | 639 | completer=IPythonPTCompleter(shell=self), |
|
638 | 640 | enable_history_search=self.enable_history_search, |
|
639 | 641 | style=self.style, |
|
640 | 642 | include_default_pygments_style=False, |
|
641 | 643 | mouse_support=self.mouse_support, |
|
642 | 644 | enable_open_in_editor=self.extra_open_editor_shortcuts, |
|
643 | 645 | color_depth=self.color_depth, |
|
644 | 646 | tempfile_suffix=".py", |
|
645 | 647 | **self._extra_prompt_options(), |
|
646 | 648 | ) |
|
647 | 649 | if isinstance(self.auto_suggest, NavigableAutoSuggestFromHistory): |
|
648 | 650 | self.auto_suggest.connect(self.pt_app) |
|
649 | 651 | |
|
650 | 652 | def _make_style_from_name_or_cls(self, name_or_cls): |
|
651 | 653 | """ |
|
652 | 654 | Small wrapper that make an IPython compatible style from a style name |
|
653 | 655 | |
|
654 | 656 | We need that to add style for prompt ... etc. |
|
655 | 657 | """ |
|
656 | 658 | style_overrides = {} |
|
657 | 659 | if name_or_cls == 'legacy': |
|
658 | 660 | legacy = self.colors.lower() |
|
659 | 661 | if legacy == 'linux': |
|
660 | 662 | style_cls = get_style_by_name('monokai') |
|
661 | 663 | style_overrides = _style_overrides_linux |
|
662 | 664 | elif legacy == 'lightbg': |
|
663 | 665 | style_overrides = _style_overrides_light_bg |
|
664 | 666 | style_cls = get_style_by_name('pastie') |
|
665 | 667 | elif legacy == 'neutral': |
|
666 | 668 | # The default theme needs to be visible on both a dark background |
|
667 | 669 | # and a light background, because we can't tell what the terminal |
|
668 | 670 | # looks like. These tweaks to the default theme help with that. |
|
669 | 671 | style_cls = get_style_by_name('default') |
|
670 | 672 | style_overrides.update({ |
|
671 | 673 | Token.Number: '#ansigreen', |
|
672 | 674 | Token.Operator: 'noinherit', |
|
673 | 675 | Token.String: '#ansiyellow', |
|
674 | 676 | Token.Name.Function: '#ansiblue', |
|
675 | 677 | Token.Name.Class: 'bold #ansiblue', |
|
676 | 678 | Token.Name.Namespace: 'bold #ansiblue', |
|
677 | 679 | Token.Name.Variable.Magic: '#ansiblue', |
|
678 | 680 | Token.Prompt: '#ansigreen', |
|
679 | 681 | Token.PromptNum: '#ansibrightgreen bold', |
|
680 | 682 | Token.OutPrompt: '#ansired', |
|
681 | 683 | Token.OutPromptNum: '#ansibrightred bold', |
|
682 | 684 | }) |
|
683 | 685 | |
|
684 | 686 | # Hack: Due to limited color support on the Windows console |
|
685 | 687 | # the prompt colors will be wrong without this |
|
686 | 688 | if os.name == 'nt': |
|
687 | 689 | style_overrides.update({ |
|
688 | 690 | Token.Prompt: '#ansidarkgreen', |
|
689 | 691 | Token.PromptNum: '#ansigreen bold', |
|
690 | 692 | Token.OutPrompt: '#ansidarkred', |
|
691 | 693 | Token.OutPromptNum: '#ansired bold', |
|
692 | 694 | }) |
|
693 | 695 | elif legacy =='nocolor': |
|
694 | 696 | style_cls=_NoStyle |
|
695 | 697 | style_overrides = {} |
|
696 | 698 | else : |
|
697 | 699 | raise ValueError('Got unknown colors: ', legacy) |
|
698 | 700 | else : |
|
699 | 701 | if isinstance(name_or_cls, str): |
|
700 | 702 | style_cls = get_style_by_name(name_or_cls) |
|
701 | 703 | else: |
|
702 | 704 | style_cls = name_or_cls |
|
703 | 705 | style_overrides = { |
|
704 | 706 | Token.Prompt: '#ansigreen', |
|
705 | 707 | Token.PromptNum: '#ansibrightgreen bold', |
|
706 | 708 | Token.OutPrompt: '#ansired', |
|
707 | 709 | Token.OutPromptNum: '#ansibrightred bold', |
|
708 | 710 | } |
|
709 | 711 | style_overrides.update(self.highlighting_style_overrides) |
|
710 | 712 | style = merge_styles([ |
|
711 | 713 | style_from_pygments_cls(style_cls), |
|
712 | 714 | style_from_pygments_dict(style_overrides), |
|
713 | 715 | ]) |
|
714 | 716 | |
|
715 | 717 | return style |
|
716 | 718 | |
|
717 | 719 | @property |
|
718 | 720 | def pt_complete_style(self): |
|
719 | 721 | return { |
|
720 | 722 | 'multicolumn': CompleteStyle.MULTI_COLUMN, |
|
721 | 723 | 'column': CompleteStyle.COLUMN, |
|
722 | 724 | 'readlinelike': CompleteStyle.READLINE_LIKE, |
|
723 | 725 | }[self.display_completions] |
|
724 | 726 | |
|
725 | 727 | @property |
|
726 | 728 | def color_depth(self): |
|
727 | 729 | return (ColorDepth.TRUE_COLOR if self.true_color else None) |
|
728 | 730 | |
|
729 | 731 | def _extra_prompt_options(self): |
|
730 | 732 | """ |
|
731 | 733 | Return the current layout option for the current Terminal InteractiveShell |
|
732 | 734 | """ |
|
733 | 735 | def get_message(): |
|
734 | 736 | return PygmentsTokens(self.prompts.in_prompt_tokens()) |
|
735 | 737 | |
|
736 | 738 | if self.editing_mode == 'emacs': |
|
737 | 739 | # with emacs mode the prompt is (usually) static, so we call only |
|
738 | 740 | # the function once. With VI mode it can toggle between [ins] and |
|
739 | 741 | # [nor] so we can't precompute. |
|
740 | 742 | # here I'm going to favor the default keybinding which almost |
|
741 | 743 | # everybody uses to decrease CPU usage. |
|
742 | 744 | # if we have issues with users with custom Prompts we can see how to |
|
743 | 745 | # work around this. |
|
744 | 746 | get_message = get_message() |
|
745 | 747 | |
|
746 | 748 | options = { |
|
747 | 749 | "complete_in_thread": False, |
|
748 | 750 | "lexer": IPythonPTLexer(), |
|
749 | 751 | "reserve_space_for_menu": self.space_for_menu, |
|
750 | 752 | "message": get_message, |
|
751 | 753 | "prompt_continuation": ( |
|
752 | 754 | lambda width, lineno, is_soft_wrap: PygmentsTokens( |
|
753 | 755 | self.prompts.continuation_prompt_tokens(width) |
|
754 | 756 | ) |
|
755 | 757 | ), |
|
756 | 758 | "multiline": True, |
|
757 | 759 | "complete_style": self.pt_complete_style, |
|
758 | 760 | "input_processors": [ |
|
759 | 761 | # Highlight matching brackets, but only when this setting is |
|
760 | 762 | # enabled, and only when the DEFAULT_BUFFER has the focus. |
|
761 | 763 | ConditionalProcessor( |
|
762 | 764 | processor=HighlightMatchingBracketProcessor(chars="[](){}"), |
|
763 | 765 | filter=HasFocus(DEFAULT_BUFFER) |
|
764 | 766 | & ~IsDone() |
|
765 | 767 | & Condition(lambda: self.highlight_matching_brackets), |
|
766 | 768 | ), |
|
767 | 769 | # Show auto-suggestion in lines other than the last line. |
|
768 | 770 | ConditionalProcessor( |
|
769 | 771 | processor=AppendAutoSuggestionInAnyLine(), |
|
770 | 772 | filter=HasFocus(DEFAULT_BUFFER) |
|
771 | 773 | & ~IsDone() |
|
772 | 774 | & Condition( |
|
773 | 775 | lambda: isinstance( |
|
774 | 776 | self.auto_suggest, NavigableAutoSuggestFromHistory |
|
775 | 777 | ) |
|
776 | 778 | ), |
|
777 | 779 | ), |
|
778 | 780 | ], |
|
779 | 781 | } |
|
780 | 782 | if not PTK3: |
|
781 | 783 | options['inputhook'] = self.inputhook |
|
782 | 784 | |
|
783 | 785 | return options |
|
784 | 786 | |
|
785 | 787 | def prompt_for_code(self): |
|
786 | 788 | if self.rl_next_input: |
|
787 | 789 | default = self.rl_next_input |
|
788 | 790 | self.rl_next_input = None |
|
789 | 791 | else: |
|
790 | 792 | default = '' |
|
791 | 793 | |
|
792 | 794 | # In order to make sure that asyncio code written in the |
|
793 | 795 | # interactive shell doesn't interfere with the prompt, we run the |
|
794 | 796 | # prompt in a different event loop. |
|
795 | 797 | # If we don't do this, people could spawn coroutine with a |
|
796 | 798 | # while/true inside which will freeze the prompt. |
|
797 | 799 | |
|
798 | 800 | policy = asyncio.get_event_loop_policy() |
|
799 | 801 | old_loop = get_asyncio_loop() |
|
800 | 802 | |
|
801 | 803 | # FIXME: prompt_toolkit is using the deprecated `asyncio.get_event_loop` |
|
802 | 804 | # to get the current event loop. |
|
803 | 805 | # This will probably be replaced by an attribute or input argument, |
|
804 | 806 | # at which point we can stop calling the soon-to-be-deprecated `set_event_loop` here. |
|
805 | 807 | if old_loop is not self.pt_loop: |
|
806 | 808 | policy.set_event_loop(self.pt_loop) |
|
807 | 809 | try: |
|
808 | 810 | with patch_stdout(raw=True): |
|
809 | 811 | text = self.pt_app.prompt( |
|
810 | 812 | default=default, |
|
811 | 813 | **self._extra_prompt_options()) |
|
812 | 814 | finally: |
|
813 | 815 | # Restore the original event loop. |
|
814 | 816 | if old_loop is not None and old_loop is not self.pt_loop: |
|
815 | 817 | policy.set_event_loop(old_loop) |
|
816 | 818 | |
|
817 | 819 | return text |
|
818 | 820 | |
|
819 | 821 | def enable_win_unicode_console(self): |
|
820 | 822 | # Since IPython 7.10 doesn't support python < 3.6 and PEP 528, Python uses the unicode APIs for the Windows |
|
821 | 823 | # console by default, so WUC shouldn't be needed. |
|
822 | 824 | warn("`enable_win_unicode_console` is deprecated since IPython 7.10, does not do anything and will be removed in the future", |
|
823 | 825 | DeprecationWarning, |
|
824 | 826 | stacklevel=2) |
|
825 | 827 | |
|
826 | 828 | def init_io(self): |
|
827 | 829 | if sys.platform not in {'win32', 'cli'}: |
|
828 | 830 | return |
|
829 | 831 | |
|
830 | 832 | import colorama |
|
831 | 833 | colorama.init() |
|
832 | 834 | |
|
833 | 835 | def init_magics(self): |
|
834 | 836 | super(TerminalInteractiveShell, self).init_magics() |
|
835 | 837 | self.register_magics(TerminalMagics) |
|
836 | 838 | |
|
837 | 839 | def init_alias(self): |
|
838 | 840 | # The parent class defines aliases that can be safely used with any |
|
839 | 841 | # frontend. |
|
840 | 842 | super(TerminalInteractiveShell, self).init_alias() |
|
841 | 843 | |
|
842 | 844 | # Now define aliases that only make sense on the terminal, because they |
|
843 | 845 | # need direct access to the console in a way that we can't emulate in |
|
844 | 846 | # GUI or web frontend |
|
845 | 847 | if os.name == 'posix': |
|
846 | 848 | for cmd in ('clear', 'more', 'less', 'man'): |
|
847 | 849 | self.alias_manager.soft_define_alias(cmd, cmd) |
|
848 | 850 | |
|
849 | 851 | |
|
850 | 852 | def __init__(self, *args, **kwargs) -> None: |
|
851 | 853 | super(TerminalInteractiveShell, self).__init__(*args, **kwargs) |
|
852 | 854 | self._set_autosuggestions(self.autosuggestions_provider) |
|
853 | 855 | self.init_prompt_toolkit_cli() |
|
854 | 856 | self.init_term_title() |
|
855 | 857 | self.keep_running = True |
|
856 | 858 | self._set_formatter(self.autoformatter) |
|
857 | 859 | |
|
858 | 860 | |
|
859 | 861 | def ask_exit(self): |
|
860 | 862 | self.keep_running = False |
|
861 | 863 | |
|
862 | 864 | rl_next_input = None |
|
863 | 865 | |
|
864 | 866 | def interact(self): |
|
865 | 867 | self.keep_running = True |
|
866 | 868 | while self.keep_running: |
|
867 | 869 | print(self.separate_in, end='') |
|
868 | 870 | |
|
869 | 871 | try: |
|
870 | 872 | code = self.prompt_for_code() |
|
871 | 873 | except EOFError: |
|
872 | 874 | if (not self.confirm_exit) \ |
|
873 | 875 | or self.ask_yes_no('Do you really want to exit ([y]/n)?','y','n'): |
|
874 | 876 | self.ask_exit() |
|
875 | 877 | |
|
876 | 878 | else: |
|
877 | 879 | if code: |
|
878 | 880 | self.run_cell(code, store_history=True) |
|
879 | 881 | |
|
880 | 882 | def mainloop(self): |
|
881 | 883 | # An extra layer of protection in case someone mashing Ctrl-C breaks |
|
882 | 884 | # out of our internal code. |
|
883 | 885 | while True: |
|
884 | 886 | try: |
|
885 | 887 | self.interact() |
|
886 | 888 | break |
|
887 | 889 | except KeyboardInterrupt as e: |
|
888 | 890 | print("\n%s escaped interact()\n" % type(e).__name__) |
|
889 | 891 | finally: |
|
890 | 892 | # An interrupt during the eventloop will mess up the |
|
891 | 893 | # internal state of the prompt_toolkit library. |
|
892 | 894 | # Stopping the eventloop fixes this, see |
|
893 | 895 | # https://github.com/ipython/ipython/pull/9867 |
|
894 | 896 | if hasattr(self, '_eventloop'): |
|
895 | 897 | self._eventloop.stop() |
|
896 | 898 | |
|
897 | 899 | self.restore_term_title() |
|
898 | 900 | |
|
899 | 901 | # try to call some at-exit operation optimistically as some things can't |
|
900 | 902 | # be done during interpreter shutdown. this is technically inaccurate as |
|
901 | 903 | # this make mainlool not re-callable, but that should be a rare if not |
|
902 | 904 | # in existent use case. |
|
903 | 905 | |
|
904 | 906 | self._atexit_once() |
|
905 | 907 | |
|
906 | 908 | |
|
907 | 909 | _inputhook = None |
|
908 | 910 | def inputhook(self, context): |
|
909 | 911 | if self._inputhook is not None: |
|
910 | 912 | self._inputhook(context) |
|
911 | 913 | |
|
912 | 914 | active_eventloop = None |
|
913 | 915 | def enable_gui(self, gui=None): |
|
914 | 916 | if self._inputhook is not None and gui is not None: |
|
915 | 917 | warn( |
|
916 | 918 | f"Shell was already running a gui event loop for {self.active_eventloop}; switching to {gui}." |
|
917 | 919 | ) |
|
918 | 920 | if gui and (gui not in {"inline", "webagg"}): |
|
919 | 921 | # This hook runs with each cycle of the `prompt_toolkit`'s event loop. |
|
920 | 922 | self.active_eventloop, self._inputhook = get_inputhook_name_and_func(gui) |
|
921 | 923 | else: |
|
922 | 924 | self.active_eventloop = self._inputhook = None |
|
923 | 925 | |
|
924 | 926 | # For prompt_toolkit 3.0. We have to create an asyncio event loop with |
|
925 | 927 | # this inputhook. |
|
926 | 928 | if PTK3: |
|
927 | 929 | import asyncio |
|
928 | 930 | from prompt_toolkit.eventloop import new_eventloop_with_inputhook |
|
929 | 931 | |
|
930 | 932 | if gui == 'asyncio': |
|
931 | 933 | # When we integrate the asyncio event loop, run the UI in the |
|
932 | 934 | # same event loop as the rest of the code. don't use an actual |
|
933 | 935 | # input hook. (Asyncio is not made for nesting event loops.) |
|
934 | 936 | self.pt_loop = get_asyncio_loop() |
|
935 | 937 | |
|
936 | 938 | elif self._inputhook: |
|
937 | 939 | # If an inputhook was set, create a new asyncio event loop with |
|
938 | 940 | # this inputhook for the prompt. |
|
939 | 941 | self.pt_loop = new_eventloop_with_inputhook(self._inputhook) |
|
940 | 942 | else: |
|
941 | 943 | # When there's no inputhook, run the prompt in a separate |
|
942 | 944 | # asyncio event loop. |
|
943 | 945 | self.pt_loop = asyncio.new_event_loop() |
|
944 | 946 | |
|
945 | 947 | # Run !system commands directly, not through pipes, so terminal programs |
|
946 | 948 | # work correctly. |
|
947 | 949 | system = InteractiveShell.system_raw |
|
948 | 950 | |
|
949 | 951 | def auto_rewrite_input(self, cmd): |
|
950 | 952 | """Overridden from the parent class to use fancy rewriting prompt""" |
|
951 | 953 | if not self.show_rewritten_input: |
|
952 | 954 | return |
|
953 | 955 | |
|
954 | 956 | tokens = self.prompts.rewrite_prompt_tokens() |
|
955 | 957 | if self.pt_app: |
|
956 | 958 | print_formatted_text(PygmentsTokens(tokens), end='', |
|
957 | 959 | style=self.pt_app.app.style) |
|
958 | 960 | print(cmd) |
|
959 | 961 | else: |
|
960 | 962 | prompt = ''.join(s for t, s in tokens) |
|
961 | 963 | print(prompt, cmd, sep='') |
|
962 | 964 | |
|
963 | 965 | _prompts_before = None |
|
964 | 966 | def switch_doctest_mode(self, mode): |
|
965 | 967 | """Switch prompts to classic for %doctest_mode""" |
|
966 | 968 | if mode: |
|
967 | 969 | self._prompts_before = self.prompts |
|
968 | 970 | self.prompts = ClassicPrompts(self) |
|
969 | 971 | elif self._prompts_before: |
|
970 | 972 | self.prompts = self._prompts_before |
|
971 | 973 | self._prompts_before = None |
|
972 | 974 | # self._update_layout() |
|
973 | 975 | |
|
974 | 976 | |
|
975 | 977 | InteractiveShellABC.register(TerminalInteractiveShell) |
|
976 | 978 | |
|
977 | 979 | if __name__ == '__main__': |
|
978 | 980 | TerminalInteractiveShell.instance().interact() |
@@ -1,1409 +1,1449 | |||
|
1 | 1 | ============ |
|
2 | 2 | 8.x Series |
|
3 | 3 | ============ |
|
4 | 4 | |
|
5 | .. _version 8.11.0: | |
|
6 | ||
|
7 | IPython 8.11 | |
|
8 | ------------ | |
|
9 | ||
|
10 | Back on almost regular monthly schedule for IPython with end-of-month | |
|
11 | really-late-Friday release, with a few new features, bugfix and UX improvements. | |
|
12 | ||
|
13 | This is a non-exhaustive list, but among other you will find: | |
|
14 | ||
|
15 | Faster Traceback Highlighting | |
|
16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
|
17 | ||
|
18 | Resurrection of pre-IPython-8 traceback highlighting code. | |
|
19 | ||
|
20 | Really long and complicated files were slow to highlight in traceback with | |
|
21 | IPython 8 despite upstream improvement that make many case better. Therefore | |
|
22 | starting with IPython 8.11 when one of the highlighted file is more than 10 000 | |
|
23 | line long by default, we'll fallback to a faster path that does not have all the | |
|
24 | features of highlighting failing AST nodes. | |
|
25 | ||
|
26 | This can be configures by setting the value of | |
|
27 | ``IPython.code.ultratb.FAST_THRESHOLD`` to an arbitrary low or large value. | |
|
28 | ||
|
29 | Miscellaneous | |
|
30 | ~~~~~~~~~~~~~ | |
|
31 | ||
|
32 | - ``%gui`` should now support PySide6. :ghpull:`13864` | |
|
33 | - Cli shortcuts can now be configured :ghpull:`13928` | |
|
34 | - Capture output should now respect ``;`` semicolon to suppress output. | |
|
35 | :ghpull:`13940` | |
|
36 | ||
|
37 | - Base64 encoded images (in jupyter frontend), will not have trailing newlines. | |
|
38 | :ghpull:`13941` | |
|
39 | ||
|
40 | As usual you can find the full list of PRs on GitHub under `the 8.10 milestone | |
|
41 | <https://github.com/ipython/ipython/milestone/113?closed=1>`__. | |
|
42 | ||
|
43 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring | |
|
44 | work on IPython and related libraries. | |
|
5 | 45 | |
|
6 | 46 | .. _version 8.10.0: |
|
7 | 47 | |
|
8 | 48 | IPython 8.10 |
|
9 | 49 | ------------ |
|
10 | 50 | |
|
11 | 51 | Out of schedule release of IPython with minor fixes to patch a potential CVE-2023-24816. |
|
12 | 52 | This is a really low severity CVE that you most likely are not affected by unless: |
|
13 | 53 | |
|
14 | 54 | - You are on windows. |
|
15 | 55 | - You have a custom build of Python without ``_ctypes`` |
|
16 | 56 | - You cd or start IPython or Jupyter in untrusted directory which names may be |
|
17 | 57 | valid shell commands. |
|
18 | 58 | |
|
19 | 59 | You can read more on `the advisory |
|
20 | 60 | <https://github.com/ipython/ipython/security/advisories/GHSA-29gw-9793-fvw7>`__. |
|
21 | 61 | |
|
22 | 62 | In addition to fixing this CVE we also fix a couple of outstanding bugs and issues. |
|
23 | 63 | |
|
24 | 64 | As usual you can find the full list of PRs on GitHub under `the 8.10 milestone |
|
25 | 65 | <https://github.com/ipython/ipython/milestone/112?closed=1>`__. |
|
26 | 66 | |
|
27 | 67 | In Particular: |
|
28 | 68 | |
|
29 | 69 | - bump minimum numpy to `>=1.21` version following NEP29. :ghpull:`13930` |
|
30 | 70 | - fix for compatibility with MyPy 1.0. :ghpull:`13933` |
|
31 | 71 | - fix nbgrader stalling when IPython's ``showtraceback`` function is |
|
32 | 72 | monkeypatched. :ghpull:`13934` |
|
33 | 73 | |
|
34 | 74 | |
|
35 | 75 | |
|
36 | 76 | As this release also contains those minimal changes in addition to fixing the |
|
37 | 77 | CVE I decided to bump the minor version anyway. |
|
38 | 78 | |
|
39 | 79 | This will not affect the normal release schedule, so IPython 8.11 is due in |
|
40 | 80 | about 2 weeks. |
|
41 | 81 | |
|
42 | 82 | .. _version 8.9.0: |
|
43 | 83 | |
|
44 | 84 | IPython 8.9.0 |
|
45 | 85 | ------------- |
|
46 | 86 | |
|
47 | 87 | Second release of IPython in 2023, last Friday of the month, we are back on |
|
48 | 88 | track. This is a small release with a few bug-fixes, and improvements, mostly |
|
49 | 89 | with respect to terminal shortcuts. |
|
50 | 90 | |
|
51 | 91 | |
|
52 | 92 | The biggest improvement for 8.9 is a drastic amelioration of the |
|
53 | 93 | auto-suggestions sponsored by D.E. Shaw and implemented by the more and more |
|
54 | 94 | active contributor `@krassowski <https://github.com/krassowski>`. |
|
55 | 95 | |
|
56 | 96 | - ``right`` accepts a single character from suggestion |
|
57 | 97 | - ``ctrl+right`` accepts a semantic token (macos default shortcuts take |
|
58 | 98 | precedence and need to be disabled to make this work) |
|
59 | 99 | - ``backspace`` deletes a character and resumes hinting autosuggestions |
|
60 | 100 | - ``ctrl-left`` accepts suggestion and moves cursor left one character. |
|
61 | 101 | - ``backspace`` deletes a character and resumes hinting autosuggestions |
|
62 | 102 | - ``down`` moves to suggestion to later in history when no lines are present below the cursors. |
|
63 | 103 | - ``up`` moves to suggestion from earlier in history when no lines are present above the cursor. |
|
64 | 104 | |
|
65 | 105 | This is best described by the Gif posted by `@krassowski |
|
66 | 106 | <https://github.com/krassowski>`, and in the PR itself :ghpull:`13888`. |
|
67 | 107 | |
|
68 | 108 | .. image:: ../_images/autosuggest.gif |
|
69 | 109 | |
|
70 | 110 | Please report any feedback in order for us to improve the user experience. |
|
71 | 111 | In particular we are also working on making the shortcuts configurable. |
|
72 | 112 | |
|
73 | 113 | If you are interested in better terminal shortcuts, I also invite you to |
|
74 | 114 | participate in issue `13879 |
|
75 | 115 | <https://github.com/ipython/ipython/issues/13879>`__. |
|
76 | 116 | |
|
77 | 117 | |
|
78 | 118 | As we follow `NEP29 |
|
79 | 119 | <https://numpy.org/neps/nep-0029-deprecation_policy.html>`__, next version of |
|
80 | 120 | IPython will officially stop supporting numpy 1.20, and will stop supporting |
|
81 | 121 | Python 3.8 after April release. |
|
82 | 122 | |
|
83 | 123 | As usual you can find the full list of PRs on GitHub under `the 8.9 milestone |
|
84 | 124 | <https://github.com/ipython/ipython/milestone/111?closed=1>`__. |
|
85 | 125 | |
|
86 | 126 | |
|
87 | 127 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
88 | 128 | work on IPython and related libraries. |
|
89 | 129 | |
|
90 | 130 | .. _version 8.8.0: |
|
91 | 131 | |
|
92 | 132 | IPython 8.8.0 |
|
93 | 133 | ------------- |
|
94 | 134 | |
|
95 | 135 | First release of IPython in 2023 as there was no release at the end of |
|
96 | 136 | December. |
|
97 | 137 | |
|
98 | 138 | This is an unusually big release (relatively speaking) with more than 15 Pull |
|
99 | 139 | Requests merged. |
|
100 | 140 | |
|
101 | 141 | Of particular interest are: |
|
102 | 142 | |
|
103 | 143 | - :ghpull:`13852` that replaces the greedy completer and improves |
|
104 | 144 | completion, in particular for dictionary keys. |
|
105 | 145 | - :ghpull:`13858` that adds ``py.typed`` to ``setup.cfg`` to make sure it is |
|
106 | 146 | bundled in wheels. |
|
107 | 147 | - :ghpull:`13869` that implements tab completions for IPython options in the |
|
108 | 148 | shell when using `argcomplete <https://github.com/kislyuk/argcomplete>`. I |
|
109 | 149 | believe this also needs a recent version of Traitlets. |
|
110 | 150 | - :ghpull:`13865` makes the ``inspector`` class of `InteractiveShell` |
|
111 | 151 | configurable. |
|
112 | 152 | - :ghpull:`13880` that removes minor-version entrypoints as the minor version |
|
113 | 153 | entry points that would be included in the wheel would be the one of the |
|
114 | 154 | Python version that was used to build the ``whl`` file. |
|
115 | 155 | |
|
116 | 156 | In no particular order, the rest of the changes update the test suite to be |
|
117 | 157 | compatible with Pygments 2.14, various docfixes, testing on more recent python |
|
118 | 158 | versions and various updates. |
|
119 | 159 | |
|
120 | 160 | As usual you can find the full list of PRs on GitHub under `the 8.8 milestone |
|
121 | 161 | <https://github.com/ipython/ipython/milestone/110>`__. |
|
122 | 162 | |
|
123 | 163 | Many thanks to @krassowski for the many PRs and @jasongrout for reviewing and |
|
124 | 164 | merging contributions. |
|
125 | 165 | |
|
126 | 166 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
127 | 167 | work on IPython and related libraries. |
|
128 | 168 | |
|
129 | 169 | .. _version 8.7.0: |
|
130 | 170 | |
|
131 | 171 | IPython 8.7.0 |
|
132 | 172 | ------------- |
|
133 | 173 | |
|
134 | 174 | |
|
135 | 175 | Small release of IPython with a couple of bug fixes and new features for this |
|
136 | 176 | month. Next month is the end of year, it is unclear if there will be a release |
|
137 | 177 | close to the new year's eve, or if the next release will be at the end of January. |
|
138 | 178 | |
|
139 | 179 | Here are a few of the relevant fixes, |
|
140 | 180 | as usual you can find the full list of PRs on GitHub under `the 8.7 milestone |
|
141 | 181 | <https://github.com/ipython/ipython/pulls?q=milestone%3A8.7>`__. |
|
142 | 182 | |
|
143 | 183 | |
|
144 | 184 | - :ghpull:`13834` bump the minimum prompt toolkit to 3.0.11. |
|
145 | 185 | - IPython shipped with the ``py.typed`` marker now, and we are progressively |
|
146 | 186 | adding more types. :ghpull:`13831` |
|
147 | 187 | - :ghpull:`13817` add configuration of code blacks formatting. |
|
148 | 188 | |
|
149 | 189 | |
|
150 | 190 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
151 | 191 | work on IPython and related libraries. |
|
152 | 192 | |
|
153 | 193 | |
|
154 | 194 | .. _version 8.6.0: |
|
155 | 195 | |
|
156 | 196 | IPython 8.6.0 |
|
157 | 197 | ------------- |
|
158 | 198 | |
|
159 | 199 | Back to a more regular release schedule (at least I try), as Friday is |
|
160 | 200 | already over by more than 24h hours. This is a slightly bigger release with a |
|
161 | 201 | few new features that contain no less than 25 PRs. |
|
162 | 202 | |
|
163 | 203 | We'll notably found a couple of non negligible changes: |
|
164 | 204 | |
|
165 | 205 | The ``install_ext`` and related functions have been removed after being |
|
166 | 206 | deprecated for years. You can use pip to install extensions. ``pip`` did not |
|
167 | 207 | exist when ``install_ext`` was introduced. You can still load local extensions |
|
168 | 208 | without installing them. Just set your ``sys.path`` for example. :ghpull:`13744` |
|
169 | 209 | |
|
170 | 210 | IPython now has extra entry points that use the major *and minor* version of |
|
171 | 211 | python. For some of you this means that you can do a quick ``ipython3.10`` to |
|
172 | 212 | launch IPython from the Python 3.10 interpreter, while still using Python 3.11 |
|
173 | 213 | as your main Python. :ghpull:`13743` |
|
174 | 214 | |
|
175 | 215 | The completer matcher API has been improved. See :ghpull:`13745`. This should |
|
176 | 216 | improve the type inference and improve dict keys completions in many use case. |
|
177 | 217 | Thanks ``@krassowski`` for all the work, and the D.E. Shaw group for sponsoring |
|
178 | 218 | it. |
|
179 | 219 | |
|
180 | 220 | The color of error nodes in tracebacks can now be customized. See |
|
181 | 221 | :ghpull:`13756`. This is a private attribute until someone finds the time to |
|
182 | 222 | properly add a configuration option. Note that with Python 3.11 that also shows |
|
183 | 223 | the relevant nodes in traceback, it would be good to leverage this information |
|
184 | 224 | (plus the "did you mean" info added on attribute errors). But that's likely work |
|
185 | 225 | I won't have time to do before long, so contributions welcome. |
|
186 | 226 | |
|
187 | 227 | As we follow NEP 29, we removed support for numpy 1.19 :ghpull:`13760`. |
|
188 | 228 | |
|
189 | 229 | |
|
190 | 230 | The ``open()`` function present in the user namespace by default will now refuse |
|
191 | 231 | to open the file descriptors 0,1,2 (stdin, out, err), to avoid crashing IPython. |
|
192 | 232 | This mostly occurs in teaching context when incorrect values get passed around. |
|
193 | 233 | |
|
194 | 234 | |
|
195 | 235 | The ``?``, ``??``, and corresponding ``pinfo``, ``pinfo2`` magics can now find |
|
196 | 236 | objects inside arrays. That is to say, the following now works:: |
|
197 | 237 | |
|
198 | 238 | |
|
199 | 239 | >>> def my_func(*arg, **kwargs):pass |
|
200 | 240 | >>> container = [my_func] |
|
201 | 241 | >>> container[0]? |
|
202 | 242 | |
|
203 | 243 | |
|
204 | 244 | If ``container`` define a custom ``getitem``, this __will__ trigger the custom |
|
205 | 245 | method. So don't put side effects in your ``getitems``. Thanks to the D.E. Shaw |
|
206 | 246 | group for the request and sponsoring the work. |
|
207 | 247 | |
|
208 | 248 | |
|
209 | 249 | As usual you can find the full list of PRs on GitHub under `the 8.6 milestone |
|
210 | 250 | <https://github.com/ipython/ipython/pulls?q=milestone%3A8.6>`__. |
|
211 | 251 | |
|
212 | 252 | Thanks to all hacktoberfest contributors, please contribute to |
|
213 | 253 | `closember.org <https://closember.org/>`__. |
|
214 | 254 | |
|
215 | 255 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
216 | 256 | work on IPython and related libraries. |
|
217 | 257 | |
|
218 | 258 | .. _version 8.5.0: |
|
219 | 259 | |
|
220 | 260 | IPython 8.5.0 |
|
221 | 261 | ------------- |
|
222 | 262 | |
|
223 | 263 | First release since a couple of month due to various reasons and timing preventing |
|
224 | 264 | me for sticking to the usual monthly release the last Friday of each month. This |
|
225 | 265 | is of non negligible size as it has more than two dozen PRs with various fixes |
|
226 | 266 | an bug fixes. |
|
227 | 267 | |
|
228 | 268 | Many thanks to everybody who contributed PRs for your patience in review and |
|
229 | 269 | merges. |
|
230 | 270 | |
|
231 | 271 | Here is a non-exhaustive list of changes that have been implemented for IPython |
|
232 | 272 | 8.5.0. As usual you can find the full list of issues and PRs tagged with `the |
|
233 | 273 | 8.5 milestone |
|
234 | 274 | <https://github.com/ipython/ipython/pulls?q=is%3Aclosed+milestone%3A8.5+>`__. |
|
235 | 275 | |
|
236 | 276 | - Added a shortcut for accepting auto suggestion. The End key shortcut for |
|
237 | 277 | accepting auto-suggestion This binding works in Vi mode too, provided |
|
238 | 278 | ``TerminalInteractiveShell.emacs_bindings_in_vi_insert_mode`` is set to be |
|
239 | 279 | ``True`` :ghpull:`13566`. |
|
240 | 280 | |
|
241 | 281 | - No popup in window for latex generation when generating latex (e.g. via |
|
242 | 282 | `_latex_repr_`) no popup window is shows under Windows. :ghpull:`13679` |
|
243 | 283 | |
|
244 | 284 | - Fixed error raised when attempting to tab-complete an input string with |
|
245 | 285 | consecutive periods or forward slashes (such as "file:///var/log/..."). |
|
246 | 286 | :ghpull:`13675` |
|
247 | 287 | |
|
248 | 288 | - Relative filenames in Latex rendering : |
|
249 | 289 | The `latex_to_png_dvipng` command internally generates input and output file |
|
250 | 290 | arguments to `latex` and `dvipis`. These arguments are now generated as |
|
251 | 291 | relative files to the current working directory instead of absolute file |
|
252 | 292 | paths. This solves a problem where the current working directory contains |
|
253 | 293 | characters that are not handled properly by `latex` and `dvips`. There are |
|
254 | 294 | no changes to the user API. :ghpull:`13680` |
|
255 | 295 | |
|
256 | 296 | - Stripping decorators bug: Fixed bug which meant that ipython code blocks in |
|
257 | 297 | restructured text documents executed with the ipython-sphinx extension |
|
258 | 298 | skipped any lines of code containing python decorators. :ghpull:`13612` |
|
259 | 299 | |
|
260 | 300 | - Allow some modules with frozen dataclasses to be reloaded. :ghpull:`13732` |
|
261 | 301 | - Fix paste magic on wayland. :ghpull:`13671` |
|
262 | 302 | - show maxlen in deque's repr. :ghpull:`13648` |
|
263 | 303 | |
|
264 | 304 | Restore line numbers for Input |
|
265 | ------------------------------ | |
|
305 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
|
266 | 306 | |
|
267 | 307 | Line number information in tracebacks from input are restored. |
|
268 | 308 | Line numbers from input were removed during the transition to v8 enhanced traceback reporting. |
|
269 | 309 | |
|
270 | 310 | So, instead of:: |
|
271 | 311 | |
|
272 | 312 | --------------------------------------------------------------------------- |
|
273 | 313 | ZeroDivisionError Traceback (most recent call last) |
|
274 | 314 | Input In [3], in <cell line: 1>() |
|
275 | 315 | ----> 1 myfunc(2) |
|
276 | 316 | |
|
277 | 317 | Input In [2], in myfunc(z) |
|
278 | 318 | 1 def myfunc(z): |
|
279 | 319 | ----> 2 foo.boo(z-1) |
|
280 | 320 | |
|
281 | 321 | File ~/code/python/ipython/foo.py:3, in boo(x) |
|
282 | 322 | 2 def boo(x): |
|
283 | 323 | ----> 3 return 1/(1-x) |
|
284 | 324 | |
|
285 | 325 | ZeroDivisionError: division by zero |
|
286 | 326 | |
|
287 | 327 | The error traceback now looks like:: |
|
288 | 328 | |
|
289 | 329 | --------------------------------------------------------------------------- |
|
290 | 330 | ZeroDivisionError Traceback (most recent call last) |
|
291 | 331 | Cell In [3], line 1 |
|
292 | 332 | ----> 1 myfunc(2) |
|
293 | 333 | |
|
294 | 334 | Cell In [2], line 2, in myfunc(z) |
|
295 | 335 | 1 def myfunc(z): |
|
296 | 336 | ----> 2 foo.boo(z-1) |
|
297 | 337 | |
|
298 | 338 | File ~/code/python/ipython/foo.py:3, in boo(x) |
|
299 | 339 | 2 def boo(x): |
|
300 | 340 | ----> 3 return 1/(1-x) |
|
301 | 341 | |
|
302 | 342 | ZeroDivisionError: division by zero |
|
303 | 343 | |
|
304 | 344 | or, with xmode=Plain:: |
|
305 | 345 | |
|
306 | 346 | Traceback (most recent call last): |
|
307 | 347 | Cell In [12], line 1 |
|
308 | 348 | myfunc(2) |
|
309 | 349 | Cell In [6], line 2 in myfunc |
|
310 | 350 | foo.boo(z-1) |
|
311 | 351 | File ~/code/python/ipython/foo.py:3 in boo |
|
312 | 352 | return 1/(1-x) |
|
313 | 353 | ZeroDivisionError: division by zero |
|
314 | 354 | |
|
315 | 355 | :ghpull:`13560` |
|
316 | 356 | |
|
317 | 357 | New setting to silence warning if working inside a virtual environment |
|
318 | ---------------------------------------------------------------------- | |
|
358 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
|
319 | 359 | |
|
320 | 360 | Previously, when starting IPython in a virtual environment without IPython installed (so IPython from the global environment is used), the following warning was printed: |
|
321 | 361 | |
|
322 | 362 | Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. |
|
323 | 363 | |
|
324 | 364 | This warning can be permanently silenced by setting ``c.InteractiveShell.warn_venv`` to ``False`` (the default is ``True``). |
|
325 | 365 | |
|
326 | 366 | :ghpull:`13706` |
|
327 | 367 | |
|
328 | 368 | ------- |
|
329 | 369 | |
|
330 | 370 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
331 | 371 | work on IPython and related libraries. |
|
332 | 372 | |
|
333 | 373 | |
|
334 | 374 | .. _version 8.4.0: |
|
335 | 375 | |
|
336 | 376 | IPython 8.4.0 |
|
337 | 377 | ------------- |
|
338 | 378 | |
|
339 | 379 | As for 7.34, this version contains a single fix: fix uncaught BdbQuit exceptions on ipdb |
|
340 | 380 | exit :ghpull:`13668`, and a single typo fix in documentation: :ghpull:`13682` |
|
341 | 381 | |
|
342 | 382 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
343 | 383 | work on IPython and related libraries. |
|
344 | 384 | |
|
345 | 385 | |
|
346 | 386 | .. _version 8.3.0: |
|
347 | 387 | |
|
348 | 388 | IPython 8.3.0 |
|
349 | 389 | ------------- |
|
350 | 390 | |
|
351 | 391 | - :ghpull:`13625`, using ``?``, ``??``, ``*?`` will not call |
|
352 | 392 | ``set_next_input`` as most frontend allow proper multiline editing and it was |
|
353 | 393 | causing issues for many users of multi-cell frontends. This has been backported to 7.33 |
|
354 | 394 | |
|
355 | 395 | |
|
356 | 396 | - :ghpull:`13600`, ``pre_run_*``-hooks will now have a ``cell_id`` attribute on |
|
357 | 397 | the info object when frontend provides it. This has been backported to 7.33 |
|
358 | 398 | |
|
359 | 399 | - :ghpull:`13624`, fixed :kbd:`End` key being broken after accepting an |
|
360 | 400 | auto-suggestion. |
|
361 | 401 | |
|
362 | 402 | - :ghpull:`13657` fixed an issue where history from different sessions would be mixed. |
|
363 | 403 | |
|
364 | 404 | .. _version 8.2.0: |
|
365 | 405 | |
|
366 | 406 | IPython 8.2.0 |
|
367 | 407 | ------------- |
|
368 | 408 | |
|
369 | 409 | IPython 8.2 mostly bring bugfixes to IPython. |
|
370 | 410 | |
|
371 | 411 | - Auto-suggestion can now be elected with the ``end`` key. :ghpull:`13566` |
|
372 | 412 | - Some traceback issues with ``assert etb is not None`` have been fixed. :ghpull:`13588` |
|
373 | 413 | - History is now pulled from the sqitel database and not from in-memory. |
|
374 | 414 | In particular when using the ``%paste`` magic, the content of the pasted text will |
|
375 | 415 | be part of the history and not the verbatim text ``%paste`` anymore. :ghpull:`13592` |
|
376 | 416 | - Fix ``Ctrl-\\`` exit cleanup :ghpull:`13603` |
|
377 | 417 | - Fixes to ``ultratb`` ipdb support when used outside of IPython. :ghpull:`13498` |
|
378 | 418 | |
|
379 | 419 | |
|
380 | 420 | I am still trying to fix and investigate :ghissue:`13598`, which seems to be |
|
381 | 421 | random, and would appreciate help if you find a reproducible minimal case. I've |
|
382 | 422 | tried to make various changes to the codebase to mitigate it, but a proper fix |
|
383 | 423 | will be difficult without understanding the cause. |
|
384 | 424 | |
|
385 | 425 | |
|
386 | 426 | All the issues on pull-requests for this release can be found in the `8.2 |
|
387 | 427 | milestone. <https://github.com/ipython/ipython/milestone/100>`__ . And some |
|
388 | 428 | documentation only PR can be found as part of the `7.33 milestone |
|
389 | 429 | <https://github.com/ipython/ipython/milestone/101>`__ (currently not released). |
|
390 | 430 | |
|
391 | 431 | Thanks to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
392 | 432 | work on IPython and related libraries. |
|
393 | 433 | |
|
394 | 434 | .. _version 8.1.1: |
|
395 | 435 | |
|
396 | 436 | IPython 8.1.1 |
|
397 | 437 | ------------- |
|
398 | 438 | |
|
399 | 439 | Fix an issue with virtualenv and Python 3.8 introduced in 8.1 |
|
400 | 440 | |
|
401 | 441 | Revert :ghpull:`13537` (fix an issue with symlinks in virtualenv) that raises an |
|
402 | 442 | error in Python 3.8, and fixed in a different way in :ghpull:`13559`. |
|
403 | 443 | |
|
404 | 444 | .. _version 8.1: |
|
405 | 445 | |
|
406 | 446 | IPython 8.1.0 |
|
407 | 447 | ------------- |
|
408 | 448 | |
|
409 | 449 | IPython 8.1 is the first minor release after 8.0 and fixes a number of bugs and |
|
410 | 450 | updates a few behaviors that were problematic with the 8.0 as with many new major |
|
411 | 451 | release. |
|
412 | 452 | |
|
413 | 453 | Note that beyond the changes listed here, IPython 8.1.0 also contains all the |
|
414 | 454 | features listed in :ref:`version 7.32`. |
|
415 | 455 | |
|
416 | 456 | - Misc and multiple fixes around quotation auto-closing. It is now disabled by |
|
417 | 457 | default. Run with ``TerminalInteractiveShell.auto_match=True`` to re-enabled |
|
418 | 458 | - Require pygments>=2.4.0 :ghpull:`13459`, this was implicit in the code, but |
|
419 | 459 | is now explicit in ``setup.cfg``/``setup.py`` |
|
420 | 460 | - Docs improvement of ``core.magic_arguments`` examples. :ghpull:`13433` |
|
421 | 461 | - Multi-line edit executes too early with await. :ghpull:`13424` |
|
422 | 462 | |
|
423 | 463 | - ``black`` is back as an optional dependency, and autoformatting disabled by |
|
424 | 464 | default until some fixes are implemented (black improperly reformat magics). |
|
425 | 465 | :ghpull:`13471` Additionally the ability to use ``yapf`` as a code |
|
426 | 466 | reformatter has been added :ghpull:`13528` . You can use |
|
427 | 467 | ``TerminalInteractiveShell.autoformatter="black"``, |
|
428 | 468 | ``TerminalInteractiveShell.autoformatter="yapf"`` to re-enable auto formating |
|
429 | 469 | with black, or switch to yapf. |
|
430 | 470 | |
|
431 | 471 | - Fix and issue where ``display`` was not defined. |
|
432 | 472 | |
|
433 | 473 | - Auto suggestions are now configurable. Currently only |
|
434 | 474 | ``AutoSuggestFromHistory`` (default) and ``None``. new provider contribution |
|
435 | 475 | welcomed. :ghpull:`13475` |
|
436 | 476 | |
|
437 | 477 | - multiple packaging/testing improvement to simplify downstream packaging |
|
438 | 478 | (xfail with reasons, try to not access network...). |
|
439 | 479 | |
|
440 | 480 | - Update deprecation. ``InteractiveShell.magic`` internal method has been |
|
441 | 481 | deprecated for many years but did not emit a warning until now. |
|
442 | 482 | |
|
443 | 483 | - internal ``appended_to_syspath`` context manager has been deprecated. |
|
444 | 484 | |
|
445 | 485 | - fix an issue with symlinks in virtualenv :ghpull:`13537` (Reverted in 8.1.1) |
|
446 | 486 | |
|
447 | 487 | - Fix an issue with vim mode, where cursor would not be reset on exit :ghpull:`13472` |
|
448 | 488 | |
|
449 | 489 | - ipython directive now remove only known pseudo-decorators :ghpull:`13532` |
|
450 | 490 | |
|
451 | 491 | - ``IPython/lib/security`` which used to be used for jupyter notebook has been |
|
452 | 492 | removed. |
|
453 | 493 | |
|
454 | 494 | - Fix an issue where ``async with`` would execute on new lines. :ghpull:`13436` |
|
455 | 495 | |
|
456 | 496 | |
|
457 | 497 | We want to remind users that IPython is part of the Jupyter organisations, and |
|
458 | 498 | thus governed by a Code of Conduct. Some of the behavior we have seen on GitHub is not acceptable. |
|
459 | 499 | Abuse and non-respectful comments on discussion will not be tolerated. |
|
460 | 500 | |
|
461 | 501 | Many thanks to all the contributors to this release, many of the above fixed issues and |
|
462 | 502 | new features were done by first time contributors, showing there is still |
|
463 | 503 | plenty of easy contribution possible in IPython |
|
464 | 504 | . You can find all individual contributions |
|
465 | 505 | to this milestone `on github <https://github.com/ipython/ipython/milestone/91>`__. |
|
466 | 506 | |
|
467 | 507 | Thanks as well to the `D. E. Shaw group <https://deshaw.com/>`__ for sponsoring |
|
468 | 508 | work on IPython and related libraries. In particular the Lazy autoloading of |
|
469 | 509 | magics that you will find described in the 7.32 release notes. |
|
470 | 510 | |
|
471 | 511 | |
|
472 | 512 | .. _version 8.0.1: |
|
473 | 513 | |
|
474 | 514 | IPython 8.0.1 (CVE-2022-21699) |
|
475 | 515 | ------------------------------ |
|
476 | 516 | |
|
477 | 517 | IPython 8.0.1, 7.31.1 and 5.11 are security releases that change some default |
|
478 | 518 | values in order to prevent potential Execution with Unnecessary Privileges. |
|
479 | 519 | |
|
480 | 520 | Almost all version of IPython looks for configuration and profiles in current |
|
481 | 521 | working directory. Since IPython was developed before pip and environments |
|
482 | 522 | existed it was used a convenient way to load code/packages in a project |
|
483 | 523 | dependant way. |
|
484 | 524 | |
|
485 | 525 | In 2022, it is not necessary anymore, and can lead to confusing behavior where |
|
486 | 526 | for example cloning a repository and starting IPython or loading a notebook from |
|
487 | 527 | any Jupyter-Compatible interface that has ipython set as a kernel can lead to |
|
488 | 528 | code execution. |
|
489 | 529 | |
|
490 | 530 | |
|
491 | 531 | I did not find any standard way for packaged to advertise CVEs they fix, I'm |
|
492 | 532 | thus trying to add a ``__patched_cves__`` attribute to the IPython module that |
|
493 | 533 | list the CVEs that should have been fixed. This attribute is informational only |
|
494 | 534 | as if a executable has a flaw, this value can always be changed by an attacker. |
|
495 | 535 | |
|
496 | 536 | .. code:: |
|
497 | 537 | |
|
498 | 538 | In [1]: import IPython |
|
499 | 539 | |
|
500 | 540 | In [2]: IPython.__patched_cves__ |
|
501 | 541 | Out[2]: {'CVE-2022-21699'} |
|
502 | 542 | |
|
503 | 543 | In [3]: 'CVE-2022-21699' in IPython.__patched_cves__ |
|
504 | 544 | Out[3]: True |
|
505 | 545 | |
|
506 | 546 | Thus starting with this version: |
|
507 | 547 | |
|
508 | 548 | - The current working directory is not searched anymore for profiles or |
|
509 | 549 | configurations files. |
|
510 | 550 | - Added a ``__patched_cves__`` attribute (set of strings) to IPython module that contain |
|
511 | 551 | the list of fixed CVE. This is informational only. |
|
512 | 552 | |
|
513 | 553 | Further details can be read on the `GitHub Advisory <https://github.com/ipython/ipython/security/advisories/GHSA-pq7m-3gw7-gq5x>`__ |
|
514 | 554 | |
|
515 | 555 | |
|
516 | 556 | .. _version 8.0: |
|
517 | 557 | |
|
518 | 558 | IPython 8.0 |
|
519 | 559 | ----------- |
|
520 | 560 | |
|
521 | 561 | IPython 8.0 is bringing a large number of new features and improvements to both the |
|
522 | 562 | user of the terminal and of the kernel via Jupyter. The removal of compatibility |
|
523 | 563 | with an older version of Python is also the opportunity to do a couple of |
|
524 | 564 | performance improvements in particular with respect to startup time. |
|
525 | 565 | The 8.x branch started diverging from its predecessor around IPython 7.12 |
|
526 | 566 | (January 2020). |
|
527 | 567 | |
|
528 | 568 | This release contains 250+ pull requests, in addition to many of the features |
|
529 | 569 | and backports that have made it to the 7.x branch. Please see the |
|
530 | 570 | `8.0 milestone <https://github.com/ipython/ipython/milestone/73?closed=1>`__ for the full list of pull requests. |
|
531 | 571 | |
|
532 | 572 | Please feel free to send pull requests to update those notes after release, |
|
533 | 573 | I have likely forgotten a few things reviewing 250+ PRs. |
|
534 | 574 | |
|
535 | 575 | Dependencies changes/downstream packaging |
|
536 | 576 | ----------------------------------------- |
|
537 | 577 | |
|
538 | 578 | Most of our building steps have been changed to be (mostly) declarative |
|
539 | 579 | and follow PEP 517. We are trying to completely remove ``setup.py`` (:ghpull:`13238`) and are |
|
540 | 580 | looking for help to do so. |
|
541 | 581 | |
|
542 | 582 | - minimum supported ``traitlets`` version is now 5+ |
|
543 | 583 | - we now require ``stack_data`` |
|
544 | 584 | - minimal Python is now 3.8 |
|
545 | 585 | - ``nose`` is not a testing requirement anymore |
|
546 | 586 | - ``pytest`` replaces nose. |
|
547 | 587 | - ``iptest``/``iptest3`` cli entrypoints do not exist anymore. |
|
548 | 588 | - the minimum officially βsupported ``numpy`` version has been bumped, but this should |
|
549 | 589 | not have much effect on packaging. |
|
550 | 590 | |
|
551 | 591 | |
|
552 | 592 | Deprecation and removal |
|
553 | 593 | ----------------------- |
|
554 | 594 | |
|
555 | 595 | We removed almost all features, arguments, functions, and modules that were |
|
556 | 596 | marked as deprecated between IPython 1.0 and 5.0. As a reminder, 5.0 was released |
|
557 | 597 | in 2016, and 1.0 in 2013. Last release of the 5 branch was 5.10.0, in May 2020. |
|
558 | 598 | The few remaining deprecated features we left have better deprecation warnings |
|
559 | 599 | or have been turned into explicit errors for better error messages. |
|
560 | 600 | |
|
561 | 601 | I will use this occasion to add the following requests to anyone emitting a |
|
562 | 602 | deprecation warning: |
|
563 | 603 | |
|
564 | 604 | - Please add at least ``stacklevel=2`` so that the warning is emitted into the |
|
565 | 605 | caller context, and not the callee one. |
|
566 | 606 | - Please add **since which version** something is deprecated. |
|
567 | 607 | |
|
568 | 608 | As a side note, it is much easier to conditionally compare version |
|
569 | 609 | numbers rather than using ``try/except`` when functionality changes with a version. |
|
570 | 610 | |
|
571 | 611 | I won't list all the removed features here, but modules like ``IPython.kernel``, |
|
572 | 612 | which was just a shim module around ``ipykernel`` for the past 8 years, have been |
|
573 | 613 | removed, and so many other similar things that pre-date the name **Jupyter** |
|
574 | 614 | itself. |
|
575 | 615 | |
|
576 | 616 | We no longer need to add ``IPython.extensions`` to the PYTHONPATH because that is being |
|
577 | 617 | handled by ``load_extension``. |
|
578 | 618 | |
|
579 | 619 | We are also removing ``Cythonmagic``, ``sympyprinting`` and ``rmagic`` as they are now in |
|
580 | 620 | other packages and no longer need to be inside IPython. |
|
581 | 621 | |
|
582 | 622 | |
|
583 | 623 | Documentation |
|
584 | 624 | ------------- |
|
585 | 625 | |
|
586 | 626 | The majority of our docstrings have now been reformatted and automatically fixed by |
|
587 | 627 | the experimental `VΓ©lin <https://pypi.org/project/velin/>`_ project to conform |
|
588 | 628 | to numpydoc. |
|
589 | 629 | |
|
590 | 630 | Type annotations |
|
591 | 631 | ---------------- |
|
592 | 632 | |
|
593 | 633 | While IPython itself is highly dynamic and can't be completely typed, many of |
|
594 | 634 | the functions now have type annotations, and part of the codebase is now checked |
|
595 | 635 | by mypy. |
|
596 | 636 | |
|
597 | 637 | |
|
598 | 638 | Featured changes |
|
599 | 639 | ---------------- |
|
600 | 640 | |
|
601 | 641 | Here is a features list of changes in IPython 8.0. This is of course non-exhaustive. |
|
602 | 642 | Please note as well that many features have been added in the 7.x branch as well |
|
603 | 643 | (and hence why you want to read the 7.x what's new notes), in particular |
|
604 | 644 | features contributed by QuantStack (with respect to debugger protocol and Xeus |
|
605 | 645 | Python), as well as many debugger features that I was pleased to implement as |
|
606 | 646 | part of my work at QuanSight and sponsored by DE Shaw. |
|
607 | 647 | |
|
608 | 648 | Traceback improvements |
|
609 | 649 | ~~~~~~~~~~~~~~~~~~~~~~ |
|
610 | 650 | |
|
611 | 651 | Previously, error tracebacks for errors happening in code cells were showing a |
|
612 | 652 | hash, the one used for compiling the Python AST:: |
|
613 | 653 | |
|
614 | 654 | In [1]: def foo(): |
|
615 | 655 | ...: return 3 / 0 |
|
616 | 656 | ...: |
|
617 | 657 | |
|
618 | 658 | In [2]: foo() |
|
619 | 659 | --------------------------------------------------------------------------- |
|
620 | 660 | ZeroDivisionError Traceback (most recent call last) |
|
621 | 661 | <ipython-input-2-c19b6d9633cf> in <module> |
|
622 | 662 | ----> 1 foo() |
|
623 | 663 | |
|
624 | 664 | <ipython-input-1-1595a74c32d5> in foo() |
|
625 | 665 | 1 def foo(): |
|
626 | 666 | ----> 2 return 3 / 0 |
|
627 | 667 | 3 |
|
628 | 668 | |
|
629 | 669 | ZeroDivisionError: division by zero |
|
630 | 670 | |
|
631 | 671 | The error traceback is now correctly formatted, showing the cell number in which the error happened:: |
|
632 | 672 | |
|
633 | 673 | In [1]: def foo(): |
|
634 | 674 | ...: return 3 / 0 |
|
635 | 675 | ...: |
|
636 | 676 | |
|
637 | 677 | Input In [2]: foo() |
|
638 | 678 | --------------------------------------------------------------------------- |
|
639 | 679 | ZeroDivisionError Traceback (most recent call last) |
|
640 | 680 | input In [2], in <module> |
|
641 | 681 | ----> 1 foo() |
|
642 | 682 | |
|
643 | 683 | Input In [1], in foo() |
|
644 | 684 | 1 def foo(): |
|
645 | 685 | ----> 2 return 3 / 0 |
|
646 | 686 | |
|
647 | 687 | ZeroDivisionError: division by zero |
|
648 | 688 | |
|
649 | 689 | The ``stack_data`` package has been integrated, which provides smarter information in the traceback; |
|
650 | 690 | in particular it will highlight the AST node where an error occurs which can help to quickly narrow down errors. |
|
651 | 691 | |
|
652 | 692 | For example in the following snippet:: |
|
653 | 693 | |
|
654 | 694 | def foo(i): |
|
655 | 695 | x = [[[0]]] |
|
656 | 696 | return x[0][i][0] |
|
657 | 697 | |
|
658 | 698 | |
|
659 | 699 | def bar(): |
|
660 | 700 | return foo(0) + foo( |
|
661 | 701 | 1 |
|
662 | 702 | ) + foo(2) |
|
663 | 703 | |
|
664 | 704 | |
|
665 | 705 | calling ``bar()`` would raise an ``IndexError`` on the return line of ``foo``, |
|
666 | 706 | and IPython 8.0 is capable of telling you where the index error occurs:: |
|
667 | 707 | |
|
668 | 708 | |
|
669 | 709 | IndexError |
|
670 | 710 | Input In [2], in <module> |
|
671 | 711 | ----> 1 bar() |
|
672 | 712 | ^^^^^ |
|
673 | 713 | |
|
674 | 714 | Input In [1], in bar() |
|
675 | 715 | 6 def bar(): |
|
676 | 716 | ----> 7 return foo(0) + foo( |
|
677 | 717 | ^^^^ |
|
678 | 718 | 8 1 |
|
679 | 719 | ^^^^^^^^ |
|
680 | 720 | 9 ) + foo(2) |
|
681 | 721 | ^^^^ |
|
682 | 722 | |
|
683 | 723 | Input In [1], in foo(i) |
|
684 | 724 | 1 def foo(i): |
|
685 | 725 | 2 x = [[[0]]] |
|
686 | 726 | ----> 3 return x[0][i][0] |
|
687 | 727 | ^^^^^^^ |
|
688 | 728 | |
|
689 | 729 | The corresponding locations marked here with ``^`` will show up highlighted in |
|
690 | 730 | the terminal and notebooks. |
|
691 | 731 | |
|
692 | 732 | Finally, a colon ``::`` and line number is appended after a filename in |
|
693 | 733 | traceback:: |
|
694 | 734 | |
|
695 | 735 | |
|
696 | 736 | ZeroDivisionError Traceback (most recent call last) |
|
697 | 737 | File ~/error.py:4, in <module> |
|
698 | 738 | 1 def f(): |
|
699 | 739 | 2 1/0 |
|
700 | 740 | ----> 4 f() |
|
701 | 741 | |
|
702 | 742 | File ~/error.py:2, in f() |
|
703 | 743 | 1 def f(): |
|
704 | 744 | ----> 2 1/0 |
|
705 | 745 | |
|
706 | 746 | Many terminals and editors have integrations enabling you to directly jump to the |
|
707 | 747 | relevant file/line when this syntax is used, so this small addition may have a high |
|
708 | 748 | impact on productivity. |
|
709 | 749 | |
|
710 | 750 | |
|
711 | 751 | Autosuggestions |
|
712 | 752 | ~~~~~~~~~~~~~~~ |
|
713 | 753 | |
|
714 | 754 | Autosuggestion is a very useful feature available in `fish <https://fishshell.com/>`__, `zsh <https://en.wikipedia.org/wiki/Z_shell>`__, and `prompt-toolkit <https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#auto-suggestion>`__. |
|
715 | 755 | |
|
716 | 756 | `Ptpython <https://github.com/prompt-toolkit/ptpython#ptpython>`__ allows users to enable this feature in |
|
717 | 757 | `ptpython/config.py <https://github.com/prompt-toolkit/ptpython/blob/master/examples/ptpython_config/config.py#L90>`__. |
|
718 | 758 | |
|
719 | 759 | This feature allows users to accept autosuggestions with ctrl e, ctrl f, |
|
720 | 760 | or right arrow as described below. |
|
721 | 761 | |
|
722 | 762 | 1. Start ipython |
|
723 | 763 | |
|
724 | 764 | .. image:: ../_images/8.0/auto_suggest_1_prompt_no_text.png |
|
725 | 765 | |
|
726 | 766 | 2. Run ``print("hello")`` |
|
727 | 767 | |
|
728 | 768 | .. image:: ../_images/8.0/auto_suggest_2_print_hello_suggest.png |
|
729 | 769 | |
|
730 | 770 | 3. start typing ``print`` again to see the autosuggestion |
|
731 | 771 | |
|
732 | 772 | .. image:: ../_images/8.0/auto_suggest_3_print_hello_suggest.png |
|
733 | 773 | |
|
734 | 774 | 4. Press ``ctrl-f``, or ``ctrl-e``, or ``right-arrow`` to accept the suggestion |
|
735 | 775 | |
|
736 | 776 | .. image:: ../_images/8.0/auto_suggest_4_print_hello.png |
|
737 | 777 | |
|
738 | 778 | You can also complete word by word: |
|
739 | 779 | |
|
740 | 780 | 1. Run ``def say_hello(): print("hello")`` |
|
741 | 781 | |
|
742 | 782 | .. image:: ../_images/8.0/auto_suggest_second_prompt.png |
|
743 | 783 | |
|
744 | 784 | 2. Start typing the first letter if ``def`` to see the autosuggestion |
|
745 | 785 | |
|
746 | 786 | .. image:: ../_images/8.0/auto_suggest_d_phantom.png |
|
747 | 787 | |
|
748 | 788 | 3. Press ``alt-f`` (or ``escape`` followed by ``f``), to accept the first word of the suggestion |
|
749 | 789 | |
|
750 | 790 | .. image:: ../_images/8.0/auto_suggest_def_phantom.png |
|
751 | 791 | |
|
752 | 792 | Importantly, this feature does not interfere with tab completion: |
|
753 | 793 | |
|
754 | 794 | 1. After running ``def say_hello(): print("hello")``, press d |
|
755 | 795 | |
|
756 | 796 | .. image:: ../_images/8.0/auto_suggest_d_phantom.png |
|
757 | 797 | |
|
758 | 798 | 2. Press Tab to start tab completion |
|
759 | 799 | |
|
760 | 800 | .. image:: ../_images/8.0/auto_suggest_d_completions.png |
|
761 | 801 | |
|
762 | 802 | 3A. Press Tab again to select the first option |
|
763 | 803 | |
|
764 | 804 | .. image:: ../_images/8.0/auto_suggest_def_completions.png |
|
765 | 805 | |
|
766 | 806 | 3B. Press ``alt f`` (``escape``, ``f``) to accept to accept the first word of the suggestion |
|
767 | 807 | |
|
768 | 808 | .. image:: ../_images/8.0/auto_suggest_def_phantom.png |
|
769 | 809 | |
|
770 | 810 | 3C. Press ``ctrl-f`` or ``ctrl-e`` to accept the entire suggestion |
|
771 | 811 | |
|
772 | 812 | .. image:: ../_images/8.0/auto_suggest_match_parens.png |
|
773 | 813 | |
|
774 | 814 | |
|
775 | 815 | Currently, autosuggestions are only shown in the emacs or vi insert editing modes: |
|
776 | 816 | |
|
777 | 817 | - The ctrl e, ctrl f, and alt f shortcuts work by default in emacs mode. |
|
778 | 818 | - To use these shortcuts in vi insert mode, you will have to create `custom keybindings in your config.py <https://github.com/mskar/setup/commit/2892fcee46f9f80ef7788f0749edc99daccc52f4/>`__. |
|
779 | 819 | |
|
780 | 820 | |
|
781 | 821 | Show pinfo information in ipdb using "?" and "??" |
|
782 | 822 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
783 | 823 | |
|
784 | 824 | In IPDB, it is now possible to show the information about an object using "?" |
|
785 | 825 | and "??", in much the same way that it can be done when using the IPython prompt:: |
|
786 | 826 | |
|
787 | 827 | ipdb> partial? |
|
788 | 828 | Init signature: partial(self, /, *args, **kwargs) |
|
789 | 829 | Docstring: |
|
790 | 830 | partial(func, *args, **keywords) - new function with partial application |
|
791 | 831 | of the given arguments and keywords. |
|
792 | 832 | File: ~/.pyenv/versions/3.8.6/lib/python3.8/functools.py |
|
793 | 833 | Type: type |
|
794 | 834 | Subclasses: |
|
795 | 835 | |
|
796 | 836 | Previously, ``pinfo`` or ``pinfo2`` command had to be used for this purpose. |
|
797 | 837 | |
|
798 | 838 | |
|
799 | 839 | Autoreload 3 feature |
|
800 | 840 | ~~~~~~~~~~~~~~~~~~~~ |
|
801 | 841 | |
|
802 | 842 | Example: When an IPython session is run with the 'autoreload' extension loaded, |
|
803 | 843 | you will now have the option '3' to select, which means the following: |
|
804 | 844 | |
|
805 | 845 | 1. replicate all functionality from option 2 |
|
806 | 846 | 2. autoload all new funcs/classes/enums/globals from the module when they are added |
|
807 | 847 | 3. autoload all newly imported funcs/classes/enums/globals from external modules |
|
808 | 848 | |
|
809 | 849 | Try ``%autoreload 3`` in an IPython session after running ``%load_ext autoreload``. |
|
810 | 850 | |
|
811 | 851 | For more information please see the following unit test : ``extensions/tests/test_autoreload.py:test_autoload_newly_added_objects`` |
|
812 | 852 | |
|
813 | 853 | Auto formatting with black in the CLI |
|
814 | 854 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
815 | 855 | |
|
816 | 856 | This feature was present in 7.x, but disabled by default. |
|
817 | 857 | |
|
818 | 858 | In 8.0, input was automatically reformatted with Black when black was installed. |
|
819 | 859 | This feature has been reverted for the time being. |
|
820 | 860 | You can re-enable it by setting ``TerminalInteractiveShell.autoformatter`` to ``"black"`` |
|
821 | 861 | |
|
822 | 862 | History Range Glob feature |
|
823 | 863 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
824 | 864 | |
|
825 | 865 | Previously, when using ``%history``, users could specify either |
|
826 | 866 | a range of sessions and lines, for example: |
|
827 | 867 | |
|
828 | 868 | .. code-block:: python |
|
829 | 869 | |
|
830 | 870 | ~8/1-~6/5 # see history from the first line of 8 sessions ago, |
|
831 | 871 | # to the fifth line of 6 sessions ago.`` |
|
832 | 872 | |
|
833 | 873 | Or users could specify a glob pattern: |
|
834 | 874 | |
|
835 | 875 | .. code-block:: python |
|
836 | 876 | |
|
837 | 877 | -g <pattern> # glob ALL history for the specified pattern. |
|
838 | 878 | |
|
839 | 879 | However users could *not* specify both. |
|
840 | 880 | |
|
841 | 881 | If a user *did* specify both a range and a glob pattern, |
|
842 | 882 | then the glob pattern would be used (globbing *all* history) *and the range would be ignored*. |
|
843 | 883 | |
|
844 | 884 | With this enhancement, if a user specifies both a range and a glob pattern, then the glob pattern will be applied to the specified range of history. |
|
845 | 885 | |
|
846 | 886 | Don't start a multi-line cell with sunken parenthesis |
|
847 | 887 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
848 | 888 | |
|
849 | 889 | From now on, IPython will not ask for the next line of input when given a single |
|
850 | 890 | line with more closing than opening brackets. For example, this means that if |
|
851 | 891 | you (mis)type ``]]`` instead of ``[]``, a ``SyntaxError`` will show up, instead of |
|
852 | 892 | the ``...:`` prompt continuation. |
|
853 | 893 | |
|
854 | 894 | IPython shell for ipdb interact |
|
855 | 895 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
856 | 896 | |
|
857 | 897 | The ipdb ``interact`` starts an IPython shell instead of Python's built-in ``code.interact()``. |
|
858 | 898 | |
|
859 | 899 | Automatic Vi prompt stripping |
|
860 | 900 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
861 | 901 | |
|
862 | 902 | When pasting code into IPython, it will strip the leading prompt characters if |
|
863 | 903 | there are any. For example, you can paste the following code into the console - |
|
864 | 904 | it will still work, even though each line is prefixed with prompts (``In``, |
|
865 | 905 | ``Out``):: |
|
866 | 906 | |
|
867 | 907 | In [1]: 2 * 2 == 4 |
|
868 | 908 | Out[1]: True |
|
869 | 909 | |
|
870 | 910 | In [2]: print("This still works as pasted") |
|
871 | 911 | |
|
872 | 912 | |
|
873 | 913 | Previously, this was not the case for the Vi-mode prompts:: |
|
874 | 914 | |
|
875 | 915 | In [1]: [ins] In [13]: 2 * 2 == 4 |
|
876 | 916 | ...: Out[13]: True |
|
877 | 917 | ...: |
|
878 | 918 | File "<ipython-input-1-727bb88eaf33>", line 1 |
|
879 | 919 | [ins] In [13]: 2 * 2 == 4 |
|
880 | 920 | ^ |
|
881 | 921 | SyntaxError: invalid syntax |
|
882 | 922 | |
|
883 | 923 | This is now fixed, and Vi prompt prefixes - ``[ins]`` and ``[nav]`` - are |
|
884 | 924 | skipped just as the normal ``In`` would be. |
|
885 | 925 | |
|
886 | 926 | IPython shell can be started in the Vi mode using ``ipython --TerminalInteractiveShell.editing_mode=vi``, |
|
887 | 927 | You should be able to change mode dynamically with ``%config TerminalInteractiveShell.editing_mode='vi'`` |
|
888 | 928 | |
|
889 | 929 | Empty History Ranges |
|
890 | 930 | ~~~~~~~~~~~~~~~~~~~~ |
|
891 | 931 | |
|
892 | 932 | A number of magics that take history ranges can now be used with an empty |
|
893 | 933 | range. These magics are: |
|
894 | 934 | |
|
895 | 935 | * ``%save`` |
|
896 | 936 | * ``%load`` |
|
897 | 937 | * ``%pastebin`` |
|
898 | 938 | * ``%pycat`` |
|
899 | 939 | |
|
900 | 940 | Using them this way will make them take the history of the current session up |
|
901 | 941 | to the point of the magic call (such that the magic itself will not be |
|
902 | 942 | included). |
|
903 | 943 | |
|
904 | 944 | Therefore it is now possible to save the whole history to a file using |
|
905 | 945 | ``%save <filename>``, load and edit it using ``%load`` (makes for a nice usage |
|
906 | 946 | when followed with :kbd:`F2`), send it to `dpaste.org <http://dpast.org>`_ using |
|
907 | 947 | ``%pastebin``, or view the whole thing syntax-highlighted with a single |
|
908 | 948 | ``%pycat``. |
|
909 | 949 | |
|
910 | 950 | |
|
911 | 951 | Windows timing implementation: Switch to process_time |
|
912 | 952 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
913 | 953 | Timing on Windows, for example with ``%%time``, was changed from being based on ``time.perf_counter`` |
|
914 | 954 | (which counted time even when the process was sleeping) to being based on ``time.process_time`` instead |
|
915 | 955 | (which only counts CPU time). This brings it closer to the behavior on Linux. See :ghpull:`12984`. |
|
916 | 956 | |
|
917 | 957 | Miscellaneous |
|
918 | 958 | ~~~~~~~~~~~~~ |
|
919 | 959 | - Non-text formatters are not disabled in the terminal, which should simplify |
|
920 | 960 | writing extensions displaying images or other mimetypes in supporting terminals. |
|
921 | 961 | :ghpull:`12315` |
|
922 | 962 | - It is now possible to automatically insert matching brackets in Terminal IPython using the |
|
923 | 963 | ``TerminalInteractiveShell.auto_match=True`` option. :ghpull:`12586` |
|
924 | 964 | - We are thinking of deprecating the current ``%%javascript`` magic in favor of a better replacement. See :ghpull:`13376`. |
|
925 | 965 | - ``~`` is now expanded when part of a path in most magics :ghpull:`13385` |
|
926 | 966 | - ``%/%%timeit`` magic now adds a comma every thousands to make reading a long number easier :ghpull:`13379` |
|
927 | 967 | - ``"info"`` messages can now be customised to hide some fields :ghpull:`13343` |
|
928 | 968 | - ``collections.UserList`` now pretty-prints :ghpull:`13320` |
|
929 | 969 | - The debugger now has a persistent history, which should make it less |
|
930 | 970 | annoying to retype commands :ghpull:`13246` |
|
931 | 971 | - ``!pip`` ``!conda`` ``!cd`` or ``!ls`` are likely doing the wrong thing. We |
|
932 | 972 | now warn users if they use one of those commands. :ghpull:`12954` |
|
933 | 973 | - Make ``%precision`` work for ``numpy.float64`` type :ghpull:`12902` |
|
934 | 974 | |
|
935 | 975 | Re-added support for XDG config directories |
|
936 | 976 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
937 | 977 | |
|
938 | 978 | XDG support through the years comes and goes. There is a tension between having |
|
939 | 979 | an identical location for configuration in all platforms versus having simple instructions. |
|
940 | 980 | After initial failures a couple of years ago, IPython was modified to automatically migrate XDG |
|
941 | 981 | config files back into ``~/.ipython``. That migration code has now been removed. |
|
942 | 982 | IPython now checks the XDG locations, so if you _manually_ move your config |
|
943 | 983 | files to your preferred location, IPython will not move them back. |
|
944 | 984 | |
|
945 | 985 | |
|
946 | 986 | Preparing for Python 3.10 |
|
947 | 987 | ------------------------- |
|
948 | 988 | |
|
949 | 989 | To prepare for Python 3.10, we have started working on removing reliance and |
|
950 | 990 | any dependency that is not compatible with Python 3.10. This includes migrating our |
|
951 | 991 | test suite to pytest and starting to remove nose. This also means that the |
|
952 | 992 | ``iptest`` command is now gone and all testing is via pytest. |
|
953 | 993 | |
|
954 | 994 | This was in large part thanks to the NumFOCUS Small Developer grant, which enabled us to |
|
955 | 995 | allocate \$4000 to hire `Nikita Kniazev (@Kojoley) <https://github.com/Kojoley>`_, |
|
956 | 996 | who did a fantastic job at updating our code base, migrating to pytest, pushing |
|
957 | 997 | our coverage, and fixing a large number of bugs. I highly recommend contacting |
|
958 | 998 | them if you need help with C++ and Python projects. |
|
959 | 999 | |
|
960 | 1000 | You can find all relevant issues and PRs with `the SDG 2021 tag <https://github.com/ipython/ipython/issues?q=label%3A%22Numfocus+SDG+2021%22+>`__ |
|
961 | 1001 | |
|
962 | 1002 | Removing support for older Python versions |
|
963 | 1003 | ------------------------------------------ |
|
964 | 1004 | |
|
965 | 1005 | |
|
966 | 1006 | We are removing support for Python up through 3.7, allowing internal code to use the more |
|
967 | 1007 | efficient ``pathlib`` and to make better use of type annotations. |
|
968 | 1008 | |
|
969 | 1009 | .. image:: ../_images/8.0/pathlib_pathlib_everywhere.jpg |
|
970 | 1010 | :alt: "Meme image of Toy Story with Woody and Buzz, with the text 'pathlib, pathlib everywhere'" |
|
971 | 1011 | |
|
972 | 1012 | |
|
973 | 1013 | We had about 34 PRs only to update some logic to update some functions from managing strings to |
|
974 | 1014 | using Pathlib. |
|
975 | 1015 | |
|
976 | 1016 | The completer has also seen significant updates and now makes use of newer Jedi APIs, |
|
977 | 1017 | offering faster and more reliable tab completion. |
|
978 | 1018 | |
|
979 | 1019 | Misc Statistics |
|
980 | 1020 | --------------- |
|
981 | 1021 | |
|
982 | 1022 | Here are some numbers:: |
|
983 | 1023 | |
|
984 | 1024 | 7.x: 296 files, 12561 blank lines, 20282 comments, 35142 line of code. |
|
985 | 1025 | 8.0: 252 files, 12053 blank lines, 19232 comments, 34505 line of code. |
|
986 | 1026 | |
|
987 | 1027 | $ git diff --stat 7.x...master | tail -1 |
|
988 | 1028 | 340 files changed, 13399 insertions(+), 12421 deletions(-) |
|
989 | 1029 | |
|
990 | 1030 | We have commits from 162 authors, who contributed 1916 commits in 23 month, excluding merges (to not bias toward |
|
991 | 1031 | maintainers pushing buttons).:: |
|
992 | 1032 | |
|
993 | 1033 | $ git shortlog -s --no-merges 7.x...master | sort -nr |
|
994 | 1034 | 535 Matthias Bussonnier |
|
995 | 1035 | 86 Nikita Kniazev |
|
996 | 1036 | 69 Blazej Michalik |
|
997 | 1037 | 49 Samuel Gaist |
|
998 | 1038 | 27 Itamar Turner-Trauring |
|
999 | 1039 | 18 Spas Kalaydzhisyki |
|
1000 | 1040 | 17 Thomas Kluyver |
|
1001 | 1041 | 17 Quentin Peter |
|
1002 | 1042 | 17 James Morris |
|
1003 | 1043 | 17 Artur Svistunov |
|
1004 | 1044 | 15 Bart Skowron |
|
1005 | 1045 | 14 Alex Hall |
|
1006 | 1046 | 13 rushabh-v |
|
1007 | 1047 | 13 Terry Davis |
|
1008 | 1048 | 13 Benjamin Ragan-Kelley |
|
1009 | 1049 | 8 martinRenou |
|
1010 | 1050 | 8 farisachugthai |
|
1011 | 1051 | 7 dswij |
|
1012 | 1052 | 7 Gal B |
|
1013 | 1053 | 7 Corentin Cadiou |
|
1014 | 1054 | 6 yuji96 |
|
1015 | 1055 | 6 Martin Skarzynski |
|
1016 | 1056 | 6 Justin Palmer |
|
1017 | 1057 | 6 Daniel Goldfarb |
|
1018 | 1058 | 6 Ben Greiner |
|
1019 | 1059 | 5 Sammy Al Hashemi |
|
1020 | 1060 | 5 Paul Ivanov |
|
1021 | 1061 | 5 Inception95 |
|
1022 | 1062 | 5 Eyenpi |
|
1023 | 1063 | 5 Douglas Blank |
|
1024 | 1064 | 5 Coco Mishra |
|
1025 | 1065 | 5 Bibo Hao |
|
1026 | 1066 | 5 AndrΓ© A. Gomes |
|
1027 | 1067 | 5 Ahmed Fasih |
|
1028 | 1068 | 4 takuya fujiwara |
|
1029 | 1069 | 4 palewire |
|
1030 | 1070 | 4 Thomas A Caswell |
|
1031 | 1071 | 4 Talley Lambert |
|
1032 | 1072 | 4 Scott Sanderson |
|
1033 | 1073 | 4 Ram Rachum |
|
1034 | 1074 | 4 Nick Muoh |
|
1035 | 1075 | 4 Nathan Goldbaum |
|
1036 | 1076 | 4 Mithil Poojary |
|
1037 | 1077 | 4 Michael T |
|
1038 | 1078 | 4 Jakub Klus |
|
1039 | 1079 | 4 Ian Castleden |
|
1040 | 1080 | 4 Eli Rykoff |
|
1041 | 1081 | 4 Ashwin Vishnu |
|
1042 | 1082 | 3 θ°δΉιΌ |
|
1043 | 1083 | 3 sleeping |
|
1044 | 1084 | 3 Sylvain Corlay |
|
1045 | 1085 | 3 Peter Corke |
|
1046 | 1086 | 3 Paul Bissex |
|
1047 | 1087 | 3 Matthew Feickert |
|
1048 | 1088 | 3 Fernando Perez |
|
1049 | 1089 | 3 Eric Wieser |
|
1050 | 1090 | 3 Daniel Mietchen |
|
1051 | 1091 | 3 Aditya Sathe |
|
1052 | 1092 | 3 007vedant |
|
1053 | 1093 | 2 rchiodo |
|
1054 | 1094 | 2 nicolaslazo |
|
1055 | 1095 | 2 luttik |
|
1056 | 1096 | 2 gorogoroumaru |
|
1057 | 1097 | 2 foobarbyte |
|
1058 | 1098 | 2 bar-hen |
|
1059 | 1099 | 2 Theo Ouzhinski |
|
1060 | 1100 | 2 Strawkage |
|
1061 | 1101 | 2 Samreen Zarroug |
|
1062 | 1102 | 2 Pete Blois |
|
1063 | 1103 | 2 Meysam Azad |
|
1064 | 1104 | 2 Matthieu Ancellin |
|
1065 | 1105 | 2 Mark Schmitz |
|
1066 | 1106 | 2 Maor Kleinberger |
|
1067 | 1107 | 2 MRCWirtz |
|
1068 | 1108 | 2 Lumir Balhar |
|
1069 | 1109 | 2 Julien Rabinow |
|
1070 | 1110 | 2 Juan Luis Cano RodrΓguez |
|
1071 | 1111 | 2 Joyce Er |
|
1072 | 1112 | 2 Jakub |
|
1073 | 1113 | 2 Faris A Chugthai |
|
1074 | 1114 | 2 Ethan Madden |
|
1075 | 1115 | 2 Dimitri Papadopoulos |
|
1076 | 1116 | 2 Diego Fernandez |
|
1077 | 1117 | 2 Daniel Shimon |
|
1078 | 1118 | 2 Coco Bennett |
|
1079 | 1119 | 2 Carlos Cordoba |
|
1080 | 1120 | 2 Boyuan Liu |
|
1081 | 1121 | 2 BaoGiang HoangVu |
|
1082 | 1122 | 2 Augusto |
|
1083 | 1123 | 2 Arthur Svistunov |
|
1084 | 1124 | 2 Arthur Moreira |
|
1085 | 1125 | 2 Ali Nabipour |
|
1086 | 1126 | 2 Adam Hackbarth |
|
1087 | 1127 | 1 richard |
|
1088 | 1128 | 1 linar-jether |
|
1089 | 1129 | 1 lbennett |
|
1090 | 1130 | 1 juacrumar |
|
1091 | 1131 | 1 gpotter2 |
|
1092 | 1132 | 1 digitalvirtuoso |
|
1093 | 1133 | 1 dalthviz |
|
1094 | 1134 | 1 Yonatan Goldschmidt |
|
1095 | 1135 | 1 Tomasz KΕoczko |
|
1096 | 1136 | 1 Tobias Bengfort |
|
1097 | 1137 | 1 Timur Kushukov |
|
1098 | 1138 | 1 Thomas |
|
1099 | 1139 | 1 Snir Broshi |
|
1100 | 1140 | 1 Shao Yang Hong |
|
1101 | 1141 | 1 Sanjana-03 |
|
1102 | 1142 | 1 Romulo Filho |
|
1103 | 1143 | 1 Rodolfo Carvalho |
|
1104 | 1144 | 1 Richard Shadrach |
|
1105 | 1145 | 1 Reilly Tucker Siemens |
|
1106 | 1146 | 1 Rakessh Roshan |
|
1107 | 1147 | 1 Piers Titus van der Torren |
|
1108 | 1148 | 1 PhanatosZou |
|
1109 | 1149 | 1 Pavel Safronov |
|
1110 | 1150 | 1 Paulo S. Costa |
|
1111 | 1151 | 1 Paul McCarthy |
|
1112 | 1152 | 1 NotWearingPants |
|
1113 | 1153 | 1 Naelson Douglas |
|
1114 | 1154 | 1 Michael Tiemann |
|
1115 | 1155 | 1 Matt Wozniski |
|
1116 | 1156 | 1 Markus Wageringel |
|
1117 | 1157 | 1 Marcus Wirtz |
|
1118 | 1158 | 1 Marcio Mazza |
|
1119 | 1159 | 1 LumΓr 'Frenzy' Balhar |
|
1120 | 1160 | 1 Lightyagami1 |
|
1121 | 1161 | 1 Leon Anavi |
|
1122 | 1162 | 1 LeafyLi |
|
1123 | 1163 | 1 L0uisJ0shua |
|
1124 | 1164 | 1 Kyle Cutler |
|
1125 | 1165 | 1 Krzysztof Cybulski |
|
1126 | 1166 | 1 Kevin Kirsche |
|
1127 | 1167 | 1 KIU Shueng Chuan |
|
1128 | 1168 | 1 Jonathan Slenders |
|
1129 | 1169 | 1 Jay Qi |
|
1130 | 1170 | 1 Jake VanderPlas |
|
1131 | 1171 | 1 Iwan Briquemont |
|
1132 | 1172 | 1 Hussaina Begum Nandyala |
|
1133 | 1173 | 1 Gordon Ball |
|
1134 | 1174 | 1 Gabriel Simonetto |
|
1135 | 1175 | 1 Frank Tobia |
|
1136 | 1176 | 1 Erik |
|
1137 | 1177 | 1 Elliott Sales de Andrade |
|
1138 | 1178 | 1 Daniel Hahler |
|
1139 | 1179 | 1 Dan Green-Leipciger |
|
1140 | 1180 | 1 Dan Green |
|
1141 | 1181 | 1 Damian Yurzola |
|
1142 | 1182 | 1 Coon, Ethan T |
|
1143 | 1183 | 1 Carol Willing |
|
1144 | 1184 | 1 Brian Lee |
|
1145 | 1185 | 1 Brendan Gerrity |
|
1146 | 1186 | 1 Blake Griffin |
|
1147 | 1187 | 1 Bastian Ebeling |
|
1148 | 1188 | 1 Bartosz Telenczuk |
|
1149 | 1189 | 1 Ankitsingh6299 |
|
1150 | 1190 | 1 Andrew Port |
|
1151 | 1191 | 1 Andrew J. Hesford |
|
1152 | 1192 | 1 Albert Zhang |
|
1153 | 1193 | 1 Adam Johnson |
|
1154 | 1194 | |
|
1155 | 1195 | This does not, of course, represent non-code contributions, for which we are also grateful. |
|
1156 | 1196 | |
|
1157 | 1197 | |
|
1158 | 1198 | API Changes using Frappuccino |
|
1159 | 1199 | ----------------------------- |
|
1160 | 1200 | |
|
1161 | 1201 | This is an experimental exhaustive API difference using `Frappuccino <https://pypi.org/project/frappuccino/>`_ |
|
1162 | 1202 | |
|
1163 | 1203 | |
|
1164 | 1204 | The following items are new in IPython 8.0 :: |
|
1165 | 1205 | |
|
1166 | 1206 | + IPython.core.async_helpers.get_asyncio_loop() |
|
1167 | 1207 | + IPython.core.completer.Dict |
|
1168 | 1208 | + IPython.core.completer.Pattern |
|
1169 | 1209 | + IPython.core.completer.Sequence |
|
1170 | 1210 | + IPython.core.completer.__skip_doctest__ |
|
1171 | 1211 | + IPython.core.debugger.Pdb.precmd(self, line) |
|
1172 | 1212 | + IPython.core.debugger.__skip_doctest__ |
|
1173 | 1213 | + IPython.core.display.__getattr__(name) |
|
1174 | 1214 | + IPython.core.display.warn |
|
1175 | 1215 | + IPython.core.display_functions |
|
1176 | 1216 | + IPython.core.display_functions.DisplayHandle |
|
1177 | 1217 | + IPython.core.display_functions.DisplayHandle.display(self, obj, **kwargs) |
|
1178 | 1218 | + IPython.core.display_functions.DisplayHandle.update(self, obj, **kwargs) |
|
1179 | 1219 | + IPython.core.display_functions.__all__ |
|
1180 | 1220 | + IPython.core.display_functions.__builtins__ |
|
1181 | 1221 | + IPython.core.display_functions.__cached__ |
|
1182 | 1222 | + IPython.core.display_functions.__doc__ |
|
1183 | 1223 | + IPython.core.display_functions.__file__ |
|
1184 | 1224 | + IPython.core.display_functions.__loader__ |
|
1185 | 1225 | + IPython.core.display_functions.__name__ |
|
1186 | 1226 | + IPython.core.display_functions.__package__ |
|
1187 | 1227 | + IPython.core.display_functions.__spec__ |
|
1188 | 1228 | + IPython.core.display_functions.b2a_hex |
|
1189 | 1229 | + IPython.core.display_functions.clear_output(wait=False) |
|
1190 | 1230 | + IPython.core.display_functions.display(*objs, include='None', exclude='None', metadata='None', transient='None', display_id='None', raw=False, clear=False, **kwargs) |
|
1191 | 1231 | + IPython.core.display_functions.publish_display_data(data, metadata='None', source='<deprecated>', *, transient='None', **kwargs) |
|
1192 | 1232 | + IPython.core.display_functions.update_display(obj, *, display_id, **kwargs) |
|
1193 | 1233 | + IPython.core.extensions.BUILTINS_EXTS |
|
1194 | 1234 | + IPython.core.inputtransformer2.has_sunken_brackets(tokens) |
|
1195 | 1235 | + IPython.core.interactiveshell.Callable |
|
1196 | 1236 | + IPython.core.interactiveshell.__annotations__ |
|
1197 | 1237 | + IPython.core.ultratb.List |
|
1198 | 1238 | + IPython.core.ultratb.Tuple |
|
1199 | 1239 | + IPython.lib.pretty.CallExpression |
|
1200 | 1240 | + IPython.lib.pretty.CallExpression.factory(name) |
|
1201 | 1241 | + IPython.lib.pretty.RawStringLiteral |
|
1202 | 1242 | + IPython.lib.pretty.RawText |
|
1203 | 1243 | + IPython.terminal.debugger.TerminalPdb.do_interact(self, arg) |
|
1204 | 1244 | + IPython.terminal.embed.Set |
|
1205 | 1245 | |
|
1206 | 1246 | The following items have been removed (or moved to superclass):: |
|
1207 | 1247 | |
|
1208 | 1248 | - IPython.core.application.BaseIPythonApplication.initialize_subcommand |
|
1209 | 1249 | - IPython.core.completer.Sentinel |
|
1210 | 1250 | - IPython.core.completer.skip_doctest |
|
1211 | 1251 | - IPython.core.debugger.Tracer |
|
1212 | 1252 | - IPython.core.display.DisplayHandle |
|
1213 | 1253 | - IPython.core.display.DisplayHandle.display |
|
1214 | 1254 | - IPython.core.display.DisplayHandle.update |
|
1215 | 1255 | - IPython.core.display.b2a_hex |
|
1216 | 1256 | - IPython.core.display.clear_output |
|
1217 | 1257 | - IPython.core.display.display |
|
1218 | 1258 | - IPython.core.display.publish_display_data |
|
1219 | 1259 | - IPython.core.display.update_display |
|
1220 | 1260 | - IPython.core.excolors.Deprec |
|
1221 | 1261 | - IPython.core.excolors.ExceptionColors |
|
1222 | 1262 | - IPython.core.history.warn |
|
1223 | 1263 | - IPython.core.hooks.late_startup_hook |
|
1224 | 1264 | - IPython.core.hooks.pre_run_code_hook |
|
1225 | 1265 | - IPython.core.hooks.shutdown_hook |
|
1226 | 1266 | - IPython.core.interactiveshell.InteractiveShell.init_deprecation_warnings |
|
1227 | 1267 | - IPython.core.interactiveshell.InteractiveShell.init_readline |
|
1228 | 1268 | - IPython.core.interactiveshell.InteractiveShell.write |
|
1229 | 1269 | - IPython.core.interactiveshell.InteractiveShell.write_err |
|
1230 | 1270 | - IPython.core.interactiveshell.get_default_colors |
|
1231 | 1271 | - IPython.core.interactiveshell.removed_co_newlocals |
|
1232 | 1272 | - IPython.core.magics.execution.ExecutionMagics.profile_missing_notice |
|
1233 | 1273 | - IPython.core.magics.script.PIPE |
|
1234 | 1274 | - IPython.core.prefilter.PrefilterManager.init_transformers |
|
1235 | 1275 | - IPython.core.release.classifiers |
|
1236 | 1276 | - IPython.core.release.description |
|
1237 | 1277 | - IPython.core.release.keywords |
|
1238 | 1278 | - IPython.core.release.long_description |
|
1239 | 1279 | - IPython.core.release.name |
|
1240 | 1280 | - IPython.core.release.platforms |
|
1241 | 1281 | - IPython.core.release.url |
|
1242 | 1282 | - IPython.core.ultratb.VerboseTB.format_records |
|
1243 | 1283 | - IPython.core.ultratb.find_recursion |
|
1244 | 1284 | - IPython.core.ultratb.findsource |
|
1245 | 1285 | - IPython.core.ultratb.fix_frame_records_filenames |
|
1246 | 1286 | - IPython.core.ultratb.inspect_error |
|
1247 | 1287 | - IPython.core.ultratb.is_recursion_error |
|
1248 | 1288 | - IPython.core.ultratb.with_patch_inspect |
|
1249 | 1289 | - IPython.external.__all__ |
|
1250 | 1290 | - IPython.external.__builtins__ |
|
1251 | 1291 | - IPython.external.__cached__ |
|
1252 | 1292 | - IPython.external.__doc__ |
|
1253 | 1293 | - IPython.external.__file__ |
|
1254 | 1294 | - IPython.external.__loader__ |
|
1255 | 1295 | - IPython.external.__name__ |
|
1256 | 1296 | - IPython.external.__package__ |
|
1257 | 1297 | - IPython.external.__path__ |
|
1258 | 1298 | - IPython.external.__spec__ |
|
1259 | 1299 | - IPython.kernel.KernelConnectionInfo |
|
1260 | 1300 | - IPython.kernel.__builtins__ |
|
1261 | 1301 | - IPython.kernel.__cached__ |
|
1262 | 1302 | - IPython.kernel.__warningregistry__ |
|
1263 | 1303 | - IPython.kernel.pkg |
|
1264 | 1304 | - IPython.kernel.protocol_version |
|
1265 | 1305 | - IPython.kernel.protocol_version_info |
|
1266 | 1306 | - IPython.kernel.src |
|
1267 | 1307 | - IPython.kernel.version_info |
|
1268 | 1308 | - IPython.kernel.warn |
|
1269 | 1309 | - IPython.lib.backgroundjobs |
|
1270 | 1310 | - IPython.lib.backgroundjobs.BackgroundJobBase |
|
1271 | 1311 | - IPython.lib.backgroundjobs.BackgroundJobBase.run |
|
1272 | 1312 | - IPython.lib.backgroundjobs.BackgroundJobBase.traceback |
|
1273 | 1313 | - IPython.lib.backgroundjobs.BackgroundJobExpr |
|
1274 | 1314 | - IPython.lib.backgroundjobs.BackgroundJobExpr.call |
|
1275 | 1315 | - IPython.lib.backgroundjobs.BackgroundJobFunc |
|
1276 | 1316 | - IPython.lib.backgroundjobs.BackgroundJobFunc.call |
|
1277 | 1317 | - IPython.lib.backgroundjobs.BackgroundJobManager |
|
1278 | 1318 | - IPython.lib.backgroundjobs.BackgroundJobManager.flush |
|
1279 | 1319 | - IPython.lib.backgroundjobs.BackgroundJobManager.new |
|
1280 | 1320 | - IPython.lib.backgroundjobs.BackgroundJobManager.remove |
|
1281 | 1321 | - IPython.lib.backgroundjobs.BackgroundJobManager.result |
|
1282 | 1322 | - IPython.lib.backgroundjobs.BackgroundJobManager.status |
|
1283 | 1323 | - IPython.lib.backgroundjobs.BackgroundJobManager.traceback |
|
1284 | 1324 | - IPython.lib.backgroundjobs.__builtins__ |
|
1285 | 1325 | - IPython.lib.backgroundjobs.__cached__ |
|
1286 | 1326 | - IPython.lib.backgroundjobs.__doc__ |
|
1287 | 1327 | - IPython.lib.backgroundjobs.__file__ |
|
1288 | 1328 | - IPython.lib.backgroundjobs.__loader__ |
|
1289 | 1329 | - IPython.lib.backgroundjobs.__name__ |
|
1290 | 1330 | - IPython.lib.backgroundjobs.__package__ |
|
1291 | 1331 | - IPython.lib.backgroundjobs.__spec__ |
|
1292 | 1332 | - IPython.lib.kernel.__builtins__ |
|
1293 | 1333 | - IPython.lib.kernel.__cached__ |
|
1294 | 1334 | - IPython.lib.kernel.__doc__ |
|
1295 | 1335 | - IPython.lib.kernel.__file__ |
|
1296 | 1336 | - IPython.lib.kernel.__loader__ |
|
1297 | 1337 | - IPython.lib.kernel.__name__ |
|
1298 | 1338 | - IPython.lib.kernel.__package__ |
|
1299 | 1339 | - IPython.lib.kernel.__spec__ |
|
1300 | 1340 | - IPython.lib.kernel.__warningregistry__ |
|
1301 | 1341 | - IPython.paths.fs_encoding |
|
1302 | 1342 | - IPython.terminal.debugger.DEFAULT_BUFFER |
|
1303 | 1343 | - IPython.terminal.debugger.cursor_in_leading_ws |
|
1304 | 1344 | - IPython.terminal.debugger.emacs_insert_mode |
|
1305 | 1345 | - IPython.terminal.debugger.has_selection |
|
1306 | 1346 | - IPython.terminal.debugger.vi_insert_mode |
|
1307 | 1347 | - IPython.terminal.interactiveshell.DISPLAY_BANNER_DEPRECATED |
|
1308 | 1348 | - IPython.terminal.ipapp.TerminalIPythonApp.parse_command_line |
|
1309 | 1349 | - IPython.testing.test |
|
1310 | 1350 | - IPython.utils.contexts.NoOpContext |
|
1311 | 1351 | - IPython.utils.io.IOStream |
|
1312 | 1352 | - IPython.utils.io.IOStream.close |
|
1313 | 1353 | - IPython.utils.io.IOStream.write |
|
1314 | 1354 | - IPython.utils.io.IOStream.writelines |
|
1315 | 1355 | - IPython.utils.io.__warningregistry__ |
|
1316 | 1356 | - IPython.utils.io.atomic_writing |
|
1317 | 1357 | - IPython.utils.io.stderr |
|
1318 | 1358 | - IPython.utils.io.stdin |
|
1319 | 1359 | - IPython.utils.io.stdout |
|
1320 | 1360 | - IPython.utils.io.unicode_std_stream |
|
1321 | 1361 | - IPython.utils.path.get_ipython_cache_dir |
|
1322 | 1362 | - IPython.utils.path.get_ipython_dir |
|
1323 | 1363 | - IPython.utils.path.get_ipython_module_path |
|
1324 | 1364 | - IPython.utils.path.get_ipython_package_dir |
|
1325 | 1365 | - IPython.utils.path.locate_profile |
|
1326 | 1366 | - IPython.utils.path.unquote_filename |
|
1327 | 1367 | - IPython.utils.py3compat.PY2 |
|
1328 | 1368 | - IPython.utils.py3compat.PY3 |
|
1329 | 1369 | - IPython.utils.py3compat.buffer_to_bytes |
|
1330 | 1370 | - IPython.utils.py3compat.builtin_mod_name |
|
1331 | 1371 | - IPython.utils.py3compat.cast_bytes |
|
1332 | 1372 | - IPython.utils.py3compat.getcwd |
|
1333 | 1373 | - IPython.utils.py3compat.isidentifier |
|
1334 | 1374 | - IPython.utils.py3compat.u_format |
|
1335 | 1375 | |
|
1336 | 1376 | The following signatures differ between 7.x and 8.0:: |
|
1337 | 1377 | |
|
1338 | 1378 | - IPython.core.completer.IPCompleter.unicode_name_matches(self, text) |
|
1339 | 1379 | + IPython.core.completer.IPCompleter.unicode_name_matches(text) |
|
1340 | 1380 | |
|
1341 | 1381 | - IPython.core.completer.match_dict_keys(keys, prefix, delims) |
|
1342 | 1382 | + IPython.core.completer.match_dict_keys(keys, prefix, delims, extra_prefix='None') |
|
1343 | 1383 | |
|
1344 | 1384 | - IPython.core.interactiveshell.InteractiveShell.object_inspect_mime(self, oname, detail_level=0) |
|
1345 | 1385 | + IPython.core.interactiveshell.InteractiveShell.object_inspect_mime(self, oname, detail_level=0, omit_sections='()') |
|
1346 | 1386 | |
|
1347 | 1387 | - IPython.core.interactiveshell.InteractiveShell.set_hook(self, name, hook, priority=50, str_key='None', re_key='None', _warn_deprecated=True) |
|
1348 | 1388 | + IPython.core.interactiveshell.InteractiveShell.set_hook(self, name, hook, priority=50, str_key='None', re_key='None') |
|
1349 | 1389 | |
|
1350 | 1390 | - IPython.core.oinspect.Inspector.info(self, obj, oname='', formatter='None', info='None', detail_level=0) |
|
1351 | 1391 | + IPython.core.oinspect.Inspector.info(self, obj, oname='', info='None', detail_level=0) |
|
1352 | 1392 | |
|
1353 | 1393 | - IPython.core.oinspect.Inspector.pinfo(self, obj, oname='', formatter='None', info='None', detail_level=0, enable_html_pager=True) |
|
1354 | 1394 | + IPython.core.oinspect.Inspector.pinfo(self, obj, oname='', formatter='None', info='None', detail_level=0, enable_html_pager=True, omit_sections='()') |
|
1355 | 1395 | |
|
1356 | 1396 | - IPython.core.profiledir.ProfileDir.copy_config_file(self, config_file, path='None', overwrite=False) |
|
1357 | 1397 | + IPython.core.profiledir.ProfileDir.copy_config_file(self, config_file, path, overwrite=False) |
|
1358 | 1398 | |
|
1359 | 1399 | - IPython.core.ultratb.VerboseTB.format_record(self, frame, file, lnum, func, lines, index) |
|
1360 | 1400 | + IPython.core.ultratb.VerboseTB.format_record(self, frame_info) |
|
1361 | 1401 | |
|
1362 | 1402 | - IPython.terminal.embed.InteractiveShellEmbed.mainloop(self, local_ns='None', module='None', stack_depth=0, display_banner='None', global_ns='None', compile_flags='None') |
|
1363 | 1403 | + IPython.terminal.embed.InteractiveShellEmbed.mainloop(self, local_ns='None', module='None', stack_depth=0, compile_flags='None') |
|
1364 | 1404 | |
|
1365 | 1405 | - IPython.terminal.embed.embed(**kwargs) |
|
1366 | 1406 | + IPython.terminal.embed.embed(*, header='', compile_flags='None', **kwargs) |
|
1367 | 1407 | |
|
1368 | 1408 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.interact(self, display_banner='<object object at 0xffffff>') |
|
1369 | 1409 | + IPython.terminal.interactiveshell.TerminalInteractiveShell.interact(self) |
|
1370 | 1410 | |
|
1371 | 1411 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.mainloop(self, display_banner='<object object at 0xffffff>') |
|
1372 | 1412 | + IPython.terminal.interactiveshell.TerminalInteractiveShell.mainloop(self) |
|
1373 | 1413 | |
|
1374 | 1414 | - IPython.utils.path.get_py_filename(name, force_win32='None') |
|
1375 | 1415 | + IPython.utils.path.get_py_filename(name) |
|
1376 | 1416 | |
|
1377 | 1417 | The following are new attributes (that might be inherited):: |
|
1378 | 1418 | |
|
1379 | 1419 | + IPython.core.completer.IPCompleter.unicode_names |
|
1380 | 1420 | + IPython.core.debugger.InterruptiblePdb.precmd |
|
1381 | 1421 | + IPython.core.debugger.Pdb.precmd |
|
1382 | 1422 | + IPython.core.ultratb.AutoFormattedTB.has_colors |
|
1383 | 1423 | + IPython.core.ultratb.ColorTB.has_colors |
|
1384 | 1424 | + IPython.core.ultratb.FormattedTB.has_colors |
|
1385 | 1425 | + IPython.core.ultratb.ListTB.has_colors |
|
1386 | 1426 | + IPython.core.ultratb.SyntaxTB.has_colors |
|
1387 | 1427 | + IPython.core.ultratb.TBTools.has_colors |
|
1388 | 1428 | + IPython.core.ultratb.VerboseTB.has_colors |
|
1389 | 1429 | + IPython.terminal.debugger.TerminalPdb.do_interact |
|
1390 | 1430 | + IPython.terminal.debugger.TerminalPdb.precmd |
|
1391 | 1431 | |
|
1392 | 1432 | The following attribute/methods have been removed:: |
|
1393 | 1433 | |
|
1394 | 1434 | - IPython.core.application.BaseIPythonApplication.deprecated_subcommands |
|
1395 | 1435 | - IPython.core.ultratb.AutoFormattedTB.format_records |
|
1396 | 1436 | - IPython.core.ultratb.ColorTB.format_records |
|
1397 | 1437 | - IPython.core.ultratb.FormattedTB.format_records |
|
1398 | 1438 | - IPython.terminal.embed.InteractiveShellEmbed.init_deprecation_warnings |
|
1399 | 1439 | - IPython.terminal.embed.InteractiveShellEmbed.init_readline |
|
1400 | 1440 | - IPython.terminal.embed.InteractiveShellEmbed.write |
|
1401 | 1441 | - IPython.terminal.embed.InteractiveShellEmbed.write_err |
|
1402 | 1442 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.init_deprecation_warnings |
|
1403 | 1443 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.init_readline |
|
1404 | 1444 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.write |
|
1405 | 1445 | - IPython.terminal.interactiveshell.TerminalInteractiveShell.write_err |
|
1406 | 1446 | - IPython.terminal.ipapp.LocateIPythonApp.deprecated_subcommands |
|
1407 | 1447 | - IPython.terminal.ipapp.LocateIPythonApp.initialize_subcommand |
|
1408 | 1448 | - IPython.terminal.ipapp.TerminalIPythonApp.deprecated_subcommands |
|
1409 | 1449 | - IPython.terminal.ipapp.TerminalIPythonApp.initialize_subcommand |
General Comments 0
You need to be logged in to leave comments.
Login now