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