##// END OF EJS Templates
Fix deactivation of embedded instance....
Matthias Bussonnier -
Show More
@@ -1,324 +1,393 b''
1 1 # encoding: utf-8
2 2 """
3 3 An embedded IPython shell.
4 4 """
5 5 # Copyright (c) IPython Development Team.
6 6 # Distributed under the terms of the Modified BSD License.
7 7
8 8
9 9 import sys
10 10 import warnings
11 11
12 12 from IPython.core import ultratb, compilerop
13 from IPython.core import magic_arguments
13 14 from IPython.core.magic import Magics, magics_class, line_magic
14 15 from IPython.core.interactiveshell import DummyMod, InteractiveShell
15 16 from IPython.terminal.interactiveshell import TerminalInteractiveShell
16 17 from IPython.terminal.ipapp import load_default_config
17 18
18 19 from traitlets import Bool, CBool, Unicode
19 20 from IPython.utils.io import ask_yes_no
20 21
21 22 class KillEmbeded(Exception):pass
22 23
23 24 # This is an additional magic that is exposed in embedded shells.
24 25 @magics_class
25 26 class EmbeddedMagics(Magics):
26 27
27 28 @line_magic
29 @magic_arguments.magic_arguments()
30 @magic_arguments.argument('-i', '--instance', action='store_true',
31 help='Kill instance instead of call location')
32 @magic_arguments.argument('-x', '--exit', action='store_true',
33 help='Also exit the current session')
34 @magic_arguments.argument('-y', '--yes', action='store_true',
35 help='Do not ask confirmation')
28 36 def kill_embedded(self, parameter_s=''):
29 """%kill_embedded : deactivate for good the current embedded IPython.
37 """%kill_embedded : deactivate for good the current embedded IPython
30 38
31 39 This function (after asking for confirmation) sets an internal flag so
32 that an embedded IPython will never activate again. This is useful to
33 permanently disable a shell that is being called inside a loop: once
34 you've figured out what you needed from it, you may then kill it and
35 the program will then continue to run without the interactive shell
36 interfering again.
40 that an embedded IPython will never activate again for the given call
41 location. This is useful to permanently disable a shell that is being
42 called inside a loop: once you've figured out what you needed from it,
43 you may then kill it and the program will then continue to run without
44 the interactive shell interfering again.
45
46
47 Kill Instance Option
48 --------------------
49
50 If for some reasons you need to kill the location where the instance is
51 created and not called, for example if you create a single instance in
52 one place and debug in many locations, you can use the ``--instance``
53 option to kill this specific instance. Like for the ``call location``
54 killing an "instance" should work even if it is recreated within a
55 loop.
56
57 .. note::
58
59 This was the default behavior before IPython 5.2
60
37 61 """
38 62
39 kill = ask_yes_no("Are you sure you want to kill this embedded instance? [y/N] ",'n')
40 if kill:
41 self.shell.embedded_active = False
42 print ("This embedded IPython will not reactivate anymore "
43 "once you exit.")
63 args = magic_arguments.parse_argstring(self.kill_embedded, parameter_s)
64 print(args)
65 if args.instance:
66 # let no ask
67 if not args.yes:
68 kill = ask_yes_no(
69 "Are you sure you want to kill this embedded instance? [y/N] ", 'n')
70 else:
71 kill = True
72 if kill:
73 self.shell._disable_init_location()
74 print("This embedded IPython instance will not reactivate anymore "
75 "once you exit.")
76 else:
77 if not args.yes:
78 kill = ask_yes_no(
79 "Are you sure you want to kill this embedded call_location? [y/N] ", 'n')
80 else:
81 kill = True
82 if kill:
83 self.shell.embedded_active = False
84 print("This embedded IPython call location will not reactivate anymore "
85 "once you exit.")
86
87 if args.exit:
88 # Ask-exit does not really ask, it just set internals flags to exit
89 # on next loop.
90 self.shell.ask_exit()
44 91
45 92
46 93 @line_magic
47 94 def exit_raise(self, parameter_s=''):
48 95 """%exit_raise Make the current embedded kernel exit and raise and exception.
49 96
50 97 This function sets an internal flag so that an embedded IPython will
51 98 raise a `IPython.terminal.embed.KillEmbeded` Exception on exit, and then exit the current I. This is
52 99 useful to permanently exit a loop that create IPython embed instance.
53 100 """
54 101
55 102 self.shell.should_raise = True
56 103 self.shell.ask_exit()
57 104
58 105
59 106
60 107 class InteractiveShellEmbed(TerminalInteractiveShell):
61 108
62 109 dummy_mode = Bool(False)
63 110 exit_msg = Unicode('')
64 111 embedded = CBool(True)
65 112 should_raise = CBool(False)
66 113 # Like the base class display_banner is not configurable, but here it
67 114 # is True by default.
68 115 display_banner = CBool(True)
69 116 exit_msg = Unicode()
70 117
71 118 # When embedding, by default we don't change the terminal title
72 119 term_title = Bool(False,
73 120 help="Automatically set the terminal title"
74 121 ).tag(config=True)
75 122
76 123 _inactive_locations = set()
77 124
78 125 @property
79 126 def embedded_active(self):
80 return self._call_location_id not in InteractiveShellEmbed._inactive_locations
127 return (self._call_location_id not in InteractiveShellEmbed._inactive_locations)\
128 and (self._init_location_id not in InteractiveShellEmbed._inactive_locations)
129
130 def _disable_init_location(self):
131 """Disable the current Instance creation location"""
132 InteractiveShellEmbed._inactive_locations.add(self._init_location_id)
81 133
82 134 @embedded_active.setter
83 135 def embedded_active(self, value):
84 if value :
85 if self._call_location_id in InteractiveShellEmbed._inactive_locations:
86 InteractiveShellEmbed._inactive_locations.remove(self._call_location_id)
136 if value:
137 InteractiveShellEmbed._inactive_locations.discard(
138 self._call_location_id)
139 InteractiveShellEmbed._inactive_locations.discard(
140 self._init_location_id)
87 141 else:
88 InteractiveShellEmbed._inactive_locations.add(self._call_location_id)
142 InteractiveShellEmbed._inactive_locations.add(
143 self._call_location_id)
89 144
90 145 def __init__(self, **kw):
91
92
93 146 if kw.get('user_global_ns', None) is not None:
94 raise DeprecationWarning("Key word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.")
147 raise DeprecationWarning(
148 "Key word argument `user_global_ns` has been replaced by `user_module` since IPython 4.0.")
95 149
96 self._call_location_id = kw.pop('_call_location_id', None)
150 clid = kw.pop('_init_location_id', None)
151 if not clid:
152 frame = sys._getframe(1)
153 clid = '%s:%s' % (frame.f_code.co_filename, frame.f_lineno)
154 self._init_location_id = clid
97 155
98 156 super(InteractiveShellEmbed,self).__init__(**kw)
99 157
100 if not self._call_location_id:
101 frame = sys._getframe(1)
102 self._call_location_id = '%s:%s' % (frame.f_code.co_filename, frame.f_lineno)
103 158 # don't use the ipython crash handler so that user exceptions aren't
104 159 # trapped
105 160 sys.excepthook = ultratb.FormattedTB(color_scheme=self.colors,
106 161 mode=self.xmode,
107 162 call_pdb=self.pdb)
108 163
109 164 def init_sys_modules(self):
165 """
166 Explicitly overwrite :any:`IPython.core.interactiveshell` to do nothing.
167 """
110 168 pass
111 169
112 170 def init_magics(self):
113 171 super(InteractiveShellEmbed, self).init_magics()
114 172 self.register_magics(EmbeddedMagics)
115 173
116 174 def __call__(self, header='', local_ns=None, module=None, dummy=None,
117 stack_depth=1, global_ns=None, compile_flags=None):
175 stack_depth=1, global_ns=None, compile_flags=None, **kw):
118 176 """Activate the interactive interpreter.
119 177
120 178 __call__(self,header='',local_ns=None,module=None,dummy=None) -> Start
121 179 the interpreter shell with the given local and global namespaces, and
122 180 optionally print a header string at startup.
123 181
124 182 The shell can be globally activated/deactivated using the
125 183 dummy_mode attribute. This allows you to turn off a shell used
126 184 for debugging globally.
127 185
128 186 However, *each* time you call the shell you can override the current
129 187 state of dummy_mode with the optional keyword parameter 'dummy'. For
130 188 example, if you set dummy mode on with IPShell.dummy_mode = True, you
131 189 can still have a specific call work by making it as IPShell(dummy=False).
132 190 """
133 191
192 # we are called, set the underlying interactiveshell not to exit.
193 self.keep_running = True
194
134 195 # If the user has turned it off, go away
196 clid = kw.pop('_call_location_id', None)
197 if not clid:
198 frame = sys._getframe(1)
199 clid = '%s:%s' % (frame.f_code.co_filename, frame.f_lineno)
200 self._call_location_id = clid
201
135 202 if not self.embedded_active:
136 203 return
137 204
138 205 # Normal exits from interactive mode set this flag, so the shell can't
139 206 # re-enter (it checks this variable at the start of interactive mode).
140 207 self.exit_now = False
141 208
142 209 # Allow the dummy parameter to override the global __dummy_mode
143 210 if dummy or (dummy != 0 and self.dummy_mode):
144 211 return
145 212
146 213 # self.banner is auto computed
147 214 if header:
148 215 self.old_banner2 = self.banner2
149 216 self.banner2 = self.banner2 + '\n' + header + '\n'
150 217 else:
151 218 self.old_banner2 = ''
152 219
153 220 if self.display_banner:
154 221 self.show_banner()
155 222
156 223 # Call the embedding code with a stack depth of 1 so it can skip over
157 224 # our call and get the original caller's namespaces.
158 225 self.mainloop(local_ns, module, stack_depth=stack_depth,
159 226 global_ns=global_ns, compile_flags=compile_flags)
160 227
161 228 self.banner2 = self.old_banner2
162 229
163 230 if self.exit_msg is not None:
164 231 print(self.exit_msg)
165 232
166 233 if self.should_raise:
167 234 raise KillEmbeded('Embedded IPython raising error, as user requested.')
168 235
169 236
170 237 def mainloop(self, local_ns=None, module=None, stack_depth=0,
171 238 display_banner=None, global_ns=None, compile_flags=None):
172 239 """Embeds IPython into a running python program.
173 240
174 241 Parameters
175 242 ----------
176 243
177 244 local_ns, module
178 245 Working local namespace (a dict) and module (a module or similar
179 246 object). If given as None, they are automatically taken from the scope
180 247 where the shell was called, so that program variables become visible.
181 248
182 249 stack_depth : int
183 250 How many levels in the stack to go to looking for namespaces (when
184 251 local_ns or module is None). This allows an intermediate caller to
185 252 make sure that this function gets the namespace from the intended
186 253 level in the stack. By default (0) it will get its locals and globals
187 254 from the immediate caller.
188 255
189 256 compile_flags
190 257 A bit field identifying the __future__ features
191 258 that are enabled, as passed to the builtin :func:`compile` function.
192 259 If given as None, they are automatically taken from the scope where
193 260 the shell was called.
194 261
195 262 """
196 263
197 264 if (global_ns is not None) and (module is None):
198 265 raise DeprecationWarning("'global_ns' keyword argument is deprecated, and has been removed in IPython 5.0 use `module` keyword argument instead.")
199 266
200 267 if (display_banner is not None):
201 268 warnings.warn("The display_banner parameter is deprecated since IPython 4.0", DeprecationWarning)
202 269
203 270 # Get locals and globals from caller
204 271 if ((local_ns is None or module is None or compile_flags is None)
205 272 and self.default_user_namespaces):
206 273 call_frame = sys._getframe(stack_depth).f_back
207 274
208 275 if local_ns is None:
209 276 local_ns = call_frame.f_locals
210 277 if module is None:
211 278 global_ns = call_frame.f_globals
212 279 try:
213 280 module = sys.modules[global_ns['__name__']]
214 281 except KeyError:
215 282 warnings.warn("Failed to get module %s" % \
216 283 global_ns.get('__name__', 'unknown module')
217 284 )
218 285 module = DummyMod()
219 286 module.__dict__ = global_ns
220 287 if compile_flags is None:
221 288 compile_flags = (call_frame.f_code.co_flags &
222 289 compilerop.PyCF_MASK)
223 290
224 291 # Save original namespace and module so we can restore them after
225 292 # embedding; otherwise the shell doesn't shut down correctly.
226 293 orig_user_module = self.user_module
227 294 orig_user_ns = self.user_ns
228 295 orig_compile_flags = self.compile.flags
229 296
230 297 # Update namespaces and fire up interpreter
231 298
232 299 # The global one is easy, we can just throw it in
233 300 if module is not None:
234 301 self.user_module = module
235 302
236 303 # But the user/local one is tricky: ipython needs it to store internal
237 304 # data, but we also need the locals. We'll throw our hidden variables
238 305 # like _ih and get_ipython() into the local namespace, but delete them
239 306 # later.
240 307 if local_ns is not None:
241 308 reentrant_local_ns = {k: v for (k, v) in local_ns.items() if k not in self.user_ns_hidden.keys()}
242 309 self.user_ns = reentrant_local_ns
243 310 self.init_user_ns()
244 311
245 312 # Compiler flags
246 313 if compile_flags is not None:
247 314 self.compile.flags = compile_flags
248 315
249 316 # make sure the tab-completer has the correct frame information, so it
250 317 # actually completes using the frame's locals/globals
251 318 self.set_completer_frame()
252 319
253 320 with self.builtin_trap, self.display_trap:
254 321 self.interact()
255 322
256 323 # now, purge out the local namespace of IPython's hidden variables.
257 324 if local_ns is not None:
258 325 local_ns.update({k: v for (k, v) in self.user_ns.items() if k not in self.user_ns_hidden.keys()})
259 326
260 327
261 328 # Restore original namespace so shell can shut down when we exit.
262 329 self.user_module = orig_user_module
263 330 self.user_ns = orig_user_ns
264 331 self.compile.flags = orig_compile_flags
265 332
266 333
267 334 def embed(**kwargs):
268 335 """Call this to embed IPython at the current point in your program.
269 336
270 337 The first invocation of this will create an :class:`InteractiveShellEmbed`
271 338 instance and then call it. Consecutive calls just call the already
272 339 created instance.
273 340
274 341 If you don't want the kernel to initialize the namespace
275 342 from the scope of the surrounding function,
276 343 and/or you want to load full IPython configuration,
277 344 you probably want `IPython.start_ipython()` instead.
278 345
279 346 Here is a simple example::
280 347
281 348 from IPython import embed
282 349 a = 10
283 350 b = 20
284 351 embed(header='First time')
285 352 c = 30
286 353 d = 40
287 354 embed()
288 355
289 356 Full customization can be done by passing a :class:`Config` in as the
290 357 config argument.
291 358 """
292 359 config = kwargs.get('config')
293 360 header = kwargs.pop('header', u'')
294 361 compile_flags = kwargs.pop('compile_flags', None)
295 362 if config is None:
296 363 config = load_default_config()
297 364 config.InteractiveShellEmbed = config.TerminalInteractiveShell
298 365 kwargs['config'] = config
299 366 #save ps1/ps2 if defined
300 367 ps1 = None
301 368 ps2 = None
302 369 try:
303 370 ps1 = sys.ps1
304 371 ps2 = sys.ps2
305 372 except AttributeError:
306 373 pass
307 374 #save previous instance
308 375 saved_shell_instance = InteractiveShell._instance
309 376 if saved_shell_instance is not None:
310 377 cls = type(saved_shell_instance)
311 378 cls.clear_instance()
312 379 frame = sys._getframe(1)
313 shell = InteractiveShellEmbed.instance(_call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno), **kwargs)
314 shell(header=header, stack_depth=2, compile_flags=compile_flags)
380 shell = InteractiveShellEmbed.instance(_init_location_id='%s:%s' % (
381 frame.f_code.co_filename, frame.f_lineno), **kwargs)
382 shell(header=header, stack_depth=2, compile_flags=compile_flags,
383 _call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno))
315 384 InteractiveShellEmbed.clear_instance()
316 385 #restore previous instance
317 386 if saved_shell_instance is not None:
318 387 cls = type(saved_shell_instance)
319 388 cls.clear_instance()
320 389 for subclass in cls._walk_mro():
321 390 subclass._instance = saved_shell_instance
322 391 if ps1 is not None:
323 392 sys.ps1 = ps1
324 393 sys.ps2 = ps2
@@ -1,230 +1,247 b''
1 1 ============
2 2 5.x Series
3 3 ============
4 4
5 5
6 6 IPython 5.2
7 7 ===========
8 8
9 9 Remarkable changes and fixes:
10 10
11 11 * restore IPython's debugger to raise on quit. :ghpull:`10009`
12 12 * The configuration value ``c.TerminalInteractiveShell.highlighting_style`` can
13 13 now directly take a class argument for custom color style. :ghpull:`9848`
14 14 * Correctly handle matplotlib figures dpi :ghpull:`9868`
15 15 * Deprecate ``-e`` flag for the ``%notebook`` magic that had no effects.
16 16 :ghpull:`9872`
17 17 * You can now press F2 while typing at a terminal prompt to edit the contents
18 18 in your favourite terminal editor. Set the :envvar:`EDITOR` environment
19 19 variable to pick which editor is used. :ghpull:`9929`
20 20 * sdists will now only be ``.tar.gz`` as per upstream PyPI requirements.
21 21 :ghpull:`9925`
22 22 * :any:`IPython.core.debugger` have gained a ``set_trace()`` method for
23 23 convenience. :ghpull:`9947`
24 24 * The 'smart command mode' added to the debugger in 5.0 was removed, as more
25 25 people preferred the previous behaviour. Therefore, debugger commands such as
26 26 ``c`` will act as debugger commands even when ``c`` is defined as a variable.
27 27 :ghpull:`10050`
28 28 * Fixes OS X event loop issues at startup, :ghpull:`10150`
29 29 * Deprecate the ``%autoindent`` magic. :ghpull:`10176`
30 30 * Emit a :any:`DeprecationWarning` when setting the deprecated
31 31 ``limit_to_all`` option of the completer. :ghpull:`10198`
32 32
33 33
34 Changes of behavior to :any:`InteractiveShellEmbed`.
35
36 :any:`InteractiveShellEmbed` interactive behavior have changed a bit in between
37 5.1 and 5.2. By default ``%kill_embedded`` magic will prevent further invocation
38 of the current ``call location`` instead of preventing further invocation of
39 the current instance creation location. For most use case this will not change
40 much for you, though previous behavior was confusing and less consistent with
41 previous IPython versions.
42
43 You can now deactivate instances by using ``%kill_embedded --instance`` flag,
44 (or ``-i`` in short). The ``%kill_embedded`` magic also gained a
45 ``--yes``/``-y`` option which skip confirmation step, and ``-x``/``--exit``
46 which also exit the current embedded call without asking for confirmation.
47
48 See :ghpull:`10207`.
49
50
34 51
35 52 IPython 5.1
36 53 ===========
37 54
38 55 * Broken ``%timeit`` on Python2 due to the use of ``__qualname__``. :ghpull:`9804`
39 56 * Restore ``%gui qt`` to create and return a ``QApplication`` if necessary. :ghpull:`9789`
40 57 * Don't set terminal title by default. :ghpull:`9801`
41 58 * Preserve indentation when inserting newlines with ``Ctrl-O``. :ghpull:`9770`
42 59 * Restore completion in debugger. :ghpull:`9785`
43 60 * Deprecate ``IPython.core.debugger.Tracer()`` in favor of simpler, newer, APIs. :ghpull:`9731`
44 61 * Restore ``NoOpContext`` context manager removed by mistake, and add `DeprecationWarning`. :ghpull:`9765`
45 62 * Add option allowing ``Prompt_toolkit`` to use 24bits colors. :ghpull:`9736`
46 63 * Fix for closing interactive matplotlib windows on OS X. :ghpull:`9854`
47 64 * An embedded interactive shell instance can be used more than once. :ghpull:`9843`
48 65 * More robust check for whether IPython is in a terminal. :ghpull:`9833`
49 66 * Better pretty-printing of dicts on PyPy. :ghpull:`9827`
50 67 * Some coloured output now looks better on dark background command prompts in Windows.
51 68 :ghpull:`9838`
52 69 * Improved tab completion of paths on Windows . :ghpull:`9826`
53 70 * Fix tkinter event loop integration on Python 2 with ``future`` installed. :ghpull:`9824`
54 71 * Restore ``Ctrl-\`` as a shortcut to quit IPython.
55 72 * Make ``get_ipython()`` accessible when modules are imported by startup files. :ghpull:`9818`
56 73 * Add support for running directories containing a ``__main__.py`` file with the
57 74 ``ipython`` command. :ghpull:`9813`
58 75
59 76
60 77 True Color feature
61 78 ------------------
62 79
63 80 ``prompt_toolkit`` uses pygments styles for syntax highlighting. By default, the
64 81 colors specified in the style are approximated using a standard 256-color
65 82 palette. ``prompt_toolkit`` also supports 24bit, a.k.a. "true", a.k.a. 16-million
66 83 color escape sequences which enable compatible terminals to display the exact
67 84 colors specified instead of an approximation. This true_color option exposes
68 85 that capability in prompt_toolkit to the IPython shell.
69 86
70 87 Here is a good source for the current state of true color support in various
71 88 terminal emulators and software projects: https://gist.github.com/XVilka/8346728
72 89
73 90
74 91
75 92 IPython 5.0
76 93 ===========
77 94
78 95 Released July 7, 2016
79 96
80 97 New terminal interface
81 98 ----------------------
82 99
83 100 IPython 5 features a major upgrade to the terminal interface, bringing live
84 101 syntax highlighting as you type, proper multiline editing and multiline paste,
85 102 and tab completions that don't clutter up your history.
86 103
87 104 .. image:: ../_images/ptshell_features.png
88 105 :alt: New terminal interface features
89 106 :align: center
90 107 :target: ../_images/ptshell_features.png
91 108
92 109 These features are provided by the Python library `prompt_toolkit
93 110 <http://python-prompt-toolkit.readthedocs.io/en/stable/>`__, which replaces
94 111 ``readline`` throughout our terminal interface.
95 112
96 113 Relying on this pure-Python, cross platform module also makes it simpler to
97 114 install IPython. We have removed dependencies on ``pyreadline`` for Windows and
98 115 ``gnureadline`` for Mac.
99 116
100 117 Backwards incompatible changes
101 118 ------------------------------
102 119
103 120 - The ``%install_ext`` magic function, deprecated since 4.0, has now been deleted.
104 121 You can distribute and install extensions as packages on PyPI.
105 122 - Callbacks registered while an event is being handled will now only be called
106 123 for subsequent events; previously they could be called for the current event.
107 124 Similarly, callbacks removed while handling an event *will* always get that
108 125 event. See :ghissue:`9447` and :ghpull:`9453`.
109 126 - Integration with pydb has been removed since pydb development has been stopped
110 127 since 2012, and pydb is not installable from PyPI.
111 128 - The ``autoedit_syntax`` option has apparently been broken for many years.
112 129 It has been removed.
113 130
114 131 New terminal interface
115 132 ~~~~~~~~~~~~~~~~~~~~~~
116 133
117 134 The overhaul of the terminal interface will probably cause a range of minor
118 135 issues for existing users.
119 136 This is inevitable for such a significant change, and we've done our best to
120 137 minimise these issues.
121 138 Some changes that we're aware of, with suggestions on how to handle them:
122 139
123 140 IPython no longer uses readline configuration (``~/.inputrc``). We hope that
124 141 the functionality you want (e.g. vi input mode) will be available by configuring
125 142 IPython directly (see :doc:`/config/options/terminal`).
126 143 If something's missing, please file an issue.
127 144
128 145 The ``PromptManager`` class has been removed, and the prompt machinery simplified.
129 146 See :ref:`custom_prompts` to customise prompts with the new machinery.
130 147
131 148 :mod:`IPython.core.debugger` now provides a plainer interface.
132 149 :mod:`IPython.terminal.debugger` contains the terminal debugger using
133 150 prompt_toolkit.
134 151
135 152 There are new options to configure the colours used in syntax highlighting.
136 153 We have tried to integrate them with our classic ``--colors`` option and
137 154 ``%colors`` magic, but there's a mismatch in possibilities, so some configurations
138 155 may produce unexpected results. See :ref:`termcolour` for more information.
139 156
140 157 The new interface is not compatible with Emacs 'inferior-shell' feature. To
141 158 continue using this, add the ``--simple-prompt`` flag to the command Emacs
142 159 runs. This flag disables most IPython features, relying on Emacs to provide
143 160 things like tab completion.
144 161
145 162 Provisional Changes
146 163 -------------------
147 164
148 165 Provisional changes are experimental functionality that may, or may not, make
149 166 it into a future version of IPython, and which API may change without warnings.
150 167 Activating these features and using these API are at your own risk, and may have
151 168 security implication for your system, especially if used with the Jupyter notebook,
152 169
153 170 When running via the Jupyter notebook interfaces, or other compatible client,
154 171 you can enable rich documentation experimental functionality:
155 172
156 173 When the ``docrepr`` package is installed setting the boolean flag
157 174 ``InteractiveShell.sphinxify_docstring`` to ``True``, will process the various
158 175 object through sphinx before displaying them (see the ``docrepr`` package
159 176 documentation for more information.
160 177
161 178 You need to also enable the IPython pager display rich HTML representation
162 179 using the ``InteractiveShell.enable_html_pager`` boolean configuration option.
163 180 As usual you can set these configuration options globally in your configuration
164 181 files, alternatively you can turn them on dynamically using the following
165 182 snippet:
166 183
167 184 .. code-block:: python
168 185
169 186 ip = get_ipython()
170 187 ip.sphinxify_docstring = True
171 188 ip.enable_html_pager = True
172 189
173 190
174 191 You can test the effect of various combinations of the above configuration in
175 192 the Jupyter notebook, with things example like :
176 193
177 194 .. code-block:: ipython
178 195
179 196 import numpy as np
180 197 np.histogram?
181 198
182 199
183 200 This is part of an effort to make Documentation in Python richer and provide in
184 201 the long term if possible dynamic examples that can contain math, images,
185 202 widgets... As stated above this is nightly experimental feature with a lot of
186 203 (fun) problem to solve. We would be happy to get your feedback and expertise on
187 204 it.
188 205
189 206
190 207
191 208 Deprecated Features
192 209 -------------------
193 210
194 211 Some deprecated features are listed in this section. Don't forget to enable
195 212 ``DeprecationWarning`` as an error if you are using IPython in a Continuous
196 213 Integration setup or in your testing in general:
197 214
198 215 .. code-block:: python
199 216
200 217 import warnings
201 218 warnings.filterwarnings('error', '.*', DeprecationWarning, module='yourmodule.*')
202 219
203 220
204 221 - ``hooks.fix_error_editor`` seems unused and is pending deprecation.
205 222 - `IPython/core/excolors.py:ExceptionColors` is deprecated.
206 223 - `IPython.core.InteractiveShell:write()` is deprecated; use `sys.stdout` instead.
207 224 - `IPython.core.InteractiveShell:write_err()` is deprecated; use `sys.stderr` instead.
208 225 - The `formatter` keyword argument to `Inspector.info` in `IPython.core.oinspec` has no effect.
209 226 - The `global_ns` keyword argument of IPython Embed was deprecated, and has no effect. Use `module` keyword argument instead.
210 227
211 228
212 229 Known Issues:
213 230 -------------
214 231
215 232 - ``<Esc>`` Key does not dismiss the completer and does not clear the current
216 233 buffer. This is an on purpose modification due to current technical
217 234 limitation. Cf :ghpull:`9572`. Escape the control character which is used
218 235 for other shortcut, and there is no practical way to distinguish. Use Ctr-G
219 236 or Ctrl-C as an alternative.
220 237
221 238 - Cannot use ``Shift-Enter`` and ``Ctrl-Enter`` to submit code in terminal. cf
222 239 :ghissue:`9587` and :ghissue:`9401`. In terminal there is no practical way to
223 240 distinguish these key sequences from a normal new line return.
224 241
225 242 - ``PageUp`` and ``pageDown`` do not move through completion menu.
226 243
227 244 - Color styles might not adapt to terminal emulator themes. This will need new
228 245 version of Pygments to be released, and can be mitigated with custom themes.
229 246
230 247
General Comments 0
You need to be logged in to leave comments. Login now