Show More
@@ -1,2827 +1,2853 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Main IPython class.""" |
|
3 | 3 | |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> |
|
6 | 6 | # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu> |
|
7 | 7 | # Copyright (C) 2008-2011 The IPython Development Team |
|
8 | 8 | # |
|
9 | 9 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | 10 | # the file COPYING, distributed as part of this software. |
|
11 | 11 | #----------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | from __future__ import with_statement |
|
18 | 18 | from __future__ import absolute_import |
|
19 | 19 | |
|
20 | 20 | import __builtin__ as builtin_mod |
|
21 | 21 | import __future__ |
|
22 | 22 | import abc |
|
23 | 23 | import ast |
|
24 | 24 | import atexit |
|
25 | import codeop | |
|
26 | import inspect | |
|
27 | 25 | import os |
|
28 | 26 | import re |
|
29 | 27 | import runpy |
|
30 | 28 | import sys |
|
31 | 29 | import tempfile |
|
32 | 30 | import types |
|
33 | ||
|
34 | try: | |
|
35 | from contextlib import nested | |
|
36 | except: | |
|
37 | from IPython.utils.nested_context import nested | |
|
31 | import urllib | |
|
32 | from io import open as io_open | |
|
38 | 33 | |
|
39 | 34 | from IPython.config.configurable import SingletonConfigurable |
|
40 | 35 | from IPython.core import debugger, oinspect |
|
41 | from IPython.core import history as ipcorehist | |
|
42 | 36 | from IPython.core import page |
|
43 | 37 | from IPython.core import prefilter |
|
44 | 38 | from IPython.core import shadowns |
|
45 | 39 | from IPython.core import ultratb |
|
46 | 40 | from IPython.core.alias import AliasManager, AliasError |
|
47 | 41 | from IPython.core.autocall import ExitAutocall |
|
48 | 42 | from IPython.core.builtin_trap import BuiltinTrap |
|
49 | 43 | from IPython.core.compilerop import CachingCompiler |
|
50 | 44 | from IPython.core.display_trap import DisplayTrap |
|
51 | 45 | from IPython.core.displayhook import DisplayHook |
|
52 | 46 | from IPython.core.displaypub import DisplayPublisher |
|
53 |
from IPython.core.error import |
|
|
47 | from IPython.core.error import UsageError | |
|
54 | 48 | from IPython.core.extensions import ExtensionManager |
|
55 | 49 | from IPython.core.fakemodule import FakeModule, init_fakemod_dict |
|
56 | 50 | from IPython.core.formatters import DisplayFormatter |
|
57 | 51 | from IPython.core.history import HistoryManager |
|
58 | 52 | from IPython.core.inputsplitter import IPythonInputSplitter |
|
59 | 53 | from IPython.core.logger import Logger |
|
60 | 54 | from IPython.core.macro import Macro |
|
61 | 55 | from IPython.core.magic import Magic |
|
62 | 56 | from IPython.core.payload import PayloadManager |
|
63 | 57 | from IPython.core.plugin import PluginManager |
|
64 | 58 | from IPython.core.prefilter import PrefilterManager, ESC_MAGIC |
|
65 | 59 | from IPython.core.profiledir import ProfileDir |
|
66 | 60 | from IPython.core.pylabtools import pylab_activate |
|
67 | 61 | from IPython.core.prompts import PromptManager |
|
68 | 62 | from IPython.utils import PyColorize |
|
69 | 63 | from IPython.utils import io |
|
70 | 64 | from IPython.utils import py3compat |
|
65 | from IPython.utils import openpy | |
|
71 | 66 | from IPython.utils.doctestreload import doctest_reload |
|
72 |
from IPython.utils.io import ask_yes_no |
|
|
67 | from IPython.utils.io import ask_yes_no | |
|
73 | 68 | from IPython.utils.ipstruct import Struct |
|
74 |
from IPython.utils.path import get_home_dir, get_ipython_dir, |
|
|
69 | from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename | |
|
75 | 70 | from IPython.utils.pickleshare import PickleShareDB |
|
76 | 71 | from IPython.utils.process import system, getoutput |
|
77 | 72 | from IPython.utils.strdispatch import StrDispatch |
|
78 | 73 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
79 |
from IPython.utils.text import ( |
|
|
74 | from IPython.utils.text import (format_screen, LSString, SList, | |
|
80 | 75 | DollarFormatter) |
|
81 | 76 | from IPython.utils.traitlets import (Integer, CBool, CaselessStrEnum, Enum, |
|
82 | 77 | List, Unicode, Instance, Type) |
|
83 |
from IPython.utils.warn import warn, error |
|
|
78 | from IPython.utils.warn import warn, error | |
|
84 | 79 | import IPython.core.hooks |
|
85 | 80 | |
|
86 | 81 | #----------------------------------------------------------------------------- |
|
87 | 82 | # Globals |
|
88 | 83 | #----------------------------------------------------------------------------- |
|
89 | 84 | |
|
90 | 85 | # compiled regexps for autoindent management |
|
91 | 86 | dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') |
|
92 | 87 | |
|
93 | 88 | #----------------------------------------------------------------------------- |
|
94 | 89 | # Utilities |
|
95 | 90 | #----------------------------------------------------------------------------- |
|
96 | 91 | |
|
97 | 92 | def softspace(file, newvalue): |
|
98 | 93 | """Copied from code.py, to remove the dependency""" |
|
99 | 94 | |
|
100 | 95 | oldvalue = 0 |
|
101 | 96 | try: |
|
102 | 97 | oldvalue = file.softspace |
|
103 | 98 | except AttributeError: |
|
104 | 99 | pass |
|
105 | 100 | try: |
|
106 | 101 | file.softspace = newvalue |
|
107 | 102 | except (AttributeError, TypeError): |
|
108 | 103 | # "attribute-less object" or "read-only attributes" |
|
109 | 104 | pass |
|
110 | 105 | return oldvalue |
|
111 | 106 | |
|
112 | 107 | |
|
113 | 108 | def no_op(*a, **kw): pass |
|
114 | 109 | |
|
115 | 110 | class NoOpContext(object): |
|
116 | 111 | def __enter__(self): pass |
|
117 | 112 | def __exit__(self, type, value, traceback): pass |
|
118 | 113 | no_op_context = NoOpContext() |
|
119 | 114 | |
|
120 | 115 | class SpaceInInput(Exception): pass |
|
121 | 116 | |
|
122 | 117 | class Bunch: pass |
|
123 | 118 | |
|
124 | 119 | |
|
125 | 120 | def get_default_colors(): |
|
126 | 121 | if sys.platform=='darwin': |
|
127 | 122 | return "LightBG" |
|
128 | 123 | elif os.name=='nt': |
|
129 | 124 | return 'Linux' |
|
130 | 125 | else: |
|
131 | 126 | return 'Linux' |
|
132 | 127 | |
|
133 | 128 | |
|
134 | 129 | class SeparateUnicode(Unicode): |
|
135 | 130 | """A Unicode subclass to validate separate_in, separate_out, etc. |
|
136 | 131 | |
|
137 | 132 | This is a Unicode based trait that converts '0'->'' and '\\n'->'\n'. |
|
138 | 133 | """ |
|
139 | 134 | |
|
140 | 135 | def validate(self, obj, value): |
|
141 | 136 | if value == '0': value = '' |
|
142 | 137 | value = value.replace('\\n','\n') |
|
143 | 138 | return super(SeparateUnicode, self).validate(obj, value) |
|
144 | 139 | |
|
145 | 140 | |
|
146 | 141 | class ReadlineNoRecord(object): |
|
147 | 142 | """Context manager to execute some code, then reload readline history |
|
148 | 143 | so that interactive input to the code doesn't appear when pressing up.""" |
|
149 | 144 | def __init__(self, shell): |
|
150 | 145 | self.shell = shell |
|
151 | 146 | self._nested_level = 0 |
|
152 | 147 | |
|
153 | 148 | def __enter__(self): |
|
154 | 149 | if self._nested_level == 0: |
|
155 | 150 | try: |
|
156 | 151 | self.orig_length = self.current_length() |
|
157 | 152 | self.readline_tail = self.get_readline_tail() |
|
158 | 153 | except (AttributeError, IndexError): # Can fail with pyreadline |
|
159 | 154 | self.orig_length, self.readline_tail = 999999, [] |
|
160 | 155 | self._nested_level += 1 |
|
161 | 156 | |
|
162 | 157 | def __exit__(self, type, value, traceback): |
|
163 | 158 | self._nested_level -= 1 |
|
164 | 159 | if self._nested_level == 0: |
|
165 | 160 | # Try clipping the end if it's got longer |
|
166 | 161 | try: |
|
167 | 162 | e = self.current_length() - self.orig_length |
|
168 | 163 | if e > 0: |
|
169 | 164 | for _ in range(e): |
|
170 | 165 | self.shell.readline.remove_history_item(self.orig_length) |
|
171 | 166 | |
|
172 | 167 | # If it still doesn't match, just reload readline history. |
|
173 | 168 | if self.current_length() != self.orig_length \ |
|
174 | 169 | or self.get_readline_tail() != self.readline_tail: |
|
175 | 170 | self.shell.refill_readline_hist() |
|
176 | 171 | except (AttributeError, IndexError): |
|
177 | 172 | pass |
|
178 | 173 | # Returning False will cause exceptions to propagate |
|
179 | 174 | return False |
|
180 | 175 | |
|
181 | 176 | def current_length(self): |
|
182 | 177 | return self.shell.readline.get_current_history_length() |
|
183 | 178 | |
|
184 | 179 | def get_readline_tail(self, n=10): |
|
185 | 180 | """Get the last n items in readline history.""" |
|
186 | 181 | end = self.shell.readline.get_current_history_length() + 1 |
|
187 | 182 | start = max(end-n, 1) |
|
188 | 183 | ghi = self.shell.readline.get_history_item |
|
189 | 184 | return [ghi(x) for x in range(start, end)] |
|
190 | 185 | |
|
191 | 186 | #----------------------------------------------------------------------------- |
|
192 | 187 | # Main IPython class |
|
193 | 188 | #----------------------------------------------------------------------------- |
|
194 | 189 | |
|
195 | 190 | class InteractiveShell(SingletonConfigurable, Magic): |
|
196 | 191 | """An enhanced, interactive shell for Python.""" |
|
197 | 192 | |
|
198 | 193 | _instance = None |
|
199 | 194 | |
|
200 | 195 | autocall = Enum((0,1,2), default_value=0, config=True, help= |
|
201 | 196 | """ |
|
202 | 197 | Make IPython automatically call any callable object even if you didn't |
|
203 | 198 | type explicit parentheses. For example, 'str 43' becomes 'str(43)' |
|
204 | 199 | automatically. The value can be '0' to disable the feature, '1' for |
|
205 | 200 | 'smart' autocall, where it is not applied if there are no more |
|
206 | 201 | arguments on the line, and '2' for 'full' autocall, where all callable |
|
207 | 202 | objects are automatically called (even if no arguments are present). |
|
208 | 203 | """ |
|
209 | 204 | ) |
|
210 | 205 | # TODO: remove all autoindent logic and put into frontends. |
|
211 | 206 | # We can't do this yet because even runlines uses the autoindent. |
|
212 | 207 | autoindent = CBool(True, config=True, help= |
|
213 | 208 | """ |
|
214 | 209 | Autoindent IPython code entered interactively. |
|
215 | 210 | """ |
|
216 | 211 | ) |
|
217 | 212 | automagic = CBool(True, config=True, help= |
|
218 | 213 | """ |
|
219 | 214 | Enable magic commands to be called without the leading %. |
|
220 | 215 | """ |
|
221 | 216 | ) |
|
222 | 217 | cache_size = Integer(1000, config=True, help= |
|
223 | 218 | """ |
|
224 | 219 | Set the size of the output cache. The default is 1000, you can |
|
225 | 220 | change it permanently in your config file. Setting it to 0 completely |
|
226 | 221 | disables the caching system, and the minimum value accepted is 20 (if |
|
227 | 222 | you provide a value less than 20, it is reset to 0 and a warning is |
|
228 | 223 | issued). This limit is defined because otherwise you'll spend more |
|
229 | 224 | time re-flushing a too small cache than working |
|
230 | 225 | """ |
|
231 | 226 | ) |
|
232 | 227 | color_info = CBool(True, config=True, help= |
|
233 | 228 | """ |
|
234 | 229 | Use colors for displaying information about objects. Because this |
|
235 | 230 | information is passed through a pager (like 'less'), and some pagers |
|
236 | 231 | get confused with color codes, this capability can be turned off. |
|
237 | 232 | """ |
|
238 | 233 | ) |
|
239 | 234 | colors = CaselessStrEnum(('NoColor','LightBG','Linux'), |
|
240 | 235 | default_value=get_default_colors(), config=True, |
|
241 | 236 | help="Set the color scheme (NoColor, Linux, or LightBG)." |
|
242 | 237 | ) |
|
243 | 238 | colors_force = CBool(False, help= |
|
244 | 239 | """ |
|
245 | 240 | Force use of ANSI color codes, regardless of OS and readline |
|
246 | 241 | availability. |
|
247 | 242 | """ |
|
248 | 243 | # FIXME: This is essentially a hack to allow ZMQShell to show colors |
|
249 | 244 | # without readline on Win32. When the ZMQ formatting system is |
|
250 | 245 | # refactored, this should be removed. |
|
251 | 246 | ) |
|
252 | 247 | debug = CBool(False, config=True) |
|
253 | 248 | deep_reload = CBool(False, config=True, help= |
|
254 | 249 | """ |
|
255 | 250 | Enable deep (recursive) reloading by default. IPython can use the |
|
256 | 251 | deep_reload module which reloads changes in modules recursively (it |
|
257 | 252 | replaces the reload() function, so you don't need to change anything to |
|
258 | 253 | use it). deep_reload() forces a full reload of modules whose code may |
|
259 | 254 | have changed, which the default reload() function does not. When |
|
260 | 255 | deep_reload is off, IPython will use the normal reload(), but |
|
261 | 256 | deep_reload will still be available as dreload(). |
|
262 | 257 | """ |
|
263 | 258 | ) |
|
264 | 259 | disable_failing_post_execute = CBool(False, config=True, |
|
265 | 260 | help="Don't call post-execute functions that have failed in the past.""" |
|
266 | 261 | ) |
|
267 | 262 | display_formatter = Instance(DisplayFormatter) |
|
268 | 263 | displayhook_class = Type(DisplayHook) |
|
269 | 264 | display_pub_class = Type(DisplayPublisher) |
|
270 | 265 | |
|
271 | 266 | exit_now = CBool(False) |
|
272 | 267 | exiter = Instance(ExitAutocall) |
|
273 | 268 | def _exiter_default(self): |
|
274 | 269 | return ExitAutocall(self) |
|
275 | 270 | # Monotonically increasing execution counter |
|
276 | 271 | execution_count = Integer(1) |
|
277 | 272 | filename = Unicode("<ipython console>") |
|
278 | 273 | ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ |
|
279 | 274 | |
|
280 | 275 | # Input splitter, to split entire cells of input into either individual |
|
281 | 276 | # interactive statements or whole blocks. |
|
282 | 277 | input_splitter = Instance('IPython.core.inputsplitter.IPythonInputSplitter', |
|
283 | 278 | (), {}) |
|
284 | 279 | logstart = CBool(False, config=True, help= |
|
285 | 280 | """ |
|
286 | 281 | Start logging to the default log file. |
|
287 | 282 | """ |
|
288 | 283 | ) |
|
289 | 284 | logfile = Unicode('', config=True, help= |
|
290 | 285 | """ |
|
291 | 286 | The name of the logfile to use. |
|
292 | 287 | """ |
|
293 | 288 | ) |
|
294 | 289 | logappend = Unicode('', config=True, help= |
|
295 | 290 | """ |
|
296 | 291 | Start logging to the given file in append mode. |
|
297 | 292 | """ |
|
298 | 293 | ) |
|
299 | 294 | object_info_string_level = Enum((0,1,2), default_value=0, |
|
300 | 295 | config=True) |
|
301 | 296 | pdb = CBool(False, config=True, help= |
|
302 | 297 | """ |
|
303 | 298 | Automatically call the pdb debugger after every exception. |
|
304 | 299 | """ |
|
305 | 300 | ) |
|
306 | 301 | multiline_history = CBool(sys.platform != 'win32', config=True, |
|
307 | 302 | help="Save multi-line entries as one entry in readline history" |
|
308 | 303 | ) |
|
309 | 304 | |
|
310 | 305 | # deprecated prompt traits: |
|
311 | 306 | |
|
312 | 307 | prompt_in1 = Unicode('In [\\#]: ', config=True, |
|
313 | 308 | help="Deprecated, use PromptManager.in_template") |
|
314 | 309 | prompt_in2 = Unicode(' .\\D.: ', config=True, |
|
315 | 310 | help="Deprecated, use PromptManager.in2_template") |
|
316 | 311 | prompt_out = Unicode('Out[\\#]: ', config=True, |
|
317 | 312 | help="Deprecated, use PromptManager.out_template") |
|
318 | 313 | prompts_pad_left = CBool(True, config=True, |
|
319 | 314 | help="Deprecated, use PromptManager.justify") |
|
320 | 315 | |
|
321 | 316 | def _prompt_trait_changed(self, name, old, new): |
|
322 | 317 | table = { |
|
323 | 318 | 'prompt_in1' : 'in_template', |
|
324 | 319 | 'prompt_in2' : 'in2_template', |
|
325 | 320 | 'prompt_out' : 'out_template', |
|
326 | 321 | 'prompts_pad_left' : 'justify', |
|
327 | 322 | } |
|
328 | 323 | warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}\n".format( |
|
329 | 324 | name=name, newname=table[name]) |
|
330 | 325 | ) |
|
331 | 326 | # protect against weird cases where self.config may not exist: |
|
332 | 327 | if self.config is not None: |
|
333 | 328 | # propagate to corresponding PromptManager trait |
|
334 | 329 | setattr(self.config.PromptManager, table[name], new) |
|
335 | 330 | |
|
336 | 331 | _prompt_in1_changed = _prompt_trait_changed |
|
337 | 332 | _prompt_in2_changed = _prompt_trait_changed |
|
338 | 333 | _prompt_out_changed = _prompt_trait_changed |
|
339 | 334 | _prompt_pad_left_changed = _prompt_trait_changed |
|
340 | 335 | |
|
341 | 336 | show_rewritten_input = CBool(True, config=True, |
|
342 | 337 | help="Show rewritten input, e.g. for autocall." |
|
343 | 338 | ) |
|
344 | 339 | |
|
345 | 340 | quiet = CBool(False, config=True) |
|
346 | 341 | |
|
347 | 342 | history_length = Integer(10000, config=True) |
|
348 | 343 | |
|
349 | 344 | # The readline stuff will eventually be moved to the terminal subclass |
|
350 | 345 | # but for now, we can't do that as readline is welded in everywhere. |
|
351 | 346 | readline_use = CBool(True, config=True) |
|
352 | 347 | readline_remove_delims = Unicode('-/~', config=True) |
|
353 | 348 | # don't use \M- bindings by default, because they |
|
354 | 349 | # conflict with 8-bit encodings. See gh-58,gh-88 |
|
355 | 350 | readline_parse_and_bind = List([ |
|
356 | 351 | 'tab: complete', |
|
357 | 352 | '"\C-l": clear-screen', |
|
358 | 353 | 'set show-all-if-ambiguous on', |
|
359 | 354 | '"\C-o": tab-insert', |
|
360 | 355 | '"\C-r": reverse-search-history', |
|
361 | 356 | '"\C-s": forward-search-history', |
|
362 | 357 | '"\C-p": history-search-backward', |
|
363 | 358 | '"\C-n": history-search-forward', |
|
364 | 359 | '"\e[A": history-search-backward', |
|
365 | 360 | '"\e[B": history-search-forward', |
|
366 | 361 | '"\C-k": kill-line', |
|
367 | 362 | '"\C-u": unix-line-discard', |
|
368 | 363 | ], allow_none=False, config=True) |
|
369 | 364 | |
|
370 | 365 | # TODO: this part of prompt management should be moved to the frontends. |
|
371 | 366 | # Use custom TraitTypes that convert '0'->'' and '\\n'->'\n' |
|
372 | 367 | separate_in = SeparateUnicode('\n', config=True) |
|
373 | 368 | separate_out = SeparateUnicode('', config=True) |
|
374 | 369 | separate_out2 = SeparateUnicode('', config=True) |
|
375 | 370 | wildcards_case_sensitive = CBool(True, config=True) |
|
376 | 371 | xmode = CaselessStrEnum(('Context','Plain', 'Verbose'), |
|
377 | 372 | default_value='Context', config=True) |
|
378 | 373 | |
|
379 | 374 | # Subcomponents of InteractiveShell |
|
380 | 375 | alias_manager = Instance('IPython.core.alias.AliasManager') |
|
381 | 376 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') |
|
382 | 377 | builtin_trap = Instance('IPython.core.builtin_trap.BuiltinTrap') |
|
383 | 378 | display_trap = Instance('IPython.core.display_trap.DisplayTrap') |
|
384 | 379 | extension_manager = Instance('IPython.core.extensions.ExtensionManager') |
|
385 | 380 | plugin_manager = Instance('IPython.core.plugin.PluginManager') |
|
386 | 381 | payload_manager = Instance('IPython.core.payload.PayloadManager') |
|
387 | 382 | history_manager = Instance('IPython.core.history.HistoryManager') |
|
388 | 383 | |
|
389 | 384 | profile_dir = Instance('IPython.core.application.ProfileDir') |
|
390 | 385 | @property |
|
391 | 386 | def profile(self): |
|
392 | 387 | if self.profile_dir is not None: |
|
393 | 388 | name = os.path.basename(self.profile_dir.location) |
|
394 | 389 | return name.replace('profile_','') |
|
395 | 390 | |
|
396 | 391 | |
|
397 | 392 | # Private interface |
|
398 | 393 | _post_execute = Instance(dict) |
|
399 | 394 | |
|
400 | 395 | def __init__(self, config=None, ipython_dir=None, profile_dir=None, |
|
401 | 396 | user_module=None, user_ns=None, |
|
402 | 397 | custom_exceptions=((), None)): |
|
403 | 398 | |
|
404 | 399 | # This is where traits with a config_key argument are updated |
|
405 | 400 | # from the values on config. |
|
406 | 401 | super(InteractiveShell, self).__init__(config=config) |
|
407 | 402 | self.configurables = [self] |
|
408 | 403 | |
|
409 | 404 | # These are relatively independent and stateless |
|
410 | 405 | self.init_ipython_dir(ipython_dir) |
|
411 | 406 | self.init_profile_dir(profile_dir) |
|
412 | 407 | self.init_instance_attrs() |
|
413 | 408 | self.init_environment() |
|
414 | 409 | |
|
415 | 410 | # Check if we're in a virtualenv, and set up sys.path. |
|
416 | 411 | self.init_virtualenv() |
|
417 | 412 | |
|
418 | 413 | # Create namespaces (user_ns, user_global_ns, etc.) |
|
419 | 414 | self.init_create_namespaces(user_module, user_ns) |
|
420 | 415 | # This has to be done after init_create_namespaces because it uses |
|
421 | 416 | # something in self.user_ns, but before init_sys_modules, which |
|
422 | 417 | # is the first thing to modify sys. |
|
423 | 418 | # TODO: When we override sys.stdout and sys.stderr before this class |
|
424 | 419 | # is created, we are saving the overridden ones here. Not sure if this |
|
425 | 420 | # is what we want to do. |
|
426 | 421 | self.save_sys_module_state() |
|
427 | 422 | self.init_sys_modules() |
|
428 | 423 | |
|
429 | 424 | # While we're trying to have each part of the code directly access what |
|
430 | 425 | # it needs without keeping redundant references to objects, we have too |
|
431 | 426 | # much legacy code that expects ip.db to exist. |
|
432 | 427 | self.db = PickleShareDB(os.path.join(self.profile_dir.location, 'db')) |
|
433 | 428 | |
|
434 | 429 | self.init_history() |
|
435 | 430 | self.init_encoding() |
|
436 | 431 | self.init_prefilter() |
|
437 | 432 | |
|
438 | 433 | Magic.__init__(self, self) |
|
439 | 434 | |
|
440 | 435 | self.init_syntax_highlighting() |
|
441 | 436 | self.init_hooks() |
|
442 | 437 | self.init_pushd_popd_magic() |
|
443 | 438 | # self.init_traceback_handlers use to be here, but we moved it below |
|
444 | 439 | # because it and init_io have to come after init_readline. |
|
445 | 440 | self.init_user_ns() |
|
446 | 441 | self.init_logger() |
|
447 | 442 | self.init_alias() |
|
448 | 443 | self.init_builtins() |
|
449 | 444 | |
|
450 | 445 | # pre_config_initialization |
|
451 | 446 | |
|
452 | 447 | # The next section should contain everything that was in ipmaker. |
|
453 | 448 | self.init_logstart() |
|
454 | 449 | |
|
455 | 450 | # The following was in post_config_initialization |
|
456 | 451 | self.init_inspector() |
|
457 | 452 | # init_readline() must come before init_io(), because init_io uses |
|
458 | 453 | # readline related things. |
|
459 | 454 | self.init_readline() |
|
460 | 455 | # We save this here in case user code replaces raw_input, but it needs |
|
461 | 456 | # to be after init_readline(), because PyPy's readline works by replacing |
|
462 | 457 | # raw_input. |
|
463 | 458 | if py3compat.PY3: |
|
464 | 459 | self.raw_input_original = input |
|
465 | 460 | else: |
|
466 | 461 | self.raw_input_original = raw_input |
|
467 | 462 | # init_completer must come after init_readline, because it needs to |
|
468 | 463 | # know whether readline is present or not system-wide to configure the |
|
469 | 464 | # completers, since the completion machinery can now operate |
|
470 | 465 | # independently of readline (e.g. over the network) |
|
471 | 466 | self.init_completer() |
|
472 | 467 | # TODO: init_io() needs to happen before init_traceback handlers |
|
473 | 468 | # because the traceback handlers hardcode the stdout/stderr streams. |
|
474 | 469 | # This logic in in debugger.Pdb and should eventually be changed. |
|
475 | 470 | self.init_io() |
|
476 | 471 | self.init_traceback_handlers(custom_exceptions) |
|
477 | 472 | self.init_prompts() |
|
478 | 473 | self.init_display_formatter() |
|
479 | 474 | self.init_display_pub() |
|
480 | 475 | self.init_displayhook() |
|
481 | 476 | self.init_reload_doctest() |
|
482 | 477 | self.init_magics() |
|
483 | 478 | self.init_pdb() |
|
484 | 479 | self.init_extension_manager() |
|
485 | 480 | self.init_plugin_manager() |
|
486 | 481 | self.init_payload() |
|
487 | 482 | self.hooks.late_startup_hook() |
|
488 | 483 | atexit.register(self.atexit_operations) |
|
489 | 484 | |
|
490 | 485 | def get_ipython(self): |
|
491 | 486 | """Return the currently running IPython instance.""" |
|
492 | 487 | return self |
|
493 | 488 | |
|
494 | 489 | #------------------------------------------------------------------------- |
|
495 | 490 | # Trait changed handlers |
|
496 | 491 | #------------------------------------------------------------------------- |
|
497 | 492 | |
|
498 | 493 | def _ipython_dir_changed(self, name, new): |
|
499 | 494 | if not os.path.isdir(new): |
|
500 | 495 | os.makedirs(new, mode = 0777) |
|
501 | 496 | |
|
502 | 497 | def set_autoindent(self,value=None): |
|
503 | 498 | """Set the autoindent flag, checking for readline support. |
|
504 | 499 | |
|
505 | 500 | If called with no arguments, it acts as a toggle.""" |
|
506 | 501 | |
|
507 | 502 | if value != 0 and not self.has_readline: |
|
508 | 503 | if os.name == 'posix': |
|
509 | 504 | warn("The auto-indent feature requires the readline library") |
|
510 | 505 | self.autoindent = 0 |
|
511 | 506 | return |
|
512 | 507 | if value is None: |
|
513 | 508 | self.autoindent = not self.autoindent |
|
514 | 509 | else: |
|
515 | 510 | self.autoindent = value |
|
516 | 511 | |
|
517 | 512 | #------------------------------------------------------------------------- |
|
518 | 513 | # init_* methods called by __init__ |
|
519 | 514 | #------------------------------------------------------------------------- |
|
520 | 515 | |
|
521 | 516 | def init_ipython_dir(self, ipython_dir): |
|
522 | 517 | if ipython_dir is not None: |
|
523 | 518 | self.ipython_dir = ipython_dir |
|
524 | 519 | return |
|
525 | 520 | |
|
526 | 521 | self.ipython_dir = get_ipython_dir() |
|
527 | 522 | |
|
528 | 523 | def init_profile_dir(self, profile_dir): |
|
529 | 524 | if profile_dir is not None: |
|
530 | 525 | self.profile_dir = profile_dir |
|
531 | 526 | return |
|
532 | 527 | self.profile_dir =\ |
|
533 | 528 | ProfileDir.create_profile_dir_by_name(self.ipython_dir, 'default') |
|
534 | 529 | |
|
535 | 530 | def init_instance_attrs(self): |
|
536 | 531 | self.more = False |
|
537 | 532 | |
|
538 | 533 | # command compiler |
|
539 | 534 | self.compile = CachingCompiler() |
|
540 | 535 | |
|
541 | 536 | # Make an empty namespace, which extension writers can rely on both |
|
542 | 537 | # existing and NEVER being used by ipython itself. This gives them a |
|
543 | 538 | # convenient location for storing additional information and state |
|
544 | 539 | # their extensions may require, without fear of collisions with other |
|
545 | 540 | # ipython names that may develop later. |
|
546 | 541 | self.meta = Struct() |
|
547 | 542 | |
|
548 | 543 | # Temporary files used for various purposes. Deleted at exit. |
|
549 | 544 | self.tempfiles = [] |
|
550 | 545 | |
|
551 | 546 | # Keep track of readline usage (later set by init_readline) |
|
552 | 547 | self.has_readline = False |
|
553 | 548 | |
|
554 | 549 | # keep track of where we started running (mainly for crash post-mortem) |
|
555 | 550 | # This is not being used anywhere currently. |
|
556 | 551 | self.starting_dir = os.getcwdu() |
|
557 | 552 | |
|
558 | 553 | # Indentation management |
|
559 | 554 | self.indent_current_nsp = 0 |
|
560 | 555 | |
|
561 | 556 | # Dict to track post-execution functions that have been registered |
|
562 | 557 | self._post_execute = {} |
|
563 | 558 | |
|
564 | 559 | def init_environment(self): |
|
565 | 560 | """Any changes we need to make to the user's environment.""" |
|
566 | 561 | pass |
|
567 | 562 | |
|
568 | 563 | def init_encoding(self): |
|
569 | 564 | # Get system encoding at startup time. Certain terminals (like Emacs |
|
570 | 565 | # under Win32 have it set to None, and we need to have a known valid |
|
571 | 566 | # encoding to use in the raw_input() method |
|
572 | 567 | try: |
|
573 | 568 | self.stdin_encoding = sys.stdin.encoding or 'ascii' |
|
574 | 569 | except AttributeError: |
|
575 | 570 | self.stdin_encoding = 'ascii' |
|
576 | 571 | |
|
577 | 572 | def init_syntax_highlighting(self): |
|
578 | 573 | # Python source parser/formatter for syntax highlighting |
|
579 | 574 | pyformat = PyColorize.Parser().format |
|
580 | 575 | self.pycolorize = lambda src: pyformat(src,'str',self.colors) |
|
581 | 576 | |
|
582 | 577 | def init_pushd_popd_magic(self): |
|
583 | 578 | # for pushd/popd management |
|
584 | 579 | self.home_dir = get_home_dir() |
|
585 | 580 | |
|
586 | 581 | self.dir_stack = [] |
|
587 | 582 | |
|
588 | 583 | def init_logger(self): |
|
589 | 584 | self.logger = Logger(self.home_dir, logfname='ipython_log.py', |
|
590 | 585 | logmode='rotate') |
|
591 | 586 | |
|
592 | 587 | def init_logstart(self): |
|
593 | 588 | """Initialize logging in case it was requested at the command line. |
|
594 | 589 | """ |
|
595 | 590 | if self.logappend: |
|
596 | 591 | self.magic_logstart(self.logappend + ' append') |
|
597 | 592 | elif self.logfile: |
|
598 | 593 | self.magic_logstart(self.logfile) |
|
599 | 594 | elif self.logstart: |
|
600 | 595 | self.magic_logstart() |
|
601 | 596 | |
|
602 | 597 | def init_builtins(self): |
|
603 | 598 | # A single, static flag that we set to True. Its presence indicates |
|
604 | 599 | # that an IPython shell has been created, and we make no attempts at |
|
605 | 600 | # removing on exit or representing the existence of more than one |
|
606 | 601 | # IPython at a time. |
|
607 | 602 | builtin_mod.__dict__['__IPYTHON__'] = True |
|
608 | 603 | |
|
609 | 604 | # In 0.11 we introduced '__IPYTHON__active' as an integer we'd try to |
|
610 | 605 | # manage on enter/exit, but with all our shells it's virtually |
|
611 | 606 | # impossible to get all the cases right. We're leaving the name in for |
|
612 | 607 | # those who adapted their codes to check for this flag, but will |
|
613 | 608 | # eventually remove it after a few more releases. |
|
614 | 609 | builtin_mod.__dict__['__IPYTHON__active'] = \ |
|
615 | 610 | 'Deprecated, check for __IPYTHON__' |
|
616 | 611 | |
|
617 | 612 | self.builtin_trap = BuiltinTrap(shell=self) |
|
618 | 613 | |
|
619 | 614 | def init_inspector(self): |
|
620 | 615 | # Object inspector |
|
621 | 616 | self.inspector = oinspect.Inspector(oinspect.InspectColors, |
|
622 | 617 | PyColorize.ANSICodeColors, |
|
623 | 618 | 'NoColor', |
|
624 | 619 | self.object_info_string_level) |
|
625 | 620 | |
|
626 | 621 | def init_io(self): |
|
627 | 622 | # This will just use sys.stdout and sys.stderr. If you want to |
|
628 | 623 | # override sys.stdout and sys.stderr themselves, you need to do that |
|
629 | 624 | # *before* instantiating this class, because io holds onto |
|
630 | 625 | # references to the underlying streams. |
|
631 | 626 | if sys.platform == 'win32' and self.has_readline: |
|
632 | 627 | io.stdout = io.stderr = io.IOStream(self.readline._outputfile) |
|
633 | 628 | else: |
|
634 | 629 | io.stdout = io.IOStream(sys.stdout) |
|
635 | 630 | io.stderr = io.IOStream(sys.stderr) |
|
636 | 631 | |
|
637 | 632 | def init_prompts(self): |
|
638 | 633 | self.prompt_manager = PromptManager(shell=self, config=self.config) |
|
639 | 634 | self.configurables.append(self.prompt_manager) |
|
640 | 635 | # Set system prompts, so that scripts can decide if they are running |
|
641 | 636 | # interactively. |
|
642 | 637 | sys.ps1 = 'In : ' |
|
643 | 638 | sys.ps2 = '...: ' |
|
644 | 639 | sys.ps3 = 'Out: ' |
|
645 | 640 | |
|
646 | 641 | def init_display_formatter(self): |
|
647 | 642 | self.display_formatter = DisplayFormatter(config=self.config) |
|
648 | 643 | self.configurables.append(self.display_formatter) |
|
649 | 644 | |
|
650 | 645 | def init_display_pub(self): |
|
651 | 646 | self.display_pub = self.display_pub_class(config=self.config) |
|
652 | 647 | self.configurables.append(self.display_pub) |
|
653 | 648 | |
|
654 | 649 | def init_displayhook(self): |
|
655 | 650 | # Initialize displayhook, set in/out prompts and printing system |
|
656 | 651 | self.displayhook = self.displayhook_class( |
|
657 | 652 | config=self.config, |
|
658 | 653 | shell=self, |
|
659 | 654 | cache_size=self.cache_size, |
|
660 | 655 | ) |
|
661 | 656 | self.configurables.append(self.displayhook) |
|
662 | 657 | # This is a context manager that installs/revmoes the displayhook at |
|
663 | 658 | # the appropriate time. |
|
664 | 659 | self.display_trap = DisplayTrap(hook=self.displayhook) |
|
665 | 660 | |
|
666 | 661 | def init_reload_doctest(self): |
|
667 | 662 | # Do a proper resetting of doctest, including the necessary displayhook |
|
668 | 663 | # monkeypatching |
|
669 | 664 | try: |
|
670 | 665 | doctest_reload() |
|
671 | 666 | except ImportError: |
|
672 | 667 | warn("doctest module does not exist.") |
|
673 | 668 | |
|
674 | 669 | def init_virtualenv(self): |
|
675 | 670 | """Add a virtualenv to sys.path so the user can import modules from it. |
|
676 | 671 | This isn't perfect: it doesn't use the Python interpreter with which the |
|
677 | 672 | virtualenv was built, and it ignores the --no-site-packages option. A |
|
678 | 673 | warning will appear suggesting the user installs IPython in the |
|
679 | 674 | virtualenv, but for many cases, it probably works well enough. |
|
680 | 675 | |
|
681 | 676 | Adapted from code snippets online. |
|
682 | 677 | |
|
683 | 678 | http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv |
|
684 | 679 | """ |
|
685 | 680 | if 'VIRTUAL_ENV' not in os.environ: |
|
686 | 681 | # Not in a virtualenv |
|
687 | 682 | return |
|
688 | 683 | |
|
689 | 684 | if sys.executable.startswith(os.environ['VIRTUAL_ENV']): |
|
690 | 685 | # Running properly in the virtualenv, don't need to do anything |
|
691 | 686 | return |
|
692 | 687 | |
|
693 | 688 | warn("Attempting to work in a virtualenv. If you encounter problems, please " |
|
694 | 689 | "install IPython inside the virtualenv.\n") |
|
695 | 690 | if sys.platform == "win32": |
|
696 | 691 | virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages') |
|
697 | 692 | else: |
|
698 | 693 | virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'lib', |
|
699 | 694 | 'python%d.%d' % sys.version_info[:2], 'site-packages') |
|
700 | 695 | |
|
701 | 696 | import site |
|
702 | 697 | sys.path.insert(0, virtual_env) |
|
703 | 698 | site.addsitedir(virtual_env) |
|
704 | 699 | |
|
705 | 700 | #------------------------------------------------------------------------- |
|
706 | 701 | # Things related to injections into the sys module |
|
707 | 702 | #------------------------------------------------------------------------- |
|
708 | 703 | |
|
709 | 704 | def save_sys_module_state(self): |
|
710 | 705 | """Save the state of hooks in the sys module. |
|
711 | 706 | |
|
712 | 707 | This has to be called after self.user_module is created. |
|
713 | 708 | """ |
|
714 | 709 | self._orig_sys_module_state = {} |
|
715 | 710 | self._orig_sys_module_state['stdin'] = sys.stdin |
|
716 | 711 | self._orig_sys_module_state['stdout'] = sys.stdout |
|
717 | 712 | self._orig_sys_module_state['stderr'] = sys.stderr |
|
718 | 713 | self._orig_sys_module_state['excepthook'] = sys.excepthook |
|
719 | 714 | self._orig_sys_modules_main_name = self.user_module.__name__ |
|
720 | 715 | |
|
721 | 716 | def restore_sys_module_state(self): |
|
722 | 717 | """Restore the state of the sys module.""" |
|
723 | 718 | try: |
|
724 | 719 | for k, v in self._orig_sys_module_state.iteritems(): |
|
725 | 720 | setattr(sys, k, v) |
|
726 | 721 | except AttributeError: |
|
727 | 722 | pass |
|
728 | 723 | # Reset what what done in self.init_sys_modules |
|
729 | 724 | sys.modules[self.user_module.__name__] = self._orig_sys_modules_main_name |
|
730 | 725 | |
|
731 | 726 | #------------------------------------------------------------------------- |
|
732 | 727 | # Things related to hooks |
|
733 | 728 | #------------------------------------------------------------------------- |
|
734 | 729 | |
|
735 | 730 | def init_hooks(self): |
|
736 | 731 | # hooks holds pointers used for user-side customizations |
|
737 | 732 | self.hooks = Struct() |
|
738 | 733 | |
|
739 | 734 | self.strdispatchers = {} |
|
740 | 735 | |
|
741 | 736 | # Set all default hooks, defined in the IPython.hooks module. |
|
742 | 737 | hooks = IPython.core.hooks |
|
743 | 738 | for hook_name in hooks.__all__: |
|
744 | 739 | # default hooks have priority 100, i.e. low; user hooks should have |
|
745 | 740 | # 0-100 priority |
|
746 | 741 | self.set_hook(hook_name,getattr(hooks,hook_name), 100) |
|
747 | 742 | |
|
748 | 743 | def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None): |
|
749 | 744 | """set_hook(name,hook) -> sets an internal IPython hook. |
|
750 | 745 | |
|
751 | 746 | IPython exposes some of its internal API as user-modifiable hooks. By |
|
752 | 747 | adding your function to one of these hooks, you can modify IPython's |
|
753 | 748 | behavior to call at runtime your own routines.""" |
|
754 | 749 | |
|
755 | 750 | # At some point in the future, this should validate the hook before it |
|
756 | 751 | # accepts it. Probably at least check that the hook takes the number |
|
757 | 752 | # of args it's supposed to. |
|
758 | 753 | |
|
759 | 754 | f = types.MethodType(hook,self) |
|
760 | 755 | |
|
761 | 756 | # check if the hook is for strdispatcher first |
|
762 | 757 | if str_key is not None: |
|
763 | 758 | sdp = self.strdispatchers.get(name, StrDispatch()) |
|
764 | 759 | sdp.add_s(str_key, f, priority ) |
|
765 | 760 | self.strdispatchers[name] = sdp |
|
766 | 761 | return |
|
767 | 762 | if re_key is not None: |
|
768 | 763 | sdp = self.strdispatchers.get(name, StrDispatch()) |
|
769 | 764 | sdp.add_re(re.compile(re_key), f, priority ) |
|
770 | 765 | self.strdispatchers[name] = sdp |
|
771 | 766 | return |
|
772 | 767 | |
|
773 | 768 | dp = getattr(self.hooks, name, None) |
|
774 | 769 | if name not in IPython.core.hooks.__all__: |
|
775 | 770 | print "Warning! Hook '%s' is not one of %s" % \ |
|
776 | 771 | (name, IPython.core.hooks.__all__ ) |
|
777 | 772 | if not dp: |
|
778 | 773 | dp = IPython.core.hooks.CommandChainDispatcher() |
|
779 | 774 | |
|
780 | 775 | try: |
|
781 | 776 | dp.add(f,priority) |
|
782 | 777 | except AttributeError: |
|
783 | 778 | # it was not commandchain, plain old func - replace |
|
784 | 779 | dp = f |
|
785 | 780 | |
|
786 | 781 | setattr(self.hooks,name, dp) |
|
787 | 782 | |
|
788 | 783 | def register_post_execute(self, func): |
|
789 | 784 | """Register a function for calling after code execution. |
|
790 | 785 | """ |
|
791 | 786 | if not callable(func): |
|
792 | 787 | raise ValueError('argument %s must be callable' % func) |
|
793 | 788 | self._post_execute[func] = True |
|
794 | 789 | |
|
795 | 790 | #------------------------------------------------------------------------- |
|
796 | 791 | # Things related to the "main" module |
|
797 | 792 | #------------------------------------------------------------------------- |
|
798 | 793 | |
|
799 | 794 | def new_main_mod(self,ns=None): |
|
800 | 795 | """Return a new 'main' module object for user code execution. |
|
801 | 796 | """ |
|
802 | 797 | main_mod = self._user_main_module |
|
803 | 798 | init_fakemod_dict(main_mod,ns) |
|
804 | 799 | return main_mod |
|
805 | 800 | |
|
806 | 801 | def cache_main_mod(self,ns,fname): |
|
807 | 802 | """Cache a main module's namespace. |
|
808 | 803 | |
|
809 | 804 | When scripts are executed via %run, we must keep a reference to the |
|
810 | 805 | namespace of their __main__ module (a FakeModule instance) around so |
|
811 | 806 | that Python doesn't clear it, rendering objects defined therein |
|
812 | 807 | useless. |
|
813 | 808 | |
|
814 | 809 | This method keeps said reference in a private dict, keyed by the |
|
815 | 810 | absolute path of the module object (which corresponds to the script |
|
816 | 811 | path). This way, for multiple executions of the same script we only |
|
817 | 812 | keep one copy of the namespace (the last one), thus preventing memory |
|
818 | 813 | leaks from old references while allowing the objects from the last |
|
819 | 814 | execution to be accessible. |
|
820 | 815 | |
|
821 | 816 | Note: we can not allow the actual FakeModule instances to be deleted, |
|
822 | 817 | because of how Python tears down modules (it hard-sets all their |
|
823 | 818 | references to None without regard for reference counts). This method |
|
824 | 819 | must therefore make a *copy* of the given namespace, to allow the |
|
825 | 820 | original module's __dict__ to be cleared and reused. |
|
826 | 821 | |
|
827 | 822 | |
|
828 | 823 | Parameters |
|
829 | 824 | ---------- |
|
830 | 825 | ns : a namespace (a dict, typically) |
|
831 | 826 | |
|
832 | 827 | fname : str |
|
833 | 828 | Filename associated with the namespace. |
|
834 | 829 | |
|
835 | 830 | Examples |
|
836 | 831 | -------- |
|
837 | 832 | |
|
838 | 833 | In [10]: import IPython |
|
839 | 834 | |
|
840 | 835 | In [11]: _ip.cache_main_mod(IPython.__dict__,IPython.__file__) |
|
841 | 836 | |
|
842 | 837 | In [12]: IPython.__file__ in _ip._main_ns_cache |
|
843 | 838 | Out[12]: True |
|
844 | 839 | """ |
|
845 | 840 | self._main_ns_cache[os.path.abspath(fname)] = ns.copy() |
|
846 | 841 | |
|
847 | 842 | def clear_main_mod_cache(self): |
|
848 | 843 | """Clear the cache of main modules. |
|
849 | 844 | |
|
850 | 845 | Mainly for use by utilities like %reset. |
|
851 | 846 | |
|
852 | 847 | Examples |
|
853 | 848 | -------- |
|
854 | 849 | |
|
855 | 850 | In [15]: import IPython |
|
856 | 851 | |
|
857 | 852 | In [16]: _ip.cache_main_mod(IPython.__dict__,IPython.__file__) |
|
858 | 853 | |
|
859 | 854 | In [17]: len(_ip._main_ns_cache) > 0 |
|
860 | 855 | Out[17]: True |
|
861 | 856 | |
|
862 | 857 | In [18]: _ip.clear_main_mod_cache() |
|
863 | 858 | |
|
864 | 859 | In [19]: len(_ip._main_ns_cache) == 0 |
|
865 | 860 | Out[19]: True |
|
866 | 861 | """ |
|
867 | 862 | self._main_ns_cache.clear() |
|
868 | 863 | |
|
869 | 864 | #------------------------------------------------------------------------- |
|
870 | 865 | # Things related to debugging |
|
871 | 866 | #------------------------------------------------------------------------- |
|
872 | 867 | |
|
873 | 868 | def init_pdb(self): |
|
874 | 869 | # Set calling of pdb on exceptions |
|
875 | 870 | # self.call_pdb is a property |
|
876 | 871 | self.call_pdb = self.pdb |
|
877 | 872 | |
|
878 | 873 | def _get_call_pdb(self): |
|
879 | 874 | return self._call_pdb |
|
880 | 875 | |
|
881 | 876 | def _set_call_pdb(self,val): |
|
882 | 877 | |
|
883 | 878 | if val not in (0,1,False,True): |
|
884 | 879 | raise ValueError,'new call_pdb value must be boolean' |
|
885 | 880 | |
|
886 | 881 | # store value in instance |
|
887 | 882 | self._call_pdb = val |
|
888 | 883 | |
|
889 | 884 | # notify the actual exception handlers |
|
890 | 885 | self.InteractiveTB.call_pdb = val |
|
891 | 886 | |
|
892 | 887 | call_pdb = property(_get_call_pdb,_set_call_pdb,None, |
|
893 | 888 | 'Control auto-activation of pdb at exceptions') |
|
894 | 889 | |
|
895 | 890 | def debugger(self,force=False): |
|
896 | 891 | """Call the pydb/pdb debugger. |
|
897 | 892 | |
|
898 | 893 | Keywords: |
|
899 | 894 | |
|
900 | 895 | - force(False): by default, this routine checks the instance call_pdb |
|
901 | 896 | flag and does not actually invoke the debugger if the flag is false. |
|
902 | 897 | The 'force' option forces the debugger to activate even if the flag |
|
903 | 898 | is false. |
|
904 | 899 | """ |
|
905 | 900 | |
|
906 | 901 | if not (force or self.call_pdb): |
|
907 | 902 | return |
|
908 | 903 | |
|
909 | 904 | if not hasattr(sys,'last_traceback'): |
|
910 | 905 | error('No traceback has been produced, nothing to debug.') |
|
911 | 906 | return |
|
912 | 907 | |
|
913 | 908 | # use pydb if available |
|
914 | 909 | if debugger.has_pydb: |
|
915 | 910 | from pydb import pm |
|
916 | 911 | else: |
|
917 | 912 | # fallback to our internal debugger |
|
918 | 913 | pm = lambda : self.InteractiveTB.debugger(force=True) |
|
919 | 914 | |
|
920 | 915 | with self.readline_no_record: |
|
921 | 916 | pm() |
|
922 | 917 | |
|
923 | 918 | #------------------------------------------------------------------------- |
|
924 | 919 | # Things related to IPython's various namespaces |
|
925 | 920 | #------------------------------------------------------------------------- |
|
926 | 921 | default_user_namespaces = True |
|
927 | 922 | |
|
928 | 923 | def init_create_namespaces(self, user_module=None, user_ns=None): |
|
929 | 924 | # Create the namespace where the user will operate. user_ns is |
|
930 | 925 | # normally the only one used, and it is passed to the exec calls as |
|
931 | 926 | # the locals argument. But we do carry a user_global_ns namespace |
|
932 | 927 | # given as the exec 'globals' argument, This is useful in embedding |
|
933 | 928 | # situations where the ipython shell opens in a context where the |
|
934 | 929 | # distinction between locals and globals is meaningful. For |
|
935 | 930 | # non-embedded contexts, it is just the same object as the user_ns dict. |
|
936 | 931 | |
|
937 | 932 | # FIXME. For some strange reason, __builtins__ is showing up at user |
|
938 | 933 | # level as a dict instead of a module. This is a manual fix, but I |
|
939 | 934 | # should really track down where the problem is coming from. Alex |
|
940 | 935 | # Schmolck reported this problem first. |
|
941 | 936 | |
|
942 | 937 | # A useful post by Alex Martelli on this topic: |
|
943 | 938 | # Re: inconsistent value from __builtins__ |
|
944 | 939 | # Von: Alex Martelli <aleaxit@yahoo.com> |
|
945 | 940 | # Datum: Freitag 01 Oktober 2004 04:45:34 nachmittags/abends |
|
946 | 941 | # Gruppen: comp.lang.python |
|
947 | 942 | |
|
948 | 943 | # Michael Hohn <hohn@hooknose.lbl.gov> wrote: |
|
949 | 944 | # > >>> print type(builtin_check.get_global_binding('__builtins__')) |
|
950 | 945 | # > <type 'dict'> |
|
951 | 946 | # > >>> print type(__builtins__) |
|
952 | 947 | # > <type 'module'> |
|
953 | 948 | # > Is this difference in return value intentional? |
|
954 | 949 | |
|
955 | 950 | # Well, it's documented that '__builtins__' can be either a dictionary |
|
956 | 951 | # or a module, and it's been that way for a long time. Whether it's |
|
957 | 952 | # intentional (or sensible), I don't know. In any case, the idea is |
|
958 | 953 | # that if you need to access the built-in namespace directly, you |
|
959 | 954 | # should start with "import __builtin__" (note, no 's') which will |
|
960 | 955 | # definitely give you a module. Yeah, it's somewhat confusing:-(. |
|
961 | 956 | |
|
962 | 957 | # These routines return a properly built module and dict as needed by |
|
963 | 958 | # the rest of the code, and can also be used by extension writers to |
|
964 | 959 | # generate properly initialized namespaces. |
|
965 | 960 | if (user_ns is not None) or (user_module is not None): |
|
966 | 961 | self.default_user_namespaces = False |
|
967 | 962 | self.user_module, self.user_ns = self.prepare_user_module(user_module, user_ns) |
|
968 | 963 | |
|
969 | 964 | # A record of hidden variables we have added to the user namespace, so |
|
970 | 965 | # we can list later only variables defined in actual interactive use. |
|
971 | 966 | self.user_ns_hidden = set() |
|
972 | 967 | |
|
973 | 968 | # Now that FakeModule produces a real module, we've run into a nasty |
|
974 | 969 | # problem: after script execution (via %run), the module where the user |
|
975 | 970 | # code ran is deleted. Now that this object is a true module (needed |
|
976 | 971 | # so docetst and other tools work correctly), the Python module |
|
977 | 972 | # teardown mechanism runs over it, and sets to None every variable |
|
978 | 973 | # present in that module. Top-level references to objects from the |
|
979 | 974 | # script survive, because the user_ns is updated with them. However, |
|
980 | 975 | # calling functions defined in the script that use other things from |
|
981 | 976 | # the script will fail, because the function's closure had references |
|
982 | 977 | # to the original objects, which are now all None. So we must protect |
|
983 | 978 | # these modules from deletion by keeping a cache. |
|
984 | 979 | # |
|
985 | 980 | # To avoid keeping stale modules around (we only need the one from the |
|
986 | 981 | # last run), we use a dict keyed with the full path to the script, so |
|
987 | 982 | # only the last version of the module is held in the cache. Note, |
|
988 | 983 | # however, that we must cache the module *namespace contents* (their |
|
989 | 984 | # __dict__). Because if we try to cache the actual modules, old ones |
|
990 | 985 | # (uncached) could be destroyed while still holding references (such as |
|
991 | 986 | # those held by GUI objects that tend to be long-lived)> |
|
992 | 987 | # |
|
993 | 988 | # The %reset command will flush this cache. See the cache_main_mod() |
|
994 | 989 | # and clear_main_mod_cache() methods for details on use. |
|
995 | 990 | |
|
996 | 991 | # This is the cache used for 'main' namespaces |
|
997 | 992 | self._main_ns_cache = {} |
|
998 | 993 | # And this is the single instance of FakeModule whose __dict__ we keep |
|
999 | 994 | # copying and clearing for reuse on each %run |
|
1000 | 995 | self._user_main_module = FakeModule() |
|
1001 | 996 | |
|
1002 | 997 | # A table holding all the namespaces IPython deals with, so that |
|
1003 | 998 | # introspection facilities can search easily. |
|
1004 | 999 | self.ns_table = {'user_global':self.user_module.__dict__, |
|
1005 | 1000 | 'user_local':self.user_ns, |
|
1006 | 1001 | 'builtin':builtin_mod.__dict__ |
|
1007 | 1002 | } |
|
1008 | 1003 | |
|
1009 | 1004 | @property |
|
1010 | 1005 | def user_global_ns(self): |
|
1011 | 1006 | return self.user_module.__dict__ |
|
1012 | 1007 | |
|
1013 | 1008 | def prepare_user_module(self, user_module=None, user_ns=None): |
|
1014 | 1009 | """Prepare the module and namespace in which user code will be run. |
|
1015 | 1010 | |
|
1016 | 1011 | When IPython is started normally, both parameters are None: a new module |
|
1017 | 1012 | is created automatically, and its __dict__ used as the namespace. |
|
1018 | 1013 | |
|
1019 | 1014 | If only user_module is provided, its __dict__ is used as the namespace. |
|
1020 | 1015 | If only user_ns is provided, a dummy module is created, and user_ns |
|
1021 | 1016 | becomes the global namespace. If both are provided (as they may be |
|
1022 | 1017 | when embedding), user_ns is the local namespace, and user_module |
|
1023 | 1018 | provides the global namespace. |
|
1024 | 1019 | |
|
1025 | 1020 | Parameters |
|
1026 | 1021 | ---------- |
|
1027 | 1022 | user_module : module, optional |
|
1028 | 1023 | The current user module in which IPython is being run. If None, |
|
1029 | 1024 | a clean module will be created. |
|
1030 | 1025 | user_ns : dict, optional |
|
1031 | 1026 | A namespace in which to run interactive commands. |
|
1032 | 1027 | |
|
1033 | 1028 | Returns |
|
1034 | 1029 | ------- |
|
1035 | 1030 | A tuple of user_module and user_ns, each properly initialised. |
|
1036 | 1031 | """ |
|
1037 | 1032 | if user_module is None and user_ns is not None: |
|
1038 | 1033 | user_ns.setdefault("__name__", "__main__") |
|
1039 | 1034 | class DummyMod(object): |
|
1040 | 1035 | "A dummy module used for IPython's interactive namespace." |
|
1041 | 1036 | pass |
|
1042 | 1037 | user_module = DummyMod() |
|
1043 | 1038 | user_module.__dict__ = user_ns |
|
1044 | 1039 | |
|
1045 | 1040 | if user_module is None: |
|
1046 | 1041 | user_module = types.ModuleType("__main__", |
|
1047 | 1042 | doc="Automatically created module for IPython interactive environment") |
|
1048 | 1043 | |
|
1049 | 1044 | # We must ensure that __builtin__ (without the final 's') is always |
|
1050 | 1045 | # available and pointing to the __builtin__ *module*. For more details: |
|
1051 | 1046 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html |
|
1052 | 1047 | user_module.__dict__.setdefault('__builtin__', builtin_mod) |
|
1053 | 1048 | user_module.__dict__.setdefault('__builtins__', builtin_mod) |
|
1054 | 1049 | |
|
1055 | 1050 | if user_ns is None: |
|
1056 | 1051 | user_ns = user_module.__dict__ |
|
1057 | 1052 | |
|
1058 | 1053 | return user_module, user_ns |
|
1059 | 1054 | |
|
1060 | 1055 | def init_sys_modules(self): |
|
1061 | 1056 | # We need to insert into sys.modules something that looks like a |
|
1062 | 1057 | # module but which accesses the IPython namespace, for shelve and |
|
1063 | 1058 | # pickle to work interactively. Normally they rely on getting |
|
1064 | 1059 | # everything out of __main__, but for embedding purposes each IPython |
|
1065 | 1060 | # instance has its own private namespace, so we can't go shoving |
|
1066 | 1061 | # everything into __main__. |
|
1067 | 1062 | |
|
1068 | 1063 | # note, however, that we should only do this for non-embedded |
|
1069 | 1064 | # ipythons, which really mimic the __main__.__dict__ with their own |
|
1070 | 1065 | # namespace. Embedded instances, on the other hand, should not do |
|
1071 | 1066 | # this because they need to manage the user local/global namespaces |
|
1072 | 1067 | # only, but they live within a 'normal' __main__ (meaning, they |
|
1073 | 1068 | # shouldn't overtake the execution environment of the script they're |
|
1074 | 1069 | # embedded in). |
|
1075 | 1070 | |
|
1076 | 1071 | # This is overridden in the InteractiveShellEmbed subclass to a no-op. |
|
1077 | 1072 | main_name = self.user_module.__name__ |
|
1078 | 1073 | sys.modules[main_name] = self.user_module |
|
1079 | 1074 | |
|
1080 | 1075 | def init_user_ns(self): |
|
1081 | 1076 | """Initialize all user-visible namespaces to their minimum defaults. |
|
1082 | 1077 | |
|
1083 | 1078 | Certain history lists are also initialized here, as they effectively |
|
1084 | 1079 | act as user namespaces. |
|
1085 | 1080 | |
|
1086 | 1081 | Notes |
|
1087 | 1082 | ----- |
|
1088 | 1083 | All data structures here are only filled in, they are NOT reset by this |
|
1089 | 1084 | method. If they were not empty before, data will simply be added to |
|
1090 | 1085 | therm. |
|
1091 | 1086 | """ |
|
1092 | 1087 | # This function works in two parts: first we put a few things in |
|
1093 | 1088 | # user_ns, and we sync that contents into user_ns_hidden so that these |
|
1094 | 1089 | # initial variables aren't shown by %who. After the sync, we add the |
|
1095 | 1090 | # rest of what we *do* want the user to see with %who even on a new |
|
1096 | 1091 | # session (probably nothing, so theye really only see their own stuff) |
|
1097 | 1092 | |
|
1098 | 1093 | # The user dict must *always* have a __builtin__ reference to the |
|
1099 | 1094 | # Python standard __builtin__ namespace, which must be imported. |
|
1100 | 1095 | # This is so that certain operations in prompt evaluation can be |
|
1101 | 1096 | # reliably executed with builtins. Note that we can NOT use |
|
1102 | 1097 | # __builtins__ (note the 's'), because that can either be a dict or a |
|
1103 | 1098 | # module, and can even mutate at runtime, depending on the context |
|
1104 | 1099 | # (Python makes no guarantees on it). In contrast, __builtin__ is |
|
1105 | 1100 | # always a module object, though it must be explicitly imported. |
|
1106 | 1101 | |
|
1107 | 1102 | # For more details: |
|
1108 | 1103 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html |
|
1109 | 1104 | ns = dict() |
|
1110 | 1105 | |
|
1111 | 1106 | # Put 'help' in the user namespace |
|
1112 | 1107 | try: |
|
1113 | 1108 | from site import _Helper |
|
1114 | 1109 | ns['help'] = _Helper() |
|
1115 | 1110 | except ImportError: |
|
1116 | 1111 | warn('help() not available - check site.py') |
|
1117 | 1112 | |
|
1118 | 1113 | # make global variables for user access to the histories |
|
1119 | 1114 | ns['_ih'] = self.history_manager.input_hist_parsed |
|
1120 | 1115 | ns['_oh'] = self.history_manager.output_hist |
|
1121 | 1116 | ns['_dh'] = self.history_manager.dir_hist |
|
1122 | 1117 | |
|
1123 | 1118 | ns['_sh'] = shadowns |
|
1124 | 1119 | |
|
1125 | 1120 | # user aliases to input and output histories. These shouldn't show up |
|
1126 | 1121 | # in %who, as they can have very large reprs. |
|
1127 | 1122 | ns['In'] = self.history_manager.input_hist_parsed |
|
1128 | 1123 | ns['Out'] = self.history_manager.output_hist |
|
1129 | 1124 | |
|
1130 | 1125 | # Store myself as the public api!!! |
|
1131 | 1126 | ns['get_ipython'] = self.get_ipython |
|
1132 | 1127 | |
|
1133 | 1128 | ns['exit'] = self.exiter |
|
1134 | 1129 | ns['quit'] = self.exiter |
|
1135 | 1130 | |
|
1136 | 1131 | # Sync what we've added so far to user_ns_hidden so these aren't seen |
|
1137 | 1132 | # by %who |
|
1138 | 1133 | self.user_ns_hidden.update(ns) |
|
1139 | 1134 | |
|
1140 | 1135 | # Anything put into ns now would show up in %who. Think twice before |
|
1141 | 1136 | # putting anything here, as we really want %who to show the user their |
|
1142 | 1137 | # stuff, not our variables. |
|
1143 | 1138 | |
|
1144 | 1139 | # Finally, update the real user's namespace |
|
1145 | 1140 | self.user_ns.update(ns) |
|
1146 | 1141 | |
|
1147 | 1142 | @property |
|
1148 | 1143 | def all_ns_refs(self): |
|
1149 | 1144 | """Get a list of references to all the namespace dictionaries in which |
|
1150 | 1145 | IPython might store a user-created object. |
|
1151 | 1146 | |
|
1152 | 1147 | Note that this does not include the displayhook, which also caches |
|
1153 | 1148 | objects from the output.""" |
|
1154 | 1149 | return [self.user_ns, self.user_global_ns, |
|
1155 | 1150 | self._user_main_module.__dict__] + self._main_ns_cache.values() |
|
1156 | 1151 | |
|
1157 | 1152 | def reset(self, new_session=True): |
|
1158 | 1153 | """Clear all internal namespaces, and attempt to release references to |
|
1159 | 1154 | user objects. |
|
1160 | 1155 | |
|
1161 | 1156 | If new_session is True, a new history session will be opened. |
|
1162 | 1157 | """ |
|
1163 | 1158 | # Clear histories |
|
1164 | 1159 | self.history_manager.reset(new_session) |
|
1165 | 1160 | # Reset counter used to index all histories |
|
1166 | 1161 | if new_session: |
|
1167 | 1162 | self.execution_count = 1 |
|
1168 | 1163 | |
|
1169 | 1164 | # Flush cached output items |
|
1170 | 1165 | if self.displayhook.do_full_cache: |
|
1171 | 1166 | self.displayhook.flush() |
|
1172 | 1167 | |
|
1173 | 1168 | # The main execution namespaces must be cleared very carefully, |
|
1174 | 1169 | # skipping the deletion of the builtin-related keys, because doing so |
|
1175 | 1170 | # would cause errors in many object's __del__ methods. |
|
1176 | 1171 | if self.user_ns is not self.user_global_ns: |
|
1177 | 1172 | self.user_ns.clear() |
|
1178 | 1173 | ns = self.user_global_ns |
|
1179 | 1174 | drop_keys = set(ns.keys()) |
|
1180 | 1175 | drop_keys.discard('__builtin__') |
|
1181 | 1176 | drop_keys.discard('__builtins__') |
|
1182 | 1177 | drop_keys.discard('__name__') |
|
1183 | 1178 | for k in drop_keys: |
|
1184 | 1179 | del ns[k] |
|
1185 | 1180 | |
|
1186 | 1181 | self.user_ns_hidden.clear() |
|
1187 | 1182 | |
|
1188 | 1183 | # Restore the user namespaces to minimal usability |
|
1189 | 1184 | self.init_user_ns() |
|
1190 | 1185 | |
|
1191 | 1186 | # Restore the default and user aliases |
|
1192 | 1187 | self.alias_manager.clear_aliases() |
|
1193 | 1188 | self.alias_manager.init_aliases() |
|
1194 | 1189 | |
|
1195 | 1190 | # Flush the private list of module references kept for script |
|
1196 | 1191 | # execution protection |
|
1197 | 1192 | self.clear_main_mod_cache() |
|
1198 | 1193 | |
|
1199 | 1194 | # Clear out the namespace from the last %run |
|
1200 | 1195 | self.new_main_mod() |
|
1201 | 1196 | |
|
1202 | 1197 | def del_var(self, varname, by_name=False): |
|
1203 | 1198 | """Delete a variable from the various namespaces, so that, as |
|
1204 | 1199 | far as possible, we're not keeping any hidden references to it. |
|
1205 | 1200 | |
|
1206 | 1201 | Parameters |
|
1207 | 1202 | ---------- |
|
1208 | 1203 | varname : str |
|
1209 | 1204 | The name of the variable to delete. |
|
1210 | 1205 | by_name : bool |
|
1211 | 1206 | If True, delete variables with the given name in each |
|
1212 | 1207 | namespace. If False (default), find the variable in the user |
|
1213 | 1208 | namespace, and delete references to it. |
|
1214 | 1209 | """ |
|
1215 | 1210 | if varname in ('__builtin__', '__builtins__'): |
|
1216 | 1211 | raise ValueError("Refusing to delete %s" % varname) |
|
1217 | 1212 | |
|
1218 | 1213 | ns_refs = self.all_ns_refs |
|
1219 | 1214 | |
|
1220 | 1215 | if by_name: # Delete by name |
|
1221 | 1216 | for ns in ns_refs: |
|
1222 | 1217 | try: |
|
1223 | 1218 | del ns[varname] |
|
1224 | 1219 | except KeyError: |
|
1225 | 1220 | pass |
|
1226 | 1221 | else: # Delete by object |
|
1227 | 1222 | try: |
|
1228 | 1223 | obj = self.user_ns[varname] |
|
1229 | 1224 | except KeyError: |
|
1230 | 1225 | raise NameError("name '%s' is not defined" % varname) |
|
1231 | 1226 | # Also check in output history |
|
1232 | 1227 | ns_refs.append(self.history_manager.output_hist) |
|
1233 | 1228 | for ns in ns_refs: |
|
1234 | 1229 | to_delete = [n for n, o in ns.iteritems() if o is obj] |
|
1235 | 1230 | for name in to_delete: |
|
1236 | 1231 | del ns[name] |
|
1237 | 1232 | |
|
1238 | 1233 | # displayhook keeps extra references, but not in a dictionary |
|
1239 | 1234 | for name in ('_', '__', '___'): |
|
1240 | 1235 | if getattr(self.displayhook, name) is obj: |
|
1241 | 1236 | setattr(self.displayhook, name, None) |
|
1242 | 1237 | |
|
1243 | 1238 | def reset_selective(self, regex=None): |
|
1244 | 1239 | """Clear selective variables from internal namespaces based on a |
|
1245 | 1240 | specified regular expression. |
|
1246 | 1241 | |
|
1247 | 1242 | Parameters |
|
1248 | 1243 | ---------- |
|
1249 | 1244 | regex : string or compiled pattern, optional |
|
1250 | 1245 | A regular expression pattern that will be used in searching |
|
1251 | 1246 | variable names in the users namespaces. |
|
1252 | 1247 | """ |
|
1253 | 1248 | if regex is not None: |
|
1254 | 1249 | try: |
|
1255 | 1250 | m = re.compile(regex) |
|
1256 | 1251 | except TypeError: |
|
1257 | 1252 | raise TypeError('regex must be a string or compiled pattern') |
|
1258 | 1253 | # Search for keys in each namespace that match the given regex |
|
1259 | 1254 | # If a match is found, delete the key/value pair. |
|
1260 | 1255 | for ns in self.all_ns_refs: |
|
1261 | 1256 | for var in ns: |
|
1262 | 1257 | if m.search(var): |
|
1263 | 1258 | del ns[var] |
|
1264 | 1259 | |
|
1265 | 1260 | def push(self, variables, interactive=True): |
|
1266 | 1261 | """Inject a group of variables into the IPython user namespace. |
|
1267 | 1262 | |
|
1268 | 1263 | Parameters |
|
1269 | 1264 | ---------- |
|
1270 | 1265 | variables : dict, str or list/tuple of str |
|
1271 | 1266 | The variables to inject into the user's namespace. If a dict, a |
|
1272 | 1267 | simple update is done. If a str, the string is assumed to have |
|
1273 | 1268 | variable names separated by spaces. A list/tuple of str can also |
|
1274 | 1269 | be used to give the variable names. If just the variable names are |
|
1275 | 1270 | give (list/tuple/str) then the variable values looked up in the |
|
1276 | 1271 | callers frame. |
|
1277 | 1272 | interactive : bool |
|
1278 | 1273 | If True (default), the variables will be listed with the ``who`` |
|
1279 | 1274 | magic. |
|
1280 | 1275 | """ |
|
1281 | 1276 | vdict = None |
|
1282 | 1277 | |
|
1283 | 1278 | # We need a dict of name/value pairs to do namespace updates. |
|
1284 | 1279 | if isinstance(variables, dict): |
|
1285 | 1280 | vdict = variables |
|
1286 | 1281 | elif isinstance(variables, (basestring, list, tuple)): |
|
1287 | 1282 | if isinstance(variables, basestring): |
|
1288 | 1283 | vlist = variables.split() |
|
1289 | 1284 | else: |
|
1290 | 1285 | vlist = variables |
|
1291 | 1286 | vdict = {} |
|
1292 | 1287 | cf = sys._getframe(1) |
|
1293 | 1288 | for name in vlist: |
|
1294 | 1289 | try: |
|
1295 | 1290 | vdict[name] = eval(name, cf.f_globals, cf.f_locals) |
|
1296 | 1291 | except: |
|
1297 | 1292 | print ('Could not get variable %s from %s' % |
|
1298 | 1293 | (name,cf.f_code.co_name)) |
|
1299 | 1294 | else: |
|
1300 | 1295 | raise ValueError('variables must be a dict/str/list/tuple') |
|
1301 | 1296 | |
|
1302 | 1297 | # Propagate variables to user namespace |
|
1303 | 1298 | self.user_ns.update(vdict) |
|
1304 | 1299 | |
|
1305 | 1300 | # And configure interactive visibility |
|
1306 | 1301 | user_ns_hidden = self.user_ns_hidden |
|
1307 | 1302 | if interactive: |
|
1308 | 1303 | user_ns_hidden.difference_update(vdict) |
|
1309 | 1304 | else: |
|
1310 | 1305 | user_ns_hidden.update(vdict) |
|
1311 | 1306 | |
|
1312 | 1307 | def drop_by_id(self, variables): |
|
1313 | 1308 | """Remove a dict of variables from the user namespace, if they are the |
|
1314 | 1309 | same as the values in the dictionary. |
|
1315 | 1310 | |
|
1316 | 1311 | This is intended for use by extensions: variables that they've added can |
|
1317 | 1312 | be taken back out if they are unloaded, without removing any that the |
|
1318 | 1313 | user has overwritten. |
|
1319 | 1314 | |
|
1320 | 1315 | Parameters |
|
1321 | 1316 | ---------- |
|
1322 | 1317 | variables : dict |
|
1323 | 1318 | A dictionary mapping object names (as strings) to the objects. |
|
1324 | 1319 | """ |
|
1325 | 1320 | for name, obj in variables.iteritems(): |
|
1326 | 1321 | if name in self.user_ns and self.user_ns[name] is obj: |
|
1327 | 1322 | del self.user_ns[name] |
|
1328 | 1323 | self.user_ns_hidden.discard(name) |
|
1329 | 1324 | |
|
1330 | 1325 | #------------------------------------------------------------------------- |
|
1331 | 1326 | # Things related to object introspection |
|
1332 | 1327 | #------------------------------------------------------------------------- |
|
1333 | 1328 | |
|
1334 | 1329 | def _ofind(self, oname, namespaces=None): |
|
1335 | 1330 | """Find an object in the available namespaces. |
|
1336 | 1331 | |
|
1337 | 1332 | self._ofind(oname) -> dict with keys: found,obj,ospace,ismagic |
|
1338 | 1333 | |
|
1339 | 1334 | Has special code to detect magic functions. |
|
1340 | 1335 | """ |
|
1341 | 1336 | oname = oname.strip() |
|
1342 | 1337 | #print '1- oname: <%r>' % oname # dbg |
|
1343 | 1338 | if not py3compat.isidentifier(oname.lstrip(ESC_MAGIC), dotted=True): |
|
1344 | 1339 | return dict(found=False) |
|
1345 | 1340 | |
|
1346 | 1341 | alias_ns = None |
|
1347 | 1342 | if namespaces is None: |
|
1348 | 1343 | # Namespaces to search in: |
|
1349 | 1344 | # Put them in a list. The order is important so that we |
|
1350 | 1345 | # find things in the same order that Python finds them. |
|
1351 | 1346 | namespaces = [ ('Interactive', self.user_ns), |
|
1352 | 1347 | ('Interactive (global)', self.user_global_ns), |
|
1353 | 1348 | ('Python builtin', builtin_mod.__dict__), |
|
1354 | 1349 | ('Alias', self.alias_manager.alias_table), |
|
1355 | 1350 | ] |
|
1356 | 1351 | alias_ns = self.alias_manager.alias_table |
|
1357 | 1352 | |
|
1358 | 1353 | # initialize results to 'null' |
|
1359 | 1354 | found = False; obj = None; ospace = None; ds = None; |
|
1360 | 1355 | ismagic = False; isalias = False; parent = None |
|
1361 | 1356 | |
|
1362 | 1357 | # We need to special-case 'print', which as of python2.6 registers as a |
|
1363 | 1358 | # function but should only be treated as one if print_function was |
|
1364 | 1359 | # loaded with a future import. In this case, just bail. |
|
1365 | 1360 | if (oname == 'print' and not py3compat.PY3 and not \ |
|
1366 | 1361 | (self.compile.compiler_flags & __future__.CO_FUTURE_PRINT_FUNCTION)): |
|
1367 | 1362 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
1368 | 1363 | 'ismagic':ismagic, 'isalias':isalias, 'parent':parent} |
|
1369 | 1364 | |
|
1370 | 1365 | # Look for the given name by splitting it in parts. If the head is |
|
1371 | 1366 | # found, then we look for all the remaining parts as members, and only |
|
1372 | 1367 | # declare success if we can find them all. |
|
1373 | 1368 | oname_parts = oname.split('.') |
|
1374 | 1369 | oname_head, oname_rest = oname_parts[0],oname_parts[1:] |
|
1375 | 1370 | for nsname,ns in namespaces: |
|
1376 | 1371 | try: |
|
1377 | 1372 | obj = ns[oname_head] |
|
1378 | 1373 | except KeyError: |
|
1379 | 1374 | continue |
|
1380 | 1375 | else: |
|
1381 | 1376 | #print 'oname_rest:', oname_rest # dbg |
|
1382 | 1377 | for part in oname_rest: |
|
1383 | 1378 | try: |
|
1384 | 1379 | parent = obj |
|
1385 | 1380 | obj = getattr(obj,part) |
|
1386 | 1381 | except: |
|
1387 | 1382 | # Blanket except b/c some badly implemented objects |
|
1388 | 1383 | # allow __getattr__ to raise exceptions other than |
|
1389 | 1384 | # AttributeError, which then crashes IPython. |
|
1390 | 1385 | break |
|
1391 | 1386 | else: |
|
1392 | 1387 | # If we finish the for loop (no break), we got all members |
|
1393 | 1388 | found = True |
|
1394 | 1389 | ospace = nsname |
|
1395 | 1390 | if ns == alias_ns: |
|
1396 | 1391 | isalias = True |
|
1397 | 1392 | break # namespace loop |
|
1398 | 1393 | |
|
1399 | 1394 | # Try to see if it's magic |
|
1400 | 1395 | if not found: |
|
1401 | 1396 | if oname.startswith(ESC_MAGIC): |
|
1402 | 1397 | oname = oname[1:] |
|
1403 | 1398 | obj = getattr(self,'magic_'+oname,None) |
|
1404 | 1399 | if obj is not None: |
|
1405 | 1400 | found = True |
|
1406 | 1401 | ospace = 'IPython internal' |
|
1407 | 1402 | ismagic = True |
|
1408 | 1403 | |
|
1409 | 1404 | # Last try: special-case some literals like '', [], {}, etc: |
|
1410 | 1405 | if not found and oname_head in ["''",'""','[]','{}','()']: |
|
1411 | 1406 | obj = eval(oname_head) |
|
1412 | 1407 | found = True |
|
1413 | 1408 | ospace = 'Interactive' |
|
1414 | 1409 | |
|
1415 | 1410 | return {'found':found, 'obj':obj, 'namespace':ospace, |
|
1416 | 1411 | 'ismagic':ismagic, 'isalias':isalias, 'parent':parent} |
|
1417 | 1412 | |
|
1418 | 1413 | def _ofind_property(self, oname, info): |
|
1419 | 1414 | """Second part of object finding, to look for property details.""" |
|
1420 | 1415 | if info.found: |
|
1421 | 1416 | # Get the docstring of the class property if it exists. |
|
1422 | 1417 | path = oname.split('.') |
|
1423 | 1418 | root = '.'.join(path[:-1]) |
|
1424 | 1419 | if info.parent is not None: |
|
1425 | 1420 | try: |
|
1426 | 1421 | target = getattr(info.parent, '__class__') |
|
1427 | 1422 | # The object belongs to a class instance. |
|
1428 | 1423 | try: |
|
1429 | 1424 | target = getattr(target, path[-1]) |
|
1430 | 1425 | # The class defines the object. |
|
1431 | 1426 | if isinstance(target, property): |
|
1432 | 1427 | oname = root + '.__class__.' + path[-1] |
|
1433 | 1428 | info = Struct(self._ofind(oname)) |
|
1434 | 1429 | except AttributeError: pass |
|
1435 | 1430 | except AttributeError: pass |
|
1436 | 1431 | |
|
1437 | 1432 | # We return either the new info or the unmodified input if the object |
|
1438 | 1433 | # hadn't been found |
|
1439 | 1434 | return info |
|
1440 | 1435 | |
|
1441 | 1436 | def _object_find(self, oname, namespaces=None): |
|
1442 | 1437 | """Find an object and return a struct with info about it.""" |
|
1443 | 1438 | inf = Struct(self._ofind(oname, namespaces)) |
|
1444 | 1439 | return Struct(self._ofind_property(oname, inf)) |
|
1445 | 1440 | |
|
1446 | 1441 | def _inspect(self, meth, oname, namespaces=None, **kw): |
|
1447 | 1442 | """Generic interface to the inspector system. |
|
1448 | 1443 | |
|
1449 | 1444 | This function is meant to be called by pdef, pdoc & friends.""" |
|
1450 | 1445 | info = self._object_find(oname) |
|
1451 | 1446 | if info.found: |
|
1452 | 1447 | pmethod = getattr(self.inspector, meth) |
|
1453 | 1448 | formatter = format_screen if info.ismagic else None |
|
1454 | 1449 | if meth == 'pdoc': |
|
1455 | 1450 | pmethod(info.obj, oname, formatter) |
|
1456 | 1451 | elif meth == 'pinfo': |
|
1457 | 1452 | pmethod(info.obj, oname, formatter, info, **kw) |
|
1458 | 1453 | else: |
|
1459 | 1454 | pmethod(info.obj, oname) |
|
1460 | 1455 | else: |
|
1461 | 1456 | print 'Object `%s` not found.' % oname |
|
1462 | 1457 | return 'not found' # so callers can take other action |
|
1463 | 1458 | |
|
1464 | 1459 | def object_inspect(self, oname, detail_level=0): |
|
1465 | 1460 | with self.builtin_trap: |
|
1466 | 1461 | info = self._object_find(oname) |
|
1467 | 1462 | if info.found: |
|
1468 | 1463 | return self.inspector.info(info.obj, oname, info=info, |
|
1469 | 1464 | detail_level=detail_level |
|
1470 | 1465 | ) |
|
1471 | 1466 | else: |
|
1472 | 1467 | return oinspect.object_info(name=oname, found=False) |
|
1473 | 1468 | |
|
1474 | 1469 | #------------------------------------------------------------------------- |
|
1475 | 1470 | # Things related to history management |
|
1476 | 1471 | #------------------------------------------------------------------------- |
|
1477 | 1472 | |
|
1478 | 1473 | def init_history(self): |
|
1479 | 1474 | """Sets up the command history, and starts regular autosaves.""" |
|
1480 | 1475 | self.history_manager = HistoryManager(shell=self, config=self.config) |
|
1481 | 1476 | self.configurables.append(self.history_manager) |
|
1482 | 1477 | |
|
1483 | 1478 | #------------------------------------------------------------------------- |
|
1484 | 1479 | # Things related to exception handling and tracebacks (not debugging) |
|
1485 | 1480 | #------------------------------------------------------------------------- |
|
1486 | 1481 | |
|
1487 | 1482 | def init_traceback_handlers(self, custom_exceptions): |
|
1488 | 1483 | # Syntax error handler. |
|
1489 | 1484 | self.SyntaxTB = ultratb.SyntaxTB(color_scheme='NoColor') |
|
1490 | 1485 | |
|
1491 | 1486 | # The interactive one is initialized with an offset, meaning we always |
|
1492 | 1487 | # want to remove the topmost item in the traceback, which is our own |
|
1493 | 1488 | # internal code. Valid modes: ['Plain','Context','Verbose'] |
|
1494 | 1489 | self.InteractiveTB = ultratb.AutoFormattedTB(mode = 'Plain', |
|
1495 | 1490 | color_scheme='NoColor', |
|
1496 | 1491 | tb_offset = 1, |
|
1497 | 1492 | check_cache=self.compile.check_cache) |
|
1498 | 1493 | |
|
1499 | 1494 | # The instance will store a pointer to the system-wide exception hook, |
|
1500 | 1495 | # so that runtime code (such as magics) can access it. This is because |
|
1501 | 1496 | # during the read-eval loop, it may get temporarily overwritten. |
|
1502 | 1497 | self.sys_excepthook = sys.excepthook |
|
1503 | 1498 | |
|
1504 | 1499 | # and add any custom exception handlers the user may have specified |
|
1505 | 1500 | self.set_custom_exc(*custom_exceptions) |
|
1506 | 1501 | |
|
1507 | 1502 | # Set the exception mode |
|
1508 | 1503 | self.InteractiveTB.set_mode(mode=self.xmode) |
|
1509 | 1504 | |
|
1510 | 1505 | def set_custom_exc(self, exc_tuple, handler): |
|
1511 | 1506 | """set_custom_exc(exc_tuple,handler) |
|
1512 | 1507 | |
|
1513 | 1508 | Set a custom exception handler, which will be called if any of the |
|
1514 | 1509 | exceptions in exc_tuple occur in the mainloop (specifically, in the |
|
1515 | 1510 | run_code() method). |
|
1516 | 1511 | |
|
1517 | 1512 | Parameters |
|
1518 | 1513 | ---------- |
|
1519 | 1514 | |
|
1520 | 1515 | exc_tuple : tuple of exception classes |
|
1521 | 1516 | A *tuple* of exception classes, for which to call the defined |
|
1522 | 1517 | handler. It is very important that you use a tuple, and NOT A |
|
1523 | 1518 | LIST here, because of the way Python's except statement works. If |
|
1524 | 1519 | you only want to trap a single exception, use a singleton tuple:: |
|
1525 | 1520 | |
|
1526 | 1521 | exc_tuple == (MyCustomException,) |
|
1527 | 1522 | |
|
1528 | 1523 | handler : callable |
|
1529 | 1524 | handler must have the following signature:: |
|
1530 | 1525 | |
|
1531 | 1526 | def my_handler(self, etype, value, tb, tb_offset=None): |
|
1532 | 1527 | ... |
|
1533 | 1528 | return structured_traceback |
|
1534 | 1529 | |
|
1535 | 1530 | Your handler must return a structured traceback (a list of strings), |
|
1536 | 1531 | or None. |
|
1537 | 1532 | |
|
1538 | 1533 | This will be made into an instance method (via types.MethodType) |
|
1539 | 1534 | of IPython itself, and it will be called if any of the exceptions |
|
1540 | 1535 | listed in the exc_tuple are caught. If the handler is None, an |
|
1541 | 1536 | internal basic one is used, which just prints basic info. |
|
1542 | 1537 | |
|
1543 | 1538 | To protect IPython from crashes, if your handler ever raises an |
|
1544 | 1539 | exception or returns an invalid result, it will be immediately |
|
1545 | 1540 | disabled. |
|
1546 | 1541 | |
|
1547 | 1542 | WARNING: by putting in your own exception handler into IPython's main |
|
1548 | 1543 | execution loop, you run a very good chance of nasty crashes. This |
|
1549 | 1544 | facility should only be used if you really know what you are doing.""" |
|
1550 | 1545 | |
|
1551 | 1546 | assert type(exc_tuple)==type(()) , \ |
|
1552 | 1547 | "The custom exceptions must be given AS A TUPLE." |
|
1553 | 1548 | |
|
1554 | 1549 | def dummy_handler(self,etype,value,tb,tb_offset=None): |
|
1555 | 1550 | print '*** Simple custom exception handler ***' |
|
1556 | 1551 | print 'Exception type :',etype |
|
1557 | 1552 | print 'Exception value:',value |
|
1558 | 1553 | print 'Traceback :',tb |
|
1559 | 1554 | #print 'Source code :','\n'.join(self.buffer) |
|
1560 | 1555 | |
|
1561 | 1556 | def validate_stb(stb): |
|
1562 | 1557 | """validate structured traceback return type |
|
1563 | 1558 | |
|
1564 | 1559 | return type of CustomTB *should* be a list of strings, but allow |
|
1565 | 1560 | single strings or None, which are harmless. |
|
1566 | 1561 | |
|
1567 | 1562 | This function will *always* return a list of strings, |
|
1568 | 1563 | and will raise a TypeError if stb is inappropriate. |
|
1569 | 1564 | """ |
|
1570 | 1565 | msg = "CustomTB must return list of strings, not %r" % stb |
|
1571 | 1566 | if stb is None: |
|
1572 | 1567 | return [] |
|
1573 | 1568 | elif isinstance(stb, basestring): |
|
1574 | 1569 | return [stb] |
|
1575 | 1570 | elif not isinstance(stb, list): |
|
1576 | 1571 | raise TypeError(msg) |
|
1577 | 1572 | # it's a list |
|
1578 | 1573 | for line in stb: |
|
1579 | 1574 | # check every element |
|
1580 | 1575 | if not isinstance(line, basestring): |
|
1581 | 1576 | raise TypeError(msg) |
|
1582 | 1577 | return stb |
|
1583 | 1578 | |
|
1584 | 1579 | if handler is None: |
|
1585 | 1580 | wrapped = dummy_handler |
|
1586 | 1581 | else: |
|
1587 | 1582 | def wrapped(self,etype,value,tb,tb_offset=None): |
|
1588 | 1583 | """wrap CustomTB handler, to protect IPython from user code |
|
1589 | 1584 | |
|
1590 | 1585 | This makes it harder (but not impossible) for custom exception |
|
1591 | 1586 | handlers to crash IPython. |
|
1592 | 1587 | """ |
|
1593 | 1588 | try: |
|
1594 | 1589 | stb = handler(self,etype,value,tb,tb_offset=tb_offset) |
|
1595 | 1590 | return validate_stb(stb) |
|
1596 | 1591 | except: |
|
1597 | 1592 | # clear custom handler immediately |
|
1598 | 1593 | self.set_custom_exc((), None) |
|
1599 | 1594 | print >> io.stderr, "Custom TB Handler failed, unregistering" |
|
1600 | 1595 | # show the exception in handler first |
|
1601 | 1596 | stb = self.InteractiveTB.structured_traceback(*sys.exc_info()) |
|
1602 | 1597 | print >> io.stdout, self.InteractiveTB.stb2text(stb) |
|
1603 | 1598 | print >> io.stdout, "The original exception:" |
|
1604 | 1599 | stb = self.InteractiveTB.structured_traceback( |
|
1605 | 1600 | (etype,value,tb), tb_offset=tb_offset |
|
1606 | 1601 | ) |
|
1607 | 1602 | return stb |
|
1608 | 1603 | |
|
1609 | 1604 | self.CustomTB = types.MethodType(wrapped,self) |
|
1610 | 1605 | self.custom_exceptions = exc_tuple |
|
1611 | 1606 | |
|
1612 | 1607 | def excepthook(self, etype, value, tb): |
|
1613 | 1608 | """One more defense for GUI apps that call sys.excepthook. |
|
1614 | 1609 | |
|
1615 | 1610 | GUI frameworks like wxPython trap exceptions and call |
|
1616 | 1611 | sys.excepthook themselves. I guess this is a feature that |
|
1617 | 1612 | enables them to keep running after exceptions that would |
|
1618 | 1613 | otherwise kill their mainloop. This is a bother for IPython |
|
1619 | 1614 | which excepts to catch all of the program exceptions with a try: |
|
1620 | 1615 | except: statement. |
|
1621 | 1616 | |
|
1622 | 1617 | Normally, IPython sets sys.excepthook to a CrashHandler instance, so if |
|
1623 | 1618 | any app directly invokes sys.excepthook, it will look to the user like |
|
1624 | 1619 | IPython crashed. In order to work around this, we can disable the |
|
1625 | 1620 | CrashHandler and replace it with this excepthook instead, which prints a |
|
1626 | 1621 | regular traceback using our InteractiveTB. In this fashion, apps which |
|
1627 | 1622 | call sys.excepthook will generate a regular-looking exception from |
|
1628 | 1623 | IPython, and the CrashHandler will only be triggered by real IPython |
|
1629 | 1624 | crashes. |
|
1630 | 1625 | |
|
1631 | 1626 | This hook should be used sparingly, only in places which are not likely |
|
1632 | 1627 | to be true IPython errors. |
|
1633 | 1628 | """ |
|
1634 | 1629 | self.showtraceback((etype,value,tb),tb_offset=0) |
|
1635 | 1630 | |
|
1636 | 1631 | def _get_exc_info(self, exc_tuple=None): |
|
1637 | 1632 | """get exc_info from a given tuple, sys.exc_info() or sys.last_type etc. |
|
1638 | 1633 | |
|
1639 | 1634 | Ensures sys.last_type,value,traceback hold the exc_info we found, |
|
1640 | 1635 | from whichever source. |
|
1641 | 1636 | |
|
1642 | 1637 | raises ValueError if none of these contain any information |
|
1643 | 1638 | """ |
|
1644 | 1639 | if exc_tuple is None: |
|
1645 | 1640 | etype, value, tb = sys.exc_info() |
|
1646 | 1641 | else: |
|
1647 | 1642 | etype, value, tb = exc_tuple |
|
1648 | 1643 | |
|
1649 | 1644 | if etype is None: |
|
1650 | 1645 | if hasattr(sys, 'last_type'): |
|
1651 | 1646 | etype, value, tb = sys.last_type, sys.last_value, \ |
|
1652 | 1647 | sys.last_traceback |
|
1653 | 1648 | |
|
1654 | 1649 | if etype is None: |
|
1655 | 1650 | raise ValueError("No exception to find") |
|
1656 | 1651 | |
|
1657 | 1652 | # Now store the exception info in sys.last_type etc. |
|
1658 | 1653 | # WARNING: these variables are somewhat deprecated and not |
|
1659 | 1654 | # necessarily safe to use in a threaded environment, but tools |
|
1660 | 1655 | # like pdb depend on their existence, so let's set them. If we |
|
1661 | 1656 | # find problems in the field, we'll need to revisit their use. |
|
1662 | 1657 | sys.last_type = etype |
|
1663 | 1658 | sys.last_value = value |
|
1664 | 1659 | sys.last_traceback = tb |
|
1665 | 1660 | |
|
1666 | 1661 | return etype, value, tb |
|
1667 | 1662 | |
|
1668 | 1663 | |
|
1669 | 1664 | def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None, |
|
1670 | 1665 | exception_only=False): |
|
1671 | 1666 | """Display the exception that just occurred. |
|
1672 | 1667 | |
|
1673 | 1668 | If nothing is known about the exception, this is the method which |
|
1674 | 1669 | should be used throughout the code for presenting user tracebacks, |
|
1675 | 1670 | rather than directly invoking the InteractiveTB object. |
|
1676 | 1671 | |
|
1677 | 1672 | A specific showsyntaxerror() also exists, but this method can take |
|
1678 | 1673 | care of calling it if needed, so unless you are explicitly catching a |
|
1679 | 1674 | SyntaxError exception, don't try to analyze the stack manually and |
|
1680 | 1675 | simply call this method.""" |
|
1681 | 1676 | |
|
1682 | 1677 | try: |
|
1683 | 1678 | try: |
|
1684 | 1679 | etype, value, tb = self._get_exc_info(exc_tuple) |
|
1685 | 1680 | except ValueError: |
|
1686 | 1681 | self.write_err('No traceback available to show.\n') |
|
1687 | 1682 | return |
|
1688 | 1683 | |
|
1689 | 1684 | if etype is SyntaxError: |
|
1690 | 1685 | # Though this won't be called by syntax errors in the input |
|
1691 | 1686 | # line, there may be SyntaxError cases with imported code. |
|
1692 | 1687 | self.showsyntaxerror(filename) |
|
1693 | 1688 | elif etype is UsageError: |
|
1694 | 1689 | self.write_err("UsageError: %s" % value) |
|
1695 | 1690 | else: |
|
1696 | 1691 | if etype in self.custom_exceptions: |
|
1697 | 1692 | stb = self.CustomTB(etype, value, tb, tb_offset) |
|
1698 | 1693 | else: |
|
1699 | 1694 | if exception_only: |
|
1700 | 1695 | stb = ['An exception has occurred, use %tb to see ' |
|
1701 | 1696 | 'the full traceback.\n'] |
|
1702 | 1697 | stb.extend(self.InteractiveTB.get_exception_only(etype, |
|
1703 | 1698 | value)) |
|
1704 | 1699 | else: |
|
1705 | 1700 | stb = self.InteractiveTB.structured_traceback(etype, |
|
1706 | 1701 | value, tb, tb_offset=tb_offset) |
|
1707 | 1702 | |
|
1708 | 1703 | self._showtraceback(etype, value, stb) |
|
1709 | 1704 | if self.call_pdb: |
|
1710 | 1705 | # drop into debugger |
|
1711 | 1706 | self.debugger(force=True) |
|
1712 | 1707 | return |
|
1713 | 1708 | |
|
1714 | 1709 | # Actually show the traceback |
|
1715 | 1710 | self._showtraceback(etype, value, stb) |
|
1716 | 1711 | |
|
1717 | 1712 | except KeyboardInterrupt: |
|
1718 | 1713 | self.write_err("\nKeyboardInterrupt\n") |
|
1719 | 1714 | |
|
1720 | 1715 | def _showtraceback(self, etype, evalue, stb): |
|
1721 | 1716 | """Actually show a traceback. |
|
1722 | 1717 | |
|
1723 | 1718 | Subclasses may override this method to put the traceback on a different |
|
1724 | 1719 | place, like a side channel. |
|
1725 | 1720 | """ |
|
1726 | 1721 | print >> io.stdout, self.InteractiveTB.stb2text(stb) |
|
1727 | 1722 | |
|
1728 | 1723 | def showsyntaxerror(self, filename=None): |
|
1729 | 1724 | """Display the syntax error that just occurred. |
|
1730 | 1725 | |
|
1731 | 1726 | This doesn't display a stack trace because there isn't one. |
|
1732 | 1727 | |
|
1733 | 1728 | If a filename is given, it is stuffed in the exception instead |
|
1734 | 1729 | of what was there before (because Python's parser always uses |
|
1735 | 1730 | "<string>" when reading from a string). |
|
1736 | 1731 | """ |
|
1737 | 1732 | etype, value, last_traceback = self._get_exc_info() |
|
1738 | 1733 | |
|
1739 | 1734 | if filename and etype is SyntaxError: |
|
1740 | 1735 | try: |
|
1741 | 1736 | value.filename = filename |
|
1742 | 1737 | except: |
|
1743 | 1738 | # Not the format we expect; leave it alone |
|
1744 | 1739 | pass |
|
1745 | 1740 | |
|
1746 | 1741 | stb = self.SyntaxTB.structured_traceback(etype, value, []) |
|
1747 | 1742 | self._showtraceback(etype, value, stb) |
|
1748 | 1743 | |
|
1749 | 1744 | # This is overridden in TerminalInteractiveShell to show a message about |
|
1750 | 1745 | # the %paste magic. |
|
1751 | 1746 | def showindentationerror(self): |
|
1752 | 1747 | """Called by run_cell when there's an IndentationError in code entered |
|
1753 | 1748 | at the prompt. |
|
1754 | 1749 | |
|
1755 | 1750 | This is overridden in TerminalInteractiveShell to show a message about |
|
1756 | 1751 | the %paste magic.""" |
|
1757 | 1752 | self.showsyntaxerror() |
|
1758 | 1753 | |
|
1759 | 1754 | #------------------------------------------------------------------------- |
|
1760 | 1755 | # Things related to readline |
|
1761 | 1756 | #------------------------------------------------------------------------- |
|
1762 | 1757 | |
|
1763 | 1758 | def init_readline(self): |
|
1764 | 1759 | """Command history completion/saving/reloading.""" |
|
1765 | 1760 | |
|
1766 | 1761 | if self.readline_use: |
|
1767 | 1762 | import IPython.utils.rlineimpl as readline |
|
1768 | 1763 | |
|
1769 | 1764 | self.rl_next_input = None |
|
1770 | 1765 | self.rl_do_indent = False |
|
1771 | 1766 | |
|
1772 | 1767 | if not self.readline_use or not readline.have_readline: |
|
1773 | 1768 | self.has_readline = False |
|
1774 | 1769 | self.readline = None |
|
1775 | 1770 | # Set a number of methods that depend on readline to be no-op |
|
1776 | 1771 | self.readline_no_record = no_op_context |
|
1777 | 1772 | self.set_readline_completer = no_op |
|
1778 | 1773 | self.set_custom_completer = no_op |
|
1779 | 1774 | self.set_completer_frame = no_op |
|
1780 | 1775 | if self.readline_use: |
|
1781 | 1776 | warn('Readline services not available or not loaded.') |
|
1782 | 1777 | else: |
|
1783 | 1778 | self.has_readline = True |
|
1784 | 1779 | self.readline = readline |
|
1785 | 1780 | sys.modules['readline'] = readline |
|
1786 | 1781 | |
|
1787 | 1782 | # Platform-specific configuration |
|
1788 | 1783 | if os.name == 'nt': |
|
1789 | 1784 | # FIXME - check with Frederick to see if we can harmonize |
|
1790 | 1785 | # naming conventions with pyreadline to avoid this |
|
1791 | 1786 | # platform-dependent check |
|
1792 | 1787 | self.readline_startup_hook = readline.set_pre_input_hook |
|
1793 | 1788 | else: |
|
1794 | 1789 | self.readline_startup_hook = readline.set_startup_hook |
|
1795 | 1790 | |
|
1796 | 1791 | # Load user's initrc file (readline config) |
|
1797 | 1792 | # Or if libedit is used, load editrc. |
|
1798 | 1793 | inputrc_name = os.environ.get('INPUTRC') |
|
1799 | 1794 | if inputrc_name is None: |
|
1800 | 1795 | inputrc_name = '.inputrc' |
|
1801 | 1796 | if readline.uses_libedit: |
|
1802 | 1797 | inputrc_name = '.editrc' |
|
1803 | 1798 | inputrc_name = os.path.join(self.home_dir, inputrc_name) |
|
1804 | 1799 | if os.path.isfile(inputrc_name): |
|
1805 | 1800 | try: |
|
1806 | 1801 | readline.read_init_file(inputrc_name) |
|
1807 | 1802 | except: |
|
1808 | 1803 | warn('Problems reading readline initialization file <%s>' |
|
1809 | 1804 | % inputrc_name) |
|
1810 | 1805 | |
|
1811 | 1806 | # Configure readline according to user's prefs |
|
1812 | 1807 | # This is only done if GNU readline is being used. If libedit |
|
1813 | 1808 | # is being used (as on Leopard) the readline config is |
|
1814 | 1809 | # not run as the syntax for libedit is different. |
|
1815 | 1810 | if not readline.uses_libedit: |
|
1816 | 1811 | for rlcommand in self.readline_parse_and_bind: |
|
1817 | 1812 | #print "loading rl:",rlcommand # dbg |
|
1818 | 1813 | readline.parse_and_bind(rlcommand) |
|
1819 | 1814 | |
|
1820 | 1815 | # Remove some chars from the delimiters list. If we encounter |
|
1821 | 1816 | # unicode chars, discard them. |
|
1822 | 1817 | delims = readline.get_completer_delims() |
|
1823 | 1818 | if not py3compat.PY3: |
|
1824 | 1819 | delims = delims.encode("ascii", "ignore") |
|
1825 | 1820 | for d in self.readline_remove_delims: |
|
1826 | 1821 | delims = delims.replace(d, "") |
|
1827 | 1822 | delims = delims.replace(ESC_MAGIC, '') |
|
1828 | 1823 | readline.set_completer_delims(delims) |
|
1829 | 1824 | # otherwise we end up with a monster history after a while: |
|
1830 | 1825 | readline.set_history_length(self.history_length) |
|
1831 | 1826 | |
|
1832 | 1827 | self.refill_readline_hist() |
|
1833 | 1828 | self.readline_no_record = ReadlineNoRecord(self) |
|
1834 | 1829 | |
|
1835 | 1830 | # Configure auto-indent for all platforms |
|
1836 | 1831 | self.set_autoindent(self.autoindent) |
|
1837 | 1832 | |
|
1838 | 1833 | def refill_readline_hist(self): |
|
1839 | 1834 | # Load the last 1000 lines from history |
|
1840 | 1835 | self.readline.clear_history() |
|
1841 | 1836 | stdin_encoding = sys.stdin.encoding or "utf-8" |
|
1842 | 1837 | last_cell = u"" |
|
1843 | 1838 | for _, _, cell in self.history_manager.get_tail(1000, |
|
1844 | 1839 | include_latest=True): |
|
1845 | 1840 | # Ignore blank lines and consecutive duplicates |
|
1846 | 1841 | cell = cell.rstrip() |
|
1847 | 1842 | if cell and (cell != last_cell): |
|
1848 | 1843 | if self.multiline_history: |
|
1849 | 1844 | self.readline.add_history(py3compat.unicode_to_str(cell, |
|
1850 | 1845 | stdin_encoding)) |
|
1851 | 1846 | else: |
|
1852 | 1847 | for line in cell.splitlines(): |
|
1853 | 1848 | self.readline.add_history(py3compat.unicode_to_str(line, |
|
1854 | 1849 | stdin_encoding)) |
|
1855 | 1850 | last_cell = cell |
|
1856 | 1851 | |
|
1857 | 1852 | def set_next_input(self, s): |
|
1858 | 1853 | """ Sets the 'default' input string for the next command line. |
|
1859 | 1854 | |
|
1860 | 1855 | Requires readline. |
|
1861 | 1856 | |
|
1862 | 1857 | Example: |
|
1863 | 1858 | |
|
1864 | 1859 | [D:\ipython]|1> _ip.set_next_input("Hello Word") |
|
1865 | 1860 | [D:\ipython]|2> Hello Word_ # cursor is here |
|
1866 | 1861 | """ |
|
1867 | 1862 | self.rl_next_input = py3compat.cast_bytes_py2(s) |
|
1868 | 1863 | |
|
1869 | 1864 | # Maybe move this to the terminal subclass? |
|
1870 | 1865 | def pre_readline(self): |
|
1871 | 1866 | """readline hook to be used at the start of each line. |
|
1872 | 1867 | |
|
1873 | 1868 | Currently it handles auto-indent only.""" |
|
1874 | 1869 | |
|
1875 | 1870 | if self.rl_do_indent: |
|
1876 | 1871 | self.readline.insert_text(self._indent_current_str()) |
|
1877 | 1872 | if self.rl_next_input is not None: |
|
1878 | 1873 | self.readline.insert_text(self.rl_next_input) |
|
1879 | 1874 | self.rl_next_input = None |
|
1880 | 1875 | |
|
1881 | 1876 | def _indent_current_str(self): |
|
1882 | 1877 | """return the current level of indentation as a string""" |
|
1883 | 1878 | return self.input_splitter.indent_spaces * ' ' |
|
1884 | 1879 | |
|
1885 | 1880 | #------------------------------------------------------------------------- |
|
1886 | 1881 | # Things related to text completion |
|
1887 | 1882 | #------------------------------------------------------------------------- |
|
1888 | 1883 | |
|
1889 | 1884 | def init_completer(self): |
|
1890 | 1885 | """Initialize the completion machinery. |
|
1891 | 1886 | |
|
1892 | 1887 | This creates completion machinery that can be used by client code, |
|
1893 | 1888 | either interactively in-process (typically triggered by the readline |
|
1894 | 1889 | library), programatically (such as in test suites) or out-of-prcess |
|
1895 | 1890 | (typically over the network by remote frontends). |
|
1896 | 1891 | """ |
|
1897 | 1892 | from IPython.core.completer import IPCompleter |
|
1898 | 1893 | from IPython.core.completerlib import (module_completer, |
|
1899 | 1894 | magic_run_completer, cd_completer, reset_completer) |
|
1900 | 1895 | |
|
1901 | 1896 | self.Completer = IPCompleter(shell=self, |
|
1902 | 1897 | namespace=self.user_ns, |
|
1903 | 1898 | global_namespace=self.user_global_ns, |
|
1904 | 1899 | alias_table=self.alias_manager.alias_table, |
|
1905 | 1900 | use_readline=self.has_readline, |
|
1906 | 1901 | config=self.config, |
|
1907 | 1902 | ) |
|
1908 | 1903 | self.configurables.append(self.Completer) |
|
1909 | 1904 | |
|
1910 | 1905 | # Add custom completers to the basic ones built into IPCompleter |
|
1911 | 1906 | sdisp = self.strdispatchers.get('complete_command', StrDispatch()) |
|
1912 | 1907 | self.strdispatchers['complete_command'] = sdisp |
|
1913 | 1908 | self.Completer.custom_completers = sdisp |
|
1914 | 1909 | |
|
1915 | 1910 | self.set_hook('complete_command', module_completer, str_key = 'import') |
|
1916 | 1911 | self.set_hook('complete_command', module_completer, str_key = 'from') |
|
1917 | 1912 | self.set_hook('complete_command', magic_run_completer, str_key = '%run') |
|
1918 | 1913 | self.set_hook('complete_command', cd_completer, str_key = '%cd') |
|
1919 | 1914 | self.set_hook('complete_command', reset_completer, str_key = '%reset') |
|
1920 | 1915 | |
|
1921 | 1916 | # Only configure readline if we truly are using readline. IPython can |
|
1922 | 1917 | # do tab-completion over the network, in GUIs, etc, where readline |
|
1923 | 1918 | # itself may be absent |
|
1924 | 1919 | if self.has_readline: |
|
1925 | 1920 | self.set_readline_completer() |
|
1926 | 1921 | |
|
1927 | 1922 | def complete(self, text, line=None, cursor_pos=None): |
|
1928 | 1923 | """Return the completed text and a list of completions. |
|
1929 | 1924 | |
|
1930 | 1925 | Parameters |
|
1931 | 1926 | ---------- |
|
1932 | 1927 | |
|
1933 | 1928 | text : string |
|
1934 | 1929 | A string of text to be completed on. It can be given as empty and |
|
1935 | 1930 | instead a line/position pair are given. In this case, the |
|
1936 | 1931 | completer itself will split the line like readline does. |
|
1937 | 1932 | |
|
1938 | 1933 | line : string, optional |
|
1939 | 1934 | The complete line that text is part of. |
|
1940 | 1935 | |
|
1941 | 1936 | cursor_pos : int, optional |
|
1942 | 1937 | The position of the cursor on the input line. |
|
1943 | 1938 | |
|
1944 | 1939 | Returns |
|
1945 | 1940 | ------- |
|
1946 | 1941 | text : string |
|
1947 | 1942 | The actual text that was completed. |
|
1948 | 1943 | |
|
1949 | 1944 | matches : list |
|
1950 | 1945 | A sorted list with all possible completions. |
|
1951 | 1946 | |
|
1952 | 1947 | The optional arguments allow the completion to take more context into |
|
1953 | 1948 | account, and are part of the low-level completion API. |
|
1954 | 1949 | |
|
1955 | 1950 | This is a wrapper around the completion mechanism, similar to what |
|
1956 | 1951 | readline does at the command line when the TAB key is hit. By |
|
1957 | 1952 | exposing it as a method, it can be used by other non-readline |
|
1958 | 1953 | environments (such as GUIs) for text completion. |
|
1959 | 1954 | |
|
1960 | 1955 | Simple usage example: |
|
1961 | 1956 | |
|
1962 | 1957 | In [1]: x = 'hello' |
|
1963 | 1958 | |
|
1964 | 1959 | In [2]: _ip.complete('x.l') |
|
1965 | 1960 | Out[2]: ('x.l', ['x.ljust', 'x.lower', 'x.lstrip']) |
|
1966 | 1961 | """ |
|
1967 | 1962 | |
|
1968 | 1963 | # Inject names into __builtin__ so we can complete on the added names. |
|
1969 | 1964 | with self.builtin_trap: |
|
1970 | 1965 | return self.Completer.complete(text, line, cursor_pos) |
|
1971 | 1966 | |
|
1972 | 1967 | def set_custom_completer(self, completer, pos=0): |
|
1973 | 1968 | """Adds a new custom completer function. |
|
1974 | 1969 | |
|
1975 | 1970 | The position argument (defaults to 0) is the index in the completers |
|
1976 | 1971 | list where you want the completer to be inserted.""" |
|
1977 | 1972 | |
|
1978 | 1973 | newcomp = types.MethodType(completer,self.Completer) |
|
1979 | 1974 | self.Completer.matchers.insert(pos,newcomp) |
|
1980 | 1975 | |
|
1981 | 1976 | def set_readline_completer(self): |
|
1982 | 1977 | """Reset readline's completer to be our own.""" |
|
1983 | 1978 | self.readline.set_completer(self.Completer.rlcomplete) |
|
1984 | 1979 | |
|
1985 | 1980 | def set_completer_frame(self, frame=None): |
|
1986 | 1981 | """Set the frame of the completer.""" |
|
1987 | 1982 | if frame: |
|
1988 | 1983 | self.Completer.namespace = frame.f_locals |
|
1989 | 1984 | self.Completer.global_namespace = frame.f_globals |
|
1990 | 1985 | else: |
|
1991 | 1986 | self.Completer.namespace = self.user_ns |
|
1992 | 1987 | self.Completer.global_namespace = self.user_global_ns |
|
1993 | 1988 | |
|
1994 | 1989 | #------------------------------------------------------------------------- |
|
1995 | 1990 | # Things related to magics |
|
1996 | 1991 | #------------------------------------------------------------------------- |
|
1997 | 1992 | |
|
1998 | 1993 | def init_magics(self): |
|
1999 | 1994 | # FIXME: Move the color initialization to the DisplayHook, which |
|
2000 | 1995 | # should be split into a prompt manager and displayhook. We probably |
|
2001 | 1996 | # even need a centralize colors management object. |
|
2002 | 1997 | self.magic_colors(self.colors) |
|
2003 | 1998 | # History was moved to a separate module |
|
2004 | 1999 | from IPython.core import history |
|
2005 | 2000 | history.init_ipython(self) |
|
2006 | 2001 | |
|
2007 | 2002 | def magic(self, arg_s, next_input=None): |
|
2008 | 2003 | """Call a magic function by name. |
|
2009 | 2004 | |
|
2010 | 2005 | Input: a string containing the name of the magic function to call and |
|
2011 | 2006 | any additional arguments to be passed to the magic. |
|
2012 | 2007 | |
|
2013 | 2008 | magic('name -opt foo bar') is equivalent to typing at the ipython |
|
2014 | 2009 | prompt: |
|
2015 | 2010 | |
|
2016 | 2011 | In[1]: %name -opt foo bar |
|
2017 | 2012 | |
|
2018 | 2013 | To call a magic without arguments, simply use magic('name'). |
|
2019 | 2014 | |
|
2020 | 2015 | This provides a proper Python function to call IPython's magics in any |
|
2021 | 2016 | valid Python code you can type at the interpreter, including loops and |
|
2022 | 2017 | compound statements. |
|
2023 | 2018 | """ |
|
2024 | 2019 | # Allow setting the next input - this is used if the user does `a=abs?`. |
|
2025 | 2020 | # We do this first so that magic functions can override it. |
|
2026 | 2021 | if next_input: |
|
2027 | 2022 | self.set_next_input(next_input) |
|
2028 | 2023 | |
|
2029 | 2024 | magic_name, _, magic_args = arg_s.partition(' ') |
|
2030 | 2025 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) |
|
2031 | 2026 | |
|
2032 | 2027 | fn = getattr(self,'magic_'+magic_name,None) |
|
2033 | 2028 | if fn is None: |
|
2034 | 2029 | error("Magic function `%s` not found." % magic_name) |
|
2035 | 2030 | else: |
|
2036 | 2031 | magic_args = self.var_expand(magic_args,1) |
|
2037 | 2032 | # Grab local namespace if we need it: |
|
2038 | 2033 | if getattr(fn, "needs_local_scope", False): |
|
2039 | 2034 | self._magic_locals = sys._getframe(1).f_locals |
|
2040 | 2035 | with self.builtin_trap: |
|
2041 | 2036 | result = fn(magic_args) |
|
2042 | 2037 | # Ensure we're not keeping object references around: |
|
2043 | 2038 | self._magic_locals = {} |
|
2044 | 2039 | return result |
|
2045 | 2040 | |
|
2046 | 2041 | def define_magic(self, magicname, func): |
|
2047 | 2042 | """Expose own function as magic function for ipython |
|
2048 | 2043 | |
|
2049 | 2044 | Example:: |
|
2050 | 2045 | |
|
2051 | 2046 | def foo_impl(self,parameter_s=''): |
|
2052 | 2047 | 'My very own magic!. (Use docstrings, IPython reads them).' |
|
2053 | 2048 | print 'Magic function. Passed parameter is between < >:' |
|
2054 | 2049 | print '<%s>' % parameter_s |
|
2055 | 2050 | print 'The self object is:', self |
|
2056 | 2051 | |
|
2057 | 2052 | ip.define_magic('foo',foo_impl) |
|
2058 | 2053 | """ |
|
2059 | 2054 | im = types.MethodType(func,self) |
|
2060 | 2055 | old = getattr(self, "magic_" + magicname, None) |
|
2061 | 2056 | setattr(self, "magic_" + magicname, im) |
|
2062 | 2057 | return old |
|
2063 | 2058 | |
|
2064 | 2059 | #------------------------------------------------------------------------- |
|
2065 | 2060 | # Things related to macros |
|
2066 | 2061 | #------------------------------------------------------------------------- |
|
2067 | 2062 | |
|
2068 | 2063 | def define_macro(self, name, themacro): |
|
2069 | 2064 | """Define a new macro |
|
2070 | 2065 | |
|
2071 | 2066 | Parameters |
|
2072 | 2067 | ---------- |
|
2073 | 2068 | name : str |
|
2074 | 2069 | The name of the macro. |
|
2075 | 2070 | themacro : str or Macro |
|
2076 | 2071 | The action to do upon invoking the macro. If a string, a new |
|
2077 | 2072 | Macro object is created by passing the string to it. |
|
2078 | 2073 | """ |
|
2079 | 2074 | |
|
2080 | 2075 | from IPython.core import macro |
|
2081 | 2076 | |
|
2082 | 2077 | if isinstance(themacro, basestring): |
|
2083 | 2078 | themacro = macro.Macro(themacro) |
|
2084 | 2079 | if not isinstance(themacro, macro.Macro): |
|
2085 | 2080 | raise ValueError('A macro must be a string or a Macro instance.') |
|
2086 | 2081 | self.user_ns[name] = themacro |
|
2087 | 2082 | |
|
2088 | 2083 | #------------------------------------------------------------------------- |
|
2089 | 2084 | # Things related to the running of system commands |
|
2090 | 2085 | #------------------------------------------------------------------------- |
|
2091 | 2086 | |
|
2092 | 2087 | def system_piped(self, cmd): |
|
2093 | 2088 | """Call the given cmd in a subprocess, piping stdout/err |
|
2094 | 2089 | |
|
2095 | 2090 | Parameters |
|
2096 | 2091 | ---------- |
|
2097 | 2092 | cmd : str |
|
2098 | 2093 | Command to execute (can not end in '&', as background processes are |
|
2099 | 2094 | not supported. Should not be a command that expects input |
|
2100 | 2095 | other than simple text. |
|
2101 | 2096 | """ |
|
2102 | 2097 | if cmd.rstrip().endswith('&'): |
|
2103 | 2098 | # this is *far* from a rigorous test |
|
2104 | 2099 | # We do not support backgrounding processes because we either use |
|
2105 | 2100 | # pexpect or pipes to read from. Users can always just call |
|
2106 | 2101 | # os.system() or use ip.system=ip.system_raw |
|
2107 | 2102 | # if they really want a background process. |
|
2108 | 2103 | raise OSError("Background processes not supported.") |
|
2109 | 2104 | |
|
2110 | 2105 | # we explicitly do NOT return the subprocess status code, because |
|
2111 | 2106 | # a non-None value would trigger :func:`sys.displayhook` calls. |
|
2112 | 2107 | # Instead, we store the exit_code in user_ns. |
|
2113 | 2108 | self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=2)) |
|
2114 | 2109 | |
|
2115 | 2110 | def system_raw(self, cmd): |
|
2116 | 2111 | """Call the given cmd in a subprocess using os.system |
|
2117 | 2112 | |
|
2118 | 2113 | Parameters |
|
2119 | 2114 | ---------- |
|
2120 | 2115 | cmd : str |
|
2121 | 2116 | Command to execute. |
|
2122 | 2117 | """ |
|
2123 | 2118 | cmd = self.var_expand(cmd, depth=2) |
|
2124 | 2119 | # protect os.system from UNC paths on Windows, which it can't handle: |
|
2125 | 2120 | if sys.platform == 'win32': |
|
2126 | 2121 | from IPython.utils._process_win32 import AvoidUNCPath |
|
2127 | 2122 | with AvoidUNCPath() as path: |
|
2128 | 2123 | if path is not None: |
|
2129 | 2124 | cmd = '"pushd %s &&"%s' % (path, cmd) |
|
2130 | 2125 | cmd = py3compat.unicode_to_str(cmd) |
|
2131 | 2126 | ec = os.system(cmd) |
|
2132 | 2127 | else: |
|
2133 | 2128 | cmd = py3compat.unicode_to_str(cmd) |
|
2134 | 2129 | ec = os.system(cmd) |
|
2135 | 2130 | |
|
2136 | 2131 | # We explicitly do NOT return the subprocess status code, because |
|
2137 | 2132 | # a non-None value would trigger :func:`sys.displayhook` calls. |
|
2138 | 2133 | # Instead, we store the exit_code in user_ns. |
|
2139 | 2134 | self.user_ns['_exit_code'] = ec |
|
2140 | 2135 | |
|
2141 | 2136 | # use piped system by default, because it is better behaved |
|
2142 | 2137 | system = system_piped |
|
2143 | 2138 | |
|
2144 | 2139 | def getoutput(self, cmd, split=True): |
|
2145 | 2140 | """Get output (possibly including stderr) from a subprocess. |
|
2146 | 2141 | |
|
2147 | 2142 | Parameters |
|
2148 | 2143 | ---------- |
|
2149 | 2144 | cmd : str |
|
2150 | 2145 | Command to execute (can not end in '&', as background processes are |
|
2151 | 2146 | not supported. |
|
2152 | 2147 | split : bool, optional |
|
2153 | 2148 | |
|
2154 | 2149 | If True, split the output into an IPython SList. Otherwise, an |
|
2155 | 2150 | IPython LSString is returned. These are objects similar to normal |
|
2156 | 2151 | lists and strings, with a few convenience attributes for easier |
|
2157 | 2152 | manipulation of line-based output. You can use '?' on them for |
|
2158 | 2153 | details. |
|
2159 | 2154 | """ |
|
2160 | 2155 | if cmd.rstrip().endswith('&'): |
|
2161 | 2156 | # this is *far* from a rigorous test |
|
2162 | 2157 | raise OSError("Background processes not supported.") |
|
2163 | 2158 | out = getoutput(self.var_expand(cmd, depth=2)) |
|
2164 | 2159 | if split: |
|
2165 | 2160 | out = SList(out.splitlines()) |
|
2166 | 2161 | else: |
|
2167 | 2162 | out = LSString(out) |
|
2168 | 2163 | return out |
|
2169 | 2164 | |
|
2170 | 2165 | #------------------------------------------------------------------------- |
|
2171 | 2166 | # Things related to aliases |
|
2172 | 2167 | #------------------------------------------------------------------------- |
|
2173 | 2168 | |
|
2174 | 2169 | def init_alias(self): |
|
2175 | 2170 | self.alias_manager = AliasManager(shell=self, config=self.config) |
|
2176 | 2171 | self.configurables.append(self.alias_manager) |
|
2177 | 2172 | self.ns_table['alias'] = self.alias_manager.alias_table, |
|
2178 | 2173 | |
|
2179 | 2174 | #------------------------------------------------------------------------- |
|
2180 | 2175 | # Things related to extensions and plugins |
|
2181 | 2176 | #------------------------------------------------------------------------- |
|
2182 | 2177 | |
|
2183 | 2178 | def init_extension_manager(self): |
|
2184 | 2179 | self.extension_manager = ExtensionManager(shell=self, config=self.config) |
|
2185 | 2180 | self.configurables.append(self.extension_manager) |
|
2186 | 2181 | |
|
2187 | 2182 | def init_plugin_manager(self): |
|
2188 | 2183 | self.plugin_manager = PluginManager(config=self.config) |
|
2189 | 2184 | self.configurables.append(self.plugin_manager) |
|
2190 | 2185 | |
|
2191 | 2186 | |
|
2192 | 2187 | #------------------------------------------------------------------------- |
|
2193 | 2188 | # Things related to payloads |
|
2194 | 2189 | #------------------------------------------------------------------------- |
|
2195 | 2190 | |
|
2196 | 2191 | def init_payload(self): |
|
2197 | 2192 | self.payload_manager = PayloadManager(config=self.config) |
|
2198 | 2193 | self.configurables.append(self.payload_manager) |
|
2199 | 2194 | |
|
2200 | 2195 | #------------------------------------------------------------------------- |
|
2201 | 2196 | # Things related to the prefilter |
|
2202 | 2197 | #------------------------------------------------------------------------- |
|
2203 | 2198 | |
|
2204 | 2199 | def init_prefilter(self): |
|
2205 | 2200 | self.prefilter_manager = PrefilterManager(shell=self, config=self.config) |
|
2206 | 2201 | self.configurables.append(self.prefilter_manager) |
|
2207 | 2202 | # Ultimately this will be refactored in the new interpreter code, but |
|
2208 | 2203 | # for now, we should expose the main prefilter method (there's legacy |
|
2209 | 2204 | # code out there that may rely on this). |
|
2210 | 2205 | self.prefilter = self.prefilter_manager.prefilter_lines |
|
2211 | 2206 | |
|
2212 | 2207 | def auto_rewrite_input(self, cmd): |
|
2213 | 2208 | """Print to the screen the rewritten form of the user's command. |
|
2214 | 2209 | |
|
2215 | 2210 | This shows visual feedback by rewriting input lines that cause |
|
2216 | 2211 | automatic calling to kick in, like:: |
|
2217 | 2212 | |
|
2218 | 2213 | /f x |
|
2219 | 2214 | |
|
2220 | 2215 | into:: |
|
2221 | 2216 | |
|
2222 | 2217 | ------> f(x) |
|
2223 | 2218 | |
|
2224 | 2219 | after the user's input prompt. This helps the user understand that the |
|
2225 | 2220 | input line was transformed automatically by IPython. |
|
2226 | 2221 | """ |
|
2227 | 2222 | if not self.show_rewritten_input: |
|
2228 | 2223 | return |
|
2229 | 2224 | |
|
2230 | 2225 | rw = self.prompt_manager.render('rewrite') + cmd |
|
2231 | 2226 | |
|
2232 | 2227 | try: |
|
2233 | 2228 | # plain ascii works better w/ pyreadline, on some machines, so |
|
2234 | 2229 | # we use it and only print uncolored rewrite if we have unicode |
|
2235 | 2230 | rw = str(rw) |
|
2236 | 2231 | print >> io.stdout, rw |
|
2237 | 2232 | except UnicodeEncodeError: |
|
2238 | 2233 | print "------> " + cmd |
|
2239 | 2234 | |
|
2240 | 2235 | #------------------------------------------------------------------------- |
|
2241 | 2236 | # Things related to extracting values/expressions from kernel and user_ns |
|
2242 | 2237 | #------------------------------------------------------------------------- |
|
2243 | 2238 | |
|
2244 | 2239 | def _simple_error(self): |
|
2245 | 2240 | etype, value = sys.exc_info()[:2] |
|
2246 | 2241 | return u'[ERROR] {e.__name__}: {v}'.format(e=etype, v=value) |
|
2247 | 2242 | |
|
2248 | 2243 | def user_variables(self, names): |
|
2249 | 2244 | """Get a list of variable names from the user's namespace. |
|
2250 | 2245 | |
|
2251 | 2246 | Parameters |
|
2252 | 2247 | ---------- |
|
2253 | 2248 | names : list of strings |
|
2254 | 2249 | A list of names of variables to be read from the user namespace. |
|
2255 | 2250 | |
|
2256 | 2251 | Returns |
|
2257 | 2252 | ------- |
|
2258 | 2253 | A dict, keyed by the input names and with the repr() of each value. |
|
2259 | 2254 | """ |
|
2260 | 2255 | out = {} |
|
2261 | 2256 | user_ns = self.user_ns |
|
2262 | 2257 | for varname in names: |
|
2263 | 2258 | try: |
|
2264 | 2259 | value = repr(user_ns[varname]) |
|
2265 | 2260 | except: |
|
2266 | 2261 | value = self._simple_error() |
|
2267 | 2262 | out[varname] = value |
|
2268 | 2263 | return out |
|
2269 | 2264 | |
|
2270 | 2265 | def user_expressions(self, expressions): |
|
2271 | 2266 | """Evaluate a dict of expressions in the user's namespace. |
|
2272 | 2267 | |
|
2273 | 2268 | Parameters |
|
2274 | 2269 | ---------- |
|
2275 | 2270 | expressions : dict |
|
2276 | 2271 | A dict with string keys and string values. The expression values |
|
2277 | 2272 | should be valid Python expressions, each of which will be evaluated |
|
2278 | 2273 | in the user namespace. |
|
2279 | 2274 | |
|
2280 | 2275 | Returns |
|
2281 | 2276 | ------- |
|
2282 | 2277 | A dict, keyed like the input expressions dict, with the repr() of each |
|
2283 | 2278 | value. |
|
2284 | 2279 | """ |
|
2285 | 2280 | out = {} |
|
2286 | 2281 | user_ns = self.user_ns |
|
2287 | 2282 | global_ns = self.user_global_ns |
|
2288 | 2283 | for key, expr in expressions.iteritems(): |
|
2289 | 2284 | try: |
|
2290 | 2285 | value = repr(eval(expr, global_ns, user_ns)) |
|
2291 | 2286 | except: |
|
2292 | 2287 | value = self._simple_error() |
|
2293 | 2288 | out[key] = value |
|
2294 | 2289 | return out |
|
2295 | 2290 | |
|
2296 | 2291 | #------------------------------------------------------------------------- |
|
2297 | 2292 | # Things related to the running of code |
|
2298 | 2293 | #------------------------------------------------------------------------- |
|
2299 | 2294 | |
|
2300 | 2295 | def ex(self, cmd): |
|
2301 | 2296 | """Execute a normal python statement in user namespace.""" |
|
2302 | 2297 | with self.builtin_trap: |
|
2303 | 2298 | exec cmd in self.user_global_ns, self.user_ns |
|
2304 | 2299 | |
|
2305 | 2300 | def ev(self, expr): |
|
2306 | 2301 | """Evaluate python expression expr in user namespace. |
|
2307 | 2302 | |
|
2308 | 2303 | Returns the result of evaluation |
|
2309 | 2304 | """ |
|
2310 | 2305 | with self.builtin_trap: |
|
2311 | 2306 | return eval(expr, self.user_global_ns, self.user_ns) |
|
2312 | 2307 | |
|
2313 | 2308 | def safe_execfile(self, fname, *where, **kw): |
|
2314 | 2309 | """A safe version of the builtin execfile(). |
|
2315 | 2310 | |
|
2316 | 2311 | This version will never throw an exception, but instead print |
|
2317 | 2312 | helpful error messages to the screen. This only works on pure |
|
2318 | 2313 | Python files with the .py extension. |
|
2319 | 2314 | |
|
2320 | 2315 | Parameters |
|
2321 | 2316 | ---------- |
|
2322 | 2317 | fname : string |
|
2323 | 2318 | The name of the file to be executed. |
|
2324 | 2319 | where : tuple |
|
2325 | 2320 | One or two namespaces, passed to execfile() as (globals,locals). |
|
2326 | 2321 | If only one is given, it is passed as both. |
|
2327 | 2322 | exit_ignore : bool (False) |
|
2328 | 2323 | If True, then silence SystemExit for non-zero status (it is always |
|
2329 | 2324 | silenced for zero status, as it is so common). |
|
2330 | 2325 | raise_exceptions : bool (False) |
|
2331 | 2326 | If True raise exceptions everywhere. Meant for testing. |
|
2332 | 2327 | |
|
2333 | 2328 | """ |
|
2334 | 2329 | kw.setdefault('exit_ignore', False) |
|
2335 | 2330 | kw.setdefault('raise_exceptions', False) |
|
2336 | 2331 | |
|
2337 | 2332 | fname = os.path.abspath(os.path.expanduser(fname)) |
|
2338 | 2333 | |
|
2339 | 2334 | # Make sure we can open the file |
|
2340 | 2335 | try: |
|
2341 | 2336 | with open(fname) as thefile: |
|
2342 | 2337 | pass |
|
2343 | 2338 | except: |
|
2344 | 2339 | warn('Could not open file <%s> for safe execution.' % fname) |
|
2345 | 2340 | return |
|
2346 | 2341 | |
|
2347 | 2342 | # Find things also in current directory. This is needed to mimic the |
|
2348 | 2343 | # behavior of running a script from the system command line, where |
|
2349 | 2344 | # Python inserts the script's directory into sys.path |
|
2350 | 2345 | dname = os.path.dirname(fname) |
|
2351 | 2346 | |
|
2352 | 2347 | with prepended_to_syspath(dname): |
|
2353 | 2348 | try: |
|
2354 | 2349 | py3compat.execfile(fname,*where) |
|
2355 | 2350 | except SystemExit, status: |
|
2356 | 2351 | # If the call was made with 0 or None exit status (sys.exit(0) |
|
2357 | 2352 | # or sys.exit() ), don't bother showing a traceback, as both of |
|
2358 | 2353 | # these are considered normal by the OS: |
|
2359 | 2354 | # > python -c'import sys;sys.exit(0)'; echo $? |
|
2360 | 2355 | # 0 |
|
2361 | 2356 | # > python -c'import sys;sys.exit()'; echo $? |
|
2362 | 2357 | # 0 |
|
2363 | 2358 | # For other exit status, we show the exception unless |
|
2364 | 2359 | # explicitly silenced, but only in short form. |
|
2365 | 2360 | if kw['raise_exceptions']: |
|
2366 | 2361 | raise |
|
2367 | 2362 | if status.code not in (0, None) and not kw['exit_ignore']: |
|
2368 | 2363 | self.showtraceback(exception_only=True) |
|
2369 | 2364 | except: |
|
2370 | 2365 | if kw['raise_exceptions']: |
|
2371 | 2366 | raise |
|
2372 | 2367 | self.showtraceback() |
|
2373 | 2368 | |
|
2374 | 2369 | def safe_execfile_ipy(self, fname): |
|
2375 | 2370 | """Like safe_execfile, but for .ipy files with IPython syntax. |
|
2376 | 2371 | |
|
2377 | 2372 | Parameters |
|
2378 | 2373 | ---------- |
|
2379 | 2374 | fname : str |
|
2380 | 2375 | The name of the file to execute. The filename must have a |
|
2381 | 2376 | .ipy extension. |
|
2382 | 2377 | """ |
|
2383 | 2378 | fname = os.path.abspath(os.path.expanduser(fname)) |
|
2384 | 2379 | |
|
2385 | 2380 | # Make sure we can open the file |
|
2386 | 2381 | try: |
|
2387 | 2382 | with open(fname) as thefile: |
|
2388 | 2383 | pass |
|
2389 | 2384 | except: |
|
2390 | 2385 | warn('Could not open file <%s> for safe execution.' % fname) |
|
2391 | 2386 | return |
|
2392 | 2387 | |
|
2393 | 2388 | # Find things also in current directory. This is needed to mimic the |
|
2394 | 2389 | # behavior of running a script from the system command line, where |
|
2395 | 2390 | # Python inserts the script's directory into sys.path |
|
2396 | 2391 | dname = os.path.dirname(fname) |
|
2397 | 2392 | |
|
2398 | 2393 | with prepended_to_syspath(dname): |
|
2399 | 2394 | try: |
|
2400 | 2395 | with open(fname) as thefile: |
|
2401 | 2396 | # self.run_cell currently captures all exceptions |
|
2402 | 2397 | # raised in user code. It would be nice if there were |
|
2403 | 2398 | # versions of runlines, execfile that did raise, so |
|
2404 | 2399 | # we could catch the errors. |
|
2405 | 2400 | self.run_cell(thefile.read(), store_history=False) |
|
2406 | 2401 | except: |
|
2407 | 2402 | self.showtraceback() |
|
2408 | 2403 | warn('Unknown failure executing file: <%s>' % fname) |
|
2409 | 2404 | |
|
2410 | 2405 | def safe_run_module(self, mod_name, where): |
|
2411 | 2406 | """A safe version of runpy.run_module(). |
|
2412 | 2407 | |
|
2413 | 2408 | This version will never throw an exception, but instead print |
|
2414 | 2409 | helpful error messages to the screen. |
|
2415 | 2410 | |
|
2416 | 2411 | Parameters |
|
2417 | 2412 | ---------- |
|
2418 | 2413 | mod_name : string |
|
2419 | 2414 | The name of the module to be executed. |
|
2420 | 2415 | where : dict |
|
2421 | 2416 | The globals namespace. |
|
2422 | 2417 | """ |
|
2423 | 2418 | try: |
|
2424 | 2419 | where.update( |
|
2425 | 2420 | runpy.run_module(str(mod_name), run_name="__main__", |
|
2426 | 2421 | alter_sys=True) |
|
2427 | 2422 | ) |
|
2428 | 2423 | except: |
|
2429 | 2424 | self.showtraceback() |
|
2430 | 2425 | warn('Unknown failure executing module: <%s>' % mod_name) |
|
2431 | 2426 | |
|
2432 | 2427 | def run_cell(self, raw_cell, store_history=False): |
|
2433 | 2428 | """Run a complete IPython cell. |
|
2434 | 2429 | |
|
2435 | 2430 | Parameters |
|
2436 | 2431 | ---------- |
|
2437 | 2432 | raw_cell : str |
|
2438 | 2433 | The code (including IPython code such as %magic functions) to run. |
|
2439 | 2434 | store_history : bool |
|
2440 | 2435 | If True, the raw and translated cell will be stored in IPython's |
|
2441 | 2436 | history. For user code calling back into IPython's machinery, this |
|
2442 | 2437 | should be set to False. |
|
2443 | 2438 | """ |
|
2444 | 2439 | if (not raw_cell) or raw_cell.isspace(): |
|
2445 | 2440 | return |
|
2446 | 2441 | |
|
2447 | 2442 | for line in raw_cell.splitlines(): |
|
2448 | 2443 | self.input_splitter.push(line) |
|
2449 | 2444 | cell = self.input_splitter.source_reset() |
|
2450 | 2445 | |
|
2451 | 2446 | with self.builtin_trap: |
|
2452 | 2447 | prefilter_failed = False |
|
2453 | 2448 | if len(cell.splitlines()) == 1: |
|
2454 | 2449 | try: |
|
2455 | 2450 | # use prefilter_lines to handle trailing newlines |
|
2456 | 2451 | # restore trailing newline for ast.parse |
|
2457 | 2452 | cell = self.prefilter_manager.prefilter_lines(cell) + '\n' |
|
2458 | 2453 | except AliasError as e: |
|
2459 | 2454 | error(e) |
|
2460 | 2455 | prefilter_failed = True |
|
2461 | 2456 | except Exception: |
|
2462 | 2457 | # don't allow prefilter errors to crash IPython |
|
2463 | 2458 | self.showtraceback() |
|
2464 | 2459 | prefilter_failed = True |
|
2465 | 2460 | |
|
2466 | 2461 | # Store raw and processed history |
|
2467 | 2462 | if store_history: |
|
2468 | 2463 | self.history_manager.store_inputs(self.execution_count, |
|
2469 | 2464 | cell, raw_cell) |
|
2470 | 2465 | |
|
2471 | 2466 | self.logger.log(cell, raw_cell) |
|
2472 | 2467 | |
|
2473 | 2468 | if not prefilter_failed: |
|
2474 | 2469 | # don't run if prefilter failed |
|
2475 | 2470 | cell_name = self.compile.cache(cell, self.execution_count) |
|
2476 | 2471 | |
|
2477 | 2472 | with self.display_trap: |
|
2478 | 2473 | try: |
|
2479 | 2474 | code_ast = self.compile.ast_parse(cell, filename=cell_name) |
|
2480 | 2475 | except IndentationError: |
|
2481 | 2476 | self.showindentationerror() |
|
2482 | 2477 | if store_history: |
|
2483 | 2478 | self.execution_count += 1 |
|
2484 | 2479 | return None |
|
2485 | 2480 | except (OverflowError, SyntaxError, ValueError, TypeError, |
|
2486 | 2481 | MemoryError): |
|
2487 | 2482 | self.showsyntaxerror() |
|
2488 | 2483 | if store_history: |
|
2489 | 2484 | self.execution_count += 1 |
|
2490 | 2485 | return None |
|
2491 | 2486 | |
|
2492 | 2487 | self.run_ast_nodes(code_ast.body, cell_name, |
|
2493 | 2488 | interactivity="last_expr") |
|
2494 | 2489 | |
|
2495 | 2490 | # Execute any registered post-execution functions. |
|
2496 | 2491 | for func, status in self._post_execute.iteritems(): |
|
2497 | 2492 | if self.disable_failing_post_execute and not status: |
|
2498 | 2493 | continue |
|
2499 | 2494 | try: |
|
2500 | 2495 | func() |
|
2501 | 2496 | except KeyboardInterrupt: |
|
2502 | 2497 | print >> io.stderr, "\nKeyboardInterrupt" |
|
2503 | 2498 | except Exception: |
|
2504 | 2499 | # register as failing: |
|
2505 | 2500 | self._post_execute[func] = False |
|
2506 | 2501 | self.showtraceback() |
|
2507 | 2502 | print >> io.stderr, '\n'.join([ |
|
2508 | 2503 | "post-execution function %r produced an error." % func, |
|
2509 | 2504 | "If this problem persists, you can disable failing post-exec functions with:", |
|
2510 | 2505 | "", |
|
2511 | 2506 | " get_ipython().disable_failing_post_execute = True" |
|
2512 | 2507 | ]) |
|
2513 | 2508 | |
|
2514 | 2509 | if store_history: |
|
2515 | 2510 | # Write output to the database. Does nothing unless |
|
2516 | 2511 | # history output logging is enabled. |
|
2517 | 2512 | self.history_manager.store_output(self.execution_count) |
|
2518 | 2513 | # Each cell is a *single* input, regardless of how many lines it has |
|
2519 | 2514 | self.execution_count += 1 |
|
2520 | 2515 | |
|
2521 | 2516 | def run_ast_nodes(self, nodelist, cell_name, interactivity='last_expr'): |
|
2522 | 2517 | """Run a sequence of AST nodes. The execution mode depends on the |
|
2523 | 2518 | interactivity parameter. |
|
2524 | 2519 | |
|
2525 | 2520 | Parameters |
|
2526 | 2521 | ---------- |
|
2527 | 2522 | nodelist : list |
|
2528 | 2523 | A sequence of AST nodes to run. |
|
2529 | 2524 | cell_name : str |
|
2530 | 2525 | Will be passed to the compiler as the filename of the cell. Typically |
|
2531 | 2526 | the value returned by ip.compile.cache(cell). |
|
2532 | 2527 | interactivity : str |
|
2533 | 2528 | 'all', 'last', 'last_expr' or 'none', specifying which nodes should be |
|
2534 | 2529 | run interactively (displaying output from expressions). 'last_expr' |
|
2535 | 2530 | will run the last node interactively only if it is an expression (i.e. |
|
2536 | 2531 | expressions in loops or other blocks are not displayed. Other values |
|
2537 | 2532 | for this parameter will raise a ValueError. |
|
2538 | 2533 | """ |
|
2539 | 2534 | if not nodelist: |
|
2540 | 2535 | return |
|
2541 | 2536 | |
|
2542 | 2537 | if interactivity == 'last_expr': |
|
2543 | 2538 | if isinstance(nodelist[-1], ast.Expr): |
|
2544 | 2539 | interactivity = "last" |
|
2545 | 2540 | else: |
|
2546 | 2541 | interactivity = "none" |
|
2547 | 2542 | |
|
2548 | 2543 | if interactivity == 'none': |
|
2549 | 2544 | to_run_exec, to_run_interactive = nodelist, [] |
|
2550 | 2545 | elif interactivity == 'last': |
|
2551 | 2546 | to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:] |
|
2552 | 2547 | elif interactivity == 'all': |
|
2553 | 2548 | to_run_exec, to_run_interactive = [], nodelist |
|
2554 | 2549 | else: |
|
2555 | 2550 | raise ValueError("Interactivity was %r" % interactivity) |
|
2556 | 2551 | |
|
2557 | 2552 | exec_count = self.execution_count |
|
2558 | 2553 | |
|
2559 | 2554 | try: |
|
2560 | 2555 | for i, node in enumerate(to_run_exec): |
|
2561 | 2556 | mod = ast.Module([node]) |
|
2562 | 2557 | code = self.compile(mod, cell_name, "exec") |
|
2563 | 2558 | if self.run_code(code): |
|
2564 | 2559 | return True |
|
2565 | 2560 | |
|
2566 | 2561 | for i, node in enumerate(to_run_interactive): |
|
2567 | 2562 | mod = ast.Interactive([node]) |
|
2568 | 2563 | code = self.compile(mod, cell_name, "single") |
|
2569 | 2564 | if self.run_code(code): |
|
2570 | 2565 | return True |
|
2571 | 2566 | |
|
2572 | 2567 | # Flush softspace |
|
2573 | 2568 | if softspace(sys.stdout, 0): |
|
2574 | 2569 | |
|
2575 | 2570 | |
|
2576 | 2571 | except: |
|
2577 | 2572 | # It's possible to have exceptions raised here, typically by |
|
2578 | 2573 | # compilation of odd code (such as a naked 'return' outside a |
|
2579 | 2574 | # function) that did parse but isn't valid. Typically the exception |
|
2580 | 2575 | # is a SyntaxError, but it's safest just to catch anything and show |
|
2581 | 2576 | # the user a traceback. |
|
2582 | 2577 | |
|
2583 | 2578 | # We do only one try/except outside the loop to minimize the impact |
|
2584 | 2579 | # on runtime, and also because if any node in the node list is |
|
2585 | 2580 | # broken, we should stop execution completely. |
|
2586 | 2581 | self.showtraceback() |
|
2587 | 2582 | |
|
2588 | 2583 | return False |
|
2589 | 2584 | |
|
2590 | 2585 | def run_code(self, code_obj): |
|
2591 | 2586 | """Execute a code object. |
|
2592 | 2587 | |
|
2593 | 2588 | When an exception occurs, self.showtraceback() is called to display a |
|
2594 | 2589 | traceback. |
|
2595 | 2590 | |
|
2596 | 2591 | Parameters |
|
2597 | 2592 | ---------- |
|
2598 | 2593 | code_obj : code object |
|
2599 | 2594 | A compiled code object, to be executed |
|
2600 | 2595 | |
|
2601 | 2596 | Returns |
|
2602 | 2597 | ------- |
|
2603 | 2598 | False : successful execution. |
|
2604 | 2599 | True : an error occurred. |
|
2605 | 2600 | """ |
|
2606 | 2601 | |
|
2607 | 2602 | # Set our own excepthook in case the user code tries to call it |
|
2608 | 2603 | # directly, so that the IPython crash handler doesn't get triggered |
|
2609 | 2604 | old_excepthook,sys.excepthook = sys.excepthook, self.excepthook |
|
2610 | 2605 | |
|
2611 | 2606 | # we save the original sys.excepthook in the instance, in case config |
|
2612 | 2607 | # code (such as magics) needs access to it. |
|
2613 | 2608 | self.sys_excepthook = old_excepthook |
|
2614 | 2609 | outflag = 1 # happens in more places, so it's easier as default |
|
2615 | 2610 | try: |
|
2616 | 2611 | try: |
|
2617 | 2612 | self.hooks.pre_run_code_hook() |
|
2618 | 2613 | #rprint('Running code', repr(code_obj)) # dbg |
|
2619 | 2614 | exec code_obj in self.user_global_ns, self.user_ns |
|
2620 | 2615 | finally: |
|
2621 | 2616 | # Reset our crash handler in place |
|
2622 | 2617 | sys.excepthook = old_excepthook |
|
2623 | 2618 | except SystemExit: |
|
2624 | 2619 | self.showtraceback(exception_only=True) |
|
2625 | 2620 | warn("To exit: use 'exit', 'quit', or Ctrl-D.", level=1) |
|
2626 | 2621 | except self.custom_exceptions: |
|
2627 | 2622 | etype,value,tb = sys.exc_info() |
|
2628 | 2623 | self.CustomTB(etype,value,tb) |
|
2629 | 2624 | except: |
|
2630 | 2625 | self.showtraceback() |
|
2631 | 2626 | else: |
|
2632 | 2627 | outflag = 0 |
|
2633 | 2628 | return outflag |
|
2634 | 2629 | |
|
2635 | 2630 | # For backwards compatibility |
|
2636 | 2631 | runcode = run_code |
|
2637 | 2632 | |
|
2638 | 2633 | #------------------------------------------------------------------------- |
|
2639 | 2634 | # Things related to GUI support and pylab |
|
2640 | 2635 | #------------------------------------------------------------------------- |
|
2641 | 2636 | |
|
2642 | 2637 | def enable_gui(self, gui=None): |
|
2643 | 2638 | raise NotImplementedError('Implement enable_gui in a subclass') |
|
2644 | 2639 | |
|
2645 | 2640 | def enable_pylab(self, gui=None, import_all=True): |
|
2646 | 2641 | """Activate pylab support at runtime. |
|
2647 | 2642 | |
|
2648 | 2643 | This turns on support for matplotlib, preloads into the interactive |
|
2649 | 2644 | namespace all of numpy and pylab, and configures IPython to correctly |
|
2650 | 2645 | interact with the GUI event loop. The GUI backend to be used can be |
|
2651 | 2646 | optionally selected with the optional :param:`gui` argument. |
|
2652 | 2647 | |
|
2653 | 2648 | Parameters |
|
2654 | 2649 | ---------- |
|
2655 | 2650 | gui : optional, string |
|
2656 | 2651 | |
|
2657 | 2652 | If given, dictates the choice of matplotlib GUI backend to use |
|
2658 | 2653 | (should be one of IPython's supported backends, 'qt', 'osx', 'tk', |
|
2659 | 2654 | 'gtk', 'wx' or 'inline'), otherwise we use the default chosen by |
|
2660 | 2655 | matplotlib (as dictated by the matplotlib build-time options plus the |
|
2661 | 2656 | user's matplotlibrc configuration file). Note that not all backends |
|
2662 | 2657 | make sense in all contexts, for example a terminal ipython can't |
|
2663 | 2658 | display figures inline. |
|
2664 | 2659 | """ |
|
2665 | 2660 | |
|
2666 | 2661 | # We want to prevent the loading of pylab to pollute the user's |
|
2667 | 2662 | # namespace as shown by the %who* magics, so we execute the activation |
|
2668 | 2663 | # code in an empty namespace, and we update *both* user_ns and |
|
2669 | 2664 | # user_ns_hidden with this information. |
|
2670 | 2665 | ns = {} |
|
2671 | 2666 | try: |
|
2672 | 2667 | gui = pylab_activate(ns, gui, import_all, self) |
|
2673 | 2668 | except KeyError: |
|
2674 | 2669 | error("Backend %r not supported" % gui) |
|
2675 | 2670 | return |
|
2676 | 2671 | self.user_ns.update(ns) |
|
2677 | 2672 | self.user_ns_hidden.update(ns) |
|
2678 | 2673 | # Now we must activate the gui pylab wants to use, and fix %run to take |
|
2679 | 2674 | # plot updates into account |
|
2680 | 2675 | self.enable_gui(gui) |
|
2681 | 2676 | self.magic_run = self._pylab_magic_run |
|
2682 | 2677 | |
|
2683 | 2678 | #------------------------------------------------------------------------- |
|
2684 | 2679 | # Utilities |
|
2685 | 2680 | #------------------------------------------------------------------------- |
|
2686 | 2681 | |
|
2687 | 2682 | def var_expand(self, cmd, depth=0, formatter=DollarFormatter()): |
|
2688 | 2683 | """Expand python variables in a string. |
|
2689 | 2684 | |
|
2690 | 2685 | The depth argument indicates how many frames above the caller should |
|
2691 | 2686 | be walked to look for the local namespace where to expand variables. |
|
2692 | 2687 | |
|
2693 | 2688 | The global namespace for expansion is always the user's interactive |
|
2694 | 2689 | namespace. |
|
2695 | 2690 | """ |
|
2696 | 2691 | ns = self.user_ns.copy() |
|
2697 | 2692 | ns.update(sys._getframe(depth+1).f_locals) |
|
2698 | 2693 | ns.pop('self', None) |
|
2699 | 2694 | try: |
|
2700 | 2695 | cmd = formatter.format(cmd, **ns) |
|
2701 | 2696 | except Exception: |
|
2702 | 2697 | # if formatter couldn't format, just let it go untransformed |
|
2703 | 2698 | pass |
|
2704 | 2699 | return cmd |
|
2705 | 2700 | |
|
2706 | 2701 | def mktempfile(self, data=None, prefix='ipython_edit_'): |
|
2707 | 2702 | """Make a new tempfile and return its filename. |
|
2708 | 2703 | |
|
2709 | 2704 | This makes a call to tempfile.mktemp, but it registers the created |
|
2710 | 2705 | filename internally so ipython cleans it up at exit time. |
|
2711 | 2706 | |
|
2712 | 2707 | Optional inputs: |
|
2713 | 2708 | |
|
2714 | 2709 | - data(None): if data is given, it gets written out to the temp file |
|
2715 | 2710 | immediately, and the file is closed again.""" |
|
2716 | 2711 | |
|
2717 | 2712 | filename = tempfile.mktemp('.py', prefix) |
|
2718 | 2713 | self.tempfiles.append(filename) |
|
2719 | 2714 | |
|
2720 | 2715 | if data: |
|
2721 | 2716 | tmp_file = open(filename,'w') |
|
2722 | 2717 | tmp_file.write(data) |
|
2723 | 2718 | tmp_file.close() |
|
2724 | 2719 | return filename |
|
2725 | 2720 | |
|
2726 | 2721 | # TODO: This should be removed when Term is refactored. |
|
2727 | 2722 | def write(self,data): |
|
2728 | 2723 | """Write a string to the default output""" |
|
2729 | 2724 | io.stdout.write(data) |
|
2730 | 2725 | |
|
2731 | 2726 | # TODO: This should be removed when Term is refactored. |
|
2732 | 2727 | def write_err(self,data): |
|
2733 | 2728 | """Write a string to the default error output""" |
|
2734 | 2729 | io.stderr.write(data) |
|
2735 | 2730 | |
|
2736 | 2731 | def ask_yes_no(self, prompt, default=None): |
|
2737 | 2732 | if self.quiet: |
|
2738 | 2733 | return True |
|
2739 | 2734 | return ask_yes_no(prompt,default) |
|
2740 | 2735 | |
|
2741 | 2736 | def show_usage(self): |
|
2742 | 2737 | """Show a usage message""" |
|
2743 | 2738 | page.page(IPython.core.usage.interactive_usage) |
|
2744 | 2739 | |
|
2745 | def find_user_code(self, target, raw=True): | |
|
2746 | """Get a code string from history, file, or a string or macro. | |
|
2740 | def find_user_code(self, target, raw=True, py_only=False): | |
|
2741 | """Get a code string from history, file, url, or a string or macro. | |
|
2747 | 2742 | |
|
2748 | 2743 | This is mainly used by magic functions. |
|
2749 | 2744 | |
|
2750 | 2745 | Parameters |
|
2751 | 2746 | ---------- |
|
2747 | ||
|
2752 | 2748 | target : str |
|
2749 | ||
|
2753 | 2750 | A string specifying code to retrieve. This will be tried respectively |
|
2754 |
as: ranges of input history (see %history for syntax), |
|
|
2755 | an expression evaluating to a string or Macro in the user namespace. | |
|
2751 | as: ranges of input history (see %history for syntax), url, | |
|
2752 | correspnding .py file, filename, or an expression evaluating to a | |
|
2753 | string or Macro in the user namespace. | |
|
2754 | ||
|
2756 | 2755 | raw : bool |
|
2757 | 2756 | If true (default), retrieve raw history. Has no effect on the other |
|
2758 | 2757 | retrieval mechanisms. |
|
2759 | 2758 | |
|
2759 | py_only : bool (default False) | |
|
2760 | Only try to fetch python code, do not try alternative methods to decode file | |
|
2761 | if unicode fails. | |
|
2762 | ||
|
2760 | 2763 | Returns |
|
2761 | 2764 | ------- |
|
2762 | 2765 | A string of code. |
|
2763 | 2766 | |
|
2764 | 2767 | ValueError is raised if nothing is found, and TypeError if it evaluates |
|
2765 | 2768 | to an object of another type. In each case, .args[0] is a printable |
|
2766 | 2769 | message. |
|
2767 | 2770 | """ |
|
2768 | 2771 | code = self.extract_input_lines(target, raw=raw) # Grab history |
|
2769 | 2772 | if code: |
|
2770 | 2773 | return code |
|
2771 | if os.path.isfile(target): # Read file | |
|
2772 | return open(target, "r").read() | |
|
2774 | utarget = unquote_filename(target) | |
|
2775 | try: | |
|
2776 | if utarget.startswith(('http://', 'https://')): | |
|
2777 | return openpy.read_py_url(utarget, skip_encoding_cookie=True) | |
|
2778 | except UnicodeDecodeError: | |
|
2779 | if not py_only : | |
|
2780 | response = urllib.urlopen(target) | |
|
2781 | return response.read().decode('latin1') | |
|
2782 | raise ValueError(("'%s' seem to be unreadable.") % utarget) | |
|
2783 | ||
|
2784 | potential_target = [target] | |
|
2785 | try : | |
|
2786 | potential_target.insert(0,get_py_filename(target)) | |
|
2787 | except IOError: | |
|
2788 | pass | |
|
2789 | ||
|
2790 | for tgt in potential_target : | |
|
2791 | if os.path.isfile(tgt): # Read file | |
|
2792 | try : | |
|
2793 | return openpy.read_py_file(tgt, skip_encoding_cookie=True) | |
|
2794 | except UnicodeDecodeError : | |
|
2795 | if not py_only : | |
|
2796 | with io_open(tgt,'r', encoding='latin1') as f : | |
|
2797 | return f.read() | |
|
2798 | raise ValueError(("'%s' seem to be unreadable.") % target) | |
|
2773 | 2799 | |
|
2774 | 2800 | try: # User namespace |
|
2775 | 2801 | codeobj = eval(target, self.user_ns) |
|
2776 | 2802 | except Exception: |
|
2777 |
raise ValueError(("'%s' was not found in history, as a file, |
|
|
2778 | " the user namespace.") % target) | |
|
2803 | raise ValueError(("'%s' was not found in history, as a file, url, " | |
|
2804 | "nor in the user namespace.") % target) | |
|
2779 | 2805 | if isinstance(codeobj, basestring): |
|
2780 | 2806 | return codeobj |
|
2781 | 2807 | elif isinstance(codeobj, Macro): |
|
2782 | 2808 | return codeobj.value |
|
2783 | 2809 | |
|
2784 | 2810 | raise TypeError("%s is neither a string nor a macro." % target, |
|
2785 | 2811 | codeobj) |
|
2786 | 2812 | |
|
2787 | 2813 | #------------------------------------------------------------------------- |
|
2788 | 2814 | # Things related to IPython exiting |
|
2789 | 2815 | #------------------------------------------------------------------------- |
|
2790 | 2816 | def atexit_operations(self): |
|
2791 | 2817 | """This will be executed at the time of exit. |
|
2792 | 2818 | |
|
2793 | 2819 | Cleanup operations and saving of persistent data that is done |
|
2794 | 2820 | unconditionally by IPython should be performed here. |
|
2795 | 2821 | |
|
2796 | 2822 | For things that may depend on startup flags or platform specifics (such |
|
2797 | 2823 | as having readline or not), register a separate atexit function in the |
|
2798 | 2824 | code that has the appropriate information, rather than trying to |
|
2799 | 2825 | clutter |
|
2800 | 2826 | """ |
|
2801 | 2827 | # Close the history session (this stores the end time and line count) |
|
2802 | 2828 | # this must be *before* the tempfile cleanup, in case of temporary |
|
2803 | 2829 | # history db |
|
2804 | 2830 | self.history_manager.end_session() |
|
2805 | 2831 | |
|
2806 | 2832 | # Cleanup all tempfiles left around |
|
2807 | 2833 | for tfile in self.tempfiles: |
|
2808 | 2834 | try: |
|
2809 | 2835 | os.unlink(tfile) |
|
2810 | 2836 | except OSError: |
|
2811 | 2837 | pass |
|
2812 | 2838 | |
|
2813 | 2839 | # Clear all user namespaces to release all references cleanly. |
|
2814 | 2840 | self.reset(new_session=False) |
|
2815 | 2841 | |
|
2816 | 2842 | # Run user hooks |
|
2817 | 2843 | self.hooks.shutdown_hook() |
|
2818 | 2844 | |
|
2819 | 2845 | def cleanup(self): |
|
2820 | 2846 | self.restore_sys_module_state() |
|
2821 | 2847 | |
|
2822 | 2848 | |
|
2823 | 2849 | class InteractiveShellABC(object): |
|
2824 | 2850 | """An abstract base class for InteractiveShell.""" |
|
2825 | 2851 | __metaclass__ = abc.ABCMeta |
|
2826 | 2852 | |
|
2827 | 2853 | InteractiveShellABC.register(InteractiveShell) |
@@ -1,3827 +1,3852 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """Magic functions for InteractiveShell. |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | 6 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
7 | 7 | # Copyright (C) 2001-2007 Fernando Perez <fperez@colorado.edu> |
|
8 | 8 | # Copyright (C) 2008-2011 The IPython Development Team |
|
9 | 9 | |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #----------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | import __builtin__ as builtin_mod |
|
19 | 19 | import __future__ |
|
20 | 20 | import bdb |
|
21 | 21 | import inspect |
|
22 | import imp | |
|
23 | 22 | import io |
|
24 | 23 | import json |
|
25 | 24 | import os |
|
26 | 25 | import sys |
|
27 | import shutil | |
|
28 | 26 | import re |
|
29 | 27 | import time |
|
30 | 28 | import gc |
|
31 | 29 | from StringIO import StringIO |
|
32 | 30 | from getopt import getopt,GetoptError |
|
33 | 31 | from pprint import pformat |
|
34 | 32 | from urllib2 import urlopen |
|
35 | 33 | |
|
36 | 34 | # cProfile was added in Python2.5 |
|
37 | 35 | try: |
|
38 | 36 | import cProfile as profile |
|
39 | 37 | import pstats |
|
40 | 38 | except ImportError: |
|
41 | 39 | # profile isn't bundled by default in Debian for license reasons |
|
42 | 40 | try: |
|
43 | 41 | import profile,pstats |
|
44 | 42 | except ImportError: |
|
45 | 43 | profile = pstats = None |
|
46 | 44 | |
|
47 | import IPython | |
|
48 | 45 | from IPython.core import debugger, oinspect |
|
49 | 46 | from IPython.core.error import TryNext |
|
50 | 47 | from IPython.core.error import UsageError |
|
51 | 48 | from IPython.core.error import StdinNotImplementedError |
|
52 | from IPython.core.fakemodule import FakeModule | |
|
53 | from IPython.core.profiledir import ProfileDir | |
|
54 | 49 | from IPython.core.macro import Macro |
|
55 | 50 | from IPython.core import magic_arguments, page |
|
56 | 51 | from IPython.core.prefilter import ESC_MAGIC |
|
57 | 52 | from IPython.core.pylabtools import mpl_runner |
|
58 | 53 | from IPython.testing.skipdoctest import skip_doctest |
|
59 | 54 | from IPython.utils import py3compat |
|
60 | from IPython.utils import openpy | |
|
61 | 55 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
62 | 56 | from IPython.utils.io import file_read, nlprint |
|
63 | 57 | from IPython.utils.module_paths import find_mod |
|
64 | 58 | from IPython.utils.path import get_py_filename, unquote_filename |
|
65 | 59 | from IPython.utils.process import arg_split, abbrev_cwd |
|
66 | 60 | from IPython.utils.terminal import set_term_title |
|
67 |
from IPython.utils.text import |
|
|
61 | from IPython.utils.text import format_screen | |
|
68 | 62 | from IPython.utils.timing import clock, clock2 |
|
69 | 63 | from IPython.utils.warn import warn, error |
|
70 | 64 | from IPython.utils.ipstruct import Struct |
|
71 | 65 | from IPython.config.application import Application |
|
72 | 66 | |
|
73 | 67 | #----------------------------------------------------------------------------- |
|
74 | 68 | # Utility functions |
|
75 | 69 | #----------------------------------------------------------------------------- |
|
76 | 70 | |
|
77 | 71 | def on_off(tag): |
|
78 | 72 | """Return an ON/OFF string for a 1/0 input. Simple utility function.""" |
|
79 | 73 | return ['OFF','ON'][tag] |
|
80 | 74 | |
|
81 | 75 | class Bunch: pass |
|
82 | 76 | |
|
83 | 77 | def compress_dhist(dh): |
|
84 | 78 | head, tail = dh[:-10], dh[-10:] |
|
85 | 79 | |
|
86 | 80 | newhead = [] |
|
87 | 81 | done = set() |
|
88 | 82 | for h in head: |
|
89 | 83 | if h in done: |
|
90 | 84 | continue |
|
91 | 85 | newhead.append(h) |
|
92 | 86 | done.add(h) |
|
93 | 87 | |
|
94 | 88 | return newhead + tail |
|
95 | 89 | |
|
96 | 90 | def needs_local_scope(func): |
|
97 | 91 | """Decorator to mark magic functions which need to local scope to run.""" |
|
98 | 92 | func.needs_local_scope = True |
|
99 | 93 | return func |
|
100 | 94 | |
|
101 | 95 | |
|
102 | 96 | # Used for exception handling in magic_edit |
|
103 | 97 | class MacroToEdit(ValueError): pass |
|
104 | 98 | |
|
105 | 99 | #*************************************************************************** |
|
106 | 100 | # Main class implementing Magic functionality |
|
107 | 101 | |
|
108 | 102 | # XXX - for some odd reason, if Magic is made a new-style class, we get errors |
|
109 | 103 | # on construction of the main InteractiveShell object. Something odd is going |
|
110 | 104 | # on with super() calls, Configurable and the MRO... For now leave it as-is, but |
|
111 | 105 | # eventually this needs to be clarified. |
|
112 | 106 | # BG: This is because InteractiveShell inherits from this, but is itself a |
|
113 | 107 | # Configurable. This messes up the MRO in some way. The fix is that we need to |
|
114 | 108 | # make Magic a configurable that InteractiveShell does not subclass. |
|
115 | 109 | |
|
116 | 110 | class Magic: |
|
117 | 111 | """Magic functions for InteractiveShell. |
|
118 | 112 | |
|
119 | 113 | Shell functions which can be reached as %function_name. All magic |
|
120 | 114 | functions should accept a string, which they can parse for their own |
|
121 | 115 | needs. This can make some functions easier to type, eg `%cd ../` |
|
122 | 116 | vs. `%cd("../")` |
|
123 | 117 | |
|
124 | 118 | ALL definitions MUST begin with the prefix magic_. The user won't need it |
|
125 | 119 | at the command line, but it is is needed in the definition. """ |
|
126 | 120 | |
|
127 | 121 | # class globals |
|
128 | 122 | auto_status = ['Automagic is OFF, % prefix IS needed for magic functions.', |
|
129 | 123 | 'Automagic is ON, % prefix NOT needed for magic functions.'] |
|
130 | 124 | |
|
131 | 125 | |
|
132 | 126 | configurables = None |
|
133 | 127 | #...................................................................... |
|
134 | 128 | # some utility functions |
|
135 | 129 | |
|
136 | 130 | def __init__(self,shell): |
|
137 | 131 | |
|
138 | 132 | self.options_table = {} |
|
139 | 133 | if profile is None: |
|
140 | 134 | self.magic_prun = self.profile_missing_notice |
|
141 | 135 | self.shell = shell |
|
142 | 136 | if self.configurables is None: |
|
143 | 137 | self.configurables = [] |
|
144 | 138 | |
|
145 | 139 | # namespace for holding state we may need |
|
146 | 140 | self._magic_state = Bunch() |
|
147 | 141 | |
|
148 | 142 | def profile_missing_notice(self, *args, **kwargs): |
|
149 | 143 | error("""\ |
|
150 | 144 | The profile module could not be found. It has been removed from the standard |
|
151 | 145 | python packages because of its non-free license. To use profiling, install the |
|
152 | 146 | python-profiler package from non-free.""") |
|
153 | 147 | |
|
154 | 148 | def default_option(self,fn,optstr): |
|
155 | 149 | """Make an entry in the options_table for fn, with value optstr""" |
|
156 | 150 | |
|
157 | 151 | if fn not in self.lsmagic(): |
|
158 | 152 | error("%s is not a magic function" % fn) |
|
159 | 153 | self.options_table[fn] = optstr |
|
160 | 154 | |
|
161 | 155 | def lsmagic(self): |
|
162 | 156 | """Return a list of currently available magic functions. |
|
163 | 157 | |
|
164 | 158 | Gives a list of the bare names after mangling (['ls','cd', ...], not |
|
165 | 159 | ['magic_ls','magic_cd',...]""" |
|
166 | 160 | |
|
167 | 161 | # FIXME. This needs a cleanup, in the way the magics list is built. |
|
168 | 162 | |
|
169 | 163 | # magics in class definition |
|
170 | 164 | class_magic = lambda fn: fn.startswith('magic_') and \ |
|
171 | 165 | callable(Magic.__dict__[fn]) |
|
172 | 166 | # in instance namespace (run-time user additions) |
|
173 | 167 | inst_magic = lambda fn: fn.startswith('magic_') and \ |
|
174 | 168 | callable(self.__dict__[fn]) |
|
175 | 169 | # and bound magics by user (so they can access self): |
|
176 | 170 | inst_bound_magic = lambda fn: fn.startswith('magic_') and \ |
|
177 | 171 | callable(self.__class__.__dict__[fn]) |
|
178 | 172 | magics = filter(class_magic,Magic.__dict__.keys()) + \ |
|
179 | 173 | filter(inst_magic,self.__dict__.keys()) + \ |
|
180 | 174 | filter(inst_bound_magic,self.__class__.__dict__.keys()) |
|
181 | 175 | out = [] |
|
182 | 176 | for fn in set(magics): |
|
183 | 177 | out.append(fn.replace('magic_','',1)) |
|
184 | 178 | out.sort() |
|
185 | 179 | return out |
|
186 | 180 | |
|
187 | 181 | def extract_input_lines(self, range_str, raw=False): |
|
188 | 182 | """Return as a string a set of input history slices. |
|
189 | 183 | |
|
190 | 184 | Parameters |
|
191 | 185 | ---------- |
|
192 | 186 | range_str : string |
|
193 | 187 | The set of slices is given as a string, like "~5/6-~4/2 4:8 9", |
|
194 | 188 | since this function is for use by magic functions which get their |
|
195 | 189 | arguments as strings. The number before the / is the session |
|
196 | 190 | number: ~n goes n back from the current session. |
|
197 | 191 | |
|
198 | 192 | Optional Parameters: |
|
199 | 193 | - raw(False): by default, the processed input is used. If this is |
|
200 | 194 | true, the raw input history is used instead. |
|
201 | 195 | |
|
202 | 196 | Note that slices can be called with two notations: |
|
203 | 197 | |
|
204 | 198 | N:M -> standard python form, means including items N...(M-1). |
|
205 | 199 | |
|
206 | 200 | N-M -> include items N..M (closed endpoint).""" |
|
207 | 201 | lines = self.shell.history_manager.\ |
|
208 | 202 | get_range_by_str(range_str, raw=raw) |
|
209 | 203 | return "\n".join(x for _, _, x in lines) |
|
210 | 204 | |
|
211 | 205 | def arg_err(self,func): |
|
212 | 206 | """Print docstring if incorrect arguments were passed""" |
|
213 | 207 | print 'Error in arguments:' |
|
214 | 208 | print oinspect.getdoc(func) |
|
215 | 209 | |
|
216 | 210 | def format_latex(self,strng): |
|
217 | 211 | """Format a string for latex inclusion.""" |
|
218 | 212 | |
|
219 | 213 | # Characters that need to be escaped for latex: |
|
220 | 214 | escape_re = re.compile(r'(%|_|\$|#|&)',re.MULTILINE) |
|
221 | 215 | # Magic command names as headers: |
|
222 | 216 | cmd_name_re = re.compile(r'^(%s.*?):' % ESC_MAGIC, |
|
223 | 217 | re.MULTILINE) |
|
224 | 218 | # Magic commands |
|
225 | 219 | cmd_re = re.compile(r'(?P<cmd>%s.+?\b)(?!\}\}:)' % ESC_MAGIC, |
|
226 | 220 | re.MULTILINE) |
|
227 | 221 | # Paragraph continue |
|
228 | 222 | par_re = re.compile(r'\\$',re.MULTILINE) |
|
229 | 223 | |
|
230 | 224 | # The "\n" symbol |
|
231 | 225 | newline_re = re.compile(r'\\n') |
|
232 | 226 | |
|
233 | 227 | # Now build the string for output: |
|
234 | 228 | #strng = cmd_name_re.sub(r'\n\\texttt{\\textsl{\\large \1}}:',strng) |
|
235 | 229 | strng = cmd_name_re.sub(r'\n\\bigskip\n\\texttt{\\textbf{ \1}}:', |
|
236 | 230 | strng) |
|
237 | 231 | strng = cmd_re.sub(r'\\texttt{\g<cmd>}',strng) |
|
238 | 232 | strng = par_re.sub(r'\\\\',strng) |
|
239 | 233 | strng = escape_re.sub(r'\\\1',strng) |
|
240 | 234 | strng = newline_re.sub(r'\\textbackslash{}n',strng) |
|
241 | 235 | return strng |
|
242 | 236 | |
|
243 | 237 | def parse_options(self,arg_str,opt_str,*long_opts,**kw): |
|
244 | 238 | """Parse options passed to an argument string. |
|
245 | 239 | |
|
246 | 240 | The interface is similar to that of getopt(), but it returns back a |
|
247 | 241 | Struct with the options as keys and the stripped argument string still |
|
248 | 242 | as a string. |
|
249 | 243 | |
|
250 | 244 | arg_str is quoted as a true sys.argv vector by using shlex.split. |
|
251 | 245 | This allows us to easily expand variables, glob files, quote |
|
252 | 246 | arguments, etc. |
|
253 | 247 | |
|
254 | 248 | Options: |
|
255 | 249 | -mode: default 'string'. If given as 'list', the argument string is |
|
256 | 250 | returned as a list (split on whitespace) instead of a string. |
|
257 | 251 | |
|
258 | 252 | -list_all: put all option values in lists. Normally only options |
|
259 | 253 | appearing more than once are put in a list. |
|
260 | 254 | |
|
261 | 255 | -posix (True): whether to split the input line in POSIX mode or not, |
|
262 | 256 | as per the conventions outlined in the shlex module from the |
|
263 | 257 | standard library.""" |
|
264 | 258 | |
|
265 | 259 | # inject default options at the beginning of the input line |
|
266 | 260 | caller = sys._getframe(1).f_code.co_name.replace('magic_','') |
|
267 | 261 | arg_str = '%s %s' % (self.options_table.get(caller,''),arg_str) |
|
268 | 262 | |
|
269 | 263 | mode = kw.get('mode','string') |
|
270 | 264 | if mode not in ['string','list']: |
|
271 | 265 | raise ValueError,'incorrect mode given: %s' % mode |
|
272 | 266 | # Get options |
|
273 | 267 | list_all = kw.get('list_all',0) |
|
274 | 268 | posix = kw.get('posix', os.name == 'posix') |
|
275 | 269 | strict = kw.get('strict', True) |
|
276 | 270 | |
|
277 | 271 | # Check if we have more than one argument to warrant extra processing: |
|
278 | 272 | odict = {} # Dictionary with options |
|
279 | 273 | args = arg_str.split() |
|
280 | 274 | if len(args) >= 1: |
|
281 | 275 | # If the list of inputs only has 0 or 1 thing in it, there's no |
|
282 | 276 | # need to look for options |
|
283 | 277 | argv = arg_split(arg_str, posix, strict) |
|
284 | 278 | # Do regular option processing |
|
285 | 279 | try: |
|
286 | 280 | opts,args = getopt(argv,opt_str,*long_opts) |
|
287 | 281 | except GetoptError,e: |
|
288 | 282 | raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str, |
|
289 | 283 | " ".join(long_opts))) |
|
290 | 284 | for o,a in opts: |
|
291 | 285 | if o.startswith('--'): |
|
292 | 286 | o = o[2:] |
|
293 | 287 | else: |
|
294 | 288 | o = o[1:] |
|
295 | 289 | try: |
|
296 | 290 | odict[o].append(a) |
|
297 | 291 | except AttributeError: |
|
298 | 292 | odict[o] = [odict[o],a] |
|
299 | 293 | except KeyError: |
|
300 | 294 | if list_all: |
|
301 | 295 | odict[o] = [a] |
|
302 | 296 | else: |
|
303 | 297 | odict[o] = a |
|
304 | 298 | |
|
305 | 299 | # Prepare opts,args for return |
|
306 | 300 | opts = Struct(odict) |
|
307 | 301 | if mode == 'string': |
|
308 | 302 | args = ' '.join(args) |
|
309 | 303 | |
|
310 | 304 | return opts,args |
|
311 | 305 | |
|
312 | 306 | #...................................................................... |
|
313 | 307 | # And now the actual magic functions |
|
314 | 308 | |
|
315 | 309 | # Functions for IPython shell work (vars,funcs, config, etc) |
|
316 | 310 | def magic_lsmagic(self, parameter_s = ''): |
|
317 | 311 | """List currently available magic functions.""" |
|
318 | 312 | mesc = ESC_MAGIC |
|
319 | 313 | print 'Available magic functions:\n'+mesc+\ |
|
320 | 314 | (' '+mesc).join(self.lsmagic()) |
|
321 | 315 | print '\n' + Magic.auto_status[self.shell.automagic] |
|
322 | 316 | return None |
|
323 | 317 | |
|
324 | 318 | def magic_magic(self, parameter_s = ''): |
|
325 | 319 | """Print information about the magic function system. |
|
326 | 320 | |
|
327 | 321 | Supported formats: -latex, -brief, -rest |
|
328 | 322 | """ |
|
329 | 323 | |
|
330 | 324 | mode = '' |
|
331 | 325 | try: |
|
332 | 326 | if parameter_s.split()[0] == '-latex': |
|
333 | 327 | mode = 'latex' |
|
334 | 328 | if parameter_s.split()[0] == '-brief': |
|
335 | 329 | mode = 'brief' |
|
336 | 330 | if parameter_s.split()[0] == '-rest': |
|
337 | 331 | mode = 'rest' |
|
338 | 332 | rest_docs = [] |
|
339 | 333 | except: |
|
340 | 334 | pass |
|
341 | 335 | |
|
342 | 336 | magic_docs = [] |
|
343 | 337 | for fname in self.lsmagic(): |
|
344 | 338 | mname = 'magic_' + fname |
|
345 | 339 | for space in (Magic,self,self.__class__): |
|
346 | 340 | try: |
|
347 | 341 | fn = space.__dict__[mname] |
|
348 | 342 | except KeyError: |
|
349 | 343 | pass |
|
350 | 344 | else: |
|
351 | 345 | break |
|
352 | 346 | if mode == 'brief': |
|
353 | 347 | # only first line |
|
354 | 348 | if fn.__doc__: |
|
355 | 349 | fndoc = fn.__doc__.split('\n',1)[0] |
|
356 | 350 | else: |
|
357 | 351 | fndoc = 'No documentation' |
|
358 | 352 | else: |
|
359 | 353 | if fn.__doc__: |
|
360 | 354 | fndoc = fn.__doc__.rstrip() |
|
361 | 355 | else: |
|
362 | 356 | fndoc = 'No documentation' |
|
363 | 357 | |
|
364 | 358 | |
|
365 | 359 | if mode == 'rest': |
|
366 | 360 | rest_docs.append('**%s%s**::\n\n\t%s\n\n' %(ESC_MAGIC, |
|
367 | 361 | fname,fndoc)) |
|
368 | 362 | |
|
369 | 363 | else: |
|
370 | 364 | magic_docs.append('%s%s:\n\t%s\n' %(ESC_MAGIC, |
|
371 | 365 | fname,fndoc)) |
|
372 | 366 | |
|
373 | 367 | magic_docs = ''.join(magic_docs) |
|
374 | 368 | |
|
375 | 369 | if mode == 'rest': |
|
376 | 370 | return "".join(rest_docs) |
|
377 | 371 | |
|
378 | 372 | if mode == 'latex': |
|
379 | 373 | print self.format_latex(magic_docs) |
|
380 | 374 | return |
|
381 | 375 | else: |
|
382 | 376 | magic_docs = format_screen(magic_docs) |
|
383 | 377 | if mode == 'brief': |
|
384 | 378 | return magic_docs |
|
385 | 379 | |
|
386 | 380 | outmsg = """ |
|
387 | 381 | IPython's 'magic' functions |
|
388 | 382 | =========================== |
|
389 | 383 | |
|
390 | 384 | The magic function system provides a series of functions which allow you to |
|
391 | 385 | control the behavior of IPython itself, plus a lot of system-type |
|
392 | 386 | features. All these functions are prefixed with a % character, but parameters |
|
393 | 387 | are given without parentheses or quotes. |
|
394 | 388 | |
|
395 | 389 | NOTE: If you have 'automagic' enabled (via the command line option or with the |
|
396 | 390 | %automagic function), you don't need to type in the % explicitly. By default, |
|
397 | 391 | IPython ships with automagic on, so you should only rarely need the % escape. |
|
398 | 392 | |
|
399 | 393 | Example: typing '%cd mydir' (without the quotes) changes you working directory |
|
400 | 394 | to 'mydir', if it exists. |
|
401 | 395 | |
|
402 | 396 | For a list of the available magic functions, use %lsmagic. For a description |
|
403 | 397 | of any of them, type %magic_name?, e.g. '%cd?'. |
|
404 | 398 | |
|
405 | 399 | Currently the magic system has the following functions:\n""" |
|
406 | 400 | |
|
407 | 401 | mesc = ESC_MAGIC |
|
408 | 402 | outmsg = ("%s\n%s\n\nSummary of magic functions (from %slsmagic):" |
|
409 | 403 | "\n\n%s%s\n\n%s" % (outmsg, |
|
410 | 404 | magic_docs,mesc,mesc, |
|
411 | 405 | (' '+mesc).join(self.lsmagic()), |
|
412 | 406 | Magic.auto_status[self.shell.automagic] ) ) |
|
413 | 407 | page.page(outmsg) |
|
414 | 408 | |
|
415 | 409 | def magic_automagic(self, parameter_s = ''): |
|
416 | 410 | """Make magic functions callable without having to type the initial %. |
|
417 | 411 | |
|
418 | 412 | Without argumentsl toggles on/off (when off, you must call it as |
|
419 | 413 | %automagic, of course). With arguments it sets the value, and you can |
|
420 | 414 | use any of (case insensitive): |
|
421 | 415 | |
|
422 | 416 | - on,1,True: to activate |
|
423 | 417 | |
|
424 | 418 | - off,0,False: to deactivate. |
|
425 | 419 | |
|
426 | 420 | Note that magic functions have lowest priority, so if there's a |
|
427 | 421 | variable whose name collides with that of a magic fn, automagic won't |
|
428 | 422 | work for that function (you get the variable instead). However, if you |
|
429 | 423 | delete the variable (del var), the previously shadowed magic function |
|
430 | 424 | becomes visible to automagic again.""" |
|
431 | 425 | |
|
432 | 426 | arg = parameter_s.lower() |
|
433 | 427 | if parameter_s in ('on','1','true'): |
|
434 | 428 | self.shell.automagic = True |
|
435 | 429 | elif parameter_s in ('off','0','false'): |
|
436 | 430 | self.shell.automagic = False |
|
437 | 431 | else: |
|
438 | 432 | self.shell.automagic = not self.shell.automagic |
|
439 | 433 | print '\n' + Magic.auto_status[self.shell.automagic] |
|
440 | 434 | |
|
441 | 435 | @skip_doctest |
|
442 | 436 | def magic_autocall(self, parameter_s = ''): |
|
443 | 437 | """Make functions callable without having to type parentheses. |
|
444 | 438 | |
|
445 | 439 | Usage: |
|
446 | 440 | |
|
447 | 441 | %autocall [mode] |
|
448 | 442 | |
|
449 | 443 | The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the |
|
450 | 444 | value is toggled on and off (remembering the previous state). |
|
451 | 445 | |
|
452 | 446 | In more detail, these values mean: |
|
453 | 447 | |
|
454 | 448 | 0 -> fully disabled |
|
455 | 449 | |
|
456 | 450 | 1 -> active, but do not apply if there are no arguments on the line. |
|
457 | 451 | |
|
458 | 452 | In this mode, you get:: |
|
459 | 453 | |
|
460 | 454 | In [1]: callable |
|
461 | 455 | Out[1]: <built-in function callable> |
|
462 | 456 | |
|
463 | 457 | In [2]: callable 'hello' |
|
464 | 458 | ------> callable('hello') |
|
465 | 459 | Out[2]: False |
|
466 | 460 | |
|
467 | 461 | 2 -> Active always. Even if no arguments are present, the callable |
|
468 | 462 | object is called:: |
|
469 | 463 | |
|
470 | 464 | In [2]: float |
|
471 | 465 | ------> float() |
|
472 | 466 | Out[2]: 0.0 |
|
473 | 467 | |
|
474 | 468 | Note that even with autocall off, you can still use '/' at the start of |
|
475 | 469 | a line to treat the first argument on the command line as a function |
|
476 | 470 | and add parentheses to it:: |
|
477 | 471 | |
|
478 | 472 | In [8]: /str 43 |
|
479 | 473 | ------> str(43) |
|
480 | 474 | Out[8]: '43' |
|
481 | 475 | |
|
482 | 476 | # all-random (note for auto-testing) |
|
483 | 477 | """ |
|
484 | 478 | |
|
485 | 479 | if parameter_s: |
|
486 | 480 | arg = int(parameter_s) |
|
487 | 481 | else: |
|
488 | 482 | arg = 'toggle' |
|
489 | 483 | |
|
490 | 484 | if not arg in (0,1,2,'toggle'): |
|
491 | 485 | error('Valid modes: (0->Off, 1->Smart, 2->Full') |
|
492 | 486 | return |
|
493 | 487 | |
|
494 | 488 | if arg in (0,1,2): |
|
495 | 489 | self.shell.autocall = arg |
|
496 | 490 | else: # toggle |
|
497 | 491 | if self.shell.autocall: |
|
498 | 492 | self._magic_state.autocall_save = self.shell.autocall |
|
499 | 493 | self.shell.autocall = 0 |
|
500 | 494 | else: |
|
501 | 495 | try: |
|
502 | 496 | self.shell.autocall = self._magic_state.autocall_save |
|
503 | 497 | except AttributeError: |
|
504 | 498 | self.shell.autocall = self._magic_state.autocall_save = 1 |
|
505 | 499 | |
|
506 | 500 | print "Automatic calling is:",['OFF','Smart','Full'][self.shell.autocall] |
|
507 | 501 | |
|
508 | 502 | |
|
509 | 503 | def magic_page(self, parameter_s=''): |
|
510 | 504 | """Pretty print the object and display it through a pager. |
|
511 | 505 | |
|
512 | 506 | %page [options] OBJECT |
|
513 | 507 | |
|
514 | 508 | If no object is given, use _ (last output). |
|
515 | 509 | |
|
516 | 510 | Options: |
|
517 | 511 | |
|
518 | 512 | -r: page str(object), don't pretty-print it.""" |
|
519 | 513 | |
|
520 | 514 | # After a function contributed by Olivier Aubert, slightly modified. |
|
521 | 515 | |
|
522 | 516 | # Process options/args |
|
523 | 517 | opts,args = self.parse_options(parameter_s,'r') |
|
524 | 518 | raw = 'r' in opts |
|
525 | 519 | |
|
526 | 520 | oname = args and args or '_' |
|
527 | 521 | info = self._ofind(oname) |
|
528 | 522 | if info['found']: |
|
529 | 523 | txt = (raw and str or pformat)( info['obj'] ) |
|
530 | 524 | page.page(txt) |
|
531 | 525 | else: |
|
532 | 526 | print 'Object `%s` not found' % oname |
|
533 | 527 | |
|
534 | 528 | def magic_profile(self, parameter_s=''): |
|
535 | 529 | """Print your currently active IPython profile.""" |
|
536 | 530 | from IPython.core.application import BaseIPythonApplication |
|
537 | 531 | if BaseIPythonApplication.initialized(): |
|
538 | 532 | print BaseIPythonApplication.instance().profile |
|
539 | 533 | else: |
|
540 | 534 | error("profile is an application-level value, but you don't appear to be in an IPython application") |
|
541 | 535 | |
|
542 | 536 | def magic_pinfo(self, parameter_s='', namespaces=None): |
|
543 | 537 | """Provide detailed information about an object. |
|
544 | 538 | |
|
545 | 539 | '%pinfo object' is just a synonym for object? or ?object.""" |
|
546 | 540 | |
|
547 | 541 | #print 'pinfo par: <%s>' % parameter_s # dbg |
|
548 | 542 | |
|
549 | 543 | |
|
550 | 544 | # detail_level: 0 -> obj? , 1 -> obj?? |
|
551 | 545 | detail_level = 0 |
|
552 | 546 | # We need to detect if we got called as 'pinfo pinfo foo', which can |
|
553 | 547 | # happen if the user types 'pinfo foo?' at the cmd line. |
|
554 | 548 | pinfo,qmark1,oname,qmark2 = \ |
|
555 | 549 | re.match('(pinfo )?(\?*)(.*?)(\??$)',parameter_s).groups() |
|
556 | 550 | if pinfo or qmark1 or qmark2: |
|
557 | 551 | detail_level = 1 |
|
558 | 552 | if "*" in oname: |
|
559 | 553 | self.magic_psearch(oname) |
|
560 | 554 | else: |
|
561 | 555 | self.shell._inspect('pinfo', oname, detail_level=detail_level, |
|
562 | 556 | namespaces=namespaces) |
|
563 | 557 | |
|
564 | 558 | def magic_pinfo2(self, parameter_s='', namespaces=None): |
|
565 | 559 | """Provide extra detailed information about an object. |
|
566 | 560 | |
|
567 | 561 | '%pinfo2 object' is just a synonym for object?? or ??object.""" |
|
568 | 562 | self.shell._inspect('pinfo', parameter_s, detail_level=1, |
|
569 | 563 | namespaces=namespaces) |
|
570 | 564 | |
|
571 | 565 | @skip_doctest |
|
572 | 566 | def magic_pdef(self, parameter_s='', namespaces=None): |
|
573 | 567 | """Print the definition header for any callable object. |
|
574 | 568 | |
|
575 | 569 | If the object is a class, print the constructor information. |
|
576 | 570 | |
|
577 | 571 | Examples |
|
578 | 572 | -------- |
|
579 | 573 | :: |
|
580 | 574 | |
|
581 | 575 | In [3]: %pdef urllib.urlopen |
|
582 | 576 | urllib.urlopen(url, data=None, proxies=None) |
|
583 | 577 | """ |
|
584 | 578 | self._inspect('pdef',parameter_s, namespaces) |
|
585 | 579 | |
|
586 | 580 | def magic_pdoc(self, parameter_s='', namespaces=None): |
|
587 | 581 | """Print the docstring for an object. |
|
588 | 582 | |
|
589 | 583 | If the given object is a class, it will print both the class and the |
|
590 | 584 | constructor docstrings.""" |
|
591 | 585 | self._inspect('pdoc',parameter_s, namespaces) |
|
592 | 586 | |
|
593 | 587 | def magic_psource(self, parameter_s='', namespaces=None): |
|
594 | 588 | """Print (or run through pager) the source code for an object.""" |
|
595 | 589 | self._inspect('psource',parameter_s, namespaces) |
|
596 | 590 | |
|
597 | 591 | def magic_pfile(self, parameter_s=''): |
|
598 | 592 | """Print (or run through pager) the file where an object is defined. |
|
599 | 593 | |
|
600 | 594 | The file opens at the line where the object definition begins. IPython |
|
601 | 595 | will honor the environment variable PAGER if set, and otherwise will |
|
602 | 596 | do its best to print the file in a convenient form. |
|
603 | 597 | |
|
604 | 598 | If the given argument is not an object currently defined, IPython will |
|
605 | 599 | try to interpret it as a filename (automatically adding a .py extension |
|
606 | 600 | if needed). You can thus use %pfile as a syntax highlighting code |
|
607 | 601 | viewer.""" |
|
608 | 602 | |
|
609 | 603 | # first interpret argument as an object name |
|
610 | 604 | out = self._inspect('pfile',parameter_s) |
|
611 | 605 | # if not, try the input as a filename |
|
612 | 606 | if out == 'not found': |
|
613 | 607 | try: |
|
614 | 608 | filename = get_py_filename(parameter_s) |
|
615 | 609 | except IOError,msg: |
|
616 | 610 | print msg |
|
617 | 611 | return |
|
618 | 612 | page.page(self.shell.inspector.format(open(filename).read())) |
|
619 | 613 | |
|
620 | 614 | def magic_psearch(self, parameter_s=''): |
|
621 | 615 | """Search for object in namespaces by wildcard. |
|
622 | 616 | |
|
623 | 617 | %psearch [options] PATTERN [OBJECT TYPE] |
|
624 | 618 | |
|
625 | 619 | Note: ? can be used as a synonym for %psearch, at the beginning or at |
|
626 | 620 | the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the |
|
627 | 621 | rest of the command line must be unchanged (options come first), so |
|
628 | 622 | for example the following forms are equivalent |
|
629 | 623 | |
|
630 | 624 | %psearch -i a* function |
|
631 | 625 | -i a* function? |
|
632 | 626 | ?-i a* function |
|
633 | 627 | |
|
634 | 628 | Arguments: |
|
635 | 629 | |
|
636 | 630 | PATTERN |
|
637 | 631 | |
|
638 | 632 | where PATTERN is a string containing * as a wildcard similar to its |
|
639 | 633 | use in a shell. The pattern is matched in all namespaces on the |
|
640 | 634 | search path. By default objects starting with a single _ are not |
|
641 | 635 | matched, many IPython generated objects have a single |
|
642 | 636 | underscore. The default is case insensitive matching. Matching is |
|
643 | 637 | also done on the attributes of objects and not only on the objects |
|
644 | 638 | in a module. |
|
645 | 639 | |
|
646 | 640 | [OBJECT TYPE] |
|
647 | 641 | |
|
648 | 642 | Is the name of a python type from the types module. The name is |
|
649 | 643 | given in lowercase without the ending type, ex. StringType is |
|
650 | 644 | written string. By adding a type here only objects matching the |
|
651 | 645 | given type are matched. Using all here makes the pattern match all |
|
652 | 646 | types (this is the default). |
|
653 | 647 | |
|
654 | 648 | Options: |
|
655 | 649 | |
|
656 | 650 | -a: makes the pattern match even objects whose names start with a |
|
657 | 651 | single underscore. These names are normally omitted from the |
|
658 | 652 | search. |
|
659 | 653 | |
|
660 | 654 | -i/-c: make the pattern case insensitive/sensitive. If neither of |
|
661 | 655 | these options are given, the default is read from your configuration |
|
662 | 656 | file, with the option ``InteractiveShell.wildcards_case_sensitive``. |
|
663 | 657 | If this option is not specified in your configuration file, IPython's |
|
664 | 658 | internal default is to do a case sensitive search. |
|
665 | 659 | |
|
666 | 660 | -e/-s NAMESPACE: exclude/search a given namespace. The pattern you |
|
667 | 661 | specify can be searched in any of the following namespaces: |
|
668 | 662 | 'builtin', 'user', 'user_global','internal', 'alias', where |
|
669 | 663 | 'builtin' and 'user' are the search defaults. Note that you should |
|
670 | 664 | not use quotes when specifying namespaces. |
|
671 | 665 | |
|
672 | 666 | 'Builtin' contains the python module builtin, 'user' contains all |
|
673 | 667 | user data, 'alias' only contain the shell aliases and no python |
|
674 | 668 | objects, 'internal' contains objects used by IPython. The |
|
675 | 669 | 'user_global' namespace is only used by embedded IPython instances, |
|
676 | 670 | and it contains module-level globals. You can add namespaces to the |
|
677 | 671 | search with -s or exclude them with -e (these options can be given |
|
678 | 672 | more than once). |
|
679 | 673 | |
|
680 | 674 | Examples |
|
681 | 675 | -------- |
|
682 | 676 | :: |
|
683 | 677 | |
|
684 | 678 | %psearch a* -> objects beginning with an a |
|
685 | 679 | %psearch -e builtin a* -> objects NOT in the builtin space starting in a |
|
686 | 680 | %psearch a* function -> all functions beginning with an a |
|
687 | 681 | %psearch re.e* -> objects beginning with an e in module re |
|
688 | 682 | %psearch r*.e* -> objects that start with e in modules starting in r |
|
689 | 683 | %psearch r*.* string -> all strings in modules beginning with r |
|
690 | 684 | |
|
691 | 685 | Case sensitive search:: |
|
692 | 686 | |
|
693 | 687 | %psearch -c a* list all object beginning with lower case a |
|
694 | 688 | |
|
695 | 689 | Show objects beginning with a single _:: |
|
696 | 690 | |
|
697 | 691 | %psearch -a _* list objects beginning with a single underscore""" |
|
698 | 692 | try: |
|
699 | 693 | parameter_s.encode('ascii') |
|
700 | 694 | except UnicodeEncodeError: |
|
701 | 695 | print 'Python identifiers can only contain ascii characters.' |
|
702 | 696 | return |
|
703 | 697 | |
|
704 | 698 | # default namespaces to be searched |
|
705 | 699 | def_search = ['user_local', 'user_global', 'builtin'] |
|
706 | 700 | |
|
707 | 701 | # Process options/args |
|
708 | 702 | opts,args = self.parse_options(parameter_s,'cias:e:',list_all=True) |
|
709 | 703 | opt = opts.get |
|
710 | 704 | shell = self.shell |
|
711 | 705 | psearch = shell.inspector.psearch |
|
712 | 706 | |
|
713 | 707 | # select case options |
|
714 | 708 | if opts.has_key('i'): |
|
715 | 709 | ignore_case = True |
|
716 | 710 | elif opts.has_key('c'): |
|
717 | 711 | ignore_case = False |
|
718 | 712 | else: |
|
719 | 713 | ignore_case = not shell.wildcards_case_sensitive |
|
720 | 714 | |
|
721 | 715 | # Build list of namespaces to search from user options |
|
722 | 716 | def_search.extend(opt('s',[])) |
|
723 | 717 | ns_exclude = ns_exclude=opt('e',[]) |
|
724 | 718 | ns_search = [nm for nm in def_search if nm not in ns_exclude] |
|
725 | 719 | |
|
726 | 720 | # Call the actual search |
|
727 | 721 | try: |
|
728 | 722 | psearch(args,shell.ns_table,ns_search, |
|
729 | 723 | show_all=opt('a'),ignore_case=ignore_case) |
|
730 | 724 | except: |
|
731 | 725 | shell.showtraceback() |
|
732 | 726 | |
|
733 | 727 | @skip_doctest |
|
734 | 728 | def magic_who_ls(self, parameter_s=''): |
|
735 | 729 | """Return a sorted list of all interactive variables. |
|
736 | 730 | |
|
737 | 731 | If arguments are given, only variables of types matching these |
|
738 | 732 | arguments are returned. |
|
739 | 733 | |
|
740 | 734 | Examples |
|
741 | 735 | -------- |
|
742 | 736 | |
|
743 | 737 | Define two variables and list them with who_ls:: |
|
744 | 738 | |
|
745 | 739 | In [1]: alpha = 123 |
|
746 | 740 | |
|
747 | 741 | In [2]: beta = 'test' |
|
748 | 742 | |
|
749 | 743 | In [3]: %who_ls |
|
750 | 744 | Out[3]: ['alpha', 'beta'] |
|
751 | 745 | |
|
752 | 746 | In [4]: %who_ls int |
|
753 | 747 | Out[4]: ['alpha'] |
|
754 | 748 | |
|
755 | 749 | In [5]: %who_ls str |
|
756 | 750 | Out[5]: ['beta'] |
|
757 | 751 | """ |
|
758 | 752 | |
|
759 | 753 | user_ns = self.shell.user_ns |
|
760 | 754 | user_ns_hidden = self.shell.user_ns_hidden |
|
761 | 755 | out = [ i for i in user_ns |
|
762 | 756 | if not i.startswith('_') \ |
|
763 | 757 | and not i in user_ns_hidden ] |
|
764 | 758 | |
|
765 | 759 | typelist = parameter_s.split() |
|
766 | 760 | if typelist: |
|
767 | 761 | typeset = set(typelist) |
|
768 | 762 | out = [i for i in out if type(user_ns[i]).__name__ in typeset] |
|
769 | 763 | |
|
770 | 764 | out.sort() |
|
771 | 765 | return out |
|
772 | 766 | |
|
773 | 767 | @skip_doctest |
|
774 | 768 | def magic_who(self, parameter_s=''): |
|
775 | 769 | """Print all interactive variables, with some minimal formatting. |
|
776 | 770 | |
|
777 | 771 | If any arguments are given, only variables whose type matches one of |
|
778 | 772 | these are printed. For example:: |
|
779 | 773 | |
|
780 | 774 | %who function str |
|
781 | 775 | |
|
782 | 776 | will only list functions and strings, excluding all other types of |
|
783 | 777 | variables. To find the proper type names, simply use type(var) at a |
|
784 | 778 | command line to see how python prints type names. For example: |
|
785 | 779 | |
|
786 | 780 | :: |
|
787 | 781 | |
|
788 | 782 | In [1]: type('hello')\\ |
|
789 | 783 | Out[1]: <type 'str'> |
|
790 | 784 | |
|
791 | 785 | indicates that the type name for strings is 'str'. |
|
792 | 786 | |
|
793 | 787 | ``%who`` always excludes executed names loaded through your configuration |
|
794 | 788 | file and things which are internal to IPython. |
|
795 | 789 | |
|
796 | 790 | This is deliberate, as typically you may load many modules and the |
|
797 | 791 | purpose of %who is to show you only what you've manually defined. |
|
798 | 792 | |
|
799 | 793 | Examples |
|
800 | 794 | -------- |
|
801 | 795 | |
|
802 | 796 | Define two variables and list them with who:: |
|
803 | 797 | |
|
804 | 798 | In [1]: alpha = 123 |
|
805 | 799 | |
|
806 | 800 | In [2]: beta = 'test' |
|
807 | 801 | |
|
808 | 802 | In [3]: %who |
|
809 | 803 | alpha beta |
|
810 | 804 | |
|
811 | 805 | In [4]: %who int |
|
812 | 806 | alpha |
|
813 | 807 | |
|
814 | 808 | In [5]: %who str |
|
815 | 809 | beta |
|
816 | 810 | """ |
|
817 | 811 | |
|
818 | 812 | varlist = self.magic_who_ls(parameter_s) |
|
819 | 813 | if not varlist: |
|
820 | 814 | if parameter_s: |
|
821 | 815 | print 'No variables match your requested type.' |
|
822 | 816 | else: |
|
823 | 817 | print 'Interactive namespace is empty.' |
|
824 | 818 | return |
|
825 | 819 | |
|
826 | 820 | # if we have variables, move on... |
|
827 | 821 | count = 0 |
|
828 | 822 | for i in varlist: |
|
829 | 823 | print i+'\t', |
|
830 | 824 | count += 1 |
|
831 | 825 | if count > 8: |
|
832 | 826 | count = 0 |
|
833 | 827 | |
|
834 | 828 | |
|
835 | 829 | |
|
836 | 830 | @skip_doctest |
|
837 | 831 | def magic_whos(self, parameter_s=''): |
|
838 | 832 | """Like %who, but gives some extra information about each variable. |
|
839 | 833 | |
|
840 | 834 | The same type filtering of %who can be applied here. |
|
841 | 835 | |
|
842 | 836 | For all variables, the type is printed. Additionally it prints: |
|
843 | 837 | |
|
844 | 838 | - For {},[],(): their length. |
|
845 | 839 | |
|
846 | 840 | - For numpy arrays, a summary with shape, number of |
|
847 | 841 | elements, typecode and size in memory. |
|
848 | 842 | |
|
849 | 843 | - Everything else: a string representation, snipping their middle if |
|
850 | 844 | too long. |
|
851 | 845 | |
|
852 | 846 | Examples |
|
853 | 847 | -------- |
|
854 | 848 | |
|
855 | 849 | Define two variables and list them with whos:: |
|
856 | 850 | |
|
857 | 851 | In [1]: alpha = 123 |
|
858 | 852 | |
|
859 | 853 | In [2]: beta = 'test' |
|
860 | 854 | |
|
861 | 855 | In [3]: %whos |
|
862 | 856 | Variable Type Data/Info |
|
863 | 857 | -------------------------------- |
|
864 | 858 | alpha int 123 |
|
865 | 859 | beta str test |
|
866 | 860 | """ |
|
867 | 861 | |
|
868 | 862 | varnames = self.magic_who_ls(parameter_s) |
|
869 | 863 | if not varnames: |
|
870 | 864 | if parameter_s: |
|
871 | 865 | print 'No variables match your requested type.' |
|
872 | 866 | else: |
|
873 | 867 | print 'Interactive namespace is empty.' |
|
874 | 868 | return |
|
875 | 869 | |
|
876 | 870 | # if we have variables, move on... |
|
877 | 871 | |
|
878 | 872 | # for these types, show len() instead of data: |
|
879 | 873 | seq_types = ['dict', 'list', 'tuple'] |
|
880 | 874 | |
|
881 | 875 | # for numpy arrays, display summary info |
|
882 | 876 | ndarray_type = None |
|
883 | 877 | if 'numpy' in sys.modules: |
|
884 | 878 | try: |
|
885 | 879 | from numpy import ndarray |
|
886 | 880 | except ImportError: |
|
887 | 881 | pass |
|
888 | 882 | else: |
|
889 | 883 | ndarray_type = ndarray.__name__ |
|
890 | 884 | |
|
891 | 885 | # Find all variable names and types so we can figure out column sizes |
|
892 | 886 | def get_vars(i): |
|
893 | 887 | return self.shell.user_ns[i] |
|
894 | 888 | |
|
895 | 889 | # some types are well known and can be shorter |
|
896 | 890 | abbrevs = {'IPython.core.macro.Macro' : 'Macro'} |
|
897 | 891 | def type_name(v): |
|
898 | 892 | tn = type(v).__name__ |
|
899 | 893 | return abbrevs.get(tn,tn) |
|
900 | 894 | |
|
901 | 895 | varlist = map(get_vars,varnames) |
|
902 | 896 | |
|
903 | 897 | typelist = [] |
|
904 | 898 | for vv in varlist: |
|
905 | 899 | tt = type_name(vv) |
|
906 | 900 | |
|
907 | 901 | if tt=='instance': |
|
908 | 902 | typelist.append( abbrevs.get(str(vv.__class__), |
|
909 | 903 | str(vv.__class__))) |
|
910 | 904 | else: |
|
911 | 905 | typelist.append(tt) |
|
912 | 906 | |
|
913 | 907 | # column labels and # of spaces as separator |
|
914 | 908 | varlabel = 'Variable' |
|
915 | 909 | typelabel = 'Type' |
|
916 | 910 | datalabel = 'Data/Info' |
|
917 | 911 | colsep = 3 |
|
918 | 912 | # variable format strings |
|
919 | 913 | vformat = "{0:<{varwidth}}{1:<{typewidth}}" |
|
920 | 914 | aformat = "%s: %s elems, type `%s`, %s bytes" |
|
921 | 915 | # find the size of the columns to format the output nicely |
|
922 | 916 | varwidth = max(max(map(len,varnames)), len(varlabel)) + colsep |
|
923 | 917 | typewidth = max(max(map(len,typelist)), len(typelabel)) + colsep |
|
924 | 918 | # table header |
|
925 | 919 | print varlabel.ljust(varwidth) + typelabel.ljust(typewidth) + \ |
|
926 | 920 | ' '+datalabel+'\n' + '-'*(varwidth+typewidth+len(datalabel)+1) |
|
927 | 921 | # and the table itself |
|
928 | 922 | kb = 1024 |
|
929 | 923 | Mb = 1048576 # kb**2 |
|
930 | 924 | for vname,var,vtype in zip(varnames,varlist,typelist): |
|
931 | 925 | print vformat.format(vname, vtype, varwidth=varwidth, typewidth=typewidth), |
|
932 | 926 | if vtype in seq_types: |
|
933 | 927 | print "n="+str(len(var)) |
|
934 | 928 | elif vtype == ndarray_type: |
|
935 | 929 | vshape = str(var.shape).replace(',','').replace(' ','x')[1:-1] |
|
936 | 930 | if vtype==ndarray_type: |
|
937 | 931 | # numpy |
|
938 | 932 | vsize = var.size |
|
939 | 933 | vbytes = vsize*var.itemsize |
|
940 | 934 | vdtype = var.dtype |
|
941 | 935 | |
|
942 | 936 | if vbytes < 100000: |
|
943 | 937 | print aformat % (vshape,vsize,vdtype,vbytes) |
|
944 | 938 | else: |
|
945 | 939 | print aformat % (vshape,vsize,vdtype,vbytes), |
|
946 | 940 | if vbytes < Mb: |
|
947 | 941 | print '(%s kb)' % (vbytes/kb,) |
|
948 | 942 | else: |
|
949 | 943 | print '(%s Mb)' % (vbytes/Mb,) |
|
950 | 944 | else: |
|
951 | 945 | try: |
|
952 | 946 | vstr = str(var) |
|
953 | 947 | except UnicodeEncodeError: |
|
954 | 948 | vstr = unicode(var).encode(DEFAULT_ENCODING, |
|
955 | 949 | 'backslashreplace') |
|
956 | 950 | except: |
|
957 | 951 | vstr = "<object with id %d (str() failed)>" % id(var) |
|
958 | 952 | vstr = vstr.replace('\n','\\n') |
|
959 | 953 | if len(vstr) < 50: |
|
960 | 954 | print vstr |
|
961 | 955 | else: |
|
962 | 956 | print vstr[:25] + "<...>" + vstr[-25:] |
|
963 | 957 | |
|
964 | 958 | def magic_reset(self, parameter_s=''): |
|
965 | 959 | """Resets the namespace by removing all names defined by the user, if |
|
966 | 960 | called without arguments, or by removing some types of objects, such |
|
967 | 961 | as everything currently in IPython's In[] and Out[] containers (see |
|
968 | 962 | the parameters for details). |
|
969 | 963 | |
|
970 | 964 | Parameters |
|
971 | 965 | ---------- |
|
972 | 966 | -f : force reset without asking for confirmation. |
|
973 | 967 | |
|
974 | 968 | -s : 'Soft' reset: Only clears your namespace, leaving history intact. |
|
975 | 969 | References to objects may be kept. By default (without this option), |
|
976 | 970 | we do a 'hard' reset, giving you a new session and removing all |
|
977 | 971 | references to objects from the current session. |
|
978 | 972 | |
|
979 | 973 | in : reset input history |
|
980 | 974 | |
|
981 | 975 | out : reset output history |
|
982 | 976 | |
|
983 | 977 | dhist : reset directory history |
|
984 | 978 | |
|
985 | 979 | array : reset only variables that are NumPy arrays |
|
986 | 980 | |
|
987 | 981 | See Also |
|
988 | 982 | -------- |
|
989 | 983 | magic_reset_selective : invoked as ``%reset_selective`` |
|
990 | 984 | |
|
991 | 985 | Examples |
|
992 | 986 | -------- |
|
993 | 987 | :: |
|
994 | 988 | |
|
995 | 989 | In [6]: a = 1 |
|
996 | 990 | |
|
997 | 991 | In [7]: a |
|
998 | 992 | Out[7]: 1 |
|
999 | 993 | |
|
1000 | 994 | In [8]: 'a' in _ip.user_ns |
|
1001 | 995 | Out[8]: True |
|
1002 | 996 | |
|
1003 | 997 | In [9]: %reset -f |
|
1004 | 998 | |
|
1005 | 999 | In [1]: 'a' in _ip.user_ns |
|
1006 | 1000 | Out[1]: False |
|
1007 | 1001 | |
|
1008 | 1002 | In [2]: %reset -f in |
|
1009 | 1003 | Flushing input history |
|
1010 | 1004 | |
|
1011 | 1005 | In [3]: %reset -f dhist in |
|
1012 | 1006 | Flushing directory history |
|
1013 | 1007 | Flushing input history |
|
1014 | 1008 | |
|
1015 | 1009 | Notes |
|
1016 | 1010 | ----- |
|
1017 | 1011 | Calling this magic from clients that do not implement standard input, |
|
1018 | 1012 | such as the ipython notebook interface, will reset the namespace |
|
1019 | 1013 | without confirmation. |
|
1020 | 1014 | """ |
|
1021 | 1015 | opts, args = self.parse_options(parameter_s,'sf', mode='list') |
|
1022 | 1016 | if 'f' in opts: |
|
1023 | 1017 | ans = True |
|
1024 | 1018 | else: |
|
1025 | 1019 | try: |
|
1026 | 1020 | ans = self.shell.ask_yes_no( |
|
1027 | 1021 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ", default='n') |
|
1028 | 1022 | except StdinNotImplementedError: |
|
1029 | 1023 | ans = True |
|
1030 | 1024 | if not ans: |
|
1031 | 1025 | print 'Nothing done.' |
|
1032 | 1026 | return |
|
1033 | 1027 | |
|
1034 | 1028 | if 's' in opts: # Soft reset |
|
1035 | 1029 | user_ns = self.shell.user_ns |
|
1036 | 1030 | for i in self.magic_who_ls(): |
|
1037 | 1031 | del(user_ns[i]) |
|
1038 | 1032 | elif len(args) == 0: # Hard reset |
|
1039 | 1033 | self.shell.reset(new_session = False) |
|
1040 | 1034 | |
|
1041 | 1035 | # reset in/out/dhist/array: previously extensinions/clearcmd.py |
|
1042 | 1036 | ip = self.shell |
|
1043 | 1037 | user_ns = self.user_ns # local lookup, heavily used |
|
1044 | 1038 | |
|
1045 | 1039 | for target in args: |
|
1046 | 1040 | target = target.lower() # make matches case insensitive |
|
1047 | 1041 | if target == 'out': |
|
1048 | 1042 | print "Flushing output cache (%d entries)" % len(user_ns['_oh']) |
|
1049 | 1043 | self.displayhook.flush() |
|
1050 | 1044 | |
|
1051 | 1045 | elif target == 'in': |
|
1052 | 1046 | print "Flushing input history" |
|
1053 | 1047 | pc = self.displayhook.prompt_count + 1 |
|
1054 | 1048 | for n in range(1, pc): |
|
1055 | 1049 | key = '_i'+repr(n) |
|
1056 | 1050 | user_ns.pop(key,None) |
|
1057 | 1051 | user_ns.update(dict(_i=u'',_ii=u'',_iii=u'')) |
|
1058 | 1052 | hm = ip.history_manager |
|
1059 | 1053 | # don't delete these, as %save and %macro depending on the length |
|
1060 | 1054 | # of these lists to be preserved |
|
1061 | 1055 | hm.input_hist_parsed[:] = [''] * pc |
|
1062 | 1056 | hm.input_hist_raw[:] = [''] * pc |
|
1063 | 1057 | # hm has internal machinery for _i,_ii,_iii, clear it out |
|
1064 | 1058 | hm._i = hm._ii = hm._iii = hm._i00 = u'' |
|
1065 | 1059 | |
|
1066 | 1060 | elif target == 'array': |
|
1067 | 1061 | # Support cleaning up numpy arrays |
|
1068 | 1062 | try: |
|
1069 | 1063 | from numpy import ndarray |
|
1070 | 1064 | # This must be done with items and not iteritems because we're |
|
1071 | 1065 | # going to modify the dict in-place. |
|
1072 | 1066 | for x,val in user_ns.items(): |
|
1073 | 1067 | if isinstance(val,ndarray): |
|
1074 | 1068 | del user_ns[x] |
|
1075 | 1069 | except ImportError: |
|
1076 | 1070 | print "reset array only works if Numpy is available." |
|
1077 | 1071 | |
|
1078 | 1072 | elif target == 'dhist': |
|
1079 | 1073 | print "Flushing directory history" |
|
1080 | 1074 | del user_ns['_dh'][:] |
|
1081 | 1075 | |
|
1082 | 1076 | else: |
|
1083 | 1077 | print "Don't know how to reset ", |
|
1084 | 1078 | print target + ", please run `%reset?` for details" |
|
1085 | 1079 | |
|
1086 | 1080 | gc.collect() |
|
1087 | 1081 | |
|
1088 | 1082 | def magic_reset_selective(self, parameter_s=''): |
|
1089 | 1083 | """Resets the namespace by removing names defined by the user. |
|
1090 | 1084 | |
|
1091 | 1085 | Input/Output history are left around in case you need them. |
|
1092 | 1086 | |
|
1093 | 1087 | %reset_selective [-f] regex |
|
1094 | 1088 | |
|
1095 | 1089 | No action is taken if regex is not included |
|
1096 | 1090 | |
|
1097 | 1091 | Options |
|
1098 | 1092 | -f : force reset without asking for confirmation. |
|
1099 | 1093 | |
|
1100 | 1094 | See Also |
|
1101 | 1095 | -------- |
|
1102 | 1096 | magic_reset : invoked as ``%reset`` |
|
1103 | 1097 | |
|
1104 | 1098 | Examples |
|
1105 | 1099 | -------- |
|
1106 | 1100 | |
|
1107 | 1101 | We first fully reset the namespace so your output looks identical to |
|
1108 | 1102 | this example for pedagogical reasons; in practice you do not need a |
|
1109 | 1103 | full reset:: |
|
1110 | 1104 | |
|
1111 | 1105 | In [1]: %reset -f |
|
1112 | 1106 | |
|
1113 | 1107 | Now, with a clean namespace we can make a few variables and use |
|
1114 | 1108 | ``%reset_selective`` to only delete names that match our regexp:: |
|
1115 | 1109 | |
|
1116 | 1110 | In [2]: a=1; b=2; c=3; b1m=4; b2m=5; b3m=6; b4m=7; b2s=8 |
|
1117 | 1111 | |
|
1118 | 1112 | In [3]: who_ls |
|
1119 | 1113 | Out[3]: ['a', 'b', 'b1m', 'b2m', 'b2s', 'b3m', 'b4m', 'c'] |
|
1120 | 1114 | |
|
1121 | 1115 | In [4]: %reset_selective -f b[2-3]m |
|
1122 | 1116 | |
|
1123 | 1117 | In [5]: who_ls |
|
1124 | 1118 | Out[5]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c'] |
|
1125 | 1119 | |
|
1126 | 1120 | In [6]: %reset_selective -f d |
|
1127 | 1121 | |
|
1128 | 1122 | In [7]: who_ls |
|
1129 | 1123 | Out[7]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c'] |
|
1130 | 1124 | |
|
1131 | 1125 | In [8]: %reset_selective -f c |
|
1132 | 1126 | |
|
1133 | 1127 | In [9]: who_ls |
|
1134 | 1128 | Out[9]: ['a', 'b', 'b1m', 'b2s', 'b4m'] |
|
1135 | 1129 | |
|
1136 | 1130 | In [10]: %reset_selective -f b |
|
1137 | 1131 | |
|
1138 | 1132 | In [11]: who_ls |
|
1139 | 1133 | Out[11]: ['a'] |
|
1140 | 1134 | |
|
1141 | 1135 | Notes |
|
1142 | 1136 | ----- |
|
1143 | 1137 | Calling this magic from clients that do not implement standard input, |
|
1144 | 1138 | such as the ipython notebook interface, will reset the namespace |
|
1145 | 1139 | without confirmation. |
|
1146 | 1140 | """ |
|
1147 | 1141 | |
|
1148 | 1142 | opts, regex = self.parse_options(parameter_s,'f') |
|
1149 | 1143 | |
|
1150 | 1144 | if opts.has_key('f'): |
|
1151 | 1145 | ans = True |
|
1152 | 1146 | else: |
|
1153 | 1147 | try: |
|
1154 | 1148 | ans = self.shell.ask_yes_no( |
|
1155 | 1149 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ", |
|
1156 | 1150 | default='n') |
|
1157 | 1151 | except StdinNotImplementedError: |
|
1158 | 1152 | ans = True |
|
1159 | 1153 | if not ans: |
|
1160 | 1154 | print 'Nothing done.' |
|
1161 | 1155 | return |
|
1162 | 1156 | user_ns = self.shell.user_ns |
|
1163 | 1157 | if not regex: |
|
1164 | 1158 | print 'No regex pattern specified. Nothing done.' |
|
1165 | 1159 | return |
|
1166 | 1160 | else: |
|
1167 | 1161 | try: |
|
1168 | 1162 | m = re.compile(regex) |
|
1169 | 1163 | except TypeError: |
|
1170 | 1164 | raise TypeError('regex must be a string or compiled pattern') |
|
1171 | 1165 | for i in self.magic_who_ls(): |
|
1172 | 1166 | if m.search(i): |
|
1173 | 1167 | del(user_ns[i]) |
|
1174 | 1168 | |
|
1175 | 1169 | def magic_xdel(self, parameter_s=''): |
|
1176 | 1170 | """Delete a variable, trying to clear it from anywhere that |
|
1177 | 1171 | IPython's machinery has references to it. By default, this uses |
|
1178 | 1172 | the identity of the named object in the user namespace to remove |
|
1179 | 1173 | references held under other names. The object is also removed |
|
1180 | 1174 | from the output history. |
|
1181 | 1175 | |
|
1182 | 1176 | Options |
|
1183 | 1177 | -n : Delete the specified name from all namespaces, without |
|
1184 | 1178 | checking their identity. |
|
1185 | 1179 | """ |
|
1186 | 1180 | opts, varname = self.parse_options(parameter_s,'n') |
|
1187 | 1181 | try: |
|
1188 | 1182 | self.shell.del_var(varname, ('n' in opts)) |
|
1189 | 1183 | except (NameError, ValueError) as e: |
|
1190 | 1184 | print type(e).__name__ +": "+ str(e) |
|
1191 | 1185 | |
|
1192 | 1186 | def magic_logstart(self,parameter_s=''): |
|
1193 | 1187 | """Start logging anywhere in a session. |
|
1194 | 1188 | |
|
1195 | 1189 | %logstart [-o|-r|-t] [log_name [log_mode]] |
|
1196 | 1190 | |
|
1197 | 1191 | If no name is given, it defaults to a file named 'ipython_log.py' in your |
|
1198 | 1192 | current directory, in 'rotate' mode (see below). |
|
1199 | 1193 | |
|
1200 | 1194 | '%logstart name' saves to file 'name' in 'backup' mode. It saves your |
|
1201 | 1195 | history up to that point and then continues logging. |
|
1202 | 1196 | |
|
1203 | 1197 | %logstart takes a second optional parameter: logging mode. This can be one |
|
1204 | 1198 | of (note that the modes are given unquoted):\\ |
|
1205 | 1199 | append: well, that says it.\\ |
|
1206 | 1200 | backup: rename (if exists) to name~ and start name.\\ |
|
1207 | 1201 | global: single logfile in your home dir, appended to.\\ |
|
1208 | 1202 | over : overwrite existing log.\\ |
|
1209 | 1203 | rotate: create rotating logs name.1~, name.2~, etc. |
|
1210 | 1204 | |
|
1211 | 1205 | Options: |
|
1212 | 1206 | |
|
1213 | 1207 | -o: log also IPython's output. In this mode, all commands which |
|
1214 | 1208 | generate an Out[NN] prompt are recorded to the logfile, right after |
|
1215 | 1209 | their corresponding input line. The output lines are always |
|
1216 | 1210 | prepended with a '#[Out]# ' marker, so that the log remains valid |
|
1217 | 1211 | Python code. |
|
1218 | 1212 | |
|
1219 | 1213 | Since this marker is always the same, filtering only the output from |
|
1220 | 1214 | a log is very easy, using for example a simple awk call:: |
|
1221 | 1215 | |
|
1222 | 1216 | awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py |
|
1223 | 1217 | |
|
1224 | 1218 | -r: log 'raw' input. Normally, IPython's logs contain the processed |
|
1225 | 1219 | input, so that user lines are logged in their final form, converted |
|
1226 | 1220 | into valid Python. For example, %Exit is logged as |
|
1227 | 1221 | _ip.magic("Exit"). If the -r flag is given, all input is logged |
|
1228 | 1222 | exactly as typed, with no transformations applied. |
|
1229 | 1223 | |
|
1230 | 1224 | -t: put timestamps before each input line logged (these are put in |
|
1231 | 1225 | comments).""" |
|
1232 | 1226 | |
|
1233 | 1227 | opts,par = self.parse_options(parameter_s,'ort') |
|
1234 | 1228 | log_output = 'o' in opts |
|
1235 | 1229 | log_raw_input = 'r' in opts |
|
1236 | 1230 | timestamp = 't' in opts |
|
1237 | 1231 | |
|
1238 | 1232 | logger = self.shell.logger |
|
1239 | 1233 | |
|
1240 | 1234 | # if no args are given, the defaults set in the logger constructor by |
|
1241 | 1235 | # ipython remain valid |
|
1242 | 1236 | if par: |
|
1243 | 1237 | try: |
|
1244 | 1238 | logfname,logmode = par.split() |
|
1245 | 1239 | except: |
|
1246 | 1240 | logfname = par |
|
1247 | 1241 | logmode = 'backup' |
|
1248 | 1242 | else: |
|
1249 | 1243 | logfname = logger.logfname |
|
1250 | 1244 | logmode = logger.logmode |
|
1251 | 1245 | # put logfname into rc struct as if it had been called on the command |
|
1252 | 1246 | # line, so it ends up saved in the log header Save it in case we need |
|
1253 | 1247 | # to restore it... |
|
1254 | 1248 | old_logfile = self.shell.logfile |
|
1255 | 1249 | if logfname: |
|
1256 | 1250 | logfname = os.path.expanduser(logfname) |
|
1257 | 1251 | self.shell.logfile = logfname |
|
1258 | 1252 | |
|
1259 | 1253 | loghead = '# IPython log file\n\n' |
|
1260 | 1254 | try: |
|
1261 | 1255 | started = logger.logstart(logfname,loghead,logmode, |
|
1262 | 1256 | log_output,timestamp,log_raw_input) |
|
1263 | 1257 | except: |
|
1264 | 1258 | self.shell.logfile = old_logfile |
|
1265 | 1259 | warn("Couldn't start log: %s" % sys.exc_info()[1]) |
|
1266 | 1260 | else: |
|
1267 | 1261 | # log input history up to this point, optionally interleaving |
|
1268 | 1262 | # output if requested |
|
1269 | 1263 | |
|
1270 | 1264 | if timestamp: |
|
1271 | 1265 | # disable timestamping for the previous history, since we've |
|
1272 | 1266 | # lost those already (no time machine here). |
|
1273 | 1267 | logger.timestamp = False |
|
1274 | 1268 | |
|
1275 | 1269 | if log_raw_input: |
|
1276 | 1270 | input_hist = self.shell.history_manager.input_hist_raw |
|
1277 | 1271 | else: |
|
1278 | 1272 | input_hist = self.shell.history_manager.input_hist_parsed |
|
1279 | 1273 | |
|
1280 | 1274 | if log_output: |
|
1281 | 1275 | log_write = logger.log_write |
|
1282 | 1276 | output_hist = self.shell.history_manager.output_hist |
|
1283 | 1277 | for n in range(1,len(input_hist)-1): |
|
1284 | 1278 | log_write(input_hist[n].rstrip() + '\n') |
|
1285 | 1279 | if n in output_hist: |
|
1286 | 1280 | log_write(repr(output_hist[n]),'output') |
|
1287 | 1281 | else: |
|
1288 | 1282 | logger.log_write('\n'.join(input_hist[1:])) |
|
1289 | 1283 | logger.log_write('\n') |
|
1290 | 1284 | if timestamp: |
|
1291 | 1285 | # re-enable timestamping |
|
1292 | 1286 | logger.timestamp = True |
|
1293 | 1287 | |
|
1294 | 1288 | print ('Activating auto-logging. ' |
|
1295 | 1289 | 'Current session state plus future input saved.') |
|
1296 | 1290 | logger.logstate() |
|
1297 | 1291 | |
|
1298 | 1292 | def magic_logstop(self,parameter_s=''): |
|
1299 | 1293 | """Fully stop logging and close log file. |
|
1300 | 1294 | |
|
1301 | 1295 | In order to start logging again, a new %logstart call needs to be made, |
|
1302 | 1296 | possibly (though not necessarily) with a new filename, mode and other |
|
1303 | 1297 | options.""" |
|
1304 | 1298 | self.logger.logstop() |
|
1305 | 1299 | |
|
1306 | 1300 | def magic_logoff(self,parameter_s=''): |
|
1307 | 1301 | """Temporarily stop logging. |
|
1308 | 1302 | |
|
1309 | 1303 | You must have previously started logging.""" |
|
1310 | 1304 | self.shell.logger.switch_log(0) |
|
1311 | 1305 | |
|
1312 | 1306 | def magic_logon(self,parameter_s=''): |
|
1313 | 1307 | """Restart logging. |
|
1314 | 1308 | |
|
1315 | 1309 | This function is for restarting logging which you've temporarily |
|
1316 | 1310 | stopped with %logoff. For starting logging for the first time, you |
|
1317 | 1311 | must use the %logstart function, which allows you to specify an |
|
1318 | 1312 | optional log filename.""" |
|
1319 | 1313 | |
|
1320 | 1314 | self.shell.logger.switch_log(1) |
|
1321 | 1315 | |
|
1322 | 1316 | def magic_logstate(self,parameter_s=''): |
|
1323 | 1317 | """Print the status of the logging system.""" |
|
1324 | 1318 | |
|
1325 | 1319 | self.shell.logger.logstate() |
|
1326 | 1320 | |
|
1327 | 1321 | def magic_pdb(self, parameter_s=''): |
|
1328 | 1322 | """Control the automatic calling of the pdb interactive debugger. |
|
1329 | 1323 | |
|
1330 | 1324 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
|
1331 | 1325 | argument it works as a toggle. |
|
1332 | 1326 | |
|
1333 | 1327 | When an exception is triggered, IPython can optionally call the |
|
1334 | 1328 | interactive pdb debugger after the traceback printout. %pdb toggles |
|
1335 | 1329 | this feature on and off. |
|
1336 | 1330 | |
|
1337 | 1331 | The initial state of this feature is set in your configuration |
|
1338 | 1332 | file (the option is ``InteractiveShell.pdb``). |
|
1339 | 1333 | |
|
1340 | 1334 | If you want to just activate the debugger AFTER an exception has fired, |
|
1341 | 1335 | without having to type '%pdb on' and rerunning your code, you can use |
|
1342 | 1336 | the %debug magic.""" |
|
1343 | 1337 | |
|
1344 | 1338 | par = parameter_s.strip().lower() |
|
1345 | 1339 | |
|
1346 | 1340 | if par: |
|
1347 | 1341 | try: |
|
1348 | 1342 | new_pdb = {'off':0,'0':0,'on':1,'1':1}[par] |
|
1349 | 1343 | except KeyError: |
|
1350 | 1344 | print ('Incorrect argument. Use on/1, off/0, ' |
|
1351 | 1345 | 'or nothing for a toggle.') |
|
1352 | 1346 | return |
|
1353 | 1347 | else: |
|
1354 | 1348 | # toggle |
|
1355 | 1349 | new_pdb = not self.shell.call_pdb |
|
1356 | 1350 | |
|
1357 | 1351 | # set on the shell |
|
1358 | 1352 | self.shell.call_pdb = new_pdb |
|
1359 | 1353 | print 'Automatic pdb calling has been turned',on_off(new_pdb) |
|
1360 | 1354 | |
|
1361 | 1355 | def magic_debug(self, parameter_s=''): |
|
1362 | 1356 | """Activate the interactive debugger in post-mortem mode. |
|
1363 | 1357 | |
|
1364 | 1358 | If an exception has just occurred, this lets you inspect its stack |
|
1365 | 1359 | frames interactively. Note that this will always work only on the last |
|
1366 | 1360 | traceback that occurred, so you must call this quickly after an |
|
1367 | 1361 | exception that you wish to inspect has fired, because if another one |
|
1368 | 1362 | occurs, it clobbers the previous one. |
|
1369 | 1363 | |
|
1370 | 1364 | If you want IPython to automatically do this on every exception, see |
|
1371 | 1365 | the %pdb magic for more details. |
|
1372 | 1366 | """ |
|
1373 | 1367 | self.shell.debugger(force=True) |
|
1374 | 1368 | |
|
1375 | 1369 | @skip_doctest |
|
1376 | 1370 | def magic_prun(self, parameter_s ='',user_mode=1, |
|
1377 | 1371 | opts=None,arg_lst=None,prog_ns=None): |
|
1378 | 1372 | |
|
1379 | 1373 | """Run a statement through the python code profiler. |
|
1380 | 1374 | |
|
1381 | 1375 | Usage: |
|
1382 | 1376 | %prun [options] statement |
|
1383 | 1377 | |
|
1384 | 1378 | The given statement (which doesn't require quote marks) is run via the |
|
1385 | 1379 | python profiler in a manner similar to the profile.run() function. |
|
1386 | 1380 | Namespaces are internally managed to work correctly; profile.run |
|
1387 | 1381 | cannot be used in IPython because it makes certain assumptions about |
|
1388 | 1382 | namespaces which do not hold under IPython. |
|
1389 | 1383 | |
|
1390 | 1384 | Options: |
|
1391 | 1385 | |
|
1392 | 1386 | -l <limit>: you can place restrictions on what or how much of the |
|
1393 | 1387 | profile gets printed. The limit value can be: |
|
1394 | 1388 | |
|
1395 | 1389 | * A string: only information for function names containing this string |
|
1396 | 1390 | is printed. |
|
1397 | 1391 | |
|
1398 | 1392 | * An integer: only these many lines are printed. |
|
1399 | 1393 | |
|
1400 | 1394 | * A float (between 0 and 1): this fraction of the report is printed |
|
1401 | 1395 | (for example, use a limit of 0.4 to see the topmost 40% only). |
|
1402 | 1396 | |
|
1403 | 1397 | You can combine several limits with repeated use of the option. For |
|
1404 | 1398 | example, '-l __init__ -l 5' will print only the topmost 5 lines of |
|
1405 | 1399 | information about class constructors. |
|
1406 | 1400 | |
|
1407 | 1401 | -r: return the pstats.Stats object generated by the profiling. This |
|
1408 | 1402 | object has all the information about the profile in it, and you can |
|
1409 | 1403 | later use it for further analysis or in other functions. |
|
1410 | 1404 | |
|
1411 | 1405 | -s <key>: sort profile by given key. You can provide more than one key |
|
1412 | 1406 | by using the option several times: '-s key1 -s key2 -s key3...'. The |
|
1413 | 1407 | default sorting key is 'time'. |
|
1414 | 1408 | |
|
1415 | 1409 | The following is copied verbatim from the profile documentation |
|
1416 | 1410 | referenced below: |
|
1417 | 1411 | |
|
1418 | 1412 | When more than one key is provided, additional keys are used as |
|
1419 | 1413 | secondary criteria when the there is equality in all keys selected |
|
1420 | 1414 | before them. |
|
1421 | 1415 | |
|
1422 | 1416 | Abbreviations can be used for any key names, as long as the |
|
1423 | 1417 | abbreviation is unambiguous. The following are the keys currently |
|
1424 | 1418 | defined: |
|
1425 | 1419 | |
|
1426 | 1420 | Valid Arg Meaning |
|
1427 | 1421 | "calls" call count |
|
1428 | 1422 | "cumulative" cumulative time |
|
1429 | 1423 | "file" file name |
|
1430 | 1424 | "module" file name |
|
1431 | 1425 | "pcalls" primitive call count |
|
1432 | 1426 | "line" line number |
|
1433 | 1427 | "name" function name |
|
1434 | 1428 | "nfl" name/file/line |
|
1435 | 1429 | "stdname" standard name |
|
1436 | 1430 | "time" internal time |
|
1437 | 1431 | |
|
1438 | 1432 | Note that all sorts on statistics are in descending order (placing |
|
1439 | 1433 | most time consuming items first), where as name, file, and line number |
|
1440 | 1434 | searches are in ascending order (i.e., alphabetical). The subtle |
|
1441 | 1435 | distinction between "nfl" and "stdname" is that the standard name is a |
|
1442 | 1436 | sort of the name as printed, which means that the embedded line |
|
1443 | 1437 | numbers get compared in an odd way. For example, lines 3, 20, and 40 |
|
1444 | 1438 | would (if the file names were the same) appear in the string order |
|
1445 | 1439 | "20" "3" and "40". In contrast, "nfl" does a numeric compare of the |
|
1446 | 1440 | line numbers. In fact, sort_stats("nfl") is the same as |
|
1447 | 1441 | sort_stats("name", "file", "line"). |
|
1448 | 1442 | |
|
1449 | 1443 | -T <filename>: save profile results as shown on screen to a text |
|
1450 | 1444 | file. The profile is still shown on screen. |
|
1451 | 1445 | |
|
1452 | 1446 | -D <filename>: save (via dump_stats) profile statistics to given |
|
1453 | 1447 | filename. This data is in a format understood by the pstats module, and |
|
1454 | 1448 | is generated by a call to the dump_stats() method of profile |
|
1455 | 1449 | objects. The profile is still shown on screen. |
|
1456 | 1450 | |
|
1457 | 1451 | -q: suppress output to the pager. Best used with -T and/or -D above. |
|
1458 | 1452 | |
|
1459 | 1453 | If you want to run complete programs under the profiler's control, use |
|
1460 | 1454 | '%run -p [prof_opts] filename.py [args to program]' where prof_opts |
|
1461 | 1455 | contains profiler specific options as described here. |
|
1462 | 1456 | |
|
1463 | 1457 | You can read the complete documentation for the profile module with:: |
|
1464 | 1458 | |
|
1465 | 1459 | In [1]: import profile; profile.help() |
|
1466 | 1460 | """ |
|
1467 | 1461 | |
|
1468 | 1462 | opts_def = Struct(D=[''],l=[],s=['time'],T=['']) |
|
1469 | 1463 | |
|
1470 | 1464 | if user_mode: # regular user call |
|
1471 | 1465 | opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:q', |
|
1472 | 1466 | list_all=1, posix=False) |
|
1473 | 1467 | namespace = self.shell.user_ns |
|
1474 | 1468 | else: # called to run a program by %run -p |
|
1475 | 1469 | try: |
|
1476 | 1470 | filename = get_py_filename(arg_lst[0]) |
|
1477 | 1471 | except IOError as e: |
|
1478 | 1472 | try: |
|
1479 | 1473 | msg = str(e) |
|
1480 | 1474 | except UnicodeError: |
|
1481 | 1475 | msg = e.message |
|
1482 | 1476 | error(msg) |
|
1483 | 1477 | return |
|
1484 | 1478 | |
|
1485 | 1479 | arg_str = 'execfile(filename,prog_ns)' |
|
1486 | 1480 | namespace = { |
|
1487 | 1481 | 'execfile': self.shell.safe_execfile, |
|
1488 | 1482 | 'prog_ns': prog_ns, |
|
1489 | 1483 | 'filename': filename |
|
1490 | 1484 | } |
|
1491 | 1485 | |
|
1492 | 1486 | opts.merge(opts_def) |
|
1493 | 1487 | |
|
1494 | 1488 | prof = profile.Profile() |
|
1495 | 1489 | try: |
|
1496 | 1490 | prof = prof.runctx(arg_str,namespace,namespace) |
|
1497 | 1491 | sys_exit = '' |
|
1498 | 1492 | except SystemExit: |
|
1499 | 1493 | sys_exit = """*** SystemExit exception caught in code being profiled.""" |
|
1500 | 1494 | |
|
1501 | 1495 | stats = pstats.Stats(prof).strip_dirs().sort_stats(*opts.s) |
|
1502 | 1496 | |
|
1503 | 1497 | lims = opts.l |
|
1504 | 1498 | if lims: |
|
1505 | 1499 | lims = [] # rebuild lims with ints/floats/strings |
|
1506 | 1500 | for lim in opts.l: |
|
1507 | 1501 | try: |
|
1508 | 1502 | lims.append(int(lim)) |
|
1509 | 1503 | except ValueError: |
|
1510 | 1504 | try: |
|
1511 | 1505 | lims.append(float(lim)) |
|
1512 | 1506 | except ValueError: |
|
1513 | 1507 | lims.append(lim) |
|
1514 | 1508 | |
|
1515 | 1509 | # Trap output. |
|
1516 | 1510 | stdout_trap = StringIO() |
|
1517 | 1511 | |
|
1518 | 1512 | if hasattr(stats,'stream'): |
|
1519 | 1513 | # In newer versions of python, the stats object has a 'stream' |
|
1520 | 1514 | # attribute to write into. |
|
1521 | 1515 | stats.stream = stdout_trap |
|
1522 | 1516 | stats.print_stats(*lims) |
|
1523 | 1517 | else: |
|
1524 | 1518 | # For older versions, we manually redirect stdout during printing |
|
1525 | 1519 | sys_stdout = sys.stdout |
|
1526 | 1520 | try: |
|
1527 | 1521 | sys.stdout = stdout_trap |
|
1528 | 1522 | stats.print_stats(*lims) |
|
1529 | 1523 | finally: |
|
1530 | 1524 | sys.stdout = sys_stdout |
|
1531 | 1525 | |
|
1532 | 1526 | output = stdout_trap.getvalue() |
|
1533 | 1527 | output = output.rstrip() |
|
1534 | 1528 | |
|
1535 | 1529 | if 'q' not in opts: |
|
1536 | 1530 | page.page(output) |
|
1537 | 1531 | print sys_exit, |
|
1538 | 1532 | |
|
1539 | 1533 | dump_file = opts.D[0] |
|
1540 | 1534 | text_file = opts.T[0] |
|
1541 | 1535 | if dump_file: |
|
1542 | 1536 | dump_file = unquote_filename(dump_file) |
|
1543 | 1537 | prof.dump_stats(dump_file) |
|
1544 | 1538 | print '\n*** Profile stats marshalled to file',\ |
|
1545 | 1539 | `dump_file`+'.',sys_exit |
|
1546 | 1540 | if text_file: |
|
1547 | 1541 | text_file = unquote_filename(text_file) |
|
1548 | 1542 | pfile = open(text_file,'w') |
|
1549 | 1543 | pfile.write(output) |
|
1550 | 1544 | pfile.close() |
|
1551 | 1545 | print '\n*** Profile printout saved to text file',\ |
|
1552 | 1546 | `text_file`+'.',sys_exit |
|
1553 | 1547 | |
|
1554 | 1548 | if opts.has_key('r'): |
|
1555 | 1549 | return stats |
|
1556 | 1550 | else: |
|
1557 | 1551 | return None |
|
1558 | 1552 | |
|
1559 | 1553 | @skip_doctest |
|
1560 | 1554 | def magic_run(self, parameter_s ='', runner=None, |
|
1561 | 1555 | file_finder=get_py_filename): |
|
1562 | 1556 | """Run the named file inside IPython as a program. |
|
1563 | 1557 | |
|
1564 | 1558 | Usage:\\ |
|
1565 | 1559 | %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args] |
|
1566 | 1560 | |
|
1567 | 1561 | Parameters after the filename are passed as command-line arguments to |
|
1568 | 1562 | the program (put in sys.argv). Then, control returns to IPython's |
|
1569 | 1563 | prompt. |
|
1570 | 1564 | |
|
1571 | 1565 | This is similar to running at a system prompt:\\ |
|
1572 | 1566 | $ python file args\\ |
|
1573 | 1567 | but with the advantage of giving you IPython's tracebacks, and of |
|
1574 | 1568 | loading all variables into your interactive namespace for further use |
|
1575 | 1569 | (unless -p is used, see below). |
|
1576 | 1570 | |
|
1577 | 1571 | The file is executed in a namespace initially consisting only of |
|
1578 | 1572 | __name__=='__main__' and sys.argv constructed as indicated. It thus |
|
1579 | 1573 | sees its environment as if it were being run as a stand-alone program |
|
1580 | 1574 | (except for sharing global objects such as previously imported |
|
1581 | 1575 | modules). But after execution, the IPython interactive namespace gets |
|
1582 | 1576 | updated with all variables defined in the program (except for __name__ |
|
1583 | 1577 | and sys.argv). This allows for very convenient loading of code for |
|
1584 | 1578 | interactive work, while giving each program a 'clean sheet' to run in. |
|
1585 | 1579 | |
|
1586 | 1580 | Options: |
|
1587 | 1581 | |
|
1588 | 1582 | -n: __name__ is NOT set to '__main__', but to the running file's name |
|
1589 | 1583 | without extension (as python does under import). This allows running |
|
1590 | 1584 | scripts and reloading the definitions in them without calling code |
|
1591 | 1585 | protected by an ' if __name__ == "__main__" ' clause. |
|
1592 | 1586 | |
|
1593 | 1587 | -i: run the file in IPython's namespace instead of an empty one. This |
|
1594 | 1588 | is useful if you are experimenting with code written in a text editor |
|
1595 | 1589 | which depends on variables defined interactively. |
|
1596 | 1590 | |
|
1597 | 1591 | -e: ignore sys.exit() calls or SystemExit exceptions in the script |
|
1598 | 1592 | being run. This is particularly useful if IPython is being used to |
|
1599 | 1593 | run unittests, which always exit with a sys.exit() call. In such |
|
1600 | 1594 | cases you are interested in the output of the test results, not in |
|
1601 | 1595 | seeing a traceback of the unittest module. |
|
1602 | 1596 | |
|
1603 | 1597 | -t: print timing information at the end of the run. IPython will give |
|
1604 | 1598 | you an estimated CPU time consumption for your script, which under |
|
1605 | 1599 | Unix uses the resource module to avoid the wraparound problems of |
|
1606 | 1600 | time.clock(). Under Unix, an estimate of time spent on system tasks |
|
1607 | 1601 | is also given (for Windows platforms this is reported as 0.0). |
|
1608 | 1602 | |
|
1609 | 1603 | If -t is given, an additional -N<N> option can be given, where <N> |
|
1610 | 1604 | must be an integer indicating how many times you want the script to |
|
1611 | 1605 | run. The final timing report will include total and per run results. |
|
1612 | 1606 | |
|
1613 | 1607 | For example (testing the script uniq_stable.py):: |
|
1614 | 1608 | |
|
1615 | 1609 | In [1]: run -t uniq_stable |
|
1616 | 1610 | |
|
1617 | 1611 | IPython CPU timings (estimated):\\ |
|
1618 | 1612 | User : 0.19597 s.\\ |
|
1619 | 1613 | System: 0.0 s.\\ |
|
1620 | 1614 | |
|
1621 | 1615 | In [2]: run -t -N5 uniq_stable |
|
1622 | 1616 | |
|
1623 | 1617 | IPython CPU timings (estimated):\\ |
|
1624 | 1618 | Total runs performed: 5\\ |
|
1625 | 1619 | Times : Total Per run\\ |
|
1626 | 1620 | User : 0.910862 s, 0.1821724 s.\\ |
|
1627 | 1621 | System: 0.0 s, 0.0 s. |
|
1628 | 1622 | |
|
1629 | 1623 | -d: run your program under the control of pdb, the Python debugger. |
|
1630 | 1624 | This allows you to execute your program step by step, watch variables, |
|
1631 | 1625 | etc. Internally, what IPython does is similar to calling: |
|
1632 | 1626 | |
|
1633 | 1627 | pdb.run('execfile("YOURFILENAME")') |
|
1634 | 1628 | |
|
1635 | 1629 | with a breakpoint set on line 1 of your file. You can change the line |
|
1636 | 1630 | number for this automatic breakpoint to be <N> by using the -bN option |
|
1637 | 1631 | (where N must be an integer). For example:: |
|
1638 | 1632 | |
|
1639 | 1633 | %run -d -b40 myscript |
|
1640 | 1634 | |
|
1641 | 1635 | will set the first breakpoint at line 40 in myscript.py. Note that |
|
1642 | 1636 | the first breakpoint must be set on a line which actually does |
|
1643 | 1637 | something (not a comment or docstring) for it to stop execution. |
|
1644 | 1638 | |
|
1645 | 1639 | When the pdb debugger starts, you will see a (Pdb) prompt. You must |
|
1646 | 1640 | first enter 'c' (without quotes) to start execution up to the first |
|
1647 | 1641 | breakpoint. |
|
1648 | 1642 | |
|
1649 | 1643 | Entering 'help' gives information about the use of the debugger. You |
|
1650 | 1644 | can easily see pdb's full documentation with "import pdb;pdb.help()" |
|
1651 | 1645 | at a prompt. |
|
1652 | 1646 | |
|
1653 | 1647 | -p: run program under the control of the Python profiler module (which |
|
1654 | 1648 | prints a detailed report of execution times, function calls, etc). |
|
1655 | 1649 | |
|
1656 | 1650 | You can pass other options after -p which affect the behavior of the |
|
1657 | 1651 | profiler itself. See the docs for %prun for details. |
|
1658 | 1652 | |
|
1659 | 1653 | In this mode, the program's variables do NOT propagate back to the |
|
1660 | 1654 | IPython interactive namespace (because they remain in the namespace |
|
1661 | 1655 | where the profiler executes them). |
|
1662 | 1656 | |
|
1663 | 1657 | Internally this triggers a call to %prun, see its documentation for |
|
1664 | 1658 | details on the options available specifically for profiling. |
|
1665 | 1659 | |
|
1666 | 1660 | There is one special usage for which the text above doesn't apply: |
|
1667 | 1661 | if the filename ends with .ipy, the file is run as ipython script, |
|
1668 | 1662 | just as if the commands were written on IPython prompt. |
|
1669 | 1663 | |
|
1670 | 1664 | -m: specify module name to load instead of script path. Similar to |
|
1671 | 1665 | the -m option for the python interpreter. Use this option last if you |
|
1672 | 1666 | want to combine with other %run options. Unlike the python interpreter |
|
1673 | 1667 | only source modules are allowed no .pyc or .pyo files. |
|
1674 | 1668 | For example:: |
|
1675 | 1669 | |
|
1676 | 1670 | %run -m example |
|
1677 | 1671 | |
|
1678 | 1672 | will run the example module. |
|
1679 | 1673 | |
|
1680 | 1674 | """ |
|
1681 | 1675 | |
|
1682 | 1676 | # get arguments and set sys.argv for program to be run. |
|
1683 | 1677 | opts, arg_lst = self.parse_options(parameter_s, 'nidtN:b:pD:l:rs:T:em:', |
|
1684 | 1678 | mode='list', list_all=1) |
|
1685 | 1679 | if "m" in opts: |
|
1686 | 1680 | modulename = opts["m"][0] |
|
1687 | 1681 | modpath = find_mod(modulename) |
|
1688 | 1682 | if modpath is None: |
|
1689 | 1683 | warn('%r is not a valid modulename on sys.path'%modulename) |
|
1690 | 1684 | return |
|
1691 | 1685 | arg_lst = [modpath] + arg_lst |
|
1692 | 1686 | try: |
|
1693 | 1687 | filename = file_finder(arg_lst[0]) |
|
1694 | 1688 | except IndexError: |
|
1695 | 1689 | warn('you must provide at least a filename.') |
|
1696 | 1690 | print '\n%run:\n', oinspect.getdoc(self.magic_run) |
|
1697 | 1691 | return |
|
1698 | 1692 | except IOError as e: |
|
1699 | 1693 | try: |
|
1700 | 1694 | msg = str(e) |
|
1701 | 1695 | except UnicodeError: |
|
1702 | 1696 | msg = e.message |
|
1703 | 1697 | error(msg) |
|
1704 | 1698 | return |
|
1705 | 1699 | |
|
1706 | 1700 | if filename.lower().endswith('.ipy'): |
|
1707 | 1701 | self.shell.safe_execfile_ipy(filename) |
|
1708 | 1702 | return |
|
1709 | 1703 | |
|
1710 | 1704 | # Control the response to exit() calls made by the script being run |
|
1711 | 1705 | exit_ignore = 'e' in opts |
|
1712 | 1706 | |
|
1713 | 1707 | # Make sure that the running script gets a proper sys.argv as if it |
|
1714 | 1708 | # were run from a system shell. |
|
1715 | 1709 | save_argv = sys.argv # save it for later restoring |
|
1716 | 1710 | |
|
1717 | 1711 | # simulate shell expansion on arguments, at least tilde expansion |
|
1718 | 1712 | args = [ os.path.expanduser(a) for a in arg_lst[1:] ] |
|
1719 | 1713 | |
|
1720 | 1714 | sys.argv = [filename] + args # put in the proper filename |
|
1721 | 1715 | # protect sys.argv from potential unicode strings on Python 2: |
|
1722 | 1716 | if not py3compat.PY3: |
|
1723 | 1717 | sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ] |
|
1724 | 1718 | |
|
1725 | 1719 | if 'i' in opts: |
|
1726 | 1720 | # Run in user's interactive namespace |
|
1727 | 1721 | prog_ns = self.shell.user_ns |
|
1728 | 1722 | __name__save = self.shell.user_ns['__name__'] |
|
1729 | 1723 | prog_ns['__name__'] = '__main__' |
|
1730 | 1724 | main_mod = self.shell.new_main_mod(prog_ns) |
|
1731 | 1725 | else: |
|
1732 | 1726 | # Run in a fresh, empty namespace |
|
1733 | 1727 | if 'n' in opts: |
|
1734 | 1728 | name = os.path.splitext(os.path.basename(filename))[0] |
|
1735 | 1729 | else: |
|
1736 | 1730 | name = '__main__' |
|
1737 | 1731 | |
|
1738 | 1732 | main_mod = self.shell.new_main_mod() |
|
1739 | 1733 | prog_ns = main_mod.__dict__ |
|
1740 | 1734 | prog_ns['__name__'] = name |
|
1741 | 1735 | |
|
1742 | 1736 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must |
|
1743 | 1737 | # set the __file__ global in the script's namespace |
|
1744 | 1738 | prog_ns['__file__'] = filename |
|
1745 | 1739 | |
|
1746 | 1740 | # pickle fix. See interactiveshell for an explanation. But we need to make sure |
|
1747 | 1741 | # that, if we overwrite __main__, we replace it at the end |
|
1748 | 1742 | main_mod_name = prog_ns['__name__'] |
|
1749 | 1743 | |
|
1750 | 1744 | if main_mod_name == '__main__': |
|
1751 | 1745 | restore_main = sys.modules['__main__'] |
|
1752 | 1746 | else: |
|
1753 | 1747 | restore_main = False |
|
1754 | 1748 | |
|
1755 | 1749 | # This needs to be undone at the end to prevent holding references to |
|
1756 | 1750 | # every single object ever created. |
|
1757 | 1751 | sys.modules[main_mod_name] = main_mod |
|
1758 | 1752 | |
|
1759 | 1753 | try: |
|
1760 | 1754 | stats = None |
|
1761 | 1755 | with self.readline_no_record: |
|
1762 | 1756 | if 'p' in opts: |
|
1763 | 1757 | stats = self.magic_prun('', 0, opts, arg_lst, prog_ns) |
|
1764 | 1758 | else: |
|
1765 | 1759 | if 'd' in opts: |
|
1766 | 1760 | deb = debugger.Pdb(self.shell.colors) |
|
1767 | 1761 | # reset Breakpoint state, which is moronically kept |
|
1768 | 1762 | # in a class |
|
1769 | 1763 | bdb.Breakpoint.next = 1 |
|
1770 | 1764 | bdb.Breakpoint.bplist = {} |
|
1771 | 1765 | bdb.Breakpoint.bpbynumber = [None] |
|
1772 | 1766 | # Set an initial breakpoint to stop execution |
|
1773 | 1767 | maxtries = 10 |
|
1774 | 1768 | bp = int(opts.get('b', [1])[0]) |
|
1775 | 1769 | checkline = deb.checkline(filename, bp) |
|
1776 | 1770 | if not checkline: |
|
1777 | 1771 | for bp in range(bp + 1, bp + maxtries + 1): |
|
1778 | 1772 | if deb.checkline(filename, bp): |
|
1779 | 1773 | break |
|
1780 | 1774 | else: |
|
1781 | 1775 | msg = ("\nI failed to find a valid line to set " |
|
1782 | 1776 | "a breakpoint\n" |
|
1783 | 1777 | "after trying up to line: %s.\n" |
|
1784 | 1778 | "Please set a valid breakpoint manually " |
|
1785 | 1779 | "with the -b option." % bp) |
|
1786 | 1780 | error(msg) |
|
1787 | 1781 | return |
|
1788 | 1782 | # if we find a good linenumber, set the breakpoint |
|
1789 | 1783 | deb.do_break('%s:%s' % (filename, bp)) |
|
1790 | 1784 | # Start file run |
|
1791 | 1785 | print "NOTE: Enter 'c' at the", |
|
1792 | 1786 | print "%s prompt to start your script." % deb.prompt |
|
1793 | 1787 | ns = {'execfile': py3compat.execfile, 'prog_ns': prog_ns} |
|
1794 | 1788 | try: |
|
1795 | 1789 | deb.run('execfile("%s", prog_ns)' % filename, ns) |
|
1796 | 1790 | |
|
1797 | 1791 | except: |
|
1798 | 1792 | etype, value, tb = sys.exc_info() |
|
1799 | 1793 | # Skip three frames in the traceback: the %run one, |
|
1800 | 1794 | # one inside bdb.py, and the command-line typed by the |
|
1801 | 1795 | # user (run by exec in pdb itself). |
|
1802 | 1796 | self.shell.InteractiveTB(etype, value, tb, tb_offset=3) |
|
1803 | 1797 | else: |
|
1804 | 1798 | if runner is None: |
|
1805 | 1799 | runner = self.shell.safe_execfile |
|
1806 | 1800 | if 't' in opts: |
|
1807 | 1801 | # timed execution |
|
1808 | 1802 | try: |
|
1809 | 1803 | nruns = int(opts['N'][0]) |
|
1810 | 1804 | if nruns < 1: |
|
1811 | 1805 | error('Number of runs must be >=1') |
|
1812 | 1806 | return |
|
1813 | 1807 | except (KeyError): |
|
1814 | 1808 | nruns = 1 |
|
1815 | 1809 | twall0 = time.time() |
|
1816 | 1810 | if nruns == 1: |
|
1817 | 1811 | t0 = clock2() |
|
1818 | 1812 | runner(filename, prog_ns, prog_ns, |
|
1819 | 1813 | exit_ignore=exit_ignore) |
|
1820 | 1814 | t1 = clock2() |
|
1821 | 1815 | t_usr = t1[0] - t0[0] |
|
1822 | 1816 | t_sys = t1[1] - t0[1] |
|
1823 | 1817 | print "\nIPython CPU timings (estimated):" |
|
1824 | 1818 | print " User : %10.2f s." % t_usr |
|
1825 | 1819 | print " System : %10.2f s." % t_sys |
|
1826 | 1820 | else: |
|
1827 | 1821 | runs = range(nruns) |
|
1828 | 1822 | t0 = clock2() |
|
1829 | 1823 | for nr in runs: |
|
1830 | 1824 | runner(filename, prog_ns, prog_ns, |
|
1831 | 1825 | exit_ignore=exit_ignore) |
|
1832 | 1826 | t1 = clock2() |
|
1833 | 1827 | t_usr = t1[0] - t0[0] |
|
1834 | 1828 | t_sys = t1[1] - t0[1] |
|
1835 | 1829 | print "\nIPython CPU timings (estimated):" |
|
1836 | 1830 | print "Total runs performed:", nruns |
|
1837 | 1831 | print " Times : %10.2f %10.2f" % ('Total', 'Per run') |
|
1838 | 1832 | print " User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns) |
|
1839 | 1833 | print " System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns) |
|
1840 | 1834 | twall1 = time.time() |
|
1841 | 1835 | print "Wall time: %10.2f s." % (twall1 - twall0) |
|
1842 | 1836 | |
|
1843 | 1837 | else: |
|
1844 | 1838 | # regular execution |
|
1845 | 1839 | runner(filename, prog_ns, prog_ns, exit_ignore=exit_ignore) |
|
1846 | 1840 | |
|
1847 | 1841 | if 'i' in opts: |
|
1848 | 1842 | self.shell.user_ns['__name__'] = __name__save |
|
1849 | 1843 | else: |
|
1850 | 1844 | # The shell MUST hold a reference to prog_ns so after %run |
|
1851 | 1845 | # exits, the python deletion mechanism doesn't zero it out |
|
1852 | 1846 | # (leaving dangling references). |
|
1853 | 1847 | self.shell.cache_main_mod(prog_ns, filename) |
|
1854 | 1848 | # update IPython interactive namespace |
|
1855 | 1849 | |
|
1856 | 1850 | # Some forms of read errors on the file may mean the |
|
1857 | 1851 | # __name__ key was never set; using pop we don't have to |
|
1858 | 1852 | # worry about a possible KeyError. |
|
1859 | 1853 | prog_ns.pop('__name__', None) |
|
1860 | 1854 | |
|
1861 | 1855 | self.shell.user_ns.update(prog_ns) |
|
1862 | 1856 | finally: |
|
1863 | 1857 | # It's a bit of a mystery why, but __builtins__ can change from |
|
1864 | 1858 | # being a module to becoming a dict missing some key data after |
|
1865 | 1859 | # %run. As best I can see, this is NOT something IPython is doing |
|
1866 | 1860 | # at all, and similar problems have been reported before: |
|
1867 | 1861 | # http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-10/0188.html |
|
1868 | 1862 | # Since this seems to be done by the interpreter itself, the best |
|
1869 | 1863 | # we can do is to at least restore __builtins__ for the user on |
|
1870 | 1864 | # exit. |
|
1871 | 1865 | self.shell.user_ns['__builtins__'] = builtin_mod |
|
1872 | 1866 | |
|
1873 | 1867 | # Ensure key global structures are restored |
|
1874 | 1868 | sys.argv = save_argv |
|
1875 | 1869 | if restore_main: |
|
1876 | 1870 | sys.modules['__main__'] = restore_main |
|
1877 | 1871 | else: |
|
1878 | 1872 | # Remove from sys.modules the reference to main_mod we'd |
|
1879 | 1873 | # added. Otherwise it will trap references to objects |
|
1880 | 1874 | # contained therein. |
|
1881 | 1875 | del sys.modules[main_mod_name] |
|
1882 | 1876 | |
|
1883 | 1877 | return stats |
|
1884 | 1878 | |
|
1885 | 1879 | @skip_doctest |
|
1886 | 1880 | def magic_timeit(self, parameter_s =''): |
|
1887 | 1881 | """Time execution of a Python statement or expression |
|
1888 | 1882 | |
|
1889 | 1883 | Usage:\\ |
|
1890 | 1884 | %timeit [-n<N> -r<R> [-t|-c]] statement |
|
1891 | 1885 | |
|
1892 | 1886 | Time execution of a Python statement or expression using the timeit |
|
1893 | 1887 | module. |
|
1894 | 1888 | |
|
1895 | 1889 | Options: |
|
1896 | 1890 | -n<N>: execute the given statement <N> times in a loop. If this value |
|
1897 | 1891 | is not given, a fitting value is chosen. |
|
1898 | 1892 | |
|
1899 | 1893 | -r<R>: repeat the loop iteration <R> times and take the best result. |
|
1900 | 1894 | Default: 3 |
|
1901 | 1895 | |
|
1902 | 1896 | -t: use time.time to measure the time, which is the default on Unix. |
|
1903 | 1897 | This function measures wall time. |
|
1904 | 1898 | |
|
1905 | 1899 | -c: use time.clock to measure the time, which is the default on |
|
1906 | 1900 | Windows and measures wall time. On Unix, resource.getrusage is used |
|
1907 | 1901 | instead and returns the CPU user time. |
|
1908 | 1902 | |
|
1909 | 1903 | -p<P>: use a precision of <P> digits to display the timing result. |
|
1910 | 1904 | Default: 3 |
|
1911 | 1905 | |
|
1912 | 1906 | |
|
1913 | 1907 | Examples |
|
1914 | 1908 | -------- |
|
1915 | 1909 | :: |
|
1916 | 1910 | |
|
1917 | 1911 | In [1]: %timeit pass |
|
1918 | 1912 | 10000000 loops, best of 3: 53.3 ns per loop |
|
1919 | 1913 | |
|
1920 | 1914 | In [2]: u = None |
|
1921 | 1915 | |
|
1922 | 1916 | In [3]: %timeit u is None |
|
1923 | 1917 | 10000000 loops, best of 3: 184 ns per loop |
|
1924 | 1918 | |
|
1925 | 1919 | In [4]: %timeit -r 4 u == None |
|
1926 | 1920 | 1000000 loops, best of 4: 242 ns per loop |
|
1927 | 1921 | |
|
1928 | 1922 | In [5]: import time |
|
1929 | 1923 | |
|
1930 | 1924 | In [6]: %timeit -n1 time.sleep(2) |
|
1931 | 1925 | 1 loops, best of 3: 2 s per loop |
|
1932 | 1926 | |
|
1933 | 1927 | |
|
1934 | 1928 | The times reported by %timeit will be slightly higher than those |
|
1935 | 1929 | reported by the timeit.py script when variables are accessed. This is |
|
1936 | 1930 | due to the fact that %timeit executes the statement in the namespace |
|
1937 | 1931 | of the shell, compared with timeit.py, which uses a single setup |
|
1938 | 1932 | statement to import function or create variables. Generally, the bias |
|
1939 | 1933 | does not matter as long as results from timeit.py are not mixed with |
|
1940 | 1934 | those from %timeit.""" |
|
1941 | 1935 | |
|
1942 | 1936 | import timeit |
|
1943 | 1937 | import math |
|
1944 | 1938 | |
|
1945 | 1939 | # XXX: Unfortunately the unicode 'micro' symbol can cause problems in |
|
1946 | 1940 | # certain terminals. Until we figure out a robust way of |
|
1947 | 1941 | # auto-detecting if the terminal can deal with it, use plain 'us' for |
|
1948 | 1942 | # microseconds. I am really NOT happy about disabling the proper |
|
1949 | 1943 | # 'micro' prefix, but crashing is worse... If anyone knows what the |
|
1950 | 1944 | # right solution for this is, I'm all ears... |
|
1951 | 1945 | # |
|
1952 | 1946 | # Note: using |
|
1953 | 1947 | # |
|
1954 | 1948 | # s = u'\xb5' |
|
1955 | 1949 | # s.encode(sys.getdefaultencoding()) |
|
1956 | 1950 | # |
|
1957 | 1951 | # is not sufficient, as I've seen terminals where that fails but |
|
1958 | 1952 | # print s |
|
1959 | 1953 | # |
|
1960 | 1954 | # succeeds |
|
1961 | 1955 | # |
|
1962 | 1956 | # See bug: https://bugs.launchpad.net/ipython/+bug/348466 |
|
1963 | 1957 | |
|
1964 | 1958 | #units = [u"s", u"ms",u'\xb5',"ns"] |
|
1965 | 1959 | units = [u"s", u"ms",u'us',"ns"] |
|
1966 | 1960 | |
|
1967 | 1961 | scaling = [1, 1e3, 1e6, 1e9] |
|
1968 | 1962 | |
|
1969 | 1963 | opts, stmt = self.parse_options(parameter_s,'n:r:tcp:', |
|
1970 | 1964 | posix=False, strict=False) |
|
1971 | 1965 | if stmt == "": |
|
1972 | 1966 | return |
|
1973 | 1967 | timefunc = timeit.default_timer |
|
1974 | 1968 | number = int(getattr(opts, "n", 0)) |
|
1975 | 1969 | repeat = int(getattr(opts, "r", timeit.default_repeat)) |
|
1976 | 1970 | precision = int(getattr(opts, "p", 3)) |
|
1977 | 1971 | if hasattr(opts, "t"): |
|
1978 | 1972 | timefunc = time.time |
|
1979 | 1973 | if hasattr(opts, "c"): |
|
1980 | 1974 | timefunc = clock |
|
1981 | 1975 | |
|
1982 | 1976 | timer = timeit.Timer(timer=timefunc) |
|
1983 | 1977 | # this code has tight coupling to the inner workings of timeit.Timer, |
|
1984 | 1978 | # but is there a better way to achieve that the code stmt has access |
|
1985 | 1979 | # to the shell namespace? |
|
1986 | 1980 | |
|
1987 | 1981 | src = timeit.template % {'stmt': timeit.reindent(stmt, 8), |
|
1988 | 1982 | 'setup': "pass"} |
|
1989 | 1983 | # Track compilation time so it can be reported if too long |
|
1990 | 1984 | # Minimum time above which compilation time will be reported |
|
1991 | 1985 | tc_min = 0.1 |
|
1992 | 1986 | |
|
1993 | 1987 | t0 = clock() |
|
1994 | 1988 | code = compile(src, "<magic-timeit>", "exec") |
|
1995 | 1989 | tc = clock()-t0 |
|
1996 | 1990 | |
|
1997 | 1991 | ns = {} |
|
1998 | 1992 | exec code in self.shell.user_ns, ns |
|
1999 | 1993 | timer.inner = ns["inner"] |
|
2000 | 1994 | |
|
2001 | 1995 | if number == 0: |
|
2002 | 1996 | # determine number so that 0.2 <= total time < 2.0 |
|
2003 | 1997 | number = 1 |
|
2004 | 1998 | for i in range(1, 10): |
|
2005 | 1999 | if timer.timeit(number) >= 0.2: |
|
2006 | 2000 | break |
|
2007 | 2001 | number *= 10 |
|
2008 | 2002 | |
|
2009 | 2003 | best = min(timer.repeat(repeat, number)) / number |
|
2010 | 2004 | |
|
2011 | 2005 | if best > 0.0 and best < 1000.0: |
|
2012 | 2006 | order = min(-int(math.floor(math.log10(best)) // 3), 3) |
|
2013 | 2007 | elif best >= 1000.0: |
|
2014 | 2008 | order = 0 |
|
2015 | 2009 | else: |
|
2016 | 2010 | order = 3 |
|
2017 | 2011 | print u"%d loops, best of %d: %.*g %s per loop" % (number, repeat, |
|
2018 | 2012 | precision, |
|
2019 | 2013 | best * scaling[order], |
|
2020 | 2014 | units[order]) |
|
2021 | 2015 | if tc > tc_min: |
|
2022 | 2016 | print "Compiler time: %.2f s" % tc |
|
2023 | 2017 | |
|
2024 | 2018 | @skip_doctest |
|
2025 | 2019 | @needs_local_scope |
|
2026 | 2020 | def magic_time(self,parameter_s = ''): |
|
2027 | 2021 | """Time execution of a Python statement or expression. |
|
2028 | 2022 | |
|
2029 | 2023 | The CPU and wall clock times are printed, and the value of the |
|
2030 | 2024 | expression (if any) is returned. Note that under Win32, system time |
|
2031 | 2025 | is always reported as 0, since it can not be measured. |
|
2032 | 2026 | |
|
2033 | 2027 | This function provides very basic timing functionality. In Python |
|
2034 | 2028 | 2.3, the timeit module offers more control and sophistication, so this |
|
2035 | 2029 | could be rewritten to use it (patches welcome). |
|
2036 | 2030 | |
|
2037 | 2031 | Examples |
|
2038 | 2032 | -------- |
|
2039 | 2033 | :: |
|
2040 | 2034 | |
|
2041 | 2035 | In [1]: time 2**128 |
|
2042 | 2036 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2043 | 2037 | Wall time: 0.00 |
|
2044 | 2038 | Out[1]: 340282366920938463463374607431768211456L |
|
2045 | 2039 | |
|
2046 | 2040 | In [2]: n = 1000000 |
|
2047 | 2041 | |
|
2048 | 2042 | In [3]: time sum(range(n)) |
|
2049 | 2043 | CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s |
|
2050 | 2044 | Wall time: 1.37 |
|
2051 | 2045 | Out[3]: 499999500000L |
|
2052 | 2046 | |
|
2053 | 2047 | In [4]: time print 'hello world' |
|
2054 | 2048 | hello world |
|
2055 | 2049 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2056 | 2050 | Wall time: 0.00 |
|
2057 | 2051 | |
|
2058 | 2052 | Note that the time needed by Python to compile the given expression |
|
2059 | 2053 | will be reported if it is more than 0.1s. In this example, the |
|
2060 | 2054 | actual exponentiation is done by Python at compilation time, so while |
|
2061 | 2055 | the expression can take a noticeable amount of time to compute, that |
|
2062 | 2056 | time is purely due to the compilation: |
|
2063 | 2057 | |
|
2064 | 2058 | In [5]: time 3**9999; |
|
2065 | 2059 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2066 | 2060 | Wall time: 0.00 s |
|
2067 | 2061 | |
|
2068 | 2062 | In [6]: time 3**999999; |
|
2069 | 2063 | CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s |
|
2070 | 2064 | Wall time: 0.00 s |
|
2071 | 2065 | Compiler : 0.78 s |
|
2072 | 2066 | """ |
|
2073 | 2067 | |
|
2074 | 2068 | # fail immediately if the given expression can't be compiled |
|
2075 | 2069 | |
|
2076 | 2070 | expr = self.shell.prefilter(parameter_s,False) |
|
2077 | 2071 | |
|
2078 | 2072 | # Minimum time above which compilation time will be reported |
|
2079 | 2073 | tc_min = 0.1 |
|
2080 | 2074 | |
|
2081 | 2075 | try: |
|
2082 | 2076 | mode = 'eval' |
|
2083 | 2077 | t0 = clock() |
|
2084 | 2078 | code = compile(expr,'<timed eval>',mode) |
|
2085 | 2079 | tc = clock()-t0 |
|
2086 | 2080 | except SyntaxError: |
|
2087 | 2081 | mode = 'exec' |
|
2088 | 2082 | t0 = clock() |
|
2089 | 2083 | code = compile(expr,'<timed exec>',mode) |
|
2090 | 2084 | tc = clock()-t0 |
|
2091 | 2085 | # skew measurement as little as possible |
|
2092 | 2086 | glob = self.shell.user_ns |
|
2093 | 2087 | locs = self._magic_locals |
|
2094 | 2088 | clk = clock2 |
|
2095 | 2089 | wtime = time.time |
|
2096 | 2090 | # time execution |
|
2097 | 2091 | wall_st = wtime() |
|
2098 | 2092 | if mode=='eval': |
|
2099 | 2093 | st = clk() |
|
2100 | 2094 | out = eval(code, glob, locs) |
|
2101 | 2095 | end = clk() |
|
2102 | 2096 | else: |
|
2103 | 2097 | st = clk() |
|
2104 | 2098 | exec code in glob, locs |
|
2105 | 2099 | end = clk() |
|
2106 | 2100 | out = None |
|
2107 | 2101 | wall_end = wtime() |
|
2108 | 2102 | # Compute actual times and report |
|
2109 | 2103 | wall_time = wall_end-wall_st |
|
2110 | 2104 | cpu_user = end[0]-st[0] |
|
2111 | 2105 | cpu_sys = end[1]-st[1] |
|
2112 | 2106 | cpu_tot = cpu_user+cpu_sys |
|
2113 | 2107 | print "CPU times: user %.2f s, sys: %.2f s, total: %.2f s" % \ |
|
2114 | 2108 | (cpu_user,cpu_sys,cpu_tot) |
|
2115 | 2109 | print "Wall time: %.2f s" % wall_time |
|
2116 | 2110 | if tc > tc_min: |
|
2117 | 2111 | print "Compiler : %.2f s" % tc |
|
2118 | 2112 | return out |
|
2119 | 2113 | |
|
2120 | 2114 | @skip_doctest |
|
2121 | 2115 | def magic_macro(self,parameter_s = ''): |
|
2122 | 2116 | """Define a macro for future re-execution. It accepts ranges of history, |
|
2123 | 2117 | filenames or string objects. |
|
2124 | 2118 | |
|
2125 | 2119 | Usage:\\ |
|
2126 | 2120 | %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ... |
|
2127 | 2121 | |
|
2128 | 2122 | Options: |
|
2129 | 2123 | |
|
2130 | 2124 | -r: use 'raw' input. By default, the 'processed' history is used, |
|
2131 | 2125 | so that magics are loaded in their transformed version to valid |
|
2132 | 2126 | Python. If this option is given, the raw input as typed as the |
|
2133 | 2127 | command line is used instead. |
|
2134 | 2128 | |
|
2135 | 2129 | This will define a global variable called `name` which is a string |
|
2136 | 2130 | made of joining the slices and lines you specify (n1,n2,... numbers |
|
2137 | 2131 | above) from your input history into a single string. This variable |
|
2138 | 2132 | acts like an automatic function which re-executes those lines as if |
|
2139 | 2133 | you had typed them. You just type 'name' at the prompt and the code |
|
2140 | 2134 | executes. |
|
2141 | 2135 | |
|
2142 | 2136 | The syntax for indicating input ranges is described in %history. |
|
2143 | 2137 | |
|
2144 | 2138 | Note: as a 'hidden' feature, you can also use traditional python slice |
|
2145 | 2139 | notation, where N:M means numbers N through M-1. |
|
2146 | 2140 | |
|
2147 | 2141 | For example, if your history contains (%hist prints it):: |
|
2148 | 2142 | |
|
2149 | 2143 | 44: x=1 |
|
2150 | 2144 | 45: y=3 |
|
2151 | 2145 | 46: z=x+y |
|
2152 | 2146 | 47: print x |
|
2153 | 2147 | 48: a=5 |
|
2154 | 2148 | 49: print 'x',x,'y',y |
|
2155 | 2149 | |
|
2156 | 2150 | you can create a macro with lines 44 through 47 (included) and line 49 |
|
2157 | 2151 | called my_macro with:: |
|
2158 | 2152 | |
|
2159 | 2153 | In [55]: %macro my_macro 44-47 49 |
|
2160 | 2154 | |
|
2161 | 2155 | Now, typing `my_macro` (without quotes) will re-execute all this code |
|
2162 | 2156 | in one pass. |
|
2163 | 2157 | |
|
2164 | 2158 | You don't need to give the line-numbers in order, and any given line |
|
2165 | 2159 | number can appear multiple times. You can assemble macros with any |
|
2166 | 2160 | lines from your input history in any order. |
|
2167 | 2161 | |
|
2168 | 2162 | The macro is a simple object which holds its value in an attribute, |
|
2169 | 2163 | but IPython's display system checks for macros and executes them as |
|
2170 | 2164 | code instead of printing them when you type their name. |
|
2171 | 2165 | |
|
2172 | 2166 | You can view a macro's contents by explicitly printing it with:: |
|
2173 | 2167 | |
|
2174 | 2168 | print macro_name |
|
2175 | 2169 | |
|
2176 | 2170 | """ |
|
2177 | 2171 | opts,args = self.parse_options(parameter_s,'r',mode='list') |
|
2178 | 2172 | if not args: # List existing macros |
|
2179 | 2173 | return sorted(k for k,v in self.shell.user_ns.iteritems() if\ |
|
2180 | 2174 | isinstance(v, Macro)) |
|
2181 | 2175 | if len(args) == 1: |
|
2182 | 2176 | raise UsageError( |
|
2183 | 2177 | "%macro insufficient args; usage '%macro name n1-n2 n3-4...") |
|
2184 | 2178 | name, codefrom = args[0], " ".join(args[1:]) |
|
2185 | 2179 | |
|
2186 | 2180 | #print 'rng',ranges # dbg |
|
2187 | 2181 | try: |
|
2188 | 2182 | lines = self.shell.find_user_code(codefrom, 'r' in opts) |
|
2189 | 2183 | except (ValueError, TypeError) as e: |
|
2190 | 2184 | print e.args[0] |
|
2191 | 2185 | return |
|
2192 | 2186 | macro = Macro(lines) |
|
2193 | 2187 | self.shell.define_macro(name, macro) |
|
2194 | 2188 | print 'Macro `%s` created. To execute, type its name (without quotes).' % name |
|
2195 | 2189 | print '=== Macro contents: ===' |
|
2196 | 2190 | print macro, |
|
2197 | 2191 | |
|
2198 | 2192 | def magic_save(self,parameter_s = ''): |
|
2199 | 2193 | """Save a set of lines or a macro to a given filename. |
|
2200 | 2194 | |
|
2201 | 2195 | Usage:\\ |
|
2202 | 2196 | %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ... |
|
2203 | 2197 | |
|
2204 | 2198 | Options: |
|
2205 | 2199 | |
|
2206 | 2200 | -r: use 'raw' input. By default, the 'processed' history is used, |
|
2207 | 2201 | so that magics are loaded in their transformed version to valid |
|
2208 | 2202 | Python. If this option is given, the raw input as typed as the |
|
2209 | 2203 | command line is used instead. |
|
2210 | 2204 | |
|
2211 | 2205 | This function uses the same syntax as %history for input ranges, |
|
2212 | 2206 | then saves the lines to the filename you specify. |
|
2213 | 2207 | |
|
2214 | 2208 | It adds a '.py' extension to the file if you don't do so yourself, and |
|
2215 | 2209 | it asks for confirmation before overwriting existing files.""" |
|
2216 | 2210 | |
|
2217 | 2211 | opts,args = self.parse_options(parameter_s,'r',mode='list') |
|
2218 | 2212 | fname, codefrom = unquote_filename(args[0]), " ".join(args[1:]) |
|
2219 | 2213 | if not fname.endswith('.py'): |
|
2220 | 2214 | fname += '.py' |
|
2221 | 2215 | if os.path.isfile(fname): |
|
2222 |
|
|
|
2223 | if ans.lower() not in ['y','yes']: | |
|
2216 | overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n') | |
|
2217 | if not overwrite : | |
|
2224 | 2218 | print 'Operation cancelled.' |
|
2225 | 2219 | return |
|
2226 | 2220 | try: |
|
2227 | 2221 | cmds = self.shell.find_user_code(codefrom, 'r' in opts) |
|
2228 | 2222 | except (TypeError, ValueError) as e: |
|
2229 | 2223 | print e.args[0] |
|
2230 | 2224 | return |
|
2231 | 2225 | with io.open(fname,'w', encoding="utf-8") as f: |
|
2232 | 2226 | f.write(u"# coding: utf-8\n") |
|
2233 | 2227 | f.write(py3compat.cast_unicode(cmds)) |
|
2234 | 2228 | print 'The following commands were written to file `%s`:' % fname |
|
2235 | 2229 | print cmds |
|
2236 | 2230 | |
|
2237 | 2231 | def magic_pastebin(self, parameter_s = ''): |
|
2238 | 2232 | """Upload code to Github's Gist paste bin, returning the URL. |
|
2239 | 2233 | |
|
2240 | 2234 | Usage:\\ |
|
2241 | 2235 | %pastebin [-d "Custom description"] 1-7 |
|
2242 | 2236 | |
|
2243 | 2237 | The argument can be an input history range, a filename, or the name of a |
|
2244 | 2238 | string or macro. |
|
2245 | 2239 | |
|
2246 | 2240 | Options: |
|
2247 | 2241 | |
|
2248 | 2242 | -d: Pass a custom description for the gist. The default will say |
|
2249 | 2243 | "Pasted from IPython". |
|
2250 | 2244 | """ |
|
2251 | 2245 | opts, args = self.parse_options(parameter_s, 'd:') |
|
2252 | 2246 | |
|
2253 | 2247 | try: |
|
2254 | 2248 | code = self.shell.find_user_code(args) |
|
2255 | 2249 | except (ValueError, TypeError) as e: |
|
2256 | 2250 | print e.args[0] |
|
2257 | 2251 | return |
|
2258 | 2252 | |
|
2259 | 2253 | post_data = json.dumps({ |
|
2260 | 2254 | "description": opts.get('d', "Pasted from IPython"), |
|
2261 | 2255 | "public": True, |
|
2262 | 2256 | "files": { |
|
2263 | 2257 | "file1.py": { |
|
2264 | 2258 | "content": code |
|
2265 | 2259 | } |
|
2266 | 2260 | } |
|
2267 | 2261 | }).encode('utf-8') |
|
2268 | 2262 | |
|
2269 | 2263 | response = urlopen("https://api.github.com/gists", post_data) |
|
2270 | 2264 | response_data = json.loads(response.read().decode('utf-8')) |
|
2271 | 2265 | return response_data['html_url'] |
|
2272 | 2266 | |
|
2273 | 2267 | def magic_loadpy(self, arg_s): |
|
2274 | """Load a .py python script into the GUI console. | |
|
2268 | """Alias of `%load` | |
|
2269 | ||
|
2270 | `%loadpy` has gained some flexibility and droped the requirement of a `.py` | |
|
2271 | extension. So it has been renamed simply into %load. You can look at | |
|
2272 | `%load`'s docstring for more info. | |
|
2273 | """ | |
|
2274 | self.magic_load(arg_s) | |
|
2275 | ||
|
2276 | def magic_load(self, arg_s): | |
|
2277 | """Load code into the current frontend. | |
|
2278 | ||
|
2279 | Usage:\\ | |
|
2280 | %load [options] source | |
|
2281 | ||
|
2282 | where source can be a filename, URL, input history range or macro | |
|
2283 | ||
|
2284 | Options: | |
|
2285 | -------- | |
|
2286 | -y : Don't ask confirmation for loading source above 200 000 characters. | |
|
2275 | 2287 | |
|
2276 |
This magic command can either take a local filename |
|
|
2288 | This magic command can either take a local filename, a URL, an history | |
|
2289 | range (see %history) or a macro as argument, it will prompt for | |
|
2290 | confirmation before loading source with more than 200 000 characters, unless | |
|
2291 | -y flag is passed or if the frontend does not support raw_input:: | |
|
2277 | 2292 | |
|
2278 |
%load |
|
|
2279 | %loadpy http://www.example.com/myscript.py | |
|
2293 | %load myscript.py | |
|
2294 | %load 7-27 | |
|
2295 | %load myMacro | |
|
2296 | %load http://www.example.com/myscript.py | |
|
2280 | 2297 | """ |
|
2281 | arg_s = unquote_filename(arg_s) | |
|
2282 | remote_url = arg_s.startswith(('http://', 'https://')) | |
|
2283 | local_url = not remote_url | |
|
2284 | if local_url and not arg_s.endswith('.py'): | |
|
2285 | # Local files must be .py; for remote URLs it's possible that the | |
|
2286 | # fetch URL doesn't have a .py in it (many servers have an opaque | |
|
2287 | # URL, such as scipy-central.org). | |
|
2288 | raise ValueError('%%loadpy only works with .py files: %s' % arg_s) | |
|
2289 | ||
|
2290 | # openpy takes care of finding the source encoding (per PEP 263) | |
|
2291 | if remote_url: | |
|
2292 | contents = openpy.read_py_url(arg_s, skip_encoding_cookie=True) | |
|
2293 | else: | |
|
2294 | contents = openpy.read_py_file(arg_s, skip_encoding_cookie=True) | |
|
2295 | ||
|
2298 | opts,args = self.parse_options(arg_s,'y') | |
|
2299 | ||
|
2300 | contents = self.shell.find_user_code(args) | |
|
2301 | l = len(contents) | |
|
2302 | ||
|
2303 | # 200 000 is ~ 2500 full 80 caracter lines | |
|
2304 | # so in average, more than 5000 lines | |
|
2305 | if l > 200000 and 'y' not in opts: | |
|
2306 | try: | |
|
2307 | ans = self.shell.ask_yes_no(("The text you're trying to load seems pretty big"\ | |
|
2308 | " (%d characters). Continue (y/[N]) ?" % l), default='n' ) | |
|
2309 | except StdinNotImplementedError: | |
|
2310 | #asume yes if raw input not implemented | |
|
2311 | ans = True | |
|
2312 | ||
|
2313 | if ans is False : | |
|
2314 | print 'Operation cancelled.' | |
|
2315 | return | |
|
2316 | ||
|
2296 | 2317 | self.set_next_input(contents) |
|
2297 | 2318 | |
|
2298 | 2319 | def _find_edit_target(self, args, opts, last_call): |
|
2299 | 2320 | """Utility method used by magic_edit to find what to edit.""" |
|
2300 | 2321 | |
|
2301 | 2322 | def make_filename(arg): |
|
2302 | 2323 | "Make a filename from the given args" |
|
2303 | 2324 | arg = unquote_filename(arg) |
|
2304 | 2325 | try: |
|
2305 | 2326 | filename = get_py_filename(arg) |
|
2306 | 2327 | except IOError: |
|
2307 | 2328 | # If it ends with .py but doesn't already exist, assume we want |
|
2308 | 2329 | # a new file. |
|
2309 | 2330 | if arg.endswith('.py'): |
|
2310 | 2331 | filename = arg |
|
2311 | 2332 | else: |
|
2312 | 2333 | filename = None |
|
2313 | 2334 | return filename |
|
2314 | 2335 | |
|
2315 | 2336 | # Set a few locals from the options for convenience: |
|
2316 | 2337 | opts_prev = 'p' in opts |
|
2317 | 2338 | opts_raw = 'r' in opts |
|
2318 | 2339 | |
|
2319 | 2340 | # custom exceptions |
|
2320 | 2341 | class DataIsObject(Exception): pass |
|
2321 | 2342 | |
|
2322 | 2343 | # Default line number value |
|
2323 | 2344 | lineno = opts.get('n',None) |
|
2324 | 2345 | |
|
2325 | 2346 | if opts_prev: |
|
2326 | 2347 | args = '_%s' % last_call[0] |
|
2327 | 2348 | if not self.shell.user_ns.has_key(args): |
|
2328 | 2349 | args = last_call[1] |
|
2329 | 2350 | |
|
2330 | 2351 | # use last_call to remember the state of the previous call, but don't |
|
2331 | 2352 | # let it be clobbered by successive '-p' calls. |
|
2332 | 2353 | try: |
|
2333 | 2354 | last_call[0] = self.shell.displayhook.prompt_count |
|
2334 | 2355 | if not opts_prev: |
|
2335 | 2356 | last_call[1] = args |
|
2336 | 2357 | except: |
|
2337 | 2358 | pass |
|
2338 | 2359 | |
|
2339 | 2360 | # by default this is done with temp files, except when the given |
|
2340 | 2361 | # arg is a filename |
|
2341 | 2362 | use_temp = True |
|
2342 | 2363 | |
|
2343 | 2364 | data = '' |
|
2344 | 2365 | |
|
2345 | 2366 | # First, see if the arguments should be a filename. |
|
2346 | 2367 | filename = make_filename(args) |
|
2347 | 2368 | if filename: |
|
2348 | 2369 | use_temp = False |
|
2349 | 2370 | elif args: |
|
2350 | 2371 | # Mode where user specifies ranges of lines, like in %macro. |
|
2351 | 2372 | data = self.extract_input_lines(args, opts_raw) |
|
2352 | 2373 | if not data: |
|
2353 | 2374 | try: |
|
2354 | 2375 | # Load the parameter given as a variable. If not a string, |
|
2355 | 2376 | # process it as an object instead (below) |
|
2356 | 2377 | |
|
2357 | 2378 | #print '*** args',args,'type',type(args) # dbg |
|
2358 | 2379 | data = eval(args, self.shell.user_ns) |
|
2359 | 2380 | if not isinstance(data, basestring): |
|
2360 | 2381 | raise DataIsObject |
|
2361 | 2382 | |
|
2362 | 2383 | except (NameError,SyntaxError): |
|
2363 | 2384 | # given argument is not a variable, try as a filename |
|
2364 | 2385 | filename = make_filename(args) |
|
2365 | 2386 | if filename is None: |
|
2366 | 2387 | warn("Argument given (%s) can't be found as a variable " |
|
2367 | 2388 | "or as a filename." % args) |
|
2368 | 2389 | return |
|
2369 | 2390 | use_temp = False |
|
2370 | 2391 | |
|
2371 | 2392 | except DataIsObject: |
|
2372 | 2393 | # macros have a special edit function |
|
2373 | 2394 | if isinstance(data, Macro): |
|
2374 | 2395 | raise MacroToEdit(data) |
|
2375 | 2396 | |
|
2376 | 2397 | # For objects, try to edit the file where they are defined |
|
2377 | 2398 | try: |
|
2378 | 2399 | filename = inspect.getabsfile(data) |
|
2379 | 2400 | if 'fakemodule' in filename.lower() and inspect.isclass(data): |
|
2380 | 2401 | # class created by %edit? Try to find source |
|
2381 | 2402 | # by looking for method definitions instead, the |
|
2382 | 2403 | # __module__ in those classes is FakeModule. |
|
2383 | 2404 | attrs = [getattr(data, aname) for aname in dir(data)] |
|
2384 | 2405 | for attr in attrs: |
|
2385 | 2406 | if not inspect.ismethod(attr): |
|
2386 | 2407 | continue |
|
2387 | 2408 | filename = inspect.getabsfile(attr) |
|
2388 | 2409 | if filename and 'fakemodule' not in filename.lower(): |
|
2389 | 2410 | # change the attribute to be the edit target instead |
|
2390 | 2411 | data = attr |
|
2391 | 2412 | break |
|
2392 | 2413 | |
|
2393 | 2414 | datafile = 1 |
|
2394 | 2415 | except TypeError: |
|
2395 | 2416 | filename = make_filename(args) |
|
2396 | 2417 | datafile = 1 |
|
2397 | 2418 | warn('Could not find file where `%s` is defined.\n' |
|
2398 | 2419 | 'Opening a file named `%s`' % (args,filename)) |
|
2399 | 2420 | # Now, make sure we can actually read the source (if it was in |
|
2400 | 2421 | # a temp file it's gone by now). |
|
2401 | 2422 | if datafile: |
|
2402 | 2423 | try: |
|
2403 | 2424 | if lineno is None: |
|
2404 | 2425 | lineno = inspect.getsourcelines(data)[1] |
|
2405 | 2426 | except IOError: |
|
2406 | 2427 | filename = make_filename(args) |
|
2407 | 2428 | if filename is None: |
|
2408 | 2429 | warn('The file `%s` where `%s` was defined cannot ' |
|
2409 | 2430 | 'be read.' % (filename,data)) |
|
2410 | 2431 | return |
|
2411 | 2432 | use_temp = False |
|
2412 | 2433 | |
|
2413 | 2434 | if use_temp: |
|
2414 | 2435 | filename = self.shell.mktempfile(data) |
|
2415 | 2436 | print 'IPython will make a temporary file named:',filename |
|
2416 | 2437 | |
|
2417 | 2438 | return filename, lineno, use_temp |
|
2418 | 2439 | |
|
2419 | 2440 | def _edit_macro(self,mname,macro): |
|
2420 | 2441 | """open an editor with the macro data in a file""" |
|
2421 | 2442 | filename = self.shell.mktempfile(macro.value) |
|
2422 | 2443 | self.shell.hooks.editor(filename) |
|
2423 | 2444 | |
|
2424 | 2445 | # and make a new macro object, to replace the old one |
|
2425 | 2446 | mfile = open(filename) |
|
2426 | 2447 | mvalue = mfile.read() |
|
2427 | 2448 | mfile.close() |
|
2428 | 2449 | self.shell.user_ns[mname] = Macro(mvalue) |
|
2429 | 2450 | |
|
2430 | 2451 | def magic_ed(self,parameter_s=''): |
|
2431 | 2452 | """Alias to %edit.""" |
|
2432 | 2453 | return self.magic_edit(parameter_s) |
|
2433 | 2454 | |
|
2434 | 2455 | @skip_doctest |
|
2435 | 2456 | def magic_edit(self,parameter_s='',last_call=['','']): |
|
2436 | 2457 | """Bring up an editor and execute the resulting code. |
|
2437 | 2458 | |
|
2438 | 2459 | Usage: |
|
2439 | 2460 | %edit [options] [args] |
|
2440 | 2461 | |
|
2441 | 2462 | %edit runs IPython's editor hook. The default version of this hook is |
|
2442 | 2463 | set to call the editor specified by your $EDITOR environment variable. |
|
2443 | 2464 | If this isn't found, it will default to vi under Linux/Unix and to |
|
2444 | 2465 | notepad under Windows. See the end of this docstring for how to change |
|
2445 | 2466 | the editor hook. |
|
2446 | 2467 | |
|
2447 | 2468 | You can also set the value of this editor via the |
|
2448 | 2469 | ``TerminalInteractiveShell.editor`` option in your configuration file. |
|
2449 | 2470 | This is useful if you wish to use a different editor from your typical |
|
2450 | 2471 | default with IPython (and for Windows users who typically don't set |
|
2451 | 2472 | environment variables). |
|
2452 | 2473 | |
|
2453 | 2474 | This command allows you to conveniently edit multi-line code right in |
|
2454 | 2475 | your IPython session. |
|
2455 | 2476 | |
|
2456 | 2477 | If called without arguments, %edit opens up an empty editor with a |
|
2457 | 2478 | temporary file and will execute the contents of this file when you |
|
2458 | 2479 | close it (don't forget to save it!). |
|
2459 | 2480 | |
|
2460 | 2481 | |
|
2461 | 2482 | Options: |
|
2462 | 2483 | |
|
2463 | 2484 | -n <number>: open the editor at a specified line number. By default, |
|
2464 | 2485 | the IPython editor hook uses the unix syntax 'editor +N filename', but |
|
2465 | 2486 | you can configure this by providing your own modified hook if your |
|
2466 | 2487 | favorite editor supports line-number specifications with a different |
|
2467 | 2488 | syntax. |
|
2468 | 2489 | |
|
2469 | 2490 | -p: this will call the editor with the same data as the previous time |
|
2470 | 2491 | it was used, regardless of how long ago (in your current session) it |
|
2471 | 2492 | was. |
|
2472 | 2493 | |
|
2473 | 2494 | -r: use 'raw' input. This option only applies to input taken from the |
|
2474 | 2495 | user's history. By default, the 'processed' history is used, so that |
|
2475 | 2496 | magics are loaded in their transformed version to valid Python. If |
|
2476 | 2497 | this option is given, the raw input as typed as the command line is |
|
2477 | 2498 | used instead. When you exit the editor, it will be executed by |
|
2478 | 2499 | IPython's own processor. |
|
2479 | 2500 | |
|
2480 | 2501 | -x: do not execute the edited code immediately upon exit. This is |
|
2481 | 2502 | mainly useful if you are editing programs which need to be called with |
|
2482 | 2503 | command line arguments, which you can then do using %run. |
|
2483 | 2504 | |
|
2484 | 2505 | |
|
2485 | 2506 | Arguments: |
|
2486 | 2507 | |
|
2487 | 2508 | If arguments are given, the following possibilities exist: |
|
2488 | 2509 | |
|
2489 | 2510 | - If the argument is a filename, IPython will load that into the |
|
2490 | 2511 | editor. It will execute its contents with execfile() when you exit, |
|
2491 | 2512 | loading any code in the file into your interactive namespace. |
|
2492 | 2513 | |
|
2493 | 2514 | - The arguments are ranges of input history, e.g. "7 ~1/4-6". |
|
2494 | 2515 | The syntax is the same as in the %history magic. |
|
2495 | 2516 | |
|
2496 | 2517 | - If the argument is a string variable, its contents are loaded |
|
2497 | 2518 | into the editor. You can thus edit any string which contains |
|
2498 | 2519 | python code (including the result of previous edits). |
|
2499 | 2520 | |
|
2500 | 2521 | - If the argument is the name of an object (other than a string), |
|
2501 | 2522 | IPython will try to locate the file where it was defined and open the |
|
2502 | 2523 | editor at the point where it is defined. You can use `%edit function` |
|
2503 | 2524 | to load an editor exactly at the point where 'function' is defined, |
|
2504 | 2525 | edit it and have the file be executed automatically. |
|
2505 | 2526 | |
|
2506 | 2527 | - If the object is a macro (see %macro for details), this opens up your |
|
2507 | 2528 | specified editor with a temporary file containing the macro's data. |
|
2508 | 2529 | Upon exit, the macro is reloaded with the contents of the file. |
|
2509 | 2530 | |
|
2510 | 2531 | Note: opening at an exact line is only supported under Unix, and some |
|
2511 | 2532 | editors (like kedit and gedit up to Gnome 2.8) do not understand the |
|
2512 | 2533 | '+NUMBER' parameter necessary for this feature. Good editors like |
|
2513 | 2534 | (X)Emacs, vi, jed, pico and joe all do. |
|
2514 | 2535 | |
|
2515 | 2536 | After executing your code, %edit will return as output the code you |
|
2516 | 2537 | typed in the editor (except when it was an existing file). This way |
|
2517 | 2538 | you can reload the code in further invocations of %edit as a variable, |
|
2518 | 2539 | via _<NUMBER> or Out[<NUMBER>], where <NUMBER> is the prompt number of |
|
2519 | 2540 | the output. |
|
2520 | 2541 | |
|
2521 | 2542 | Note that %edit is also available through the alias %ed. |
|
2522 | 2543 | |
|
2523 | 2544 | This is an example of creating a simple function inside the editor and |
|
2524 | 2545 | then modifying it. First, start up the editor:: |
|
2525 | 2546 | |
|
2526 | 2547 | In [1]: ed |
|
2527 | 2548 | Editing... done. Executing edited code... |
|
2528 | 2549 | Out[1]: 'def foo():\\n print "foo() was defined in an editing |
|
2529 | 2550 | session"\\n' |
|
2530 | 2551 | |
|
2531 | 2552 | We can then call the function foo():: |
|
2532 | 2553 | |
|
2533 | 2554 | In [2]: foo() |
|
2534 | 2555 | foo() was defined in an editing session |
|
2535 | 2556 | |
|
2536 | 2557 | Now we edit foo. IPython automatically loads the editor with the |
|
2537 | 2558 | (temporary) file where foo() was previously defined:: |
|
2538 | 2559 | |
|
2539 | 2560 | In [3]: ed foo |
|
2540 | 2561 | Editing... done. Executing edited code... |
|
2541 | 2562 | |
|
2542 | 2563 | And if we call foo() again we get the modified version:: |
|
2543 | 2564 | |
|
2544 | 2565 | In [4]: foo() |
|
2545 | 2566 | foo() has now been changed! |
|
2546 | 2567 | |
|
2547 | 2568 | Here is an example of how to edit a code snippet successive |
|
2548 | 2569 | times. First we call the editor:: |
|
2549 | 2570 | |
|
2550 | 2571 | In [5]: ed |
|
2551 | 2572 | Editing... done. Executing edited code... |
|
2552 | 2573 | hello |
|
2553 | 2574 | Out[5]: "print 'hello'\\n" |
|
2554 | 2575 | |
|
2555 | 2576 | Now we call it again with the previous output (stored in _):: |
|
2556 | 2577 | |
|
2557 | 2578 | In [6]: ed _ |
|
2558 | 2579 | Editing... done. Executing edited code... |
|
2559 | 2580 | hello world |
|
2560 | 2581 | Out[6]: "print 'hello world'\\n" |
|
2561 | 2582 | |
|
2562 | 2583 | Now we call it with the output #8 (stored in _8, also as Out[8]):: |
|
2563 | 2584 | |
|
2564 | 2585 | In [7]: ed _8 |
|
2565 | 2586 | Editing... done. Executing edited code... |
|
2566 | 2587 | hello again |
|
2567 | 2588 | Out[7]: "print 'hello again'\\n" |
|
2568 | 2589 | |
|
2569 | 2590 | |
|
2570 | 2591 | Changing the default editor hook: |
|
2571 | 2592 | |
|
2572 | 2593 | If you wish to write your own editor hook, you can put it in a |
|
2573 | 2594 | configuration file which you load at startup time. The default hook |
|
2574 | 2595 | is defined in the IPython.core.hooks module, and you can use that as a |
|
2575 | 2596 | starting example for further modifications. That file also has |
|
2576 | 2597 | general instructions on how to set a new hook for use once you've |
|
2577 | 2598 | defined it.""" |
|
2578 | 2599 | opts,args = self.parse_options(parameter_s,'prxn:') |
|
2579 | 2600 | |
|
2580 | 2601 | try: |
|
2581 | 2602 | filename, lineno, is_temp = self._find_edit_target(args, opts, last_call) |
|
2582 | 2603 | except MacroToEdit as e: |
|
2583 | 2604 | self._edit_macro(args, e.args[0]) |
|
2584 | 2605 | return |
|
2585 | 2606 | |
|
2586 | 2607 | # do actual editing here |
|
2587 | 2608 | print 'Editing...', |
|
2588 | 2609 | sys.stdout.flush() |
|
2589 | 2610 | try: |
|
2590 | 2611 | # Quote filenames that may have spaces in them |
|
2591 | 2612 | if ' ' in filename: |
|
2592 | 2613 | filename = "'%s'" % filename |
|
2593 | 2614 | self.shell.hooks.editor(filename,lineno) |
|
2594 | 2615 | except TryNext: |
|
2595 | 2616 | warn('Could not open editor') |
|
2596 | 2617 | return |
|
2597 | 2618 | |
|
2598 | 2619 | # XXX TODO: should this be generalized for all string vars? |
|
2599 | 2620 | # For now, this is special-cased to blocks created by cpaste |
|
2600 | 2621 | if args.strip() == 'pasted_block': |
|
2601 | 2622 | self.shell.user_ns['pasted_block'] = file_read(filename) |
|
2602 | 2623 | |
|
2603 | 2624 | if 'x' in opts: # -x prevents actual execution |
|
2604 | 2625 | |
|
2605 | 2626 | else: |
|
2606 | 2627 | print 'done. Executing edited code...' |
|
2607 | 2628 | if 'r' in opts: # Untranslated IPython code |
|
2608 | 2629 | self.shell.run_cell(file_read(filename), |
|
2609 | 2630 | store_history=False) |
|
2610 | 2631 | else: |
|
2611 | 2632 | self.shell.safe_execfile(filename,self.shell.user_ns, |
|
2612 | 2633 | self.shell.user_ns) |
|
2613 | 2634 | |
|
2614 | 2635 | if is_temp: |
|
2615 | 2636 | try: |
|
2616 | 2637 | return open(filename).read() |
|
2617 | 2638 | except IOError,msg: |
|
2618 | 2639 | if msg.filename == filename: |
|
2619 | 2640 | warn('File not found. Did you forget to save?') |
|
2620 | 2641 | return |
|
2621 | 2642 | else: |
|
2622 | 2643 | self.shell.showtraceback() |
|
2623 | 2644 | |
|
2624 | 2645 | def magic_xmode(self,parameter_s = ''): |
|
2625 | 2646 | """Switch modes for the exception handlers. |
|
2626 | 2647 | |
|
2627 | 2648 | Valid modes: Plain, Context and Verbose. |
|
2628 | 2649 | |
|
2629 | 2650 | If called without arguments, acts as a toggle.""" |
|
2630 | 2651 | |
|
2631 | 2652 | def xmode_switch_err(name): |
|
2632 | 2653 | warn('Error changing %s exception modes.\n%s' % |
|
2633 | 2654 | (name,sys.exc_info()[1])) |
|
2634 | 2655 | |
|
2635 | 2656 | shell = self.shell |
|
2636 | 2657 | new_mode = parameter_s.strip().capitalize() |
|
2637 | 2658 | try: |
|
2638 | 2659 | shell.InteractiveTB.set_mode(mode=new_mode) |
|
2639 | 2660 | print 'Exception reporting mode:',shell.InteractiveTB.mode |
|
2640 | 2661 | except: |
|
2641 | 2662 | xmode_switch_err('user') |
|
2642 | 2663 | |
|
2643 | 2664 | def magic_colors(self,parameter_s = ''): |
|
2644 | 2665 | """Switch color scheme for prompts, info system and exception handlers. |
|
2645 | 2666 | |
|
2646 | 2667 | Currently implemented schemes: NoColor, Linux, LightBG. |
|
2647 | 2668 | |
|
2648 | 2669 | Color scheme names are not case-sensitive. |
|
2649 | 2670 | |
|
2650 | 2671 | Examples |
|
2651 | 2672 | -------- |
|
2652 | 2673 | To get a plain black and white terminal:: |
|
2653 | 2674 | |
|
2654 | 2675 | %colors nocolor |
|
2655 | 2676 | """ |
|
2656 | 2677 | |
|
2657 | 2678 | def color_switch_err(name): |
|
2658 | 2679 | warn('Error changing %s color schemes.\n%s' % |
|
2659 | 2680 | (name,sys.exc_info()[1])) |
|
2660 | 2681 | |
|
2661 | 2682 | |
|
2662 | 2683 | new_scheme = parameter_s.strip() |
|
2663 | 2684 | if not new_scheme: |
|
2664 | 2685 | raise UsageError( |
|
2665 | 2686 | "%colors: you must specify a color scheme. See '%colors?'") |
|
2666 | 2687 | return |
|
2667 | 2688 | # local shortcut |
|
2668 | 2689 | shell = self.shell |
|
2669 | 2690 | |
|
2670 | 2691 | import IPython.utils.rlineimpl as readline |
|
2671 | 2692 | |
|
2672 | 2693 | if not shell.colors_force and \ |
|
2673 | 2694 | not readline.have_readline and sys.platform == "win32": |
|
2674 | 2695 | msg = """\ |
|
2675 | 2696 | Proper color support under MS Windows requires the pyreadline library. |
|
2676 | 2697 | You can find it at: |
|
2677 | 2698 | http://ipython.org/pyreadline.html |
|
2678 | 2699 | Gary's readline needs the ctypes module, from: |
|
2679 | 2700 | http://starship.python.net/crew/theller/ctypes |
|
2680 | 2701 | (Note that ctypes is already part of Python versions 2.5 and newer). |
|
2681 | 2702 | |
|
2682 | 2703 | Defaulting color scheme to 'NoColor'""" |
|
2683 | 2704 | new_scheme = 'NoColor' |
|
2684 | 2705 | warn(msg) |
|
2685 | 2706 | |
|
2686 | 2707 | # readline option is 0 |
|
2687 | 2708 | if not shell.colors_force and not shell.has_readline: |
|
2688 | 2709 | new_scheme = 'NoColor' |
|
2689 | 2710 | |
|
2690 | 2711 | # Set prompt colors |
|
2691 | 2712 | try: |
|
2692 | 2713 | shell.prompt_manager.color_scheme = new_scheme |
|
2693 | 2714 | except: |
|
2694 | 2715 | color_switch_err('prompt') |
|
2695 | 2716 | else: |
|
2696 | 2717 | shell.colors = \ |
|
2697 | 2718 | shell.prompt_manager.color_scheme_table.active_scheme_name |
|
2698 | 2719 | # Set exception colors |
|
2699 | 2720 | try: |
|
2700 | 2721 | shell.InteractiveTB.set_colors(scheme = new_scheme) |
|
2701 | 2722 | shell.SyntaxTB.set_colors(scheme = new_scheme) |
|
2702 | 2723 | except: |
|
2703 | 2724 | color_switch_err('exception') |
|
2704 | 2725 | |
|
2705 | 2726 | # Set info (for 'object?') colors |
|
2706 | 2727 | if shell.color_info: |
|
2707 | 2728 | try: |
|
2708 | 2729 | shell.inspector.set_active_scheme(new_scheme) |
|
2709 | 2730 | except: |
|
2710 | 2731 | color_switch_err('object inspector') |
|
2711 | 2732 | else: |
|
2712 | 2733 | shell.inspector.set_active_scheme('NoColor') |
|
2713 | 2734 | |
|
2714 | 2735 | def magic_pprint(self, parameter_s=''): |
|
2715 | 2736 | """Toggle pretty printing on/off.""" |
|
2716 | 2737 | ptformatter = self.shell.display_formatter.formatters['text/plain'] |
|
2717 | 2738 | ptformatter.pprint = bool(1 - ptformatter.pprint) |
|
2718 | 2739 | print 'Pretty printing has been turned', \ |
|
2719 | 2740 | ['OFF','ON'][ptformatter.pprint] |
|
2720 | 2741 | |
|
2721 | 2742 | #...................................................................... |
|
2722 | 2743 | # Functions to implement unix shell-type things |
|
2723 | 2744 | |
|
2724 | 2745 | @skip_doctest |
|
2725 | 2746 | def magic_alias(self, parameter_s = ''): |
|
2726 | 2747 | """Define an alias for a system command. |
|
2727 | 2748 | |
|
2728 | 2749 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
|
2729 | 2750 | |
|
2730 | 2751 | Then, typing 'alias_name params' will execute the system command 'cmd |
|
2731 | 2752 | params' (from your underlying operating system). |
|
2732 | 2753 | |
|
2733 | 2754 | Aliases have lower precedence than magic functions and Python normal |
|
2734 | 2755 | variables, so if 'foo' is both a Python variable and an alias, the |
|
2735 | 2756 | alias can not be executed until 'del foo' removes the Python variable. |
|
2736 | 2757 | |
|
2737 | 2758 | You can use the %l specifier in an alias definition to represent the |
|
2738 | 2759 | whole line when the alias is called. For example:: |
|
2739 | 2760 | |
|
2740 | 2761 | In [2]: alias bracket echo "Input in brackets: <%l>" |
|
2741 | 2762 | In [3]: bracket hello world |
|
2742 | 2763 | Input in brackets: <hello world> |
|
2743 | 2764 | |
|
2744 | 2765 | You can also define aliases with parameters using %s specifiers (one |
|
2745 | 2766 | per parameter):: |
|
2746 | 2767 | |
|
2747 | 2768 | In [1]: alias parts echo first %s second %s |
|
2748 | 2769 | In [2]: %parts A B |
|
2749 | 2770 | first A second B |
|
2750 | 2771 | In [3]: %parts A |
|
2751 | 2772 | Incorrect number of arguments: 2 expected. |
|
2752 | 2773 | parts is an alias to: 'echo first %s second %s' |
|
2753 | 2774 | |
|
2754 | 2775 | Note that %l and %s are mutually exclusive. You can only use one or |
|
2755 | 2776 | the other in your aliases. |
|
2756 | 2777 | |
|
2757 | 2778 | Aliases expand Python variables just like system calls using ! or !! |
|
2758 | 2779 | do: all expressions prefixed with '$' get expanded. For details of |
|
2759 | 2780 | the semantic rules, see PEP-215: |
|
2760 | 2781 | http://www.python.org/peps/pep-0215.html. This is the library used by |
|
2761 | 2782 | IPython for variable expansion. If you want to access a true shell |
|
2762 | 2783 | variable, an extra $ is necessary to prevent its expansion by |
|
2763 | 2784 | IPython:: |
|
2764 | 2785 | |
|
2765 | 2786 | In [6]: alias show echo |
|
2766 | 2787 | In [7]: PATH='A Python string' |
|
2767 | 2788 | In [8]: show $PATH |
|
2768 | 2789 | A Python string |
|
2769 | 2790 | In [9]: show $$PATH |
|
2770 | 2791 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
|
2771 | 2792 | |
|
2772 | 2793 | You can use the alias facility to acess all of $PATH. See the %rehash |
|
2773 | 2794 | and %rehashx functions, which automatically create aliases for the |
|
2774 | 2795 | contents of your $PATH. |
|
2775 | 2796 | |
|
2776 | 2797 | If called with no parameters, %alias prints the current alias table.""" |
|
2777 | 2798 | |
|
2778 | 2799 | par = parameter_s.strip() |
|
2779 | 2800 | if not par: |
|
2780 | 2801 | stored = self.db.get('stored_aliases', {} ) |
|
2781 | 2802 | aliases = sorted(self.shell.alias_manager.aliases) |
|
2782 | 2803 | # for k, v in stored: |
|
2783 | 2804 | # atab.append(k, v[0]) |
|
2784 | 2805 | |
|
2785 | 2806 | print "Total number of aliases:", len(aliases) |
|
2786 | 2807 | sys.stdout.flush() |
|
2787 | 2808 | return aliases |
|
2788 | 2809 | |
|
2789 | 2810 | # Now try to define a new one |
|
2790 | 2811 | try: |
|
2791 | 2812 | alias,cmd = par.split(None, 1) |
|
2792 | 2813 | except: |
|
2793 | 2814 | print oinspect.getdoc(self.magic_alias) |
|
2794 | 2815 | else: |
|
2795 | 2816 | self.shell.alias_manager.soft_define_alias(alias, cmd) |
|
2796 | 2817 | # end magic_alias |
|
2797 | 2818 | |
|
2798 | 2819 | def magic_unalias(self, parameter_s = ''): |
|
2799 | 2820 | """Remove an alias""" |
|
2800 | 2821 | |
|
2801 | 2822 | aname = parameter_s.strip() |
|
2802 | 2823 | self.shell.alias_manager.undefine_alias(aname) |
|
2803 | 2824 | stored = self.db.get('stored_aliases', {} ) |
|
2804 | 2825 | if aname in stored: |
|
2805 | 2826 | print "Removing %stored alias",aname |
|
2806 | 2827 | del stored[aname] |
|
2807 | 2828 | self.db['stored_aliases'] = stored |
|
2808 | 2829 | |
|
2809 | 2830 | def magic_rehashx(self, parameter_s = ''): |
|
2810 | 2831 | """Update the alias table with all executable files in $PATH. |
|
2811 | 2832 | |
|
2812 | 2833 | This version explicitly checks that every entry in $PATH is a file |
|
2813 | 2834 | with execute access (os.X_OK), so it is much slower than %rehash. |
|
2814 | 2835 | |
|
2815 | 2836 | Under Windows, it checks executability as a match against a |
|
2816 | 2837 | '|'-separated string of extensions, stored in the IPython config |
|
2817 | 2838 | variable win_exec_ext. This defaults to 'exe|com|bat'. |
|
2818 | 2839 | |
|
2819 | 2840 | This function also resets the root module cache of module completer, |
|
2820 | 2841 | used on slow filesystems. |
|
2821 | 2842 | """ |
|
2822 | 2843 | from IPython.core.alias import InvalidAliasError |
|
2823 | 2844 | |
|
2824 | 2845 | # for the benefit of module completer in ipy_completers.py |
|
2825 | 2846 | del self.shell.db['rootmodules'] |
|
2826 | 2847 | |
|
2827 | 2848 | path = [os.path.abspath(os.path.expanduser(p)) for p in |
|
2828 | 2849 | os.environ.get('PATH','').split(os.pathsep)] |
|
2829 | 2850 | path = filter(os.path.isdir,path) |
|
2830 | 2851 | |
|
2831 | 2852 | syscmdlist = [] |
|
2832 | 2853 | # Now define isexec in a cross platform manner. |
|
2833 | 2854 | if os.name == 'posix': |
|
2834 | 2855 | isexec = lambda fname:os.path.isfile(fname) and \ |
|
2835 | 2856 | os.access(fname,os.X_OK) |
|
2836 | 2857 | else: |
|
2837 | 2858 | try: |
|
2838 | 2859 | winext = os.environ['pathext'].replace(';','|').replace('.','') |
|
2839 | 2860 | except KeyError: |
|
2840 | 2861 | winext = 'exe|com|bat|py' |
|
2841 | 2862 | if 'py' not in winext: |
|
2842 | 2863 | winext += '|py' |
|
2843 | 2864 | execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE) |
|
2844 | 2865 | isexec = lambda fname:os.path.isfile(fname) and execre.match(fname) |
|
2845 | 2866 | savedir = os.getcwdu() |
|
2846 | 2867 | |
|
2847 | 2868 | # Now walk the paths looking for executables to alias. |
|
2848 | 2869 | try: |
|
2849 | 2870 | # write the whole loop for posix/Windows so we don't have an if in |
|
2850 | 2871 | # the innermost part |
|
2851 | 2872 | if os.name == 'posix': |
|
2852 | 2873 | for pdir in path: |
|
2853 | 2874 | os.chdir(pdir) |
|
2854 | 2875 | for ff in os.listdir(pdir): |
|
2855 | 2876 | if isexec(ff): |
|
2856 | 2877 | try: |
|
2857 | 2878 | # Removes dots from the name since ipython |
|
2858 | 2879 | # will assume names with dots to be python. |
|
2859 | 2880 | self.shell.alias_manager.define_alias( |
|
2860 | 2881 | ff.replace('.',''), ff) |
|
2861 | 2882 | except InvalidAliasError: |
|
2862 | 2883 | pass |
|
2863 | 2884 | else: |
|
2864 | 2885 | syscmdlist.append(ff) |
|
2865 | 2886 | else: |
|
2866 | 2887 | no_alias = self.shell.alias_manager.no_alias |
|
2867 | 2888 | for pdir in path: |
|
2868 | 2889 | os.chdir(pdir) |
|
2869 | 2890 | for ff in os.listdir(pdir): |
|
2870 | 2891 | base, ext = os.path.splitext(ff) |
|
2871 | 2892 | if isexec(ff) and base.lower() not in no_alias: |
|
2872 | 2893 | if ext.lower() == '.exe': |
|
2873 | 2894 | ff = base |
|
2874 | 2895 | try: |
|
2875 | 2896 | # Removes dots from the name since ipython |
|
2876 | 2897 | # will assume names with dots to be python. |
|
2877 | 2898 | self.shell.alias_manager.define_alias( |
|
2878 | 2899 | base.lower().replace('.',''), ff) |
|
2879 | 2900 | except InvalidAliasError: |
|
2880 | 2901 | pass |
|
2881 | 2902 | syscmdlist.append(ff) |
|
2882 | 2903 | self.shell.db['syscmdlist'] = syscmdlist |
|
2883 | 2904 | finally: |
|
2884 | 2905 | os.chdir(savedir) |
|
2885 | 2906 | |
|
2886 | 2907 | @skip_doctest |
|
2887 | 2908 | def magic_pwd(self, parameter_s = ''): |
|
2888 | 2909 | """Return the current working directory path. |
|
2889 | 2910 | |
|
2890 | 2911 | Examples |
|
2891 | 2912 | -------- |
|
2892 | 2913 | :: |
|
2893 | 2914 | |
|
2894 | 2915 | In [9]: pwd |
|
2895 | 2916 | Out[9]: '/home/tsuser/sprint/ipython' |
|
2896 | 2917 | """ |
|
2897 | 2918 | return os.getcwdu() |
|
2898 | 2919 | |
|
2899 | 2920 | @skip_doctest |
|
2900 | 2921 | def magic_cd(self, parameter_s=''): |
|
2901 | 2922 | """Change the current working directory. |
|
2902 | 2923 | |
|
2903 | 2924 | This command automatically maintains an internal list of directories |
|
2904 | 2925 | you visit during your IPython session, in the variable _dh. The |
|
2905 | 2926 | command %dhist shows this history nicely formatted. You can also |
|
2906 | 2927 | do 'cd -<tab>' to see directory history conveniently. |
|
2907 | 2928 | |
|
2908 | 2929 | Usage: |
|
2909 | 2930 | |
|
2910 | 2931 | cd 'dir': changes to directory 'dir'. |
|
2911 | 2932 | |
|
2912 | 2933 | cd -: changes to the last visited directory. |
|
2913 | 2934 | |
|
2914 | 2935 | cd -<n>: changes to the n-th directory in the directory history. |
|
2915 | 2936 | |
|
2916 | 2937 | cd --foo: change to directory that matches 'foo' in history |
|
2917 | 2938 | |
|
2918 | 2939 | cd -b <bookmark_name>: jump to a bookmark set by %bookmark |
|
2919 | 2940 | (note: cd <bookmark_name> is enough if there is no |
|
2920 | 2941 | directory <bookmark_name>, but a bookmark with the name exists.) |
|
2921 | 2942 | 'cd -b <tab>' allows you to tab-complete bookmark names. |
|
2922 | 2943 | |
|
2923 | 2944 | Options: |
|
2924 | 2945 | |
|
2925 | 2946 | -q: quiet. Do not print the working directory after the cd command is |
|
2926 | 2947 | executed. By default IPython's cd command does print this directory, |
|
2927 | 2948 | since the default prompts do not display path information. |
|
2928 | 2949 | |
|
2929 | 2950 | Note that !cd doesn't work for this purpose because the shell where |
|
2930 | 2951 | !command runs is immediately discarded after executing 'command'. |
|
2931 | 2952 | |
|
2932 | 2953 | Examples |
|
2933 | 2954 | -------- |
|
2934 | 2955 | :: |
|
2935 | 2956 | |
|
2936 | 2957 | In [10]: cd parent/child |
|
2937 | 2958 | /home/tsuser/parent/child |
|
2938 | 2959 | """ |
|
2939 | 2960 | |
|
2940 | 2961 | parameter_s = parameter_s.strip() |
|
2941 | 2962 | #bkms = self.shell.persist.get("bookmarks",{}) |
|
2942 | 2963 | |
|
2943 | 2964 | oldcwd = os.getcwdu() |
|
2944 | 2965 | numcd = re.match(r'(-)(\d+)$',parameter_s) |
|
2945 | 2966 | # jump in directory history by number |
|
2946 | 2967 | if numcd: |
|
2947 | 2968 | nn = int(numcd.group(2)) |
|
2948 | 2969 | try: |
|
2949 | 2970 | ps = self.shell.user_ns['_dh'][nn] |
|
2950 | 2971 | except IndexError: |
|
2951 | 2972 | print 'The requested directory does not exist in history.' |
|
2952 | 2973 | return |
|
2953 | 2974 | else: |
|
2954 | 2975 | opts = {} |
|
2955 | 2976 | elif parameter_s.startswith('--'): |
|
2956 | 2977 | ps = None |
|
2957 | 2978 | fallback = None |
|
2958 | 2979 | pat = parameter_s[2:] |
|
2959 | 2980 | dh = self.shell.user_ns['_dh'] |
|
2960 | 2981 | # first search only by basename (last component) |
|
2961 | 2982 | for ent in reversed(dh): |
|
2962 | 2983 | if pat in os.path.basename(ent) and os.path.isdir(ent): |
|
2963 | 2984 | ps = ent |
|
2964 | 2985 | break |
|
2965 | 2986 | |
|
2966 | 2987 | if fallback is None and pat in ent and os.path.isdir(ent): |
|
2967 | 2988 | fallback = ent |
|
2968 | 2989 | |
|
2969 | 2990 | # if we have no last part match, pick the first full path match |
|
2970 | 2991 | if ps is None: |
|
2971 | 2992 | ps = fallback |
|
2972 | 2993 | |
|
2973 | 2994 | if ps is None: |
|
2974 | 2995 | print "No matching entry in directory history" |
|
2975 | 2996 | return |
|
2976 | 2997 | else: |
|
2977 | 2998 | opts = {} |
|
2978 | 2999 | |
|
2979 | 3000 | |
|
2980 | 3001 | else: |
|
2981 | 3002 | #turn all non-space-escaping backslashes to slashes, |
|
2982 | 3003 | # for c:\windows\directory\names\ |
|
2983 | 3004 | parameter_s = re.sub(r'\\(?! )','/', parameter_s) |
|
2984 | 3005 | opts,ps = self.parse_options(parameter_s,'qb',mode='string') |
|
2985 | 3006 | # jump to previous |
|
2986 | 3007 | if ps == '-': |
|
2987 | 3008 | try: |
|
2988 | 3009 | ps = self.shell.user_ns['_dh'][-2] |
|
2989 | 3010 | except IndexError: |
|
2990 | 3011 | raise UsageError('%cd -: No previous directory to change to.') |
|
2991 | 3012 | # jump to bookmark if needed |
|
2992 | 3013 | else: |
|
2993 | 3014 | if not os.path.isdir(ps) or opts.has_key('b'): |
|
2994 | 3015 | bkms = self.db.get('bookmarks', {}) |
|
2995 | 3016 | |
|
2996 | 3017 | if bkms.has_key(ps): |
|
2997 | 3018 | target = bkms[ps] |
|
2998 | 3019 | print '(bookmark:%s) -> %s' % (ps,target) |
|
2999 | 3020 | ps = target |
|
3000 | 3021 | else: |
|
3001 | 3022 | if opts.has_key('b'): |
|
3002 | 3023 | raise UsageError("Bookmark '%s' not found. " |
|
3003 | 3024 | "Use '%%bookmark -l' to see your bookmarks." % ps) |
|
3004 | 3025 | |
|
3005 | 3026 | # strip extra quotes on Windows, because os.chdir doesn't like them |
|
3006 | 3027 | ps = unquote_filename(ps) |
|
3007 | 3028 | # at this point ps should point to the target dir |
|
3008 | 3029 | if ps: |
|
3009 | 3030 | try: |
|
3010 | 3031 | os.chdir(os.path.expanduser(ps)) |
|
3011 | 3032 | if hasattr(self.shell, 'term_title') and self.shell.term_title: |
|
3012 | 3033 | set_term_title('IPython: ' + abbrev_cwd()) |
|
3013 | 3034 | except OSError: |
|
3014 | 3035 | print sys.exc_info()[1] |
|
3015 | 3036 | else: |
|
3016 | 3037 | cwd = os.getcwdu() |
|
3017 | 3038 | dhist = self.shell.user_ns['_dh'] |
|
3018 | 3039 | if oldcwd != cwd: |
|
3019 | 3040 | dhist.append(cwd) |
|
3020 | 3041 | self.db['dhist'] = compress_dhist(dhist)[-100:] |
|
3021 | 3042 | |
|
3022 | 3043 | else: |
|
3023 | 3044 | os.chdir(self.shell.home_dir) |
|
3024 | 3045 | if hasattr(self.shell, 'term_title') and self.shell.term_title: |
|
3025 | 3046 | set_term_title('IPython: ' + '~') |
|
3026 | 3047 | cwd = os.getcwdu() |
|
3027 | 3048 | dhist = self.shell.user_ns['_dh'] |
|
3028 | 3049 | |
|
3029 | 3050 | if oldcwd != cwd: |
|
3030 | 3051 | dhist.append(cwd) |
|
3031 | 3052 | self.db['dhist'] = compress_dhist(dhist)[-100:] |
|
3032 | 3053 | if not 'q' in opts and self.shell.user_ns['_dh']: |
|
3033 | 3054 | print self.shell.user_ns['_dh'][-1] |
|
3034 | 3055 | |
|
3035 | 3056 | |
|
3036 | 3057 | def magic_env(self, parameter_s=''): |
|
3037 | 3058 | """List environment variables.""" |
|
3038 | 3059 | |
|
3039 | 3060 | return dict(os.environ) |
|
3040 | 3061 | |
|
3041 | 3062 | def magic_pushd(self, parameter_s=''): |
|
3042 | 3063 | """Place the current dir on stack and change directory. |
|
3043 | 3064 | |
|
3044 | 3065 | Usage:\\ |
|
3045 | 3066 | %pushd ['dirname'] |
|
3046 | 3067 | """ |
|
3047 | 3068 | |
|
3048 | 3069 | dir_s = self.shell.dir_stack |
|
3049 | 3070 | tgt = os.path.expanduser(unquote_filename(parameter_s)) |
|
3050 | 3071 | cwd = os.getcwdu().replace(self.home_dir,'~') |
|
3051 | 3072 | if tgt: |
|
3052 | 3073 | self.magic_cd(parameter_s) |
|
3053 | 3074 | dir_s.insert(0,cwd) |
|
3054 | 3075 | return self.magic_dirs() |
|
3055 | 3076 | |
|
3056 | 3077 | def magic_popd(self, parameter_s=''): |
|
3057 | 3078 | """Change to directory popped off the top of the stack. |
|
3058 | 3079 | """ |
|
3059 | 3080 | if not self.shell.dir_stack: |
|
3060 | 3081 | raise UsageError("%popd on empty stack") |
|
3061 | 3082 | top = self.shell.dir_stack.pop(0) |
|
3062 | 3083 | self.magic_cd(top) |
|
3063 | 3084 | print "popd ->",top |
|
3064 | 3085 | |
|
3065 | 3086 | def magic_dirs(self, parameter_s=''): |
|
3066 | 3087 | """Return the current directory stack.""" |
|
3067 | 3088 | |
|
3068 | 3089 | return self.shell.dir_stack |
|
3069 | 3090 | |
|
3070 | 3091 | def magic_dhist(self, parameter_s=''): |
|
3071 | 3092 | """Print your history of visited directories. |
|
3072 | 3093 | |
|
3073 | 3094 | %dhist -> print full history\\ |
|
3074 | 3095 | %dhist n -> print last n entries only\\ |
|
3075 | 3096 | %dhist n1 n2 -> print entries between n1 and n2 (n1 not included)\\ |
|
3076 | 3097 | |
|
3077 | 3098 | This history is automatically maintained by the %cd command, and |
|
3078 | 3099 | always available as the global list variable _dh. You can use %cd -<n> |
|
3079 | 3100 | to go to directory number <n>. |
|
3080 | 3101 | |
|
3081 | 3102 | Note that most of time, you should view directory history by entering |
|
3082 | 3103 | cd -<TAB>. |
|
3083 | 3104 | |
|
3084 | 3105 | """ |
|
3085 | 3106 | |
|
3086 | 3107 | dh = self.shell.user_ns['_dh'] |
|
3087 | 3108 | if parameter_s: |
|
3088 | 3109 | try: |
|
3089 | 3110 | args = map(int,parameter_s.split()) |
|
3090 | 3111 | except: |
|
3091 | 3112 | self.arg_err(Magic.magic_dhist) |
|
3092 | 3113 | return |
|
3093 | 3114 | if len(args) == 1: |
|
3094 | 3115 | ini,fin = max(len(dh)-(args[0]),0),len(dh) |
|
3095 | 3116 | elif len(args) == 2: |
|
3096 | 3117 | ini,fin = args |
|
3097 | 3118 | else: |
|
3098 | 3119 | self.arg_err(Magic.magic_dhist) |
|
3099 | 3120 | return |
|
3100 | 3121 | else: |
|
3101 | 3122 | ini,fin = 0,len(dh) |
|
3102 | 3123 | nlprint(dh, |
|
3103 | 3124 | header = 'Directory history (kept in _dh)', |
|
3104 | 3125 | start=ini,stop=fin) |
|
3105 | 3126 | |
|
3106 | 3127 | @skip_doctest |
|
3107 | 3128 | def magic_sc(self, parameter_s=''): |
|
3108 | 3129 | """Shell capture - execute a shell command and capture its output. |
|
3109 | 3130 | |
|
3110 | 3131 | DEPRECATED. Suboptimal, retained for backwards compatibility. |
|
3111 | 3132 | |
|
3112 | 3133 | You should use the form 'var = !command' instead. Example: |
|
3113 | 3134 | |
|
3114 | 3135 | "%sc -l myfiles = ls ~" should now be written as |
|
3115 | 3136 | |
|
3116 | 3137 | "myfiles = !ls ~" |
|
3117 | 3138 | |
|
3118 | 3139 | myfiles.s, myfiles.l and myfiles.n still apply as documented |
|
3119 | 3140 | below. |
|
3120 | 3141 | |
|
3121 | 3142 | -- |
|
3122 | 3143 | %sc [options] varname=command |
|
3123 | 3144 | |
|
3124 | 3145 | IPython will run the given command using commands.getoutput(), and |
|
3125 | 3146 | will then update the user's interactive namespace with a variable |
|
3126 | 3147 | called varname, containing the value of the call. Your command can |
|
3127 | 3148 | contain shell wildcards, pipes, etc. |
|
3128 | 3149 | |
|
3129 | 3150 | The '=' sign in the syntax is mandatory, and the variable name you |
|
3130 | 3151 | supply must follow Python's standard conventions for valid names. |
|
3131 | 3152 | |
|
3132 | 3153 | (A special format without variable name exists for internal use) |
|
3133 | 3154 | |
|
3134 | 3155 | Options: |
|
3135 | 3156 | |
|
3136 | 3157 | -l: list output. Split the output on newlines into a list before |
|
3137 | 3158 | assigning it to the given variable. By default the output is stored |
|
3138 | 3159 | as a single string. |
|
3139 | 3160 | |
|
3140 | 3161 | -v: verbose. Print the contents of the variable. |
|
3141 | 3162 | |
|
3142 | 3163 | In most cases you should not need to split as a list, because the |
|
3143 | 3164 | returned value is a special type of string which can automatically |
|
3144 | 3165 | provide its contents either as a list (split on newlines) or as a |
|
3145 | 3166 | space-separated string. These are convenient, respectively, either |
|
3146 | 3167 | for sequential processing or to be passed to a shell command. |
|
3147 | 3168 | |
|
3148 | 3169 | For example:: |
|
3149 | 3170 | |
|
3150 | 3171 | # Capture into variable a |
|
3151 | 3172 | In [1]: sc a=ls *py |
|
3152 | 3173 | |
|
3153 | 3174 | # a is a string with embedded newlines |
|
3154 | 3175 | In [2]: a |
|
3155 | 3176 | Out[2]: 'setup.py\\nwin32_manual_post_install.py' |
|
3156 | 3177 | |
|
3157 | 3178 | # which can be seen as a list: |
|
3158 | 3179 | In [3]: a.l |
|
3159 | 3180 | Out[3]: ['setup.py', 'win32_manual_post_install.py'] |
|
3160 | 3181 | |
|
3161 | 3182 | # or as a whitespace-separated string: |
|
3162 | 3183 | In [4]: a.s |
|
3163 | 3184 | Out[4]: 'setup.py win32_manual_post_install.py' |
|
3164 | 3185 | |
|
3165 | 3186 | # a.s is useful to pass as a single command line: |
|
3166 | 3187 | In [5]: !wc -l $a.s |
|
3167 | 3188 | 146 setup.py |
|
3168 | 3189 | 130 win32_manual_post_install.py |
|
3169 | 3190 | 276 total |
|
3170 | 3191 | |
|
3171 | 3192 | # while the list form is useful to loop over: |
|
3172 | 3193 | In [6]: for f in a.l: |
|
3173 | 3194 | ...: !wc -l $f |
|
3174 | 3195 | ...: |
|
3175 | 3196 | 146 setup.py |
|
3176 | 3197 | 130 win32_manual_post_install.py |
|
3177 | 3198 | |
|
3178 | 3199 | Similarly, the lists returned by the -l option are also special, in |
|
3179 | 3200 | the sense that you can equally invoke the .s attribute on them to |
|
3180 | 3201 | automatically get a whitespace-separated string from their contents:: |
|
3181 | 3202 | |
|
3182 | 3203 | In [7]: sc -l b=ls *py |
|
3183 | 3204 | |
|
3184 | 3205 | In [8]: b |
|
3185 | 3206 | Out[8]: ['setup.py', 'win32_manual_post_install.py'] |
|
3186 | 3207 | |
|
3187 | 3208 | In [9]: b.s |
|
3188 | 3209 | Out[9]: 'setup.py win32_manual_post_install.py' |
|
3189 | 3210 | |
|
3190 | 3211 | In summary, both the lists and strings used for output capture have |
|
3191 | 3212 | the following special attributes:: |
|
3192 | 3213 | |
|
3193 | 3214 | .l (or .list) : value as list. |
|
3194 | 3215 | .n (or .nlstr): value as newline-separated string. |
|
3195 | 3216 | .s (or .spstr): value as space-separated string. |
|
3196 | 3217 | """ |
|
3197 | 3218 | |
|
3198 | 3219 | opts,args = self.parse_options(parameter_s,'lv') |
|
3199 | 3220 | # Try to get a variable name and command to run |
|
3200 | 3221 | try: |
|
3201 | 3222 | # the variable name must be obtained from the parse_options |
|
3202 | 3223 | # output, which uses shlex.split to strip options out. |
|
3203 | 3224 | var,_ = args.split('=',1) |
|
3204 | 3225 | var = var.strip() |
|
3205 | 3226 | # But the command has to be extracted from the original input |
|
3206 | 3227 | # parameter_s, not on what parse_options returns, to avoid the |
|
3207 | 3228 | # quote stripping which shlex.split performs on it. |
|
3208 | 3229 | _,cmd = parameter_s.split('=',1) |
|
3209 | 3230 | except ValueError: |
|
3210 | 3231 | var,cmd = '','' |
|
3211 | 3232 | # If all looks ok, proceed |
|
3212 | 3233 | split = 'l' in opts |
|
3213 | 3234 | out = self.shell.getoutput(cmd, split=split) |
|
3214 | 3235 | if opts.has_key('v'): |
|
3215 | 3236 | print '%s ==\n%s' % (var,pformat(out)) |
|
3216 | 3237 | if var: |
|
3217 | 3238 | self.shell.user_ns.update({var:out}) |
|
3218 | 3239 | else: |
|
3219 | 3240 | return out |
|
3220 | 3241 | |
|
3221 | 3242 | def magic_sx(self, parameter_s=''): |
|
3222 | 3243 | """Shell execute - run a shell command and capture its output. |
|
3223 | 3244 | |
|
3224 | 3245 | %sx command |
|
3225 | 3246 | |
|
3226 | 3247 | IPython will run the given command using commands.getoutput(), and |
|
3227 | 3248 | return the result formatted as a list (split on '\\n'). Since the |
|
3228 | 3249 | output is _returned_, it will be stored in ipython's regular output |
|
3229 | 3250 | cache Out[N] and in the '_N' automatic variables. |
|
3230 | 3251 | |
|
3231 | 3252 | Notes: |
|
3232 | 3253 | |
|
3233 | 3254 | 1) If an input line begins with '!!', then %sx is automatically |
|
3234 | 3255 | invoked. That is, while:: |
|
3235 | 3256 | |
|
3236 | 3257 | !ls |
|
3237 | 3258 | |
|
3238 | 3259 | causes ipython to simply issue system('ls'), typing:: |
|
3239 | 3260 | |
|
3240 | 3261 | !!ls |
|
3241 | 3262 | |
|
3242 | 3263 | is a shorthand equivalent to:: |
|
3243 | 3264 | |
|
3244 | 3265 | %sx ls |
|
3245 | 3266 | |
|
3246 | 3267 | 2) %sx differs from %sc in that %sx automatically splits into a list, |
|
3247 | 3268 | like '%sc -l'. The reason for this is to make it as easy as possible |
|
3248 | 3269 | to process line-oriented shell output via further python commands. |
|
3249 | 3270 | %sc is meant to provide much finer control, but requires more |
|
3250 | 3271 | typing. |
|
3251 | 3272 | |
|
3252 | 3273 | 3) Just like %sc -l, this is a list with special attributes: |
|
3253 | 3274 | :: |
|
3254 | 3275 | |
|
3255 | 3276 | .l (or .list) : value as list. |
|
3256 | 3277 | .n (or .nlstr): value as newline-separated string. |
|
3257 | 3278 | .s (or .spstr): value as whitespace-separated string. |
|
3258 | 3279 | |
|
3259 | 3280 | This is very useful when trying to use such lists as arguments to |
|
3260 | 3281 | system commands.""" |
|
3261 | 3282 | |
|
3262 | 3283 | if parameter_s: |
|
3263 | 3284 | return self.shell.getoutput(parameter_s) |
|
3264 | 3285 | |
|
3265 | 3286 | |
|
3266 | 3287 | def magic_bookmark(self, parameter_s=''): |
|
3267 | 3288 | """Manage IPython's bookmark system. |
|
3268 | 3289 | |
|
3269 | 3290 | %bookmark <name> - set bookmark to current dir |
|
3270 | 3291 | %bookmark <name> <dir> - set bookmark to <dir> |
|
3271 | 3292 | %bookmark -l - list all bookmarks |
|
3272 | 3293 | %bookmark -d <name> - remove bookmark |
|
3273 | 3294 | %bookmark -r - remove all bookmarks |
|
3274 | 3295 | |
|
3275 | 3296 | You can later on access a bookmarked folder with:: |
|
3276 | 3297 | |
|
3277 | 3298 | %cd -b <name> |
|
3278 | 3299 | |
|
3279 | 3300 | or simply '%cd <name>' if there is no directory called <name> AND |
|
3280 | 3301 | there is such a bookmark defined. |
|
3281 | 3302 | |
|
3282 | 3303 | Your bookmarks persist through IPython sessions, but they are |
|
3283 | 3304 | associated with each profile.""" |
|
3284 | 3305 | |
|
3285 | 3306 | opts,args = self.parse_options(parameter_s,'drl',mode='list') |
|
3286 | 3307 | if len(args) > 2: |
|
3287 | 3308 | raise UsageError("%bookmark: too many arguments") |
|
3288 | 3309 | |
|
3289 | 3310 | bkms = self.db.get('bookmarks',{}) |
|
3290 | 3311 | |
|
3291 | 3312 | if opts.has_key('d'): |
|
3292 | 3313 | try: |
|
3293 | 3314 | todel = args[0] |
|
3294 | 3315 | except IndexError: |
|
3295 | 3316 | raise UsageError( |
|
3296 | 3317 | "%bookmark -d: must provide a bookmark to delete") |
|
3297 | 3318 | else: |
|
3298 | 3319 | try: |
|
3299 | 3320 | del bkms[todel] |
|
3300 | 3321 | except KeyError: |
|
3301 | 3322 | raise UsageError( |
|
3302 | 3323 | "%%bookmark -d: Can't delete bookmark '%s'" % todel) |
|
3303 | 3324 | |
|
3304 | 3325 | elif opts.has_key('r'): |
|
3305 | 3326 | bkms = {} |
|
3306 | 3327 | elif opts.has_key('l'): |
|
3307 | 3328 | bks = bkms.keys() |
|
3308 | 3329 | bks.sort() |
|
3309 | 3330 | if bks: |
|
3310 | 3331 | size = max(map(len,bks)) |
|
3311 | 3332 | else: |
|
3312 | 3333 | size = 0 |
|
3313 | 3334 | fmt = '%-'+str(size)+'s -> %s' |
|
3314 | 3335 | print 'Current bookmarks:' |
|
3315 | 3336 | for bk in bks: |
|
3316 | 3337 | print fmt % (bk,bkms[bk]) |
|
3317 | 3338 | else: |
|
3318 | 3339 | if not args: |
|
3319 | 3340 | raise UsageError("%bookmark: You must specify the bookmark name") |
|
3320 | 3341 | elif len(args)==1: |
|
3321 | 3342 | bkms[args[0]] = os.getcwdu() |
|
3322 | 3343 | elif len(args)==2: |
|
3323 | 3344 | bkms[args[0]] = args[1] |
|
3324 | 3345 | self.db['bookmarks'] = bkms |
|
3325 | 3346 | |
|
3347 | ||
|
3326 | 3348 | def magic_pycat(self, parameter_s=''): |
|
3327 | 3349 | """Show a syntax-highlighted file through a pager. |
|
3328 | 3350 | |
|
3329 | 3351 | This magic is similar to the cat utility, but it will assume the file |
|
3330 |
to be Python source and will show it with syntax highlighting. |
|
|
3352 | to be Python source and will show it with syntax highlighting. | |
|
3331 | 3353 |
|
|
3332 | try: | |
|
3333 | filename = get_py_filename(parameter_s) | |
|
3334 | cont = file_read(filename) | |
|
3335 | except IOError: | |
|
3336 | try: | |
|
3337 | cont = eval(parameter_s,self.user_ns) | |
|
3338 | except NameError: | |
|
3339 | cont = None | |
|
3340 | if cont is None: | |
|
3341 | print "Error: no such file or variable" | |
|
3354 | This magic command can either take a local filename, an url, | |
|
3355 | an history range (see %history) or a macro as argument :: | |
|
3356 | ||
|
3357 | %pycat myscript.py | |
|
3358 | %pycat 7-27 | |
|
3359 | %pycat myMacro | |
|
3360 | %pycat http://www.example.com/myscript.py | |
|
3361 | """ | |
|
3362 | ||
|
3363 | try : | |
|
3364 | cont = self.shell.find_user_code(parameter_s) | |
|
3365 | except ValueError, IOError: | |
|
3366 | print "Error: no such file, variable, URL, history range or macro" | |
|
3342 | 3367 | return |
|
3343 | 3368 | |
|
3344 | 3369 | page.page(self.shell.pycolorize(cont)) |
|
3345 | 3370 | |
|
3346 | 3371 | def magic_quickref(self,arg): |
|
3347 | 3372 | """ Show a quick reference sheet """ |
|
3348 | 3373 | import IPython.core.usage |
|
3349 | 3374 | qr = IPython.core.usage.quick_reference + self.magic_magic('-brief') |
|
3350 | 3375 | |
|
3351 | 3376 | page.page(qr) |
|
3352 | 3377 | |
|
3353 | 3378 | def magic_doctest_mode(self,parameter_s=''): |
|
3354 | 3379 | """Toggle doctest mode on and off. |
|
3355 | 3380 | |
|
3356 | 3381 | This mode is intended to make IPython behave as much as possible like a |
|
3357 | 3382 | plain Python shell, from the perspective of how its prompts, exceptions |
|
3358 | 3383 | and output look. This makes it easy to copy and paste parts of a |
|
3359 | 3384 | session into doctests. It does so by: |
|
3360 | 3385 | |
|
3361 | 3386 | - Changing the prompts to the classic ``>>>`` ones. |
|
3362 | 3387 | - Changing the exception reporting mode to 'Plain'. |
|
3363 | 3388 | - Disabling pretty-printing of output. |
|
3364 | 3389 | |
|
3365 | 3390 | Note that IPython also supports the pasting of code snippets that have |
|
3366 | 3391 | leading '>>>' and '...' prompts in them. This means that you can paste |
|
3367 | 3392 | doctests from files or docstrings (even if they have leading |
|
3368 | 3393 | whitespace), and the code will execute correctly. You can then use |
|
3369 | 3394 | '%history -t' to see the translated history; this will give you the |
|
3370 | 3395 | input after removal of all the leading prompts and whitespace, which |
|
3371 | 3396 | can be pasted back into an editor. |
|
3372 | 3397 | |
|
3373 | 3398 | With these features, you can switch into this mode easily whenever you |
|
3374 | 3399 | need to do testing and changes to doctests, without having to leave |
|
3375 | 3400 | your existing IPython session. |
|
3376 | 3401 | """ |
|
3377 | 3402 | |
|
3378 | 3403 | from IPython.utils.ipstruct import Struct |
|
3379 | 3404 | |
|
3380 | 3405 | # Shorthands |
|
3381 | 3406 | shell = self.shell |
|
3382 | 3407 | pm = shell.prompt_manager |
|
3383 | 3408 | meta = shell.meta |
|
3384 | 3409 | disp_formatter = self.shell.display_formatter |
|
3385 | 3410 | ptformatter = disp_formatter.formatters['text/plain'] |
|
3386 | 3411 | # dstore is a data store kept in the instance metadata bag to track any |
|
3387 | 3412 | # changes we make, so we can undo them later. |
|
3388 | 3413 | dstore = meta.setdefault('doctest_mode',Struct()) |
|
3389 | 3414 | save_dstore = dstore.setdefault |
|
3390 | 3415 | |
|
3391 | 3416 | # save a few values we'll need to recover later |
|
3392 | 3417 | mode = save_dstore('mode',False) |
|
3393 | 3418 | save_dstore('rc_pprint',ptformatter.pprint) |
|
3394 | 3419 | save_dstore('xmode',shell.InteractiveTB.mode) |
|
3395 | 3420 | save_dstore('rc_separate_out',shell.separate_out) |
|
3396 | 3421 | save_dstore('rc_separate_out2',shell.separate_out2) |
|
3397 | 3422 | save_dstore('rc_prompts_pad_left',pm.justify) |
|
3398 | 3423 | save_dstore('rc_separate_in',shell.separate_in) |
|
3399 | 3424 | save_dstore('rc_plain_text_only',disp_formatter.plain_text_only) |
|
3400 | 3425 | save_dstore('prompt_templates',(pm.in_template, pm.in2_template, pm.out_template)) |
|
3401 | 3426 | |
|
3402 | 3427 | if mode == False: |
|
3403 | 3428 | # turn on |
|
3404 | 3429 | pm.in_template = '>>> ' |
|
3405 | 3430 | pm.in2_template = '... ' |
|
3406 | 3431 | pm.out_template = '' |
|
3407 | 3432 | |
|
3408 | 3433 | # Prompt separators like plain python |
|
3409 | 3434 | shell.separate_in = '' |
|
3410 | 3435 | shell.separate_out = '' |
|
3411 | 3436 | shell.separate_out2 = '' |
|
3412 | 3437 | |
|
3413 | 3438 | pm.justify = False |
|
3414 | 3439 | |
|
3415 | 3440 | ptformatter.pprint = False |
|
3416 | 3441 | disp_formatter.plain_text_only = True |
|
3417 | 3442 | |
|
3418 | 3443 | shell.magic_xmode('Plain') |
|
3419 | 3444 | else: |
|
3420 | 3445 | # turn off |
|
3421 | 3446 | pm.in_template, pm.in2_template, pm.out_template = dstore.prompt_templates |
|
3422 | 3447 | |
|
3423 | 3448 | shell.separate_in = dstore.rc_separate_in |
|
3424 | 3449 | |
|
3425 | 3450 | shell.separate_out = dstore.rc_separate_out |
|
3426 | 3451 | shell.separate_out2 = dstore.rc_separate_out2 |
|
3427 | 3452 | |
|
3428 | 3453 | pm.justify = dstore.rc_prompts_pad_left |
|
3429 | 3454 | |
|
3430 | 3455 | ptformatter.pprint = dstore.rc_pprint |
|
3431 | 3456 | disp_formatter.plain_text_only = dstore.rc_plain_text_only |
|
3432 | 3457 | |
|
3433 | 3458 | shell.magic_xmode(dstore.xmode) |
|
3434 | 3459 | |
|
3435 | 3460 | # Store new mode and inform |
|
3436 | 3461 | dstore.mode = bool(1-int(mode)) |
|
3437 | 3462 | mode_label = ['OFF','ON'][dstore.mode] |
|
3438 | 3463 | print 'Doctest mode is:', mode_label |
|
3439 | 3464 | |
|
3440 | 3465 | def magic_gui(self, parameter_s=''): |
|
3441 | 3466 | """Enable or disable IPython GUI event loop integration. |
|
3442 | 3467 | |
|
3443 | 3468 | %gui [GUINAME] |
|
3444 | 3469 | |
|
3445 | 3470 | This magic replaces IPython's threaded shells that were activated |
|
3446 | 3471 | using the (pylab/wthread/etc.) command line flags. GUI toolkits |
|
3447 | 3472 | can now be enabled at runtime and keyboard |
|
3448 | 3473 | interrupts should work without any problems. The following toolkits |
|
3449 | 3474 | are supported: wxPython, PyQt4, PyGTK, Tk and Cocoa (OSX):: |
|
3450 | 3475 | |
|
3451 | 3476 | %gui wx # enable wxPython event loop integration |
|
3452 | 3477 | %gui qt4|qt # enable PyQt4 event loop integration |
|
3453 | 3478 | %gui gtk # enable PyGTK event loop integration |
|
3454 | 3479 | %gui gtk3 # enable Gtk3 event loop integration |
|
3455 | 3480 | %gui tk # enable Tk event loop integration |
|
3456 | 3481 | %gui OSX # enable Cocoa event loop integration |
|
3457 | 3482 | # (requires %matplotlib 1.1) |
|
3458 | 3483 | %gui # disable all event loop integration |
|
3459 | 3484 | |
|
3460 | 3485 | WARNING: after any of these has been called you can simply create |
|
3461 | 3486 | an application object, but DO NOT start the event loop yourself, as |
|
3462 | 3487 | we have already handled that. |
|
3463 | 3488 | """ |
|
3464 | 3489 | opts, arg = self.parse_options(parameter_s, '') |
|
3465 | 3490 | if arg=='': arg = None |
|
3466 | 3491 | try: |
|
3467 | 3492 | return self.enable_gui(arg) |
|
3468 | 3493 | except Exception as e: |
|
3469 | 3494 | # print simple error message, rather than traceback if we can't |
|
3470 | 3495 | # hook up the GUI |
|
3471 | 3496 | error(str(e)) |
|
3472 | 3497 | |
|
3473 | 3498 | def magic_install_ext(self, parameter_s): |
|
3474 | 3499 | """Download and install an extension from a URL, e.g.:: |
|
3475 | 3500 | |
|
3476 | 3501 | %install_ext https://bitbucket.org/birkenfeld/ipython-physics/raw/d1310a2ab15d/physics.py |
|
3477 | 3502 | |
|
3478 | 3503 | The URL should point to an importable Python module - either a .py file |
|
3479 | 3504 | or a .zip file. |
|
3480 | 3505 | |
|
3481 | 3506 | Parameters: |
|
3482 | 3507 | |
|
3483 | 3508 | -n filename : Specify a name for the file, rather than taking it from |
|
3484 | 3509 | the URL. |
|
3485 | 3510 | """ |
|
3486 | 3511 | opts, args = self.parse_options(parameter_s, 'n:') |
|
3487 | 3512 | try: |
|
3488 | 3513 | filename = self.extension_manager.install_extension(args, opts.get('n')) |
|
3489 | 3514 | except ValueError as e: |
|
3490 | 3515 | print e |
|
3491 | 3516 | return |
|
3492 | 3517 | |
|
3493 | 3518 | filename = os.path.basename(filename) |
|
3494 | 3519 | print "Installed %s. To use it, type:" % filename |
|
3495 | 3520 | print " %%load_ext %s" % os.path.splitext(filename)[0] |
|
3496 | 3521 | |
|
3497 | 3522 | |
|
3498 | 3523 | def magic_load_ext(self, module_str): |
|
3499 | 3524 | """Load an IPython extension by its module name.""" |
|
3500 | 3525 | return self.extension_manager.load_extension(module_str) |
|
3501 | 3526 | |
|
3502 | 3527 | def magic_unload_ext(self, module_str): |
|
3503 | 3528 | """Unload an IPython extension by its module name.""" |
|
3504 | 3529 | self.extension_manager.unload_extension(module_str) |
|
3505 | 3530 | |
|
3506 | 3531 | def magic_reload_ext(self, module_str): |
|
3507 | 3532 | """Reload an IPython extension by its module name.""" |
|
3508 | 3533 | self.extension_manager.reload_extension(module_str) |
|
3509 | 3534 | |
|
3510 | 3535 | def magic_install_profiles(self, s): |
|
3511 | 3536 | """%install_profiles has been deprecated.""" |
|
3512 | 3537 | print '\n'.join([ |
|
3513 | 3538 | "%install_profiles has been deprecated.", |
|
3514 | 3539 | "Use `ipython profile list` to view available profiles.", |
|
3515 | 3540 | "Requesting a profile with `ipython profile create <name>`", |
|
3516 | 3541 | "or `ipython --profile=<name>` will start with the bundled", |
|
3517 | 3542 | "profile of that name if it exists." |
|
3518 | 3543 | ]) |
|
3519 | 3544 | |
|
3520 | 3545 | def magic_install_default_config(self, s): |
|
3521 | 3546 | """%install_default_config has been deprecated.""" |
|
3522 | 3547 | print '\n'.join([ |
|
3523 | 3548 | "%install_default_config has been deprecated.", |
|
3524 | 3549 | "Use `ipython profile create <name>` to initialize a profile", |
|
3525 | 3550 | "with the default config files.", |
|
3526 | 3551 | "Add `--reset` to overwrite already existing config files with defaults." |
|
3527 | 3552 | ]) |
|
3528 | 3553 | |
|
3529 | 3554 | # Pylab support: simple wrappers that activate pylab, load gui input |
|
3530 | 3555 | # handling and modify slightly %run |
|
3531 | 3556 | |
|
3532 | 3557 | @skip_doctest |
|
3533 | 3558 | def _pylab_magic_run(self, parameter_s=''): |
|
3534 | 3559 | Magic.magic_run(self, parameter_s, |
|
3535 | 3560 | runner=mpl_runner(self.shell.safe_execfile)) |
|
3536 | 3561 | |
|
3537 | 3562 | _pylab_magic_run.__doc__ = magic_run.__doc__ |
|
3538 | 3563 | |
|
3539 | 3564 | @skip_doctest |
|
3540 | 3565 | def magic_pylab(self, s): |
|
3541 | 3566 | """Load numpy and matplotlib to work interactively. |
|
3542 | 3567 | |
|
3543 | 3568 | %pylab [GUINAME] |
|
3544 | 3569 | |
|
3545 | 3570 | This function lets you activate pylab (matplotlib, numpy and |
|
3546 | 3571 | interactive support) at any point during an IPython session. |
|
3547 | 3572 | |
|
3548 | 3573 | It will import at the top level numpy as np, pyplot as plt, matplotlib, |
|
3549 | 3574 | pylab and mlab, as well as all names from numpy and pylab. |
|
3550 | 3575 | |
|
3551 | 3576 | If you are using the inline matplotlib backend for embedded figures, |
|
3552 | 3577 | you can adjust its behavior via the %config magic:: |
|
3553 | 3578 | |
|
3554 | 3579 | # enable SVG figures, necessary for SVG+XHTML export in the qtconsole |
|
3555 | 3580 | In [1]: %config InlineBackend.figure_format = 'svg' |
|
3556 | 3581 | |
|
3557 | 3582 | # change the behavior of closing all figures at the end of each |
|
3558 | 3583 | # execution (cell), or allowing reuse of active figures across |
|
3559 | 3584 | # cells: |
|
3560 | 3585 | In [2]: %config InlineBackend.close_figures = False |
|
3561 | 3586 | |
|
3562 | 3587 | Parameters |
|
3563 | 3588 | ---------- |
|
3564 | 3589 | guiname : optional |
|
3565 | 3590 | One of the valid arguments to the %gui magic ('qt', 'wx', 'gtk', |
|
3566 | 3591 | 'osx' or 'tk'). If given, the corresponding Matplotlib backend is |
|
3567 | 3592 | used, otherwise matplotlib's default (which you can override in your |
|
3568 | 3593 | matplotlib config file) is used. |
|
3569 | 3594 | |
|
3570 | 3595 | Examples |
|
3571 | 3596 | -------- |
|
3572 | 3597 | In this case, where the MPL default is TkAgg:: |
|
3573 | 3598 | |
|
3574 | 3599 | In [2]: %pylab |
|
3575 | 3600 | |
|
3576 | 3601 | Welcome to pylab, a matplotlib-based Python environment. |
|
3577 | 3602 | Backend in use: TkAgg |
|
3578 | 3603 | For more information, type 'help(pylab)'. |
|
3579 | 3604 | |
|
3580 | 3605 | But you can explicitly request a different backend:: |
|
3581 | 3606 | |
|
3582 | 3607 | In [3]: %pylab qt |
|
3583 | 3608 | |
|
3584 | 3609 | Welcome to pylab, a matplotlib-based Python environment. |
|
3585 | 3610 | Backend in use: Qt4Agg |
|
3586 | 3611 | For more information, type 'help(pylab)'. |
|
3587 | 3612 | """ |
|
3588 | 3613 | |
|
3589 | 3614 | if Application.initialized(): |
|
3590 | 3615 | app = Application.instance() |
|
3591 | 3616 | try: |
|
3592 | 3617 | import_all_status = app.pylab_import_all |
|
3593 | 3618 | except AttributeError: |
|
3594 | 3619 | import_all_status = True |
|
3595 | 3620 | else: |
|
3596 | 3621 | import_all_status = True |
|
3597 | 3622 | |
|
3598 | 3623 | self.shell.enable_pylab(s, import_all=import_all_status) |
|
3599 | 3624 | |
|
3600 | 3625 | def magic_tb(self, s): |
|
3601 | 3626 | """Print the last traceback with the currently active exception mode. |
|
3602 | 3627 | |
|
3603 | 3628 | See %xmode for changing exception reporting modes.""" |
|
3604 | 3629 | self.shell.showtraceback() |
|
3605 | 3630 | |
|
3606 | 3631 | @skip_doctest |
|
3607 | 3632 | def magic_precision(self, s=''): |
|
3608 | 3633 | """Set floating point precision for pretty printing. |
|
3609 | 3634 | |
|
3610 | 3635 | Can set either integer precision or a format string. |
|
3611 | 3636 | |
|
3612 | 3637 | If numpy has been imported and precision is an int, |
|
3613 | 3638 | numpy display precision will also be set, via ``numpy.set_printoptions``. |
|
3614 | 3639 | |
|
3615 | 3640 | If no argument is given, defaults will be restored. |
|
3616 | 3641 | |
|
3617 | 3642 | Examples |
|
3618 | 3643 | -------- |
|
3619 | 3644 | :: |
|
3620 | 3645 | |
|
3621 | 3646 | In [1]: from math import pi |
|
3622 | 3647 | |
|
3623 | 3648 | In [2]: %precision 3 |
|
3624 | 3649 | Out[2]: u'%.3f' |
|
3625 | 3650 | |
|
3626 | 3651 | In [3]: pi |
|
3627 | 3652 | Out[3]: 3.142 |
|
3628 | 3653 | |
|
3629 | 3654 | In [4]: %precision %i |
|
3630 | 3655 | Out[4]: u'%i' |
|
3631 | 3656 | |
|
3632 | 3657 | In [5]: pi |
|
3633 | 3658 | Out[5]: 3 |
|
3634 | 3659 | |
|
3635 | 3660 | In [6]: %precision %e |
|
3636 | 3661 | Out[6]: u'%e' |
|
3637 | 3662 | |
|
3638 | 3663 | In [7]: pi**10 |
|
3639 | 3664 | Out[7]: 9.364805e+04 |
|
3640 | 3665 | |
|
3641 | 3666 | In [8]: %precision |
|
3642 | 3667 | Out[8]: u'%r' |
|
3643 | 3668 | |
|
3644 | 3669 | In [9]: pi**10 |
|
3645 | 3670 | Out[9]: 93648.047476082982 |
|
3646 | 3671 | |
|
3647 | 3672 | """ |
|
3648 | 3673 | |
|
3649 | 3674 | ptformatter = self.shell.display_formatter.formatters['text/plain'] |
|
3650 | 3675 | ptformatter.float_precision = s |
|
3651 | 3676 | return ptformatter.float_format |
|
3652 | 3677 | |
|
3653 | 3678 | |
|
3654 | 3679 | @magic_arguments.magic_arguments() |
|
3655 | 3680 | @magic_arguments.argument( |
|
3656 | 3681 | '-e', '--export', action='store_true', default=False, |
|
3657 | 3682 | help='Export IPython history as a notebook. The filename argument ' |
|
3658 | 3683 | 'is used to specify the notebook name and format. For example ' |
|
3659 | 3684 | 'a filename of notebook.ipynb will result in a notebook name ' |
|
3660 | 3685 | 'of "notebook" and a format of "xml". Likewise using a ".json" ' |
|
3661 | 3686 | 'or ".py" file extension will write the notebook in the json ' |
|
3662 | 3687 | 'or py formats.' |
|
3663 | 3688 | ) |
|
3664 | 3689 | @magic_arguments.argument( |
|
3665 | 3690 | '-f', '--format', |
|
3666 | 3691 | help='Convert an existing IPython notebook to a new format. This option ' |
|
3667 | 3692 | 'specifies the new format and can have the values: xml, json, py. ' |
|
3668 | 3693 | 'The target filename is chosen automatically based on the new ' |
|
3669 | 3694 | 'format. The filename argument gives the name of the source file.' |
|
3670 | 3695 | ) |
|
3671 | 3696 | @magic_arguments.argument( |
|
3672 | 3697 | 'filename', type=unicode, |
|
3673 | 3698 | help='Notebook name or filename' |
|
3674 | 3699 | ) |
|
3675 | 3700 | def magic_notebook(self, s): |
|
3676 | 3701 | """Export and convert IPython notebooks. |
|
3677 | 3702 | |
|
3678 | 3703 | This function can export the current IPython history to a notebook file |
|
3679 | 3704 | or can convert an existing notebook file into a different format. For |
|
3680 | 3705 | example, to export the history to "foo.ipynb" do "%notebook -e foo.ipynb". |
|
3681 | 3706 | To export the history to "foo.py" do "%notebook -e foo.py". To convert |
|
3682 | 3707 | "foo.ipynb" to "foo.json" do "%notebook -f json foo.ipynb". Possible |
|
3683 | 3708 | formats include (json/ipynb, py). |
|
3684 | 3709 | """ |
|
3685 | 3710 | args = magic_arguments.parse_argstring(self.magic_notebook, s) |
|
3686 | 3711 | |
|
3687 | 3712 | from IPython.nbformat import current |
|
3688 | 3713 | args.filename = unquote_filename(args.filename) |
|
3689 | 3714 | if args.export: |
|
3690 | 3715 | fname, name, format = current.parse_filename(args.filename) |
|
3691 | 3716 | cells = [] |
|
3692 | 3717 | hist = list(self.history_manager.get_range()) |
|
3693 | 3718 | for session, prompt_number, input in hist[:-1]: |
|
3694 | 3719 | cells.append(current.new_code_cell(prompt_number=prompt_number, input=input)) |
|
3695 | 3720 | worksheet = current.new_worksheet(cells=cells) |
|
3696 | 3721 | nb = current.new_notebook(name=name,worksheets=[worksheet]) |
|
3697 | 3722 | with io.open(fname, 'w', encoding='utf-8') as f: |
|
3698 | 3723 | current.write(nb, f, format); |
|
3699 | 3724 | elif args.format is not None: |
|
3700 | 3725 | old_fname, old_name, old_format = current.parse_filename(args.filename) |
|
3701 | 3726 | new_format = args.format |
|
3702 | 3727 | if new_format == u'xml': |
|
3703 | 3728 | raise ValueError('Notebooks cannot be written as xml.') |
|
3704 | 3729 | elif new_format == u'ipynb' or new_format == u'json': |
|
3705 | 3730 | new_fname = old_name + u'.ipynb' |
|
3706 | 3731 | new_format = u'json' |
|
3707 | 3732 | elif new_format == u'py': |
|
3708 | 3733 | new_fname = old_name + u'.py' |
|
3709 | 3734 | else: |
|
3710 | 3735 | raise ValueError('Invalid notebook format: %s' % new_format) |
|
3711 | 3736 | with io.open(old_fname, 'r', encoding='utf-8') as f: |
|
3712 | 3737 | nb = current.read(f, old_format) |
|
3713 | 3738 | with io.open(new_fname, 'w', encoding='utf-8') as f: |
|
3714 | 3739 | current.write(nb, f, new_format) |
|
3715 | 3740 | |
|
3716 | 3741 | def magic_config(self, s): |
|
3717 | 3742 | """configure IPython |
|
3718 | 3743 | |
|
3719 | 3744 | %config Class[.trait=value] |
|
3720 | 3745 | |
|
3721 | 3746 | This magic exposes most of the IPython config system. Any |
|
3722 | 3747 | Configurable class should be able to be configured with the simple |
|
3723 | 3748 | line:: |
|
3724 | 3749 | |
|
3725 | 3750 | %config Class.trait=value |
|
3726 | 3751 | |
|
3727 | 3752 | Where `value` will be resolved in the user's namespace, if it is an |
|
3728 | 3753 | expression or variable name. |
|
3729 | 3754 | |
|
3730 | 3755 | Examples |
|
3731 | 3756 | -------- |
|
3732 | 3757 | |
|
3733 | 3758 | To see what classes are available for config, pass no arguments:: |
|
3734 | 3759 | |
|
3735 | 3760 | In [1]: %config |
|
3736 | 3761 | Available objects for config: |
|
3737 | 3762 | TerminalInteractiveShell |
|
3738 | 3763 | HistoryManager |
|
3739 | 3764 | PrefilterManager |
|
3740 | 3765 | AliasManager |
|
3741 | 3766 | IPCompleter |
|
3742 | 3767 | PromptManager |
|
3743 | 3768 | DisplayFormatter |
|
3744 | 3769 | |
|
3745 | 3770 | To view what is configurable on a given class, just pass the class |
|
3746 | 3771 | name:: |
|
3747 | 3772 | |
|
3748 | 3773 | In [2]: %config IPCompleter |
|
3749 | 3774 | IPCompleter options |
|
3750 | 3775 | ----------------- |
|
3751 | 3776 | IPCompleter.omit__names=<Enum> |
|
3752 | 3777 | Current: 2 |
|
3753 | 3778 | Choices: (0, 1, 2) |
|
3754 | 3779 | Instruct the completer to omit private method names |
|
3755 | 3780 | Specifically, when completing on ``object.<tab>``. |
|
3756 | 3781 | When 2 [default]: all names that start with '_' will be excluded. |
|
3757 | 3782 | When 1: all 'magic' names (``__foo__``) will be excluded. |
|
3758 | 3783 | When 0: nothing will be excluded. |
|
3759 | 3784 | IPCompleter.merge_completions=<CBool> |
|
3760 | 3785 | Current: True |
|
3761 | 3786 | Whether to merge completion results into a single list |
|
3762 | 3787 | If False, only the completion results from the first non-empty completer |
|
3763 | 3788 | will be returned. |
|
3764 | 3789 | IPCompleter.limit_to__all__=<CBool> |
|
3765 | 3790 | Current: False |
|
3766 | 3791 | Instruct the completer to use __all__ for the completion |
|
3767 | 3792 | Specifically, when completing on ``object.<tab>``. |
|
3768 | 3793 | When True: only those names in obj.__all__ will be included. |
|
3769 | 3794 | When False [default]: the __all__ attribute is ignored |
|
3770 | 3795 | IPCompleter.greedy=<CBool> |
|
3771 | 3796 | Current: False |
|
3772 | 3797 | Activate greedy completion |
|
3773 | 3798 | This will enable completion on elements of lists, results of function calls, |
|
3774 | 3799 | etc., but can be unsafe because the code is actually evaluated on TAB. |
|
3775 | 3800 | |
|
3776 | 3801 | but the real use is in setting values:: |
|
3777 | 3802 | |
|
3778 | 3803 | In [3]: %config IPCompleter.greedy = True |
|
3779 | 3804 | |
|
3780 | 3805 | and these values are read from the user_ns if they are variables:: |
|
3781 | 3806 | |
|
3782 | 3807 | In [4]: feeling_greedy=False |
|
3783 | 3808 | |
|
3784 | 3809 | In [5]: %config IPCompleter.greedy = feeling_greedy |
|
3785 | 3810 | |
|
3786 | 3811 | """ |
|
3787 | 3812 | from IPython.config.loader import Config |
|
3788 | 3813 | # some IPython objects are Configurable, but do not yet have |
|
3789 | 3814 | # any configurable traits. Exclude them from the effects of |
|
3790 | 3815 | # this magic, as their presence is just noise: |
|
3791 | 3816 | configurables = [ c for c in self.configurables if c.__class__.class_traits(config=True) ] |
|
3792 | 3817 | classnames = [ c.__class__.__name__ for c in configurables ] |
|
3793 | 3818 | |
|
3794 | 3819 | line = s.strip() |
|
3795 | 3820 | if not line: |
|
3796 | 3821 | # print available configurable names |
|
3797 | 3822 | print "Available objects for config:" |
|
3798 | 3823 | for name in classnames: |
|
3799 | 3824 | print " ", name |
|
3800 | 3825 | return |
|
3801 | 3826 | elif line in classnames: |
|
3802 | 3827 | # `%config TerminalInteractiveShell` will print trait info for |
|
3803 | 3828 | # TerminalInteractiveShell |
|
3804 | 3829 | c = configurables[classnames.index(line)] |
|
3805 | 3830 | cls = c.__class__ |
|
3806 | 3831 | help = cls.class_get_help(c) |
|
3807 | 3832 | # strip leading '--' from cl-args: |
|
3808 | 3833 | help = re.sub(re.compile(r'^--', re.MULTILINE), '', help) |
|
3809 | 3834 | print help |
|
3810 | 3835 | return |
|
3811 | 3836 | elif '=' not in line: |
|
3812 | 3837 | raise UsageError("Invalid config statement: %r, should be Class.trait = value" % line) |
|
3813 | 3838 | |
|
3814 | 3839 | |
|
3815 | 3840 | # otherwise, assume we are setting configurables. |
|
3816 | 3841 | # leave quotes on args when splitting, because we want |
|
3817 | 3842 | # unquoted args to eval in user_ns |
|
3818 | 3843 | cfg = Config() |
|
3819 | 3844 | exec "cfg."+line in locals(), self.user_ns |
|
3820 | 3845 | |
|
3821 | 3846 | for configurable in configurables: |
|
3822 | 3847 | try: |
|
3823 | 3848 | configurable.update_config(cfg) |
|
3824 | 3849 | except Exception as e: |
|
3825 | 3850 | error(e) |
|
3826 | 3851 | |
|
3827 | 3852 | # end Magic |
@@ -1,275 +1,275 b'' | |||
|
1 | 1 | """A notebook manager that uses the local file system for storage. |
|
2 | 2 | |
|
3 | 3 | Authors: |
|
4 | 4 | |
|
5 | 5 | * Brian Granger |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | # Copyright (C) 2008-2011 The IPython Development Team |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 12 | # the file COPYING, distributed as part of this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | import datetime |
|
20 | 20 | import io |
|
21 | 21 | import os |
|
22 | 22 | import uuid |
|
23 | 23 | import glob |
|
24 | 24 | |
|
25 | 25 | from tornado import web |
|
26 | 26 | |
|
27 | 27 | from IPython.config.configurable import LoggingConfigurable |
|
28 | 28 | from IPython.nbformat import current |
|
29 | 29 | from IPython.utils.traitlets import Unicode, List, Dict, Bool |
|
30 | 30 | |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | # Classes |
|
33 | 33 | #----------------------------------------------------------------------------- |
|
34 | 34 | |
|
35 | 35 | class NotebookManager(LoggingConfigurable): |
|
36 | 36 | |
|
37 | 37 | notebook_dir = Unicode(os.getcwdu(), config=True, help=""" |
|
38 | 38 | The directory to use for notebooks. |
|
39 | 39 | """) |
|
40 | 40 | |
|
41 | 41 | save_script = Bool(False, config=True, |
|
42 | 42 | help="""Automatically create a Python script when saving the notebook. |
|
43 | 43 | |
|
44 |
For easier use of import, %run and %load |
|
|
44 | For easier use of import, %run and %load across notebooks, a | |
|
45 | 45 | <notebook-name>.py script will be created next to any |
|
46 | 46 | <notebook-name>.ipynb on each save. This can also be set with the |
|
47 | 47 | short `--script` flag. |
|
48 | 48 | """ |
|
49 | 49 | ) |
|
50 | 50 | |
|
51 | 51 | filename_ext = Unicode(u'.ipynb') |
|
52 | 52 | allowed_formats = List([u'json',u'py']) |
|
53 | 53 | |
|
54 | 54 | # Map notebook_ids to notebook names |
|
55 | 55 | mapping = Dict() |
|
56 | 56 | # Map notebook names to notebook_ids |
|
57 | 57 | rev_mapping = Dict() |
|
58 | 58 | |
|
59 | 59 | def list_notebooks(self): |
|
60 | 60 | """List all notebooks in the notebook dir. |
|
61 | 61 | |
|
62 | 62 | This returns a list of dicts of the form:: |
|
63 | 63 | |
|
64 | 64 | dict(notebook_id=notebook,name=name) |
|
65 | 65 | """ |
|
66 | 66 | names = glob.glob(os.path.join(self.notebook_dir, |
|
67 | 67 | '*' + self.filename_ext)) |
|
68 | 68 | names = [os.path.splitext(os.path.basename(name))[0] |
|
69 | 69 | for name in names] |
|
70 | 70 | |
|
71 | 71 | data = [] |
|
72 | 72 | for name in names: |
|
73 | 73 | if name not in self.rev_mapping: |
|
74 | 74 | notebook_id = self.new_notebook_id(name) |
|
75 | 75 | else: |
|
76 | 76 | notebook_id = self.rev_mapping[name] |
|
77 | 77 | data.append(dict(notebook_id=notebook_id,name=name)) |
|
78 | 78 | data = sorted(data, key=lambda item: item['name']) |
|
79 | 79 | return data |
|
80 | 80 | |
|
81 | 81 | def new_notebook_id(self, name): |
|
82 | 82 | """Generate a new notebook_id for a name and store its mappings.""" |
|
83 | 83 | # TODO: the following will give stable urls for notebooks, but unless |
|
84 | 84 | # the notebooks are immediately redirected to their new urls when their |
|
85 | 85 | # filemname changes, nasty inconsistencies result. So for now it's |
|
86 | 86 | # disabled and instead we use a random uuid4() call. But we leave the |
|
87 | 87 | # logic here so that we can later reactivate it, whhen the necessary |
|
88 | 88 | # url redirection code is written. |
|
89 | 89 | #notebook_id = unicode(uuid.uuid5(uuid.NAMESPACE_URL, |
|
90 | 90 | # 'file://'+self.get_path_by_name(name).encode('utf-8'))) |
|
91 | 91 | |
|
92 | 92 | notebook_id = unicode(uuid.uuid4()) |
|
93 | 93 | |
|
94 | 94 | self.mapping[notebook_id] = name |
|
95 | 95 | self.rev_mapping[name] = notebook_id |
|
96 | 96 | return notebook_id |
|
97 | 97 | |
|
98 | 98 | def delete_notebook_id(self, notebook_id): |
|
99 | 99 | """Delete a notebook's id only. This doesn't delete the actual notebook.""" |
|
100 | 100 | name = self.mapping[notebook_id] |
|
101 | 101 | del self.mapping[notebook_id] |
|
102 | 102 | del self.rev_mapping[name] |
|
103 | 103 | |
|
104 | 104 | def notebook_exists(self, notebook_id): |
|
105 | 105 | """Does a notebook exist?""" |
|
106 | 106 | if notebook_id not in self.mapping: |
|
107 | 107 | return False |
|
108 | 108 | path = self.get_path_by_name(self.mapping[notebook_id]) |
|
109 | 109 | return os.path.isfile(path) |
|
110 | 110 | |
|
111 | 111 | def find_path(self, notebook_id): |
|
112 | 112 | """Return a full path to a notebook given its notebook_id.""" |
|
113 | 113 | try: |
|
114 | 114 | name = self.mapping[notebook_id] |
|
115 | 115 | except KeyError: |
|
116 | 116 | raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id) |
|
117 | 117 | return self.get_path_by_name(name) |
|
118 | 118 | |
|
119 | 119 | def get_path_by_name(self, name): |
|
120 | 120 | """Return a full path to a notebook given its name.""" |
|
121 | 121 | filename = name + self.filename_ext |
|
122 | 122 | path = os.path.join(self.notebook_dir, filename) |
|
123 | 123 | return path |
|
124 | 124 | |
|
125 | 125 | def get_notebook(self, notebook_id, format=u'json'): |
|
126 | 126 | """Get the representation of a notebook in format by notebook_id.""" |
|
127 | 127 | format = unicode(format) |
|
128 | 128 | if format not in self.allowed_formats: |
|
129 | 129 | raise web.HTTPError(415, u'Invalid notebook format: %s' % format) |
|
130 | 130 | last_modified, nb = self.get_notebook_object(notebook_id) |
|
131 | 131 | kwargs = {} |
|
132 | 132 | if format == 'json': |
|
133 | 133 | # don't split lines for sending over the wire, because it |
|
134 | 134 | # should match the Python in-memory format. |
|
135 | 135 | kwargs['split_lines'] = False |
|
136 | 136 | data = current.writes(nb, format, **kwargs) |
|
137 | 137 | name = nb.get('name','notebook') |
|
138 | 138 | return last_modified, name, data |
|
139 | 139 | |
|
140 | 140 | def get_notebook_object(self, notebook_id): |
|
141 | 141 | """Get the NotebookNode representation of a notebook by notebook_id.""" |
|
142 | 142 | path = self.find_path(notebook_id) |
|
143 | 143 | if not os.path.isfile(path): |
|
144 | 144 | raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id) |
|
145 | 145 | info = os.stat(path) |
|
146 | 146 | last_modified = datetime.datetime.utcfromtimestamp(info.st_mtime) |
|
147 | 147 | with open(path,'r') as f: |
|
148 | 148 | s = f.read() |
|
149 | 149 | try: |
|
150 | 150 | # v1 and v2 and json in the .ipynb files. |
|
151 | 151 | nb = current.reads(s, u'json') |
|
152 | 152 | except: |
|
153 | 153 | raise web.HTTPError(500, u'Unreadable JSON notebook.') |
|
154 | 154 | if 'name' not in nb: |
|
155 | 155 | nb.name = os.path.split(path)[-1].split(u'.')[0] |
|
156 | 156 | return last_modified, nb |
|
157 | 157 | |
|
158 | 158 | def save_new_notebook(self, data, name=None, format=u'json'): |
|
159 | 159 | """Save a new notebook and return its notebook_id. |
|
160 | 160 | |
|
161 | 161 | If a name is passed in, it overrides any values in the notebook data |
|
162 | 162 | and the value in the data is updated to use that value. |
|
163 | 163 | """ |
|
164 | 164 | if format not in self.allowed_formats: |
|
165 | 165 | raise web.HTTPError(415, u'Invalid notebook format: %s' % format) |
|
166 | 166 | |
|
167 | 167 | try: |
|
168 | 168 | nb = current.reads(data.decode('utf-8'), format) |
|
169 | 169 | except: |
|
170 | 170 | raise web.HTTPError(400, u'Invalid JSON data') |
|
171 | 171 | |
|
172 | 172 | if name is None: |
|
173 | 173 | try: |
|
174 | 174 | name = nb.metadata.name |
|
175 | 175 | except AttributeError: |
|
176 | 176 | raise web.HTTPError(400, u'Missing notebook name') |
|
177 | 177 | nb.metadata.name = name |
|
178 | 178 | |
|
179 | 179 | notebook_id = self.new_notebook_id(name) |
|
180 | 180 | self.save_notebook_object(notebook_id, nb) |
|
181 | 181 | return notebook_id |
|
182 | 182 | |
|
183 | 183 | def save_notebook(self, notebook_id, data, name=None, format=u'json'): |
|
184 | 184 | """Save an existing notebook by notebook_id.""" |
|
185 | 185 | if format not in self.allowed_formats: |
|
186 | 186 | raise web.HTTPError(415, u'Invalid notebook format: %s' % format) |
|
187 | 187 | |
|
188 | 188 | try: |
|
189 | 189 | nb = current.reads(data.decode('utf-8'), format) |
|
190 | 190 | except: |
|
191 | 191 | raise web.HTTPError(400, u'Invalid JSON data') |
|
192 | 192 | |
|
193 | 193 | if name is not None: |
|
194 | 194 | nb.metadata.name = name |
|
195 | 195 | self.save_notebook_object(notebook_id, nb) |
|
196 | 196 | |
|
197 | 197 | def save_notebook_object(self, notebook_id, nb): |
|
198 | 198 | """Save an existing notebook object by notebook_id.""" |
|
199 | 199 | if notebook_id not in self.mapping: |
|
200 | 200 | raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id) |
|
201 | 201 | old_name = self.mapping[notebook_id] |
|
202 | 202 | try: |
|
203 | 203 | new_name = nb.metadata.name |
|
204 | 204 | except AttributeError: |
|
205 | 205 | raise web.HTTPError(400, u'Missing notebook name') |
|
206 | 206 | path = self.get_path_by_name(new_name) |
|
207 | 207 | try: |
|
208 | 208 | with open(path,'w') as f: |
|
209 | 209 | current.write(nb, f, u'json') |
|
210 | 210 | except Exception as e: |
|
211 | 211 | raise web.HTTPError(400, u'Unexpected error while saving notebook: %s' % e) |
|
212 | 212 | # save .py script as well |
|
213 | 213 | if self.save_script: |
|
214 | 214 | pypath = os.path.splitext(path)[0] + '.py' |
|
215 | 215 | try: |
|
216 | 216 | with io.open(pypath,'w', encoding='utf-8') as f: |
|
217 | 217 | current.write(nb, f, u'py') |
|
218 | 218 | except Exception as e: |
|
219 | 219 | raise web.HTTPError(400, u'Unexpected error while saving notebook as script: %s' % e) |
|
220 | 220 | |
|
221 | 221 | if old_name != new_name: |
|
222 | 222 | old_path = self.get_path_by_name(old_name) |
|
223 | 223 | if os.path.isfile(old_path): |
|
224 | 224 | os.unlink(old_path) |
|
225 | 225 | if self.save_script: |
|
226 | 226 | old_pypath = os.path.splitext(old_path)[0] + '.py' |
|
227 | 227 | if os.path.isfile(old_pypath): |
|
228 | 228 | os.unlink(old_pypath) |
|
229 | 229 | self.mapping[notebook_id] = new_name |
|
230 | 230 | self.rev_mapping[new_name] = notebook_id |
|
231 | 231 | |
|
232 | 232 | def delete_notebook(self, notebook_id): |
|
233 | 233 | """Delete notebook by notebook_id.""" |
|
234 | 234 | path = self.find_path(notebook_id) |
|
235 | 235 | if not os.path.isfile(path): |
|
236 | 236 | raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id) |
|
237 | 237 | os.unlink(path) |
|
238 | 238 | self.delete_notebook_id(notebook_id) |
|
239 | 239 | |
|
240 | 240 | def increment_filename(self, basename): |
|
241 | 241 | """Return a non-used filename of the form basename<int>. |
|
242 | 242 | |
|
243 | 243 | This searches through the filenames (basename0, basename1, ...) |
|
244 | 244 | until is find one that is not already being used. It is used to |
|
245 | 245 | create Untitled and Copy names that are unique. |
|
246 | 246 | """ |
|
247 | 247 | i = 0 |
|
248 | 248 | while True: |
|
249 | 249 | name = u'%s%i' % (basename,i) |
|
250 | 250 | path = self.get_path_by_name(name) |
|
251 | 251 | if not os.path.isfile(path): |
|
252 | 252 | break |
|
253 | 253 | else: |
|
254 | 254 | i = i+1 |
|
255 | 255 | return path, name |
|
256 | 256 | |
|
257 | 257 | def new_notebook(self): |
|
258 | 258 | """Create a new notebook and return its notebook_id.""" |
|
259 | 259 | path, name = self.increment_filename('Untitled') |
|
260 | 260 | notebook_id = self.new_notebook_id(name) |
|
261 | 261 | metadata = current.new_metadata(name=name) |
|
262 | 262 | nb = current.new_notebook(metadata=metadata) |
|
263 | 263 | with open(path,'w') as f: |
|
264 | 264 | current.write(nb, f, u'json') |
|
265 | 265 | return notebook_id |
|
266 | 266 | |
|
267 | 267 | def copy_notebook(self, notebook_id): |
|
268 | 268 | """Copy an existing notebook and return its notebook_id.""" |
|
269 | 269 | last_mod, nb = self.get_notebook_object(notebook_id) |
|
270 | 270 | name = nb.metadata.name + '-Copy' |
|
271 | 271 | path, name = self.increment_filename(name) |
|
272 | 272 | nb.metadata.name = name |
|
273 | 273 | notebook_id = self.new_notebook_id(name) |
|
274 | 274 | self.save_notebook_object(notebook_id, nb) |
|
275 | 275 | return notebook_id |
@@ -1,910 +1,910 b'' | |||
|
1 | 1 | """The Qt MainWindow for the QtConsole |
|
2 | 2 | |
|
3 | 3 | This is a tabbed pseudo-terminal of IPython sessions, with a menu bar for |
|
4 | 4 | common actions. |
|
5 | 5 | |
|
6 | 6 | Authors: |
|
7 | 7 | |
|
8 | 8 | * Evan Patterson |
|
9 | 9 | * Min RK |
|
10 | 10 | * Erik Tollerud |
|
11 | 11 | * Fernando Perez |
|
12 | 12 | * Bussonnier Matthias |
|
13 | 13 | * Thomas Kluyver |
|
14 | 14 | |
|
15 | 15 | """ |
|
16 | 16 | |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | # Imports |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | |
|
21 | 21 | # stdlib imports |
|
22 | 22 | import sys |
|
23 | 23 | import re |
|
24 | 24 | import webbrowser |
|
25 | 25 | from threading import Thread |
|
26 | 26 | |
|
27 | 27 | # System library imports |
|
28 | 28 | from IPython.external.qt import QtGui,QtCore |
|
29 | 29 | |
|
30 | 30 | def background(f): |
|
31 | 31 | """call a function in a simple thread, to prevent blocking""" |
|
32 | 32 | t = Thread(target=f) |
|
33 | 33 | t.start() |
|
34 | 34 | return t |
|
35 | 35 | |
|
36 | 36 | #----------------------------------------------------------------------------- |
|
37 | 37 | # Classes |
|
38 | 38 | #----------------------------------------------------------------------------- |
|
39 | 39 | |
|
40 | 40 | class MainWindow(QtGui.QMainWindow): |
|
41 | 41 | |
|
42 | 42 | #--------------------------------------------------------------------------- |
|
43 | 43 | # 'object' interface |
|
44 | 44 | #--------------------------------------------------------------------------- |
|
45 | 45 | |
|
46 | 46 | def __init__(self, app, |
|
47 | 47 | confirm_exit=True, |
|
48 | 48 | new_frontend_factory=None, slave_frontend_factory=None, |
|
49 | 49 | ): |
|
50 | 50 | """ Create a tabbed MainWindow for managing IPython FrontendWidgets |
|
51 | 51 | |
|
52 | 52 | Parameters |
|
53 | 53 | ---------- |
|
54 | 54 | |
|
55 | 55 | app : reference to QApplication parent |
|
56 | 56 | confirm_exit : bool, optional |
|
57 | 57 | Whether we should prompt on close of tabs |
|
58 | 58 | new_frontend_factory : callable |
|
59 | 59 | A callable that returns a new IPythonWidget instance, attached to |
|
60 | 60 | its own running kernel. |
|
61 | 61 | slave_frontend_factory : callable |
|
62 | 62 | A callable that takes an existing IPythonWidget, and returns a new |
|
63 | 63 | IPythonWidget instance, attached to the same kernel. |
|
64 | 64 | """ |
|
65 | 65 | |
|
66 | 66 | super(MainWindow, self).__init__() |
|
67 | 67 | self._kernel_counter = 0 |
|
68 | 68 | self._app = app |
|
69 | 69 | self.confirm_exit = confirm_exit |
|
70 | 70 | self.new_frontend_factory = new_frontend_factory |
|
71 | 71 | self.slave_frontend_factory = slave_frontend_factory |
|
72 | 72 | |
|
73 | 73 | self.tab_widget = QtGui.QTabWidget(self) |
|
74 | 74 | self.tab_widget.setDocumentMode(True) |
|
75 | 75 | self.tab_widget.setTabsClosable(True) |
|
76 | 76 | self.tab_widget.tabCloseRequested[int].connect(self.close_tab) |
|
77 | 77 | |
|
78 | 78 | self.setCentralWidget(self.tab_widget) |
|
79 | 79 | # hide tab bar at first, since we have no tabs: |
|
80 | 80 | self.tab_widget.tabBar().setVisible(False) |
|
81 | 81 | # prevent focus in tab bar |
|
82 | 82 | self.tab_widget.setFocusPolicy(QtCore.Qt.NoFocus) |
|
83 | 83 | |
|
84 | 84 | def update_tab_bar_visibility(self): |
|
85 | 85 | """ update visibility of the tabBar depending of the number of tab |
|
86 | 86 | |
|
87 | 87 | 0 or 1 tab, tabBar hidden |
|
88 | 88 | 2+ tabs, tabBar visible |
|
89 | 89 | |
|
90 | 90 | send a self.close if number of tab ==0 |
|
91 | 91 | |
|
92 | 92 | need to be called explicitely, or be connected to tabInserted/tabRemoved |
|
93 | 93 | """ |
|
94 | 94 | if self.tab_widget.count() <= 1: |
|
95 | 95 | self.tab_widget.tabBar().setVisible(False) |
|
96 | 96 | else: |
|
97 | 97 | self.tab_widget.tabBar().setVisible(True) |
|
98 | 98 | if self.tab_widget.count()==0 : |
|
99 | 99 | self.close() |
|
100 | 100 | |
|
101 | 101 | @property |
|
102 | 102 | def next_kernel_id(self): |
|
103 | 103 | """constantly increasing counter for kernel IDs""" |
|
104 | 104 | c = self._kernel_counter |
|
105 | 105 | self._kernel_counter += 1 |
|
106 | 106 | return c |
|
107 | 107 | |
|
108 | 108 | @property |
|
109 | 109 | def active_frontend(self): |
|
110 | 110 | return self.tab_widget.currentWidget() |
|
111 | 111 | |
|
112 | 112 | def create_tab_with_new_frontend(self): |
|
113 | 113 | """create a new frontend and attach it to a new tab""" |
|
114 | 114 | widget = self.new_frontend_factory() |
|
115 | 115 | self.add_tab_with_frontend(widget) |
|
116 | 116 | |
|
117 | 117 | def create_tab_with_current_kernel(self): |
|
118 | 118 | """create a new frontend attached to the same kernel as the current tab""" |
|
119 | 119 | current_widget = self.tab_widget.currentWidget() |
|
120 | 120 | current_widget_index = self.tab_widget.indexOf(current_widget) |
|
121 | 121 | current_widget_name = self.tab_widget.tabText(current_widget_index) |
|
122 | 122 | widget = self.slave_frontend_factory(current_widget) |
|
123 | 123 | if 'slave' in current_widget_name: |
|
124 | 124 | # don't keep stacking slaves |
|
125 | 125 | name = current_widget_name |
|
126 | 126 | else: |
|
127 | 127 | name = '(%s) slave' % current_widget_name |
|
128 | 128 | self.add_tab_with_frontend(widget,name=name) |
|
129 | 129 | |
|
130 | 130 | def close_tab(self,current_tab): |
|
131 | 131 | """ Called when you need to try to close a tab. |
|
132 | 132 | |
|
133 | 133 | It takes the number of the tab to be closed as argument, or a referece |
|
134 | 134 | to the wiget insite this tab |
|
135 | 135 | """ |
|
136 | 136 | |
|
137 | 137 | # let's be sure "tab" and "closing widget are respectivey the index of the tab to close |
|
138 | 138 | # and a reference to the trontend to close |
|
139 | 139 | if type(current_tab) is not int : |
|
140 | 140 | current_tab = self.tab_widget.indexOf(current_tab) |
|
141 | 141 | closing_widget=self.tab_widget.widget(current_tab) |
|
142 | 142 | |
|
143 | 143 | |
|
144 | 144 | # when trying to be closed, widget might re-send a request to be closed again, but will |
|
145 | 145 | # be deleted when event will be processed. So need to check that widget still exist and |
|
146 | 146 | # skip if not. One example of this is when 'exit' is send in a slave tab. 'exit' will be |
|
147 | 147 | # re-send by this fonction on the master widget, which ask all slaves widget to exit |
|
148 | 148 | if closing_widget==None: |
|
149 | 149 | return |
|
150 | 150 | |
|
151 | 151 | #get a list of all slave widgets on the same kernel. |
|
152 | 152 | slave_tabs = self.find_slave_widgets(closing_widget) |
|
153 | 153 | |
|
154 | 154 | keepkernel = None #Use the prompt by default |
|
155 | 155 | if hasattr(closing_widget,'_keep_kernel_on_exit'): #set by exit magic |
|
156 | 156 | keepkernel = closing_widget._keep_kernel_on_exit |
|
157 | 157 | # If signal sent by exit magic (_keep_kernel_on_exit, exist and not None) |
|
158 | 158 | # we set local slave tabs._hidden to True to avoid prompting for kernel |
|
159 | 159 | # restart when they get the signal. and then "forward" the 'exit' |
|
160 | 160 | # to the main window |
|
161 | 161 | if keepkernel is not None: |
|
162 | 162 | for tab in slave_tabs: |
|
163 | 163 | tab._hidden = True |
|
164 | 164 | if closing_widget in slave_tabs: |
|
165 | 165 | try : |
|
166 | 166 | self.find_master_tab(closing_widget).execute('exit') |
|
167 | 167 | except AttributeError: |
|
168 | 168 | self.log.info("Master already closed or not local, closing only current tab") |
|
169 | 169 | self.tab_widget.removeTab(current_tab) |
|
170 | 170 | self.update_tab_bar_visibility() |
|
171 | 171 | return |
|
172 | 172 | |
|
173 | 173 | kernel_manager = closing_widget.kernel_manager |
|
174 | 174 | |
|
175 | 175 | if keepkernel is None and not closing_widget._confirm_exit: |
|
176 | 176 | # don't prompt, just terminate the kernel if we own it |
|
177 | 177 | # or leave it alone if we don't |
|
178 | 178 | keepkernel = closing_widget._existing |
|
179 | 179 | if keepkernel is None: #show prompt |
|
180 | 180 | if kernel_manager and kernel_manager.channels_running: |
|
181 | 181 | title = self.window().windowTitle() |
|
182 | 182 | cancel = QtGui.QMessageBox.Cancel |
|
183 | 183 | okay = QtGui.QMessageBox.Ok |
|
184 | 184 | if closing_widget._may_close: |
|
185 | 185 | msg = "You are closing the tab : "+'"'+self.tab_widget.tabText(current_tab)+'"' |
|
186 | 186 | info = "Would you like to quit the Kernel and close all attached Consoles as well?" |
|
187 | 187 | justthis = QtGui.QPushButton("&No, just this Tab", self) |
|
188 | 188 | justthis.setShortcut('N') |
|
189 | 189 | closeall = QtGui.QPushButton("&Yes, close all", self) |
|
190 | 190 | closeall.setShortcut('Y') |
|
191 | 191 | # allow ctrl-d ctrl-d exit, like in terminal |
|
192 | 192 | closeall.setShortcut('Ctrl+D') |
|
193 | 193 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, |
|
194 | 194 | title, msg) |
|
195 | 195 | box.setInformativeText(info) |
|
196 | 196 | box.addButton(cancel) |
|
197 | 197 | box.addButton(justthis, QtGui.QMessageBox.NoRole) |
|
198 | 198 | box.addButton(closeall, QtGui.QMessageBox.YesRole) |
|
199 | 199 | box.setDefaultButton(closeall) |
|
200 | 200 | box.setEscapeButton(cancel) |
|
201 | 201 | pixmap = QtGui.QPixmap(self._app.icon.pixmap(QtCore.QSize(64,64))) |
|
202 | 202 | box.setIconPixmap(pixmap) |
|
203 | 203 | reply = box.exec_() |
|
204 | 204 | if reply == 1: # close All |
|
205 | 205 | for slave in slave_tabs: |
|
206 | 206 | background(slave.kernel_manager.stop_channels) |
|
207 | 207 | self.tab_widget.removeTab(self.tab_widget.indexOf(slave)) |
|
208 | 208 | closing_widget.execute("exit") |
|
209 | 209 | self.tab_widget.removeTab(current_tab) |
|
210 | 210 | background(kernel_manager.stop_channels) |
|
211 | 211 | elif reply == 0: # close Console |
|
212 | 212 | if not closing_widget._existing: |
|
213 | 213 | # Have kernel: don't quit, just close the tab |
|
214 | 214 | closing_widget.execute("exit True") |
|
215 | 215 | self.tab_widget.removeTab(current_tab) |
|
216 | 216 | background(kernel_manager.stop_channels) |
|
217 | 217 | else: |
|
218 | 218 | reply = QtGui.QMessageBox.question(self, title, |
|
219 | 219 | "Are you sure you want to close this Console?"+ |
|
220 | 220 | "\nThe Kernel and other Consoles will remain active.", |
|
221 | 221 | okay|cancel, |
|
222 | 222 | defaultButton=okay |
|
223 | 223 | ) |
|
224 | 224 | if reply == okay: |
|
225 | 225 | self.tab_widget.removeTab(current_tab) |
|
226 | 226 | elif keepkernel: #close console but leave kernel running (no prompt) |
|
227 | 227 | self.tab_widget.removeTab(current_tab) |
|
228 | 228 | background(kernel_manager.stop_channels) |
|
229 | 229 | else: #close console and kernel (no prompt) |
|
230 | 230 | self.tab_widget.removeTab(current_tab) |
|
231 | 231 | if kernel_manager and kernel_manager.channels_running: |
|
232 | 232 | for slave in slave_tabs: |
|
233 | 233 | background(slave.kernel_manager.stop_channels) |
|
234 | 234 | self.tab_widget.removeTab(self.tab_widget.indexOf(slave)) |
|
235 | 235 | kernel_manager.shutdown_kernel() |
|
236 | 236 | background(kernel_manager.stop_channels) |
|
237 | 237 | |
|
238 | 238 | self.update_tab_bar_visibility() |
|
239 | 239 | |
|
240 | 240 | def add_tab_with_frontend(self,frontend,name=None): |
|
241 | 241 | """ insert a tab with a given frontend in the tab bar, and give it a name |
|
242 | 242 | |
|
243 | 243 | """ |
|
244 | 244 | if not name: |
|
245 | 245 | name = 'kernel %i' % self.next_kernel_id |
|
246 | 246 | self.tab_widget.addTab(frontend,name) |
|
247 | 247 | self.update_tab_bar_visibility() |
|
248 | 248 | self.make_frontend_visible(frontend) |
|
249 | 249 | frontend.exit_requested.connect(self.close_tab) |
|
250 | 250 | |
|
251 | 251 | def next_tab(self): |
|
252 | 252 | self.tab_widget.setCurrentIndex((self.tab_widget.currentIndex()+1)) |
|
253 | 253 | |
|
254 | 254 | def prev_tab(self): |
|
255 | 255 | self.tab_widget.setCurrentIndex((self.tab_widget.currentIndex()-1)) |
|
256 | 256 | |
|
257 | 257 | def make_frontend_visible(self,frontend): |
|
258 | 258 | widget_index=self.tab_widget.indexOf(frontend) |
|
259 | 259 | if widget_index > 0 : |
|
260 | 260 | self.tab_widget.setCurrentIndex(widget_index) |
|
261 | 261 | |
|
262 | 262 | def find_master_tab(self,tab,as_list=False): |
|
263 | 263 | """ |
|
264 | 264 | Try to return the frontend that own the kernel attached to the given widget/tab. |
|
265 | 265 | |
|
266 | 266 | Only find frontend owed by the current application. Selection |
|
267 | 267 | based on port of the kernel, might be inacurate if several kernel |
|
268 | 268 | on different ip use same port number. |
|
269 | 269 | |
|
270 | 270 | This fonction does the conversion tabNumber/widget if needed. |
|
271 | 271 | Might return None if no master widget (non local kernel) |
|
272 | 272 | Will crash IPython if more than 1 masterWidget |
|
273 | 273 | |
|
274 | 274 | When asList set to True, always return a list of widget(s) owning |
|
275 | 275 | the kernel. The list might be empty or containing several Widget. |
|
276 | 276 | """ |
|
277 | 277 | |
|
278 | 278 | #convert from/to int/richIpythonWidget if needed |
|
279 | 279 | if isinstance(tab, int): |
|
280 | 280 | tab = self.tab_widget.widget(tab) |
|
281 | 281 | km=tab.kernel_manager |
|
282 | 282 | |
|
283 | 283 | #build list of all widgets |
|
284 | 284 | widget_list = [self.tab_widget.widget(i) for i in range(self.tab_widget.count())] |
|
285 | 285 | |
|
286 | 286 | # widget that are candidate to be the owner of the kernel does have all the same port of the curent widget |
|
287 | 287 | # And should have a _may_close attribute |
|
288 | 288 | filtered_widget_list = [ widget for widget in widget_list if |
|
289 | 289 | widget.kernel_manager.connection_file == km.connection_file and |
|
290 | 290 | hasattr(widget,'_may_close') ] |
|
291 | 291 | # the master widget is the one that may close the kernel |
|
292 | 292 | master_widget= [ widget for widget in filtered_widget_list if widget._may_close] |
|
293 | 293 | if as_list: |
|
294 | 294 | return master_widget |
|
295 | 295 | assert(len(master_widget)<=1 ) |
|
296 | 296 | if len(master_widget)==0: |
|
297 | 297 | return None |
|
298 | 298 | |
|
299 | 299 | return master_widget[0] |
|
300 | 300 | |
|
301 | 301 | def find_slave_widgets(self,tab): |
|
302 | 302 | """return all the frontends that do not own the kernel attached to the given widget/tab. |
|
303 | 303 | |
|
304 | 304 | Only find frontends owned by the current application. Selection |
|
305 | 305 | based on connection file of the kernel. |
|
306 | 306 | |
|
307 | 307 | This function does the conversion tabNumber/widget if needed. |
|
308 | 308 | """ |
|
309 | 309 | #convert from/to int/richIpythonWidget if needed |
|
310 | 310 | if isinstance(tab, int): |
|
311 | 311 | tab = self.tab_widget.widget(tab) |
|
312 | 312 | km=tab.kernel_manager |
|
313 | 313 | |
|
314 | 314 | #build list of all widgets |
|
315 | 315 | widget_list = [self.tab_widget.widget(i) for i in range(self.tab_widget.count())] |
|
316 | 316 | |
|
317 | 317 | # widget that are candidate not to be the owner of the kernel does have all the same port of the curent widget |
|
318 | 318 | filtered_widget_list = ( widget for widget in widget_list if |
|
319 | 319 | widget.kernel_manager.connection_file == km.connection_file) |
|
320 | 320 | # Get a list of all widget owning the same kernel and removed it from |
|
321 | 321 | # the previous cadidate. (better using sets ?) |
|
322 | 322 | master_widget_list = self.find_master_tab(tab, as_list=True) |
|
323 | 323 | slave_list = [widget for widget in filtered_widget_list if widget not in master_widget_list] |
|
324 | 324 | |
|
325 | 325 | return slave_list |
|
326 | 326 | |
|
327 | 327 | # Populate the menu bar with common actions and shortcuts |
|
328 | 328 | def add_menu_action(self, menu, action, defer_shortcut=False): |
|
329 | 329 | """Add action to menu as well as self |
|
330 | 330 | |
|
331 | 331 | So that when the menu bar is invisible, its actions are still available. |
|
332 | 332 | |
|
333 | 333 | If defer_shortcut is True, set the shortcut context to widget-only, |
|
334 | 334 | where it will avoid conflict with shortcuts already bound to the |
|
335 | 335 | widgets themselves. |
|
336 | 336 | """ |
|
337 | 337 | menu.addAction(action) |
|
338 | 338 | self.addAction(action) |
|
339 | 339 | |
|
340 | 340 | if defer_shortcut: |
|
341 | 341 | action.setShortcutContext(QtCore.Qt.WidgetShortcut) |
|
342 | 342 | |
|
343 | 343 | def init_menu_bar(self): |
|
344 | 344 | #create menu in the order they should appear in the menu bar |
|
345 | 345 | self.init_file_menu() |
|
346 | 346 | self.init_edit_menu() |
|
347 | 347 | self.init_view_menu() |
|
348 | 348 | self.init_kernel_menu() |
|
349 | 349 | self.init_magic_menu() |
|
350 | 350 | self.init_window_menu() |
|
351 | 351 | self.init_help_menu() |
|
352 | 352 | |
|
353 | 353 | def init_file_menu(self): |
|
354 | 354 | self.file_menu = self.menuBar().addMenu("&File") |
|
355 | 355 | |
|
356 | 356 | self.new_kernel_tab_act = QtGui.QAction("New Tab with &New kernel", |
|
357 | 357 | self, |
|
358 | 358 | shortcut="Ctrl+T", |
|
359 | 359 | triggered=self.create_tab_with_new_frontend) |
|
360 | 360 | self.add_menu_action(self.file_menu, self.new_kernel_tab_act) |
|
361 | 361 | |
|
362 | 362 | self.slave_kernel_tab_act = QtGui.QAction("New Tab with Sa&me kernel", |
|
363 | 363 | self, |
|
364 | 364 | shortcut="Ctrl+Shift+T", |
|
365 | 365 | triggered=self.create_tab_with_current_kernel) |
|
366 | 366 | self.add_menu_action(self.file_menu, self.slave_kernel_tab_act) |
|
367 | 367 | |
|
368 | 368 | self.file_menu.addSeparator() |
|
369 | 369 | |
|
370 | 370 | self.close_action=QtGui.QAction("&Close Tab", |
|
371 | 371 | self, |
|
372 | 372 | shortcut=QtGui.QKeySequence.Close, |
|
373 | 373 | triggered=self.close_active_frontend |
|
374 | 374 | ) |
|
375 | 375 | self.add_menu_action(self.file_menu, self.close_action) |
|
376 | 376 | |
|
377 | 377 | self.export_action=QtGui.QAction("&Save to HTML/XHTML", |
|
378 | 378 | self, |
|
379 | 379 | shortcut=QtGui.QKeySequence.Save, |
|
380 | 380 | triggered=self.export_action_active_frontend |
|
381 | 381 | ) |
|
382 | 382 | self.add_menu_action(self.file_menu, self.export_action, True) |
|
383 | 383 | |
|
384 | 384 | self.file_menu.addSeparator() |
|
385 | 385 | |
|
386 | 386 | printkey = QtGui.QKeySequence(QtGui.QKeySequence.Print) |
|
387 | 387 | if printkey.matches("Ctrl+P") and sys.platform != 'darwin': |
|
388 | 388 | # Only override the default if there is a collision. |
|
389 | 389 | # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. |
|
390 | 390 | printkey = "Ctrl+Shift+P" |
|
391 | 391 | self.print_action = QtGui.QAction("&Print", |
|
392 | 392 | self, |
|
393 | 393 | shortcut=printkey, |
|
394 | 394 | triggered=self.print_action_active_frontend) |
|
395 | 395 | self.add_menu_action(self.file_menu, self.print_action, True) |
|
396 | 396 | |
|
397 | 397 | if sys.platform != 'darwin': |
|
398 | 398 | # OSX always has Quit in the Application menu, only add it |
|
399 | 399 | # to the File menu elsewhere. |
|
400 | 400 | |
|
401 | 401 | self.file_menu.addSeparator() |
|
402 | 402 | |
|
403 | 403 | self.quit_action = QtGui.QAction("&Quit", |
|
404 | 404 | self, |
|
405 | 405 | shortcut=QtGui.QKeySequence.Quit, |
|
406 | 406 | triggered=self.close, |
|
407 | 407 | ) |
|
408 | 408 | self.add_menu_action(self.file_menu, self.quit_action) |
|
409 | 409 | |
|
410 | 410 | |
|
411 | 411 | def init_edit_menu(self): |
|
412 | 412 | self.edit_menu = self.menuBar().addMenu("&Edit") |
|
413 | 413 | |
|
414 | 414 | self.undo_action = QtGui.QAction("&Undo", |
|
415 | 415 | self, |
|
416 | 416 | shortcut=QtGui.QKeySequence.Undo, |
|
417 | 417 | statusTip="Undo last action if possible", |
|
418 | 418 | triggered=self.undo_active_frontend |
|
419 | 419 | ) |
|
420 | 420 | self.add_menu_action(self.edit_menu, self.undo_action) |
|
421 | 421 | |
|
422 | 422 | self.redo_action = QtGui.QAction("&Redo", |
|
423 | 423 | self, |
|
424 | 424 | shortcut=QtGui.QKeySequence.Redo, |
|
425 | 425 | statusTip="Redo last action if possible", |
|
426 | 426 | triggered=self.redo_active_frontend) |
|
427 | 427 | self.add_menu_action(self.edit_menu, self.redo_action) |
|
428 | 428 | |
|
429 | 429 | self.edit_menu.addSeparator() |
|
430 | 430 | |
|
431 | 431 | self.cut_action = QtGui.QAction("&Cut", |
|
432 | 432 | self, |
|
433 | 433 | shortcut=QtGui.QKeySequence.Cut, |
|
434 | 434 | triggered=self.cut_active_frontend |
|
435 | 435 | ) |
|
436 | 436 | self.add_menu_action(self.edit_menu, self.cut_action, True) |
|
437 | 437 | |
|
438 | 438 | self.copy_action = QtGui.QAction("&Copy", |
|
439 | 439 | self, |
|
440 | 440 | shortcut=QtGui.QKeySequence.Copy, |
|
441 | 441 | triggered=self.copy_active_frontend |
|
442 | 442 | ) |
|
443 | 443 | self.add_menu_action(self.edit_menu, self.copy_action, True) |
|
444 | 444 | |
|
445 | 445 | self.copy_raw_action = QtGui.QAction("Copy (&Raw Text)", |
|
446 | 446 | self, |
|
447 | 447 | shortcut="Ctrl+Shift+C", |
|
448 | 448 | triggered=self.copy_raw_active_frontend |
|
449 | 449 | ) |
|
450 | 450 | self.add_menu_action(self.edit_menu, self.copy_raw_action, True) |
|
451 | 451 | |
|
452 | 452 | self.paste_action = QtGui.QAction("&Paste", |
|
453 | 453 | self, |
|
454 | 454 | shortcut=QtGui.QKeySequence.Paste, |
|
455 | 455 | triggered=self.paste_active_frontend |
|
456 | 456 | ) |
|
457 | 457 | self.add_menu_action(self.edit_menu, self.paste_action, True) |
|
458 | 458 | |
|
459 | 459 | self.edit_menu.addSeparator() |
|
460 | 460 | |
|
461 | 461 | selectall = QtGui.QKeySequence(QtGui.QKeySequence.SelectAll) |
|
462 | 462 | if selectall.matches("Ctrl+A") and sys.platform != 'darwin': |
|
463 | 463 | # Only override the default if there is a collision. |
|
464 | 464 | # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. |
|
465 | 465 | selectall = "Ctrl+Shift+A" |
|
466 | 466 | self.select_all_action = QtGui.QAction("Select &All", |
|
467 | 467 | self, |
|
468 | 468 | shortcut=selectall, |
|
469 | 469 | triggered=self.select_all_active_frontend |
|
470 | 470 | ) |
|
471 | 471 | self.add_menu_action(self.edit_menu, self.select_all_action, True) |
|
472 | 472 | |
|
473 | 473 | |
|
474 | 474 | def init_view_menu(self): |
|
475 | 475 | self.view_menu = self.menuBar().addMenu("&View") |
|
476 | 476 | |
|
477 | 477 | if sys.platform != 'darwin': |
|
478 | 478 | # disable on OSX, where there is always a menu bar |
|
479 | 479 | self.toggle_menu_bar_act = QtGui.QAction("Toggle &Menu Bar", |
|
480 | 480 | self, |
|
481 | 481 | shortcut="Ctrl+Shift+M", |
|
482 | 482 | statusTip="Toggle visibility of menubar", |
|
483 | 483 | triggered=self.toggle_menu_bar) |
|
484 | 484 | self.add_menu_action(self.view_menu, self.toggle_menu_bar_act) |
|
485 | 485 | |
|
486 | 486 | fs_key = "Ctrl+Meta+F" if sys.platform == 'darwin' else "F11" |
|
487 | 487 | self.full_screen_act = QtGui.QAction("&Full Screen", |
|
488 | 488 | self, |
|
489 | 489 | shortcut=fs_key, |
|
490 | 490 | statusTip="Toggle between Fullscreen and Normal Size", |
|
491 | 491 | triggered=self.toggleFullScreen) |
|
492 | 492 | self.add_menu_action(self.view_menu, self.full_screen_act) |
|
493 | 493 | |
|
494 | 494 | self.view_menu.addSeparator() |
|
495 | 495 | |
|
496 | 496 | self.increase_font_size = QtGui.QAction("Zoom &In", |
|
497 | 497 | self, |
|
498 | 498 | shortcut=QtGui.QKeySequence.ZoomIn, |
|
499 | 499 | triggered=self.increase_font_size_active_frontend |
|
500 | 500 | ) |
|
501 | 501 | self.add_menu_action(self.view_menu, self.increase_font_size, True) |
|
502 | 502 | |
|
503 | 503 | self.decrease_font_size = QtGui.QAction("Zoom &Out", |
|
504 | 504 | self, |
|
505 | 505 | shortcut=QtGui.QKeySequence.ZoomOut, |
|
506 | 506 | triggered=self.decrease_font_size_active_frontend |
|
507 | 507 | ) |
|
508 | 508 | self.add_menu_action(self.view_menu, self.decrease_font_size, True) |
|
509 | 509 | |
|
510 | 510 | self.reset_font_size = QtGui.QAction("Zoom &Reset", |
|
511 | 511 | self, |
|
512 | 512 | shortcut="Ctrl+0", |
|
513 | 513 | triggered=self.reset_font_size_active_frontend |
|
514 | 514 | ) |
|
515 | 515 | self.add_menu_action(self.view_menu, self.reset_font_size, True) |
|
516 | 516 | |
|
517 | 517 | self.view_menu.addSeparator() |
|
518 | 518 | |
|
519 | 519 | self.clear_action = QtGui.QAction("&Clear Screen", |
|
520 | 520 | self, |
|
521 | 521 | shortcut='Ctrl+L', |
|
522 | 522 | statusTip="Clear the console", |
|
523 | 523 | triggered=self.clear_magic_active_frontend) |
|
524 | 524 | self.add_menu_action(self.view_menu, self.clear_action) |
|
525 | 525 | |
|
526 | 526 | def init_kernel_menu(self): |
|
527 | 527 | self.kernel_menu = self.menuBar().addMenu("&Kernel") |
|
528 | 528 | # Qt on OSX maps Ctrl to Cmd, and Meta to Ctrl |
|
529 | 529 | # keep the signal shortcuts to ctrl, rather than |
|
530 | 530 | # platform-default like we do elsewhere. |
|
531 | 531 | |
|
532 | 532 | ctrl = "Meta" if sys.platform == 'darwin' else "Ctrl" |
|
533 | 533 | |
|
534 | 534 | self.interrupt_kernel_action = QtGui.QAction("Interrupt current Kernel", |
|
535 | 535 | self, |
|
536 | 536 | triggered=self.interrupt_kernel_active_frontend, |
|
537 | 537 | shortcut=ctrl+"+C", |
|
538 | 538 | ) |
|
539 | 539 | self.add_menu_action(self.kernel_menu, self.interrupt_kernel_action) |
|
540 | 540 | |
|
541 | 541 | self.restart_kernel_action = QtGui.QAction("Restart current Kernel", |
|
542 | 542 | self, |
|
543 | 543 | triggered=self.restart_kernel_active_frontend, |
|
544 | 544 | shortcut=ctrl+"+.", |
|
545 | 545 | ) |
|
546 | 546 | self.add_menu_action(self.kernel_menu, self.restart_kernel_action) |
|
547 | 547 | |
|
548 | 548 | self.kernel_menu.addSeparator() |
|
549 | 549 | |
|
550 | 550 | def _make_dynamic_magic(self,magic): |
|
551 | 551 | """Return a function `fun` that will execute `magic` on active frontend. |
|
552 | 552 | |
|
553 | 553 | Parameters |
|
554 | 554 | ---------- |
|
555 | 555 | magic : string |
|
556 | 556 | string that will be executed as is when the returned function is called |
|
557 | 557 | |
|
558 | 558 | Returns |
|
559 | 559 | ------- |
|
560 | 560 | fun : function |
|
561 | 561 | function with no parameters, when called will execute `magic` on the |
|
562 | 562 | current active frontend at call time |
|
563 | 563 | |
|
564 | 564 | See Also |
|
565 | 565 | -------- |
|
566 | 566 | populate_all_magic_menu : generate the "All Magics..." menu |
|
567 | 567 | |
|
568 | 568 | Notes |
|
569 | 569 | ----- |
|
570 | 570 | `fun` execute `magic` an active frontend at the moment it is triggerd, |
|
571 | 571 | not the active frontend at the moment it has been created. |
|
572 | 572 | |
|
573 | 573 | This function is mostly used to create the "All Magics..." Menu at run time. |
|
574 | 574 | """ |
|
575 | 575 | # need to level nested function to be sure to past magic |
|
576 | 576 | # on active frontend **at run time**. |
|
577 | 577 | def inner_dynamic_magic(): |
|
578 | 578 | self.active_frontend.execute(magic) |
|
579 | 579 | inner_dynamic_magic.__name__ = "dynamics_magic_s" |
|
580 | 580 | return inner_dynamic_magic |
|
581 | 581 | |
|
582 | 582 | def populate_all_magic_menu(self, listofmagic=None): |
|
583 | 583 | """Clean "All Magics..." menu and repopulate it with `listofmagic` |
|
584 | 584 | |
|
585 | 585 | Parameters |
|
586 | 586 | ---------- |
|
587 | 587 | listofmagic : string, |
|
588 | 588 | repr() of a list of strings, send back by the kernel |
|
589 | 589 | |
|
590 | 590 | Notes |
|
591 | 591 | ----- |
|
592 | 592 | `listofmagic`is a repr() of list because it is fed with the result of |
|
593 | 593 | a 'user_expression' |
|
594 | 594 | """ |
|
595 | 595 | alm_magic_menu = self.all_magic_menu |
|
596 | 596 | alm_magic_menu.clear() |
|
597 | 597 | |
|
598 | 598 | # list of protected magic that don't like to be called without argument |
|
599 | 599 | # append '?' to the end to print the docstring when called from the menu |
|
600 | protected_magic = set(["more","less","load_ext","pycat","loadpy","save"]) | |
|
600 | protected_magic = set(["more","less","load_ext","pycat","loadpy","load","save"]) | |
|
601 | 601 | magics=re.findall('\w+', listofmagic) |
|
602 | 602 | for magic in magics: |
|
603 | 603 | if magic in protected_magic: |
|
604 | 604 | pmagic = '%s%s%s'%('%',magic,'?') |
|
605 | 605 | else: |
|
606 | 606 | pmagic = '%s%s'%('%',magic) |
|
607 | 607 | xaction = QtGui.QAction(pmagic, |
|
608 | 608 | self, |
|
609 | 609 | triggered=self._make_dynamic_magic(pmagic) |
|
610 | 610 | ) |
|
611 | 611 | alm_magic_menu.addAction(xaction) |
|
612 | 612 | |
|
613 | 613 | def update_all_magic_menu(self): |
|
614 | 614 | """ Update the list on magic in the "All Magics..." Menu |
|
615 | 615 | |
|
616 | 616 | Request the kernel with the list of availlable magic and populate the |
|
617 | 617 | menu with the list received back |
|
618 | 618 | |
|
619 | 619 | """ |
|
620 | 620 | # first define a callback which will get the list of all magic and put it in the menu. |
|
621 | 621 | self.active_frontend._silent_exec_callback('get_ipython().lsmagic()', self.populate_all_magic_menu) |
|
622 | 622 | |
|
623 | 623 | def init_magic_menu(self): |
|
624 | 624 | self.magic_menu = self.menuBar().addMenu("&Magic") |
|
625 | 625 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") |
|
626 | 626 | |
|
627 | 627 | # This action should usually not appear as it will be cleared when menu |
|
628 | 628 | # is updated at first kernel response. Though, it is necessary when |
|
629 | 629 | # connecting through X-forwarding, as in this case, the menu is not |
|
630 | 630 | # auto updated, SO DO NOT DELETE. |
|
631 | 631 | self.pop = QtGui.QAction("&Update All Magic Menu ", |
|
632 | 632 | self, triggered=self.update_all_magic_menu) |
|
633 | 633 | self.add_menu_action(self.all_magic_menu, self.pop) |
|
634 | 634 | # we need to populate the 'Magic Menu' once the kernel has answer at |
|
635 | 635 | # least once let's do it immedialy, but it's assured to works |
|
636 | 636 | self.pop.trigger() |
|
637 | 637 | |
|
638 | 638 | self.reset_action = QtGui.QAction("&Reset", |
|
639 | 639 | self, |
|
640 | 640 | statusTip="Clear all varible from workspace", |
|
641 | 641 | triggered=self.reset_magic_active_frontend) |
|
642 | 642 | self.add_menu_action(self.magic_menu, self.reset_action) |
|
643 | 643 | |
|
644 | 644 | self.history_action = QtGui.QAction("&History", |
|
645 | 645 | self, |
|
646 | 646 | statusTip="show command history", |
|
647 | 647 | triggered=self.history_magic_active_frontend) |
|
648 | 648 | self.add_menu_action(self.magic_menu, self.history_action) |
|
649 | 649 | |
|
650 | 650 | self.save_action = QtGui.QAction("E&xport History ", |
|
651 | 651 | self, |
|
652 | 652 | statusTip="Export History as Python File", |
|
653 | 653 | triggered=self.save_magic_active_frontend) |
|
654 | 654 | self.add_menu_action(self.magic_menu, self.save_action) |
|
655 | 655 | |
|
656 | 656 | self.who_action = QtGui.QAction("&Who", |
|
657 | 657 | self, |
|
658 | 658 | statusTip="List interactive variable", |
|
659 | 659 | triggered=self.who_magic_active_frontend) |
|
660 | 660 | self.add_menu_action(self.magic_menu, self.who_action) |
|
661 | 661 | |
|
662 | 662 | self.who_ls_action = QtGui.QAction("Wh&o ls", |
|
663 | 663 | self, |
|
664 | 664 | statusTip="Return a list of interactive variable", |
|
665 | 665 | triggered=self.who_ls_magic_active_frontend) |
|
666 | 666 | self.add_menu_action(self.magic_menu, self.who_ls_action) |
|
667 | 667 | |
|
668 | 668 | self.whos_action = QtGui.QAction("Who&s", |
|
669 | 669 | self, |
|
670 | 670 | statusTip="List interactive variable with detail", |
|
671 | 671 | triggered=self.whos_magic_active_frontend) |
|
672 | 672 | self.add_menu_action(self.magic_menu, self.whos_action) |
|
673 | 673 | |
|
674 | 674 | def init_window_menu(self): |
|
675 | 675 | self.window_menu = self.menuBar().addMenu("&Window") |
|
676 | 676 | if sys.platform == 'darwin': |
|
677 | 677 | # add min/maximize actions to OSX, which lacks default bindings. |
|
678 | 678 | self.minimizeAct = QtGui.QAction("Mini&mize", |
|
679 | 679 | self, |
|
680 | 680 | shortcut="Ctrl+m", |
|
681 | 681 | statusTip="Minimize the window/Restore Normal Size", |
|
682 | 682 | triggered=self.toggleMinimized) |
|
683 | 683 | # maximize is called 'Zoom' on OSX for some reason |
|
684 | 684 | self.maximizeAct = QtGui.QAction("&Zoom", |
|
685 | 685 | self, |
|
686 | 686 | shortcut="Ctrl+Shift+M", |
|
687 | 687 | statusTip="Maximize the window/Restore Normal Size", |
|
688 | 688 | triggered=self.toggleMaximized) |
|
689 | 689 | |
|
690 | 690 | self.add_menu_action(self.window_menu, self.minimizeAct) |
|
691 | 691 | self.add_menu_action(self.window_menu, self.maximizeAct) |
|
692 | 692 | self.window_menu.addSeparator() |
|
693 | 693 | |
|
694 | 694 | prev_key = "Ctrl+Shift+Left" if sys.platform == 'darwin' else "Ctrl+PgUp" |
|
695 | 695 | self.prev_tab_act = QtGui.QAction("Pre&vious Tab", |
|
696 | 696 | self, |
|
697 | 697 | shortcut=prev_key, |
|
698 | 698 | statusTip="Select previous tab", |
|
699 | 699 | triggered=self.prev_tab) |
|
700 | 700 | self.add_menu_action(self.window_menu, self.prev_tab_act) |
|
701 | 701 | |
|
702 | 702 | next_key = "Ctrl+Shift+Right" if sys.platform == 'darwin' else "Ctrl+PgDown" |
|
703 | 703 | self.next_tab_act = QtGui.QAction("Ne&xt Tab", |
|
704 | 704 | self, |
|
705 | 705 | shortcut=next_key, |
|
706 | 706 | statusTip="Select next tab", |
|
707 | 707 | triggered=self.next_tab) |
|
708 | 708 | self.add_menu_action(self.window_menu, self.next_tab_act) |
|
709 | 709 | |
|
710 | 710 | def init_help_menu(self): |
|
711 | 711 | # please keep the Help menu in Mac Os even if empty. It will |
|
712 | 712 | # automatically contain a search field to search inside menus and |
|
713 | 713 | # please keep it spelled in English, as long as Qt Doesn't support |
|
714 | 714 | # a QAction.MenuRole like HelpMenuRole otherwise it will loose |
|
715 | 715 | # this search field fonctionality |
|
716 | 716 | |
|
717 | 717 | self.help_menu = self.menuBar().addMenu("&Help") |
|
718 | 718 | |
|
719 | 719 | |
|
720 | 720 | # Help Menu |
|
721 | 721 | |
|
722 | 722 | self.intro_active_frontend_action = QtGui.QAction("&Intro to IPython", |
|
723 | 723 | self, |
|
724 | 724 | triggered=self.intro_active_frontend |
|
725 | 725 | ) |
|
726 | 726 | self.add_menu_action(self.help_menu, self.intro_active_frontend_action) |
|
727 | 727 | |
|
728 | 728 | self.quickref_active_frontend_action = QtGui.QAction("IPython &Cheat Sheet", |
|
729 | 729 | self, |
|
730 | 730 | triggered=self.quickref_active_frontend |
|
731 | 731 | ) |
|
732 | 732 | self.add_menu_action(self.help_menu, self.quickref_active_frontend_action) |
|
733 | 733 | |
|
734 | 734 | self.guiref_active_frontend_action = QtGui.QAction("&Qt Console", |
|
735 | 735 | self, |
|
736 | 736 | triggered=self.guiref_active_frontend |
|
737 | 737 | ) |
|
738 | 738 | self.add_menu_action(self.help_menu, self.guiref_active_frontend_action) |
|
739 | 739 | |
|
740 | 740 | self.onlineHelpAct = QtGui.QAction("Open Online &Help", |
|
741 | 741 | self, |
|
742 | 742 | triggered=self._open_online_help) |
|
743 | 743 | self.add_menu_action(self.help_menu, self.onlineHelpAct) |
|
744 | 744 | |
|
745 | 745 | # minimize/maximize/fullscreen actions: |
|
746 | 746 | |
|
747 | 747 | def toggle_menu_bar(self): |
|
748 | 748 | menu_bar = self.menuBar() |
|
749 | 749 | if menu_bar.isVisible(): |
|
750 | 750 | menu_bar.setVisible(False) |
|
751 | 751 | else: |
|
752 | 752 | menu_bar.setVisible(True) |
|
753 | 753 | |
|
754 | 754 | def toggleMinimized(self): |
|
755 | 755 | if not self.isMinimized(): |
|
756 | 756 | self.showMinimized() |
|
757 | 757 | else: |
|
758 | 758 | self.showNormal() |
|
759 | 759 | |
|
760 | 760 | def _open_online_help(self): |
|
761 | 761 | filename="http://ipython.org/ipython-doc/stable/index.html" |
|
762 | 762 | webbrowser.open(filename, new=1, autoraise=True) |
|
763 | 763 | |
|
764 | 764 | def toggleMaximized(self): |
|
765 | 765 | if not self.isMaximized(): |
|
766 | 766 | self.showMaximized() |
|
767 | 767 | else: |
|
768 | 768 | self.showNormal() |
|
769 | 769 | |
|
770 | 770 | # Min/Max imizing while in full screen give a bug |
|
771 | 771 | # when going out of full screen, at least on OSX |
|
772 | 772 | def toggleFullScreen(self): |
|
773 | 773 | if not self.isFullScreen(): |
|
774 | 774 | self.showFullScreen() |
|
775 | 775 | if sys.platform == 'darwin': |
|
776 | 776 | self.maximizeAct.setEnabled(False) |
|
777 | 777 | self.minimizeAct.setEnabled(False) |
|
778 | 778 | else: |
|
779 | 779 | self.showNormal() |
|
780 | 780 | if sys.platform == 'darwin': |
|
781 | 781 | self.maximizeAct.setEnabled(True) |
|
782 | 782 | self.minimizeAct.setEnabled(True) |
|
783 | 783 | |
|
784 | 784 | def close_active_frontend(self): |
|
785 | 785 | self.close_tab(self.active_frontend) |
|
786 | 786 | |
|
787 | 787 | def restart_kernel_active_frontend(self): |
|
788 | 788 | self.active_frontend.request_restart_kernel() |
|
789 | 789 | |
|
790 | 790 | def interrupt_kernel_active_frontend(self): |
|
791 | 791 | self.active_frontend.request_interrupt_kernel() |
|
792 | 792 | |
|
793 | 793 | def cut_active_frontend(self): |
|
794 | 794 | widget = self.active_frontend |
|
795 | 795 | if widget.can_cut(): |
|
796 | 796 | widget.cut() |
|
797 | 797 | |
|
798 | 798 | def copy_active_frontend(self): |
|
799 | 799 | widget = self.active_frontend |
|
800 | 800 | widget.copy() |
|
801 | 801 | |
|
802 | 802 | def copy_raw_active_frontend(self): |
|
803 | 803 | self.active_frontend._copy_raw_action.trigger() |
|
804 | 804 | |
|
805 | 805 | def paste_active_frontend(self): |
|
806 | 806 | widget = self.active_frontend |
|
807 | 807 | if widget.can_paste(): |
|
808 | 808 | widget.paste() |
|
809 | 809 | |
|
810 | 810 | def undo_active_frontend(self): |
|
811 | 811 | self.active_frontend.undo() |
|
812 | 812 | |
|
813 | 813 | def redo_active_frontend(self): |
|
814 | 814 | self.active_frontend.redo() |
|
815 | 815 | |
|
816 | 816 | def reset_magic_active_frontend(self): |
|
817 | 817 | self.active_frontend.execute("%reset") |
|
818 | 818 | |
|
819 | 819 | def history_magic_active_frontend(self): |
|
820 | 820 | self.active_frontend.execute("%history") |
|
821 | 821 | |
|
822 | 822 | def save_magic_active_frontend(self): |
|
823 | 823 | self.active_frontend.save_magic() |
|
824 | 824 | |
|
825 | 825 | def clear_magic_active_frontend(self): |
|
826 | 826 | self.active_frontend.execute("%clear") |
|
827 | 827 | |
|
828 | 828 | def who_magic_active_frontend(self): |
|
829 | 829 | self.active_frontend.execute("%who") |
|
830 | 830 | |
|
831 | 831 | def who_ls_magic_active_frontend(self): |
|
832 | 832 | self.active_frontend.execute("%who_ls") |
|
833 | 833 | |
|
834 | 834 | def whos_magic_active_frontend(self): |
|
835 | 835 | self.active_frontend.execute("%whos") |
|
836 | 836 | |
|
837 | 837 | def print_action_active_frontend(self): |
|
838 | 838 | self.active_frontend.print_action.trigger() |
|
839 | 839 | |
|
840 | 840 | def export_action_active_frontend(self): |
|
841 | 841 | self.active_frontend.export_action.trigger() |
|
842 | 842 | |
|
843 | 843 | def select_all_active_frontend(self): |
|
844 | 844 | self.active_frontend.select_all_action.trigger() |
|
845 | 845 | |
|
846 | 846 | def increase_font_size_active_frontend(self): |
|
847 | 847 | self.active_frontend.increase_font_size.trigger() |
|
848 | 848 | |
|
849 | 849 | def decrease_font_size_active_frontend(self): |
|
850 | 850 | self.active_frontend.decrease_font_size.trigger() |
|
851 | 851 | |
|
852 | 852 | def reset_font_size_active_frontend(self): |
|
853 | 853 | self.active_frontend.reset_font_size.trigger() |
|
854 | 854 | |
|
855 | 855 | def guiref_active_frontend(self): |
|
856 | 856 | self.active_frontend.execute("%guiref") |
|
857 | 857 | |
|
858 | 858 | def intro_active_frontend(self): |
|
859 | 859 | self.active_frontend.execute("?") |
|
860 | 860 | |
|
861 | 861 | def quickref_active_frontend(self): |
|
862 | 862 | self.active_frontend.execute("%quickref") |
|
863 | 863 | #--------------------------------------------------------------------------- |
|
864 | 864 | # QWidget interface |
|
865 | 865 | #--------------------------------------------------------------------------- |
|
866 | 866 | |
|
867 | 867 | def closeEvent(self, event): |
|
868 | 868 | """ Forward the close event to every tabs contained by the windows |
|
869 | 869 | """ |
|
870 | 870 | if self.tab_widget.count() == 0: |
|
871 | 871 | # no tabs, just close |
|
872 | 872 | event.accept() |
|
873 | 873 | return |
|
874 | 874 | # Do Not loop on the widget count as it change while closing |
|
875 | 875 | title = self.window().windowTitle() |
|
876 | 876 | cancel = QtGui.QMessageBox.Cancel |
|
877 | 877 | okay = QtGui.QMessageBox.Ok |
|
878 | 878 | |
|
879 | 879 | if self.confirm_exit: |
|
880 | 880 | if self.tab_widget.count() > 1: |
|
881 | 881 | msg = "Close all tabs, stop all kernels, and Quit?" |
|
882 | 882 | else: |
|
883 | 883 | msg = "Close console, stop kernel, and Quit?" |
|
884 | 884 | info = "Kernels not started here (e.g. notebooks) will be left alone." |
|
885 | 885 | closeall = QtGui.QPushButton("&Quit", self) |
|
886 | 886 | closeall.setShortcut('Q') |
|
887 | 887 | box = QtGui.QMessageBox(QtGui.QMessageBox.Question, |
|
888 | 888 | title, msg) |
|
889 | 889 | box.setInformativeText(info) |
|
890 | 890 | box.addButton(cancel) |
|
891 | 891 | box.addButton(closeall, QtGui.QMessageBox.YesRole) |
|
892 | 892 | box.setDefaultButton(closeall) |
|
893 | 893 | box.setEscapeButton(cancel) |
|
894 | 894 | pixmap = QtGui.QPixmap(self._app.icon.pixmap(QtCore.QSize(64,64))) |
|
895 | 895 | box.setIconPixmap(pixmap) |
|
896 | 896 | reply = box.exec_() |
|
897 | 897 | else: |
|
898 | 898 | reply = okay |
|
899 | 899 | |
|
900 | 900 | if reply == cancel: |
|
901 | 901 | event.ignore() |
|
902 | 902 | return |
|
903 | 903 | if reply == okay: |
|
904 | 904 | while self.tab_widget.count() >= 1: |
|
905 | 905 | # prevent further confirmations: |
|
906 | 906 | widget = self.active_frontend |
|
907 | 907 | widget._confirm_exit = False |
|
908 | 908 | self.close_tab(widget) |
|
909 | 909 | event.accept() |
|
910 | 910 |
@@ -1,192 +1,192 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Tools to open .py files as Unicode, using the encoding specified within the file, |
|
3 | 3 | as per PEP 263. |
|
4 | 4 | |
|
5 | 5 | Much of the code is taken from the tokenize module in Python 3.2. |
|
6 | 6 | """ |
|
7 | 7 | from __future__ import absolute_import |
|
8 | 8 | |
|
9 | import __builtin__ | |
|
10 | 9 | import io |
|
11 | 10 | from io import TextIOWrapper |
|
12 | 11 | import re |
|
13 | 12 | import urllib |
|
14 | 13 | |
|
15 | 14 | cookie_re = re.compile(ur"coding[:=]\s*([-\w.]+)", re.UNICODE) |
|
16 | 15 | cookie_comment_re = re.compile(ur"^\s*#.*coding[:=]\s*([-\w.]+)", re.UNICODE) |
|
17 | 16 | |
|
18 | 17 | try: |
|
19 | 18 | # Available in Python 3 |
|
20 | 19 | from tokenize import detect_encoding |
|
21 | 20 | except ImportError: |
|
22 | 21 | from codecs import lookup, BOM_UTF8 |
|
23 | 22 | |
|
24 | 23 | # Copied from Python 3.2 tokenize |
|
25 | 24 | def _get_normal_name(orig_enc): |
|
26 | 25 | """Imitates get_normal_name in tokenizer.c.""" |
|
27 | 26 | # Only care about the first 12 characters. |
|
28 | 27 | enc = orig_enc[:12].lower().replace("_", "-") |
|
29 | 28 | if enc == "utf-8" or enc.startswith("utf-8-"): |
|
30 | 29 | return "utf-8" |
|
31 | 30 | if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \ |
|
32 | 31 | enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")): |
|
33 | 32 | return "iso-8859-1" |
|
34 | 33 | return orig_enc |
|
35 | 34 | |
|
36 | 35 | # Copied from Python 3.2 tokenize |
|
37 | 36 | def detect_encoding(readline): |
|
38 | 37 | """ |
|
39 | 38 | The detect_encoding() function is used to detect the encoding that should |
|
40 | 39 | be used to decode a Python source file. It requires one argment, readline, |
|
41 | 40 | in the same way as the tokenize() generator. |
|
42 | 41 | |
|
43 | 42 | It will call readline a maximum of twice, and return the encoding used |
|
44 | 43 | (as a string) and a list of any lines (left as bytes) it has read in. |
|
45 | 44 | |
|
46 | 45 | It detects the encoding from the presence of a utf-8 bom or an encoding |
|
47 | 46 | cookie as specified in pep-0263. If both a bom and a cookie are present, |
|
48 | 47 | but disagree, a SyntaxError will be raised. If the encoding cookie is an |
|
49 | 48 | invalid charset, raise a SyntaxError. Note that if a utf-8 bom is found, |
|
50 | 49 | 'utf-8-sig' is returned. |
|
51 | 50 | |
|
52 | 51 | If no encoding is specified, then the default of 'utf-8' will be returned. |
|
53 | 52 | """ |
|
54 | 53 | bom_found = False |
|
55 | 54 | encoding = None |
|
56 | 55 | default = 'utf-8' |
|
57 | 56 | def read_or_stop(): |
|
58 | 57 | try: |
|
59 | 58 | return readline() |
|
60 | 59 | except StopIteration: |
|
61 | 60 | return b'' |
|
62 | 61 | |
|
63 | 62 | def find_cookie(line): |
|
64 | 63 | try: |
|
65 | 64 | line_string = line.decode('ascii') |
|
66 | 65 | except UnicodeDecodeError: |
|
67 | 66 | return None |
|
68 | 67 | |
|
69 | 68 | matches = cookie_re.findall(line_string) |
|
70 | 69 | if not matches: |
|
71 | 70 | return None |
|
72 | 71 | encoding = _get_normal_name(matches[0]) |
|
73 | 72 | try: |
|
74 | 73 | codec = lookup(encoding) |
|
75 | 74 | except LookupError: |
|
76 | 75 | # This behaviour mimics the Python interpreter |
|
77 | 76 | raise SyntaxError("unknown encoding: " + encoding) |
|
78 | 77 | |
|
79 | 78 | if bom_found: |
|
80 | 79 | if codec.name != 'utf-8': |
|
81 | 80 | # This behaviour mimics the Python interpreter |
|
82 | 81 | raise SyntaxError('encoding problem: utf-8') |
|
83 | 82 | encoding += '-sig' |
|
84 | 83 | return encoding |
|
85 | 84 | |
|
86 | 85 | first = read_or_stop() |
|
87 | 86 | if first.startswith(BOM_UTF8): |
|
88 | 87 | bom_found = True |
|
89 | 88 | first = first[3:] |
|
90 | 89 | default = 'utf-8-sig' |
|
91 | 90 | if not first: |
|
92 | 91 | return default, [] |
|
93 | 92 | |
|
94 | 93 | encoding = find_cookie(first) |
|
95 | 94 | if encoding: |
|
96 | 95 | return encoding, [first] |
|
97 | 96 | |
|
98 | 97 | second = read_or_stop() |
|
99 | 98 | if not second: |
|
100 | 99 | return default, [first] |
|
101 | 100 | |
|
102 | 101 | encoding = find_cookie(second) |
|
103 | 102 | if encoding: |
|
104 | 103 | return encoding, [first, second] |
|
105 | 104 | |
|
106 | 105 | return default, [first, second] |
|
107 | 106 | |
|
108 | 107 | try: |
|
109 | 108 | # Available in Python 3.2 and above. |
|
110 | 109 | from tokenize import open |
|
111 | 110 | except ImportError: |
|
112 | 111 | # Copied from Python 3.2 tokenize |
|
113 | 112 | def open(filename): |
|
114 | 113 | """Open a file in read only mode using the encoding detected by |
|
115 | 114 | detect_encoding(). |
|
116 | 115 | """ |
|
117 | 116 | buffer = io.open(filename, 'rb') # Tweaked to use io.open for Python 2 |
|
118 | 117 | encoding, lines = detect_encoding(buffer.readline) |
|
119 | 118 | buffer.seek(0) |
|
120 | 119 | text = TextIOWrapper(buffer, encoding, line_buffering=True) |
|
121 | 120 | text.mode = 'r' |
|
122 | 121 | return text |
|
123 | 122 | |
|
124 | 123 | def strip_encoding_cookie(filelike): |
|
125 | 124 | """Generator to pull lines from a text-mode file, skipping the encoding |
|
126 | 125 | cookie if it is found in the first two lines. |
|
127 | 126 | """ |
|
128 | 127 | it = iter(filelike) |
|
129 | 128 | try: |
|
130 | 129 | first = next(it) |
|
131 | 130 | if not cookie_comment_re.match(first): |
|
132 | 131 | yield first |
|
133 | 132 | second = next(it) |
|
134 | 133 | if not cookie_comment_re.match(second): |
|
135 | 134 | yield second |
|
136 | 135 | except StopIteration: |
|
137 | 136 | return |
|
138 | 137 | |
|
139 | 138 | for line in it: |
|
140 | 139 | yield line |
|
141 | 140 | |
|
142 | 141 | def read_py_file(filename, skip_encoding_cookie=True): |
|
143 | 142 | """Read a Python file, using the encoding declared inside the file. |
|
144 | 143 | |
|
145 | 144 | Parameters |
|
146 | 145 | ---------- |
|
147 | 146 | filename : str |
|
148 | 147 | The path to the file to read. |
|
149 | 148 | skip_encoding_cookie : bool |
|
150 | 149 | If True (the default), and the encoding declaration is found in the first |
|
151 | 150 | two lines, that line will be excluded from the output - compiling a |
|
152 | 151 | unicode string with an encoding declaration is a SyntaxError in Python 2. |
|
153 | 152 | |
|
154 | 153 | Returns |
|
155 | 154 | ------- |
|
156 | 155 | A unicode string containing the contents of the file. |
|
157 | 156 | """ |
|
158 | 157 | with open(filename) as f: # the open function defined in this module. |
|
159 | 158 | if skip_encoding_cookie: |
|
160 | 159 | return "".join(strip_encoding_cookie(f)) |
|
161 | 160 | else: |
|
162 | 161 | return f.read() |
|
163 | 162 | |
|
164 | 163 | def read_py_url(url, errors='replace', skip_encoding_cookie=True): |
|
165 | 164 | """Read a Python file from a URL, using the encoding declared inside the file. |
|
166 | 165 | |
|
167 | 166 | Parameters |
|
168 | 167 | ---------- |
|
169 | 168 | url : str |
|
170 | 169 | The URL from which to fetch the file. |
|
171 | 170 | errors : str |
|
172 | 171 | How to handle decoding errors in the file. Options are the same as for |
|
173 | 172 | bytes.decode(), but here 'replace' is the default. |
|
174 | 173 | skip_encoding_cookie : bool |
|
175 | 174 | If True (the default), and the encoding declaration is found in the first |
|
176 | 175 | two lines, that line will be excluded from the output - compiling a |
|
177 | 176 | unicode string with an encoding declaration is a SyntaxError in Python 2. |
|
178 | 177 | |
|
179 | 178 | Returns |
|
180 | 179 | ------- |
|
181 | 180 | A unicode string containing the contents of the file. |
|
182 | 181 | """ |
|
183 | 182 | response = urllib.urlopen(url) |
|
184 | 183 | buffer = io.BytesIO(response.read()) |
|
185 | 184 | encoding, lines = detect_encoding(buffer.readline) |
|
186 | 185 | buffer.seek(0) |
|
187 | 186 | text = TextIOWrapper(buffer, encoding, errors=errors, line_buffering=True) |
|
188 | 187 | text.mode = 'r' |
|
189 | 188 | if skip_encoding_cookie: |
|
190 | 189 | return "".join(strip_encoding_cookie(text)) |
|
191 | 190 | else: |
|
192 | 191 | return text.read() |
|
192 |
@@ -1,1093 +1,1093 b'' | |||
|
1 | 1 | { |
|
2 | 2 | "metadata": { |
|
3 | 3 | "name": "00_notebook_tour" |
|
4 | 4 | }, |
|
5 | 5 | "nbformat": 3, |
|
6 | 6 | "worksheets": [ |
|
7 | 7 | { |
|
8 | 8 | "cells": [ |
|
9 | 9 | { |
|
10 | 10 | "cell_type": "markdown", |
|
11 | 11 | "source": [ |
|
12 | 12 | "# A brief tour of the IPython notebook", |
|
13 | 13 | "", |
|
14 | 14 | "This document will give you a brief tour of the capabilities of the IPython notebook. ", |
|
15 | 15 | "You can view its contents by scrolling around, or execute each cell by typing `Shift-Enter`.", |
|
16 | 16 | "After you conclude this brief high-level tour, you should read the accompanying notebook ", |
|
17 | 17 | "titled `01_notebook_introduction`, which takes a more step-by-step approach to the features of the", |
|
18 | 18 | "system. ", |
|
19 | 19 | "", |
|
20 | 20 | "The rest of the notebooks in this directory illustrate various other aspects and ", |
|
21 | 21 | "capabilities of the IPython notebook; some of them may require additional libraries to be executed.", |
|
22 | 22 | "", |
|
23 | 23 | "**NOTE:** This notebook *must* be run from its own directory, so you must ``cd``", |
|
24 | 24 | "to this directory and then start the notebook, but do *not* use the ``--notebook-dir``", |
|
25 | 25 | "option to run it from another location.", |
|
26 | 26 | "", |
|
27 | 27 | "The first thing you need to know is that you are still controlling the same old IPython you're used to,", |
|
28 | 28 | "so things like shell aliases and magic commands still work:" |
|
29 | 29 | ] |
|
30 | 30 | }, |
|
31 | 31 | { |
|
32 | 32 | "cell_type": "code", |
|
33 | 33 | "collapsed": false, |
|
34 | 34 | "input": [ |
|
35 | 35 | "pwd" |
|
36 | 36 | ], |
|
37 | 37 | "language": "python", |
|
38 | 38 | "outputs": [ |
|
39 | 39 | { |
|
40 | 40 | "output_type": "pyout", |
|
41 | 41 | "prompt_number": 1, |
|
42 | 42 | "text": [ |
|
43 | 43 | "u'/home/fperez/ipython/ipython/docs/examples/notebooks'" |
|
44 | 44 | ] |
|
45 | 45 | } |
|
46 | 46 | ], |
|
47 | 47 | "prompt_number": 1 |
|
48 | 48 | }, |
|
49 | 49 | { |
|
50 | 50 | "cell_type": "code", |
|
51 | 51 | "collapsed": false, |
|
52 | 52 | "input": [ |
|
53 | 53 | "ls" |
|
54 | 54 | ], |
|
55 | 55 | "language": "python", |
|
56 | 56 | "outputs": [ |
|
57 | 57 | { |
|
58 | 58 | "output_type": "stream", |
|
59 | 59 | "stream": "stdout", |
|
60 | 60 | "text": [ |
|
61 | 61 | "00_notebook_tour.ipynb python-logo.svg", |
|
62 | 62 | "01_notebook_introduction.ipynb sympy.ipynb", |
|
63 | 63 | "animation.m4v sympy_quantum_computing.ipynb", |
|
64 | 64 | "display_protocol.ipynb trapezoid_rule.ipynb", |
|
65 | 65 | "formatting.ipynb" |
|
66 | 66 | ] |
|
67 | 67 | } |
|
68 | 68 | ], |
|
69 | 69 | "prompt_number": 2 |
|
70 | 70 | }, |
|
71 | 71 | { |
|
72 | 72 | "cell_type": "code", |
|
73 | 73 | "collapsed": false, |
|
74 | 74 | "input": [ |
|
75 | 75 | "message = 'The IPython notebook is great!'", |
|
76 | 76 | "# note: the echo command does not run on Windows, it's a unix command.", |
|
77 | 77 | "!echo $message" |
|
78 | 78 | ], |
|
79 | 79 | "language": "python", |
|
80 | 80 | "outputs": [ |
|
81 | 81 | { |
|
82 | 82 | "output_type": "stream", |
|
83 | 83 | "stream": "stdout", |
|
84 | 84 | "text": [ |
|
85 | 85 | "The IPython notebook is great!" |
|
86 | 86 | ] |
|
87 | 87 | } |
|
88 | 88 | ], |
|
89 | 89 | "prompt_number": 3 |
|
90 | 90 | }, |
|
91 | 91 | { |
|
92 | 92 | "cell_type": "markdown", |
|
93 | 93 | "source": [ |
|
94 | 94 | "Plots with matplotlib: do *not* execute the next below if you do not have matplotlib installed or didn't start up ", |
|
95 | 95 | "this notebook with the `--pylab` option, as the code will not work." |
|
96 | 96 | ] |
|
97 | 97 | }, |
|
98 | 98 | { |
|
99 | 99 | "cell_type": "code", |
|
100 | 100 | "collapsed": false, |
|
101 | 101 | "input": [ |
|
102 | 102 | "x = linspace(0, 3*pi, 500)", |
|
103 | 103 | "plot(x, sin(x**2))", |
|
104 | 104 | "title('A simple chirp');" |
|
105 | 105 | ], |
|
106 | 106 | "language": "python", |
|
107 | 107 | "outputs": [ |
|
108 | 108 | { |
|
109 | 109 | "output_type": "display_data", |
|
110 | 110 | "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAECCAYAAAASDQdFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztfXl0VtW5/vOFIAnzkIkhzJEQEAkCERUMSkGrYlutys+F\nS6FepLXSex1WvfVW6Kpee60XvV4XpX94FYe2FrRo1VJQY0SF4AQKsRKEEmQKCYSMkOH7/bHdycnJ\nGfZ4zvmS/ayVBUnOHr4v33n2c5733e+OxePxOAwMDAwMugWSwp6AgYGBgUFwMKRvYGBg0I1gSN/A\nwMCgG8GQvoGBgUE3giF9AwMDg24EQ/oGBgYG3QiG9A0SHi+88AIWLFigpe9bb70V//Ef/6G0z5Ur\nV2Lx4sWuv588eTKKi4uVjmlgQGFI3yB0FBYWYvDgwTh79qxQ+5tvvhmbNm1SPCuCWCyGWCymvE8v\nfPHFF5gzZ47SMQ0MKAzpG4SKAwcOoKSkBBkZGXj11VfDno4jVO9flOmvpaVF4UwMuiMM6RuEinXr\n1mHevHlYvHgxnn32Wc9rN27ciLlz52LgwIEYO3YsXnzxRQDA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0WLFuHtt9/GLbfcEva0QsP48eMxYcIEXHPNNUhN\nTcWiRYvw5ptvhj2tUFBSUoILL7wQ48ePx5AhQ/DDH/4QxcXFYU8rVMyYMQOlpaUAgNLSUsxgqIcS\nKumbPP52xONxLF26FJMnT8bPfvazsKcTGh5++GGUl5dj//79+OMf/4jLLrsM69atC3taoSInJwfb\nt29Ha2srXn/9dcybNy/sKYWC2bNn46OPPkJVVRXOnDmDN998E/Pnzw97WqGioKAATz/9NBoaGvD0\n008ziebQ7R2Tx0/w/vvv4/nnn8fbb7+N/Px85Ofnd4rUd0eY7B3gt7/9LVasWIFp06YhJSUFN910\nU9hTCgX9+/fHAw88gO9///u45JJLcP7552Pu3LlhTyswLFq0CBdddBG++uorZGdn4//+7/+wfPly\nHDx4EBMmTMA333yDO+64w7efWNwYpwYGBgbdBqErfQMDAwOD4GBI38DAwKAbwZC+gYGBQTeCIX0D\nAwODbgRD+gYGBgbdCIb0DQwMDLoR/j8U8QHdaUyIsAAAAABJRU5ErkJggg==\n" |
|
111 | 111 | } |
|
112 | 112 | ], |
|
113 | 113 | "prompt_number": 4 |
|
114 | 114 | }, |
|
115 | 115 | { |
|
116 | 116 | "cell_type": "markdown", |
|
117 | 117 | "source": [ |
|
118 | 118 | "You can paste blocks of input with prompt markers, such as those from", |
|
119 | 119 | "[the official Python tutorial](http://docs.python.org/tutorial/interpreter.html#interactive-mode)" |
|
120 | 120 | ] |
|
121 | 121 | }, |
|
122 | 122 | { |
|
123 | 123 | "cell_type": "code", |
|
124 | 124 | "collapsed": false, |
|
125 | 125 | "input": [ |
|
126 | 126 | ">>> the_world_is_flat = 1", |
|
127 | 127 | ">>> if the_world_is_flat:", |
|
128 | 128 | "... print \"Be careful not to fall off!\"" |
|
129 | 129 | ], |
|
130 | 130 | "language": "python", |
|
131 | 131 | "outputs": [ |
|
132 | 132 | { |
|
133 | 133 | "output_type": "stream", |
|
134 | 134 | "stream": "stdout", |
|
135 | 135 | "text": [ |
|
136 | 136 | "Be careful not to fall off!" |
|
137 | 137 | ] |
|
138 | 138 | } |
|
139 | 139 | ], |
|
140 | 140 | "prompt_number": 5 |
|
141 | 141 | }, |
|
142 | 142 | { |
|
143 | 143 | "cell_type": "markdown", |
|
144 | 144 | "source": [ |
|
145 | 145 | "Errors are shown in informative ways:" |
|
146 | 146 | ] |
|
147 | 147 | }, |
|
148 | 148 | { |
|
149 | 149 | "cell_type": "code", |
|
150 | 150 | "collapsed": false, |
|
151 | 151 | "input": [ |
|
152 | 152 | "%run non_existent_file" |
|
153 | 153 | ], |
|
154 | 154 | "language": "python", |
|
155 | 155 | "outputs": [ |
|
156 | 156 | { |
|
157 | 157 | "output_type": "stream", |
|
158 | 158 | "stream": "stderr", |
|
159 | 159 | "text": [ |
|
160 | 160 | "ERROR: File `non_existent_file.py` not found." |
|
161 | 161 | ] |
|
162 | 162 | } |
|
163 | 163 | ], |
|
164 | 164 | "prompt_number": 6 |
|
165 | 165 | }, |
|
166 | 166 | { |
|
167 | 167 | "cell_type": "code", |
|
168 | 168 | "collapsed": false, |
|
169 | 169 | "input": [ |
|
170 | 170 | "x = 1", |
|
171 | 171 | "y = 4", |
|
172 | 172 | "z = y/(1-x)" |
|
173 | 173 | ], |
|
174 | 174 | "language": "python", |
|
175 | 175 | "outputs": [ |
|
176 | 176 | { |
|
177 | 177 | "ename": "ZeroDivisionError", |
|
178 | 178 | "evalue": "integer division or modulo by zero", |
|
179 | 179 | "output_type": "pyerr", |
|
180 | 180 | "traceback": [ |
|
181 | 181 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", |
|
182 | 182 | "\u001b[0;32m/home/fperez/ipython/ipython/docs/examples/notebooks/<ipython-input-7-dc39888fd1d2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mz\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", |
|
183 | 183 | "\u001b[0;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" |
|
184 | 184 | ] |
|
185 | 185 | } |
|
186 | 186 | ], |
|
187 | 187 | "prompt_number": 7 |
|
188 | 188 | }, |
|
189 | 189 | { |
|
190 | 190 | "cell_type": "markdown", |
|
191 | 191 | "source": [ |
|
192 | 192 | "When IPython needs to display additional information (such as providing details on an object via `x?`", |
|
193 | 193 | "it will automatically invoke a pager at the bottom of the screen:" |
|
194 | 194 | ] |
|
195 | 195 | }, |
|
196 | 196 | { |
|
197 | 197 | "cell_type": "code", |
|
198 | 198 | "collapsed": true, |
|
199 | 199 | "input": [ |
|
200 | 200 | "magic" |
|
201 | 201 | ], |
|
202 | 202 | "language": "python", |
|
203 | 203 | "outputs": [], |
|
204 | 204 | "prompt_number": 8 |
|
205 | 205 | }, |
|
206 | 206 | { |
|
207 | 207 | "cell_type": "markdown", |
|
208 | 208 | "source": [ |
|
209 | 209 | "## Non-blocking output of kernel", |
|
210 | 210 | "", |
|
211 | 211 | "If you execute the next cell, you will see the output arriving as it is generated, not all at the end." |
|
212 | 212 | ] |
|
213 | 213 | }, |
|
214 | 214 | { |
|
215 | 215 | "cell_type": "code", |
|
216 | 216 | "collapsed": false, |
|
217 | 217 | "input": [ |
|
218 | 218 | "import time, sys", |
|
219 | 219 | "for i in range(8):", |
|
220 | 220 | " print i,", |
|
221 | 221 | " time.sleep(0.5)" |
|
222 | 222 | ], |
|
223 | 223 | "language": "python", |
|
224 | 224 | "outputs": [ |
|
225 | 225 | { |
|
226 | 226 | "output_type": "stream", |
|
227 | 227 | "stream": "stdout", |
|
228 | 228 | "text": [ |
|
229 | 229 | "0 " |
|
230 | 230 | ] |
|
231 | 231 | }, |
|
232 | 232 | { |
|
233 | 233 | "output_type": "stream", |
|
234 | 234 | "stream": "stdout", |
|
235 | 235 | "text": [ |
|
236 | 236 | "1 " |
|
237 | 237 | ] |
|
238 | 238 | }, |
|
239 | 239 | { |
|
240 | 240 | "output_type": "stream", |
|
241 | 241 | "stream": "stdout", |
|
242 | 242 | "text": [ |
|
243 | 243 | "2 " |
|
244 | 244 | ] |
|
245 | 245 | }, |
|
246 | 246 | { |
|
247 | 247 | "output_type": "stream", |
|
248 | 248 | "stream": "stdout", |
|
249 | 249 | "text": [ |
|
250 | 250 | "3 " |
|
251 | 251 | ] |
|
252 | 252 | }, |
|
253 | 253 | { |
|
254 | 254 | "output_type": "stream", |
|
255 | 255 | "stream": "stdout", |
|
256 | 256 | "text": [ |
|
257 | 257 | "4 " |
|
258 | 258 | ] |
|
259 | 259 | }, |
|
260 | 260 | { |
|
261 | 261 | "output_type": "stream", |
|
262 | 262 | "stream": "stdout", |
|
263 | 263 | "text": [ |
|
264 | 264 | "5 " |
|
265 | 265 | ] |
|
266 | 266 | }, |
|
267 | 267 | { |
|
268 | 268 | "output_type": "stream", |
|
269 | 269 | "stream": "stdout", |
|
270 | 270 | "text": [ |
|
271 | 271 | "6 " |
|
272 | 272 | ] |
|
273 | 273 | }, |
|
274 | 274 | { |
|
275 | 275 | "output_type": "stream", |
|
276 | 276 | "stream": "stdout", |
|
277 | 277 | "text": [ |
|
278 | 278 | "7" |
|
279 | 279 | ] |
|
280 | 280 | } |
|
281 | 281 | ], |
|
282 | 282 | "prompt_number": 9 |
|
283 | 283 | }, |
|
284 | 284 | { |
|
285 | 285 | "cell_type": "markdown", |
|
286 | 286 | "source": [ |
|
287 | 287 | "## Clean crash and restart", |
|
288 | 288 | "", |
|
289 | 289 | "We call the low-level system libc.time routine with the wrong argument via", |
|
290 | 290 | "ctypes to segfault the Python interpreter:" |
|
291 | 291 | ] |
|
292 | 292 | }, |
|
293 | 293 | { |
|
294 | 294 | "cell_type": "code", |
|
295 | 295 | "collapsed": true, |
|
296 | 296 | "input": [ |
|
297 | 297 | "from ctypes import CDLL", |
|
298 | 298 | "# This will crash a linux system; equivalent calls can be made on Windows or Mac", |
|
299 | 299 | "libc = CDLL(\"libc.so.6\") ", |
|
300 | 300 | "libc.time(-1) # BOOM!!" |
|
301 | 301 | ], |
|
302 | 302 | "language": "python", |
|
303 | 303 | "outputs": [], |
|
304 | 304 | "prompt_number": "*" |
|
305 | 305 | }, |
|
306 | 306 | { |
|
307 | 307 | "cell_type": "markdown", |
|
308 | 308 | "source": [ |
|
309 | 309 | "## Markdown cells can contain formatted text and code", |
|
310 | 310 | "", |
|
311 | 311 | "You can *italicize*, **boldface**", |
|
312 | 312 | "", |
|
313 | 313 | "* build", |
|
314 | 314 | "* lists", |
|
315 | 315 | "", |
|
316 | 316 | "and embed code meant for illustration instead of execution in Python:", |
|
317 | 317 | "", |
|
318 | 318 | " def f(x):", |
|
319 | 319 | " \"\"\"a docstring\"\"\"", |
|
320 | 320 | " return x**2", |
|
321 | 321 | "", |
|
322 | 322 | "or other languages:", |
|
323 | 323 | "", |
|
324 | 324 | " if (i=0; i<n; i++) {", |
|
325 | 325 | " printf(\"hello %d\\n\", i);", |
|
326 | 326 | " x += 4;", |
|
327 | 327 | " }" |
|
328 | 328 | ] |
|
329 | 329 | }, |
|
330 | 330 | { |
|
331 | 331 | "cell_type": "markdown", |
|
332 | 332 | "source": [ |
|
333 | 333 | "Courtesy of MathJax, you can include mathematical expressions both inline: ", |
|
334 | 334 | "$e^{i\\pi} + 1 = 0$ and displayed:", |
|
335 | 335 | "", |
|
336 | 336 | "$$e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i$$" |
|
337 | 337 | ] |
|
338 | 338 | }, |
|
339 | 339 | { |
|
340 | 340 | "cell_type": "markdown", |
|
341 | 341 | "source": [ |
|
342 | 342 | "## Rich displays: include anyting a browser can show", |
|
343 | 343 | "", |
|
344 | 344 | "Note that we have an actual protocol for this, see the `display_protocol` notebook for further details.", |
|
345 | 345 | "", |
|
346 | 346 | "### Images" |
|
347 | 347 | ] |
|
348 | 348 | }, |
|
349 | 349 | { |
|
350 | 350 | "cell_type": "code", |
|
351 | 351 | "collapsed": false, |
|
352 | 352 | "input": [ |
|
353 | 353 | "from IPython.core.display import Image", |
|
354 | 354 | "Image(filename='../../source/_static/logo.png')" |
|
355 | 355 | ], |
|
356 | 356 | "language": "python", |
|
357 | 357 | "outputs": [ |
|
358 | 358 | { |
|
359 | 359 | "output_type": "pyout", |
|
360 | 360 | "png": "iVBORw0KGgoAAAANSUhEUgAAAggAAABDCAYAAAD5/P3lAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAH3AAAB9wBYvxo6AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURB\nVHic7Z15uBxF1bjfugkJhCWBsCSAJGACNg4QCI3RT1lEAVE+UEBNOmwCDcjHT1wQgU+WD3dFxA1o\nCAikAZFFVlnCjizpsCUjHQjBIAkQlpCFJGS79fvjdGf69vTsc2fuza33eeaZmeqq6jM9vZw6dc4p\nBUwC+tE+fqW1fqmRDpRSHjCggS40sBxYDCxKvL8KzNBaL21EPoPB0DPIWVY/4NlE0ffzYfhgu+Qx\nGHoy/YFjaK+CcB3QkIIAHAWs3wRZsuhUSs0CXgQeBm7UWi/spn0Z+jA5yxpEfYruqnwYllRic5a1\nMaWv8U5gaT4M19Sx396IAnZLfB/SLkEMhp5O/3YL0AvoAHaKXl8HLlZK3QZcpbWe0lbJDOsaHuDU\n0e4u4JAy2wPk/C1JzrKWArOQ0fUtwH35MOysQxaDwbCO0NFuAXoh6wPjgQeUUv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rJ\ndv0hFPwTnjBRDAaDwWAw9A3+hPgOHRPl25iK+FhsiuR4OARx0Lwf+J1REAwGg8Fg6AMEnvNklL78\nHMRRca/E5hVINNIVwI2B56z6/3ExLRI31pXNAAAAAElFTkSuQmCC\n", |
|
361 | 361 | "prompt_number": 1, |
|
362 | 362 | "text": [ |
|
363 | 363 | "<IPython.core.display.Image at 0x41d4690>" |
|
364 | 364 | ] |
|
365 | 365 | } |
|
366 | 366 | ], |
|
367 | 367 | "prompt_number": 1 |
|
368 | 368 | }, |
|
369 | 369 | { |
|
370 | 370 | "cell_type": "markdown", |
|
371 | 371 | "source": [ |
|
372 | 372 | "An image can also be displayed from raw data or a url" |
|
373 | 373 | ] |
|
374 | 374 | }, |
|
375 | 375 | { |
|
376 | 376 | "cell_type": "code", |
|
377 | 377 | "collapsed": false, |
|
378 | 378 | "input": [ |
|
379 | 379 | "Image('http://python.org/images/python-logo.gif')" |
|
380 | 380 | ], |
|
381 | 381 | "language": "python", |
|
382 | 382 | "outputs": [ |
|
383 | 383 | { |
|
384 | 384 | "html": [ |
|
385 | 385 | "<img src=\"http://python.org/images/python-logo.gif\" />" |
|
386 | 386 | ], |
|
387 | 387 | "output_type": "pyout", |
|
388 | 388 | "prompt_number": 2, |
|
389 | 389 | "text": [ |
|
390 | 390 | "<IPython.core.display.Image at 0x41d4550>" |
|
391 | 391 | ] |
|
392 | 392 | } |
|
393 | 393 | ], |
|
394 | 394 | "prompt_number": 2 |
|
395 | 395 | }, |
|
396 | 396 | { |
|
397 | 397 | "cell_type": "markdown", |
|
398 | 398 | "source": [ |
|
399 | 399 | "SVG images are also supported out of the box (since modern browsers do a good job of rendering them):" |
|
400 | 400 | ] |
|
401 | 401 | }, |
|
402 | 402 | { |
|
403 | 403 | "cell_type": "code", |
|
404 | 404 | "collapsed": false, |
|
405 | 405 | "input": [ |
|
406 | 406 | "from IPython.core.display import SVG", |
|
407 | 407 | "SVG(filename='python-logo.svg')" |
|
408 | 408 | ], |
|
409 | 409 | "language": "python", |
|
410 | 410 | "outputs": [ |
|
411 | 411 | { |
|
412 | 412 | "output_type": "pyout", |
|
413 | 413 | "prompt_number": 3, |
|
414 | 414 | "svg": [ |
|
415 | 415 | "<svg height=\"115.02pt\" id=\"svg2\" inkscape:version=\"0.43\" sodipodi:docbase=\"/home/sdeibel\" sodipodi:docname=\"logo-python-generic.svg\" sodipodi:version=\"0.32\" version=\"1.0\" width=\"388.84pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:cc=\"http://web.resource.org/cc/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:sodipodi=\"http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">", |
|
416 | 416 | " <metadata id=\"metadata2193\">", |
|
417 | 417 | " <rdf:RDF>", |
|
418 | 418 | " <cc:Work rdf:about=\"\">", |
|
419 | 419 | " <dc:format>image/svg+xml</dc:format>", |
|
420 | 420 | " <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>", |
|
421 | 421 | " </cc:Work>", |
|
422 | 422 | " </rdf:RDF>", |
|
423 | 423 | " </metadata>", |
|
424 | 424 | " <sodipodi:namedview bordercolor=\"#666666\" borderopacity=\"1.0\" id=\"base\" inkscape:current-layer=\"svg2\" inkscape:cx=\"243.02499\" inkscape:cy=\"71.887497\" inkscape:pageopacity=\"0.0\" inkscape:pageshadow=\"2\" inkscape:window-height=\"543\" inkscape:window-width=\"791\" inkscape:window-x=\"0\" inkscape:window-y=\"0\" inkscape:zoom=\"1.4340089\" pagecolor=\"#ffffff\"/>", |
|
425 | 425 | " <defs id=\"defs4\">", |
|
426 | 426 | " <linearGradient id=\"linearGradient2795\">", |
|
427 | 427 | " <stop id=\"stop2797\" offset=\"0\" style=\"stop-color:#b8b8b8;stop-opacity:0.49803922\"/>", |
|
428 | 428 | " <stop id=\"stop2799\" offset=\"1\" style=\"stop-color:#7f7f7f;stop-opacity:0\"/>", |
|
429 | 429 | " </linearGradient>", |
|
430 | 430 | " <linearGradient id=\"linearGradient2787\">", |
|
431 | 431 | " <stop id=\"stop2789\" offset=\"0\" style=\"stop-color:#7f7f7f;stop-opacity:0.5\"/>", |
|
432 | 432 | " <stop id=\"stop2791\" offset=\"1\" style=\"stop-color:#7f7f7f;stop-opacity:0\"/>", |
|
433 | 433 | " </linearGradient>", |
|
434 | 434 | " <linearGradient id=\"linearGradient3676\">", |
|
435 | 435 | " <stop id=\"stop3678\" offset=\"0\" style=\"stop-color:#b2b2b2;stop-opacity:0.5\"/>", |
|
436 | 436 | " <stop id=\"stop3680\" offset=\"1\" style=\"stop-color:#b3b3b3;stop-opacity:0\"/>", |
|
437 | 437 | " </linearGradient>", |
|
438 | 438 | " <linearGradient id=\"linearGradient3236\">", |
|
439 | 439 | " <stop id=\"stop3244\" offset=\"0\" style=\"stop-color:#f4f4f4;stop-opacity:1\"/>", |
|
440 | 440 | " <stop id=\"stop3240\" offset=\"1\" style=\"stop-color:#ffffff;stop-opacity:1\"/>", |
|
441 | 441 | " </linearGradient>", |
|
442 | 442 | " <linearGradient id=\"linearGradient4671\">", |
|
443 | 443 | " <stop id=\"stop4673\" offset=\"0\" style=\"stop-color:#ffd43b;stop-opacity:1\"/>", |
|
444 | 444 | " <stop id=\"stop4675\" offset=\"1\" style=\"stop-color:#ffe873;stop-opacity:1\"/>", |
|
445 | 445 | " </linearGradient>", |
|
446 | 446 | " <linearGradient id=\"linearGradient4689\">", |
|
447 | 447 | " <stop id=\"stop4691\" offset=\"0\" style=\"stop-color:#5a9fd4;stop-opacity:1\"/>", |
|
448 | 448 | " <stop id=\"stop4693\" offset=\"1\" style=\"stop-color:#306998;stop-opacity:1\"/>", |
|
449 | 449 | " </linearGradient>", |
|
450 | 450 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2987\" x1=\"224.23996\" x2=\"-65.308502\" xlink:href=\"#linearGradient4671\" y1=\"144.75717\" y2=\"144.75717\"/>", |
|
451 | 451 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2990\" x1=\"172.94208\" x2=\"26.670298\" xlink:href=\"#linearGradient4689\" y1=\"77.475983\" y2=\"76.313133\"/>", |
|
452 | 452 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2587\" x1=\"172.94208\" x2=\"26.670298\" xlink:href=\"#linearGradient4689\" y1=\"77.475983\" y2=\"76.313133\"/>", |
|
453 | 453 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2589\" x1=\"224.23996\" x2=\"-65.308502\" xlink:href=\"#linearGradient4671\" y1=\"144.75717\" y2=\"144.75717\"/>", |
|
454 | 454 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2248\" x1=\"172.94208\" x2=\"26.670298\" xlink:href=\"#linearGradient4689\" y1=\"77.475983\" y2=\"76.313133\"/>", |
|
455 | 455 | " <linearGradient gradientTransform=\"translate(100.2702,99.61116)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2250\" x1=\"224.23996\" x2=\"-65.308502\" xlink:href=\"#linearGradient4671\" y1=\"144.75717\" y2=\"144.75717\"/>", |
|
456 | 456 | " <linearGradient gradientTransform=\"matrix(0.562541,0,0,0.567972,-11.5974,-7.60954)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2255\" x1=\"224.23996\" x2=\"-65.308502\" xlink:href=\"#linearGradient4671\" y1=\"144.75717\" y2=\"144.75717\"/>", |
|
457 | 457 | " <linearGradient gradientTransform=\"matrix(0.562541,0,0,0.567972,-11.5974,-7.60954)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient2258\" x1=\"172.94208\" x2=\"26.670298\" xlink:href=\"#linearGradient4689\" y1=\"76.176224\" y2=\"76.313133\"/>", |
|
458 | 458 | " <radialGradient cx=\"61.518883\" cy=\"132.28575\" fx=\"61.518883\" fy=\"132.28575\" gradientTransform=\"matrix(1,0,0,0.177966,0,108.7434)\" gradientUnits=\"userSpaceOnUse\" id=\"radialGradient2801\" r=\"29.036913\" xlink:href=\"#linearGradient2795\"/>", |
|
459 | 459 | " <linearGradient gradientTransform=\"matrix(0.562541,0,0,0.567972,-9.399749,-5.305317)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient1475\" x1=\"150.96111\" x2=\"112.03144\" xlink:href=\"#linearGradient4671\" y1=\"192.35176\" y2=\"137.27299\"/>", |
|
460 | 460 | " <linearGradient gradientTransform=\"matrix(0.562541,0,0,0.567972,-9.399749,-5.305317)\" gradientUnits=\"userSpaceOnUse\" id=\"linearGradient1478\" x1=\"26.648937\" x2=\"135.66525\" xlink:href=\"#linearGradient4689\" y1=\"20.603781\" y2=\"114.39767\"/>", |
|
461 | 461 | " <radialGradient cx=\"61.518883\" cy=\"132.28575\" fx=\"61.518883\" fy=\"132.28575\" gradientTransform=\"matrix(2.382716e-8,-0.296405,1.43676,4.683673e-7,-128.544,150.5202)\" gradientUnits=\"userSpaceOnUse\" id=\"radialGradient1480\" r=\"29.036913\" xlink:href=\"#linearGradient2795\"/>", |
|
462 | 462 | " </defs>", |
|
463 | 463 | " <g id=\"g2303\">", |
|
464 | 464 | " <path d=\"M 184.61344,61.929363 C 184.61344,47.367213 180.46118,39.891193 172.15666,39.481813 C 168.85239,39.325863 165.62611,39.852203 162.48754,41.070593 C 159.98254,41.967323 158.2963,42.854313 157.40931,43.751043 L 157.40931,78.509163 C 162.72147,81.842673 167.43907,83.392453 171.55234,83.148783 C 180.25649,82.573703 184.61344,75.507063 184.61344,61.929363 z M 194.85763,62.533683 C 194.85763,69.931723 193.12265,76.072393 189.63319,80.955683 C 185.7441,86.482283 180.35396,89.328433 173.46277,89.484393 C 168.26757,89.650093 162.91642,88.022323 157.40931,84.610843 L 157.40931,116.20116 L 148.50047,113.02361 L 148.50047,42.903043 C 149.96253,41.109583 151.84372,39.569543 154.12454,38.263433 C 159.42696,35.173603 165.86978,33.584823 173.45302,33.506853 L 173.57973,33.633563 C 180.50991,33.545833 185.85132,36.391993 189.60395,42.162263 C 193.10315,47.454933 194.85763,54.238913 194.85763,62.533683 z \" id=\"path46\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
465 | 465 | " <path d=\"M 249.30487,83.265743 C 249.30487,93.188283 248.31067,100.05998 246.32227,103.88084 C 244.32411,107.7017 240.52275,110.75254 234.90842,113.02361 C 230.35653,114.81707 225.43425,115.79178 220.15133,115.95748 L 218.67952,110.34316 C 224.05016,109.61213 227.83204,108.88109 230.02513,108.15006 C 234.34309,106.688 237.30621,104.44617 238.93397,101.44406 C 240.24008,98.997543 240.88339,94.328693 240.88339,87.418003 L 240.88339,85.098203 C 234.79146,87.866373 228.40711,89.240713 221.73036,89.240713 C 217.34417,89.240713 213.47457,87.866373 210.14107,85.098203 C 206.39818,82.086343 204.52674,78.265483 204.52674,73.635623 L 204.52674,36.557693 L 213.43558,33.506853 L 213.43558,70.828453 C 213.43558,74.815013 214.7222,77.885353 217.29543,80.039463 C 219.86866,82.193563 223.20217,83.226753 227.2862,83.148783 C 231.37023,83.061053 235.74667,81.482023 240.39603,78.392203 L 240.39603,34.851953 L 249.30487,34.851953 L 249.30487,83.265743 z \" id=\"path48\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
466 | 466 | " <path d=\"M 284.08249,88.997033 C 283.02006,89.084753 282.04535,89.123743 281.14862,89.123743 C 276.10937,89.123743 272.18129,87.924853 269.37413,85.517323 C 266.57671,83.109793 265.17314,79.786033 265.17314,75.546053 L 265.17314,40.456523 L 259.07146,40.456523 L 259.07146,34.851953 L 265.17314,34.851953 L 265.17314,19.968143 L 274.07223,16.800333 L 274.07223,34.851953 L 284.08249,34.851953 L 284.08249,40.456523 L 274.07223,40.456523 L 274.07223,75.302373 C 274.07223,78.645623 274.96896,81.014163 276.76243,82.398253 C 278.30247,83.538663 280.74899,84.191723 284.08249,84.357423 L 284.08249,88.997033 z \" id=\"path50\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
467 | 467 | " <path d=\"M 338.02288,88.266003 L 329.11404,88.266003 L 329.11404,53.878273 C 329.11404,50.379063 328.29528,47.367213 326.66753,44.852463 C 324.78634,42.006313 322.17411,40.583233 318.82112,40.583233 C 314.73708,40.583233 309.6296,42.737343 303.4987,47.045563 L 303.4987,88.266003 L 294.58985,88.266003 L 294.58985,6.0687929 L 303.4987,3.2616329 L 303.4987,40.700203 C 309.191,36.557693 315.40963,34.481563 322.16436,34.481563 C 326.88196,34.481563 330.70282,36.070333 333.62694,39.238143 C 336.56082,42.405943 338.02288,46.353513 338.02288,51.071103 L 338.02288,88.266003 L 338.02288,88.266003 z \" id=\"path52\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
468 | 468 | " <path d=\"M 385.37424,60.525783 C 385.37424,54.930953 384.31182,50.310833 382.19669,46.655673 C 379.68195,42.201253 375.77337,39.852203 370.49044,39.608523 C 360.72386,40.173863 355.85032,47.172273 355.85032,60.584263 C 355.85032,66.734683 356.86401,71.871393 358.91089,75.994413 C 361.52312,81.248093 365.44145,83.840823 370.66589,83.753103 C 380.47146,83.675123 385.37424,75.935933 385.37424,60.525783 z M 395.13109,60.584263 C 395.13109,68.547643 393.09395,75.175663 389.02941,80.468333 C 384.5555,86.394563 378.37584,89.367423 370.49044,89.367423 C 362.67328,89.367423 356.58135,86.394563 352.18541,80.468333 C 348.19885,75.175663 346.21044,68.547643 346.21044,60.584263 C 346.21044,53.098503 348.36455,46.801883 352.67276,41.674913 C 357.22466,36.236033 363.20937,33.506853 370.6074,33.506853 C 378.00545,33.506853 384.02914,36.236033 388.66877,41.674913 C 392.97697,46.801883 395.13109,53.098503 395.13109,60.584263 z \" id=\"path54\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
469 | 469 | " <path d=\"M 446.20583,88.266003 L 437.29699,88.266003 L 437.29699,51.928853 C 437.29699,47.942293 436.0981,44.832973 433.70032,42.591133 C 431.30253,40.359053 428.10549,39.277123 424.11893,39.364853 C 419.8887,39.442833 415.86314,40.826913 412.04229,43.507363 L 412.04229,88.266003 L 403.13345,88.266003 L 403.13345,42.405943 C 408.26042,38.672813 412.97801,36.236033 417.28621,35.095623 C 421.35076,34.033193 424.93769,33.506853 428.02752,33.506853 C 430.14264,33.506853 432.13104,33.711543 434.00248,34.120913 C 437.50169,34.929923 440.34783,36.430973 442.54093,38.633823 C 444.98744,41.070593 446.20583,43.994723 446.20583,47.415943 L 446.20583,88.266003 z \" id=\"path56\" style=\"fill:#646464;fill-opacity:1\"/>", |
|
470 | 470 | " <path d=\"M 60.510156,6.3979729 C 55.926503,6.4192712 51.549217,6.8101906 47.697656,7.4917229 C 36.35144,9.4962267 34.291407,13.691825 34.291406,21.429223 L 34.291406,31.647973 L 61.103906,31.647973 L 61.103906,35.054223 L 34.291406,35.054223 L 24.228906,35.054223 C 16.436447,35.054223 9.6131468,39.73794 7.4789058,48.647973 C 5.0170858,58.860939 4.9078907,65.233996 7.4789058,75.897973 C 9.3848341,83.835825 13.936449,89.491721 21.728906,89.491723 L 30.947656,89.491723 L 30.947656,77.241723 C 30.947656,68.391821 38.6048,60.585475 47.697656,60.585473 L 74.478906,60.585473 C 81.933857,60.585473 87.885159,54.447309 87.885156,46.960473 L 87.885156,21.429223 C 87.885156,14.162884 81.755176,8.7044455 74.478906,7.4917229 C 69.872919,6.7249976 65.093809,6.3766746 60.510156,6.3979729 z M 46.010156,14.616723 C 48.779703,14.616723 51.041406,16.915369 51.041406,19.741723 C 51.041404,22.558059 48.779703,24.835473 46.010156,24.835473 C 43.23068,24.835472 40.978906,22.558058 40.978906,19.741723 C 40.978905,16.91537 43.23068,14.616723 46.010156,14.616723 z \" id=\"path1948\" style=\"fill:url(#linearGradient1478);fill-opacity:1\"/>", |
|
471 | 471 | " <path d=\"M 91.228906,35.054223 L 91.228906,46.960473 C 91.228906,56.191228 83.403011,63.960472 74.478906,63.960473 L 47.697656,63.960473 C 40.361823,63.960473 34.291407,70.238956 34.291406,77.585473 L 34.291406,103.11672 C 34.291406,110.38306 40.609994,114.65704 47.697656,116.74172 C 56.184987,119.23733 64.323893,119.68835 74.478906,116.74172 C 81.229061,114.78733 87.885159,110.85411 87.885156,103.11672 L 87.885156,92.897973 L 61.103906,92.897973 L 61.103906,89.491723 L 87.885156,89.491723 L 101.29141,89.491723 C 109.08387,89.491723 111.98766,84.056315 114.69765,75.897973 C 117.49698,67.499087 117.37787,59.422197 114.69765,48.647973 C 112.77187,40.890532 109.09378,35.054223 101.29141,35.054223 L 91.228906,35.054223 z M 76.166406,99.710473 C 78.945884,99.710476 81.197656,101.98789 81.197656,104.80422 C 81.197654,107.63057 78.945881,109.92922 76.166406,109.92922 C 73.396856,109.92922 71.135156,107.63057 71.135156,104.80422 C 71.135158,101.98789 73.396853,99.710473 76.166406,99.710473 z \" id=\"path1950\" style=\"fill:url(#linearGradient1475);fill-opacity:1\"/>", |
|
472 | 472 | " <path d=\"M 463.5544,26.909383 L 465.11635,26.909383 L 465.11635,17.113143 L 468.81648,17.113143 L 468.81648,15.945483 L 459.85427,15.945483 L 459.85427,17.113143 L 463.5544,17.113143 L 463.5544,26.909383 M 470.20142,26.909383 L 471.53589,26.909383 L 471.53589,17.962353 L 474.4323,26.908259 L 475.91799,26.908259 L 478.93615,17.992683 L 478.93615,26.909383 L 480.39194,26.909383 L 480.39194,15.945483 L 478.46605,15.945483 L 475.16774,25.33834 L 472.35477,15.945483 L 470.20142,15.945483 L 470.20142,26.909383\" id=\"text3004\" style=\"font-size:15.16445827px;font-style:normal;font-weight:normal;line-height:125%;fill:#646464;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans\"/>", |
|
473 | 473 | " <path d=\"M 110.46717 132.28575 A 48.948284 8.6066771 0 1 1 12.570599,132.28575 A 48.948284 8.6066771 0 1 1 110.46717 132.28575 z\" id=\"path1894\" style=\"opacity:0.44382019;fill:url(#radialGradient1480);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:20;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\" transform=\"matrix(0.73406,0,0,0.809524,16.24958,27.00935)\"/>", |
|
474 | 474 | " </g>", |
|
475 | 475 | "</svg>" |
|
476 | 476 | ], |
|
477 | 477 | "text": [ |
|
478 | 478 | "<IPython.core.display.SVG at 0x41d4910>" |
|
479 | 479 | ] |
|
480 | 480 | } |
|
481 | 481 | ], |
|
482 | 482 | "prompt_number": 3 |
|
483 | 483 | }, |
|
484 | 484 | { |
|
485 | 485 | "cell_type": "markdown", |
|
486 | 486 | "source": [ |
|
487 | 487 | "#### Embedded vs Non-embedded Images" |
|
488 | 488 | ] |
|
489 | 489 | }, |
|
490 | 490 | { |
|
491 | 491 | "cell_type": "markdown", |
|
492 | 492 | "source": [ |
|
493 | 493 | "As of IPython 0.13, images are embedded by default for compatibility with QtConsole, and the ability to still be displayed offline.", |
|
494 | 494 | "", |
|
495 | 495 | "Let's look at the differences:" |
|
496 | 496 | ] |
|
497 | 497 | }, |
|
498 | 498 | { |
|
499 | 499 | "cell_type": "code", |
|
500 | 500 | "collapsed": false, |
|
501 | 501 | "input": [ |
|
502 | 502 | "# by default Image data are embedded", |
|
503 | 503 | "Embed = Image( 'http://www.google.fr/images/srpr/logo3w.png')", |
|
504 | 504 | "", |
|
505 | 505 | "# if kwarg `url` is given, the embedding is assumed to be false", |
|
506 | 506 | "SoftLinked = Image(url='http://www.google.fr/images/srpr/logo3w.png')", |
|
507 | 507 | "", |
|
508 | 508 | "# In each case, embed can be specified explicitly with the `embed` kwarg", |
|
509 | 509 | "# ForceEmbed = Image(url='http://www.google.fr/images/srpr/logo3w.png', embed=True)" |
|
510 | 510 | ], |
|
511 | 511 | "language": "python", |
|
512 | 512 | "outputs": [], |
|
513 | 513 | "prompt_number": 6 |
|
514 | 514 | }, |
|
515 | 515 | { |
|
516 | 516 | "cell_type": "markdown", |
|
517 | 517 | "source": [ |
|
518 | 518 | "Today's Google doodle, (at the time I created this notebook). This should also work in the Qtconsole.", |
|
519 | 519 | "Drawback is that the saved notebook will be larger, but the image will still be present offline." |
|
520 | 520 | ] |
|
521 | 521 | }, |
|
522 | 522 | { |
|
523 | 523 | "cell_type": "code", |
|
524 | 524 | "collapsed": false, |
|
525 | 525 | "input": [ |
|
526 | 526 | "Embed" |
|
527 | 527 | ], |
|
528 | 528 | "language": "python", |
|
529 | 529 | "outputs": [ |
|
530 | 530 | { |
|
531 | 531 | "jpeg": "/9j/2wBDAAMCAgICAgMCAgMFAwMDBQUEAwMEBQYFBQUFBQYIBgcHBwcGCAgJCgoKCQgMDAwMDAwO\nDg4ODhAQEBAQEBAQEBD/2wBDAQMEBAYGBgwICAwSDgwOEhQQEBAQFBEQEBAQEBEREBAQEBAQERAQ\nEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCADIAaoDAREAAhEBAxEB/8QAHQAAAQQDAQEA\nAAAAAAAAAAAAAAUGBwgDBAkBAv/EAE0QAAEDAwIEAwQGBgYIBQQDAAECAwQFBhEAEgcTITEIIkEU\nMlFhCRUjcYGRFkJyobHBM1JikrLRJCVDU4KiwuEXY3ODkxgmRKM0s8P/xAAUAQEAAAAAAAAAAAAA\nAAAAAAAA/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8A6p6A0BoDQGgNAaA0BoDQ\nGgNAaA0BoDQJdXqT0SbS4EfG+oPqbUr1S220t1RGf2caBJh8RbInVWVQYF2UmVUoLq48ynCZHMll\n5tW1SFtpc3JUD0IKdA4g9KwFcpKweoU2sHI/4gP46D32pI6ONuI/4CofmnOg9TMiqOA6nPwJwfyO\ngygg9R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mr0AKJLV/T1aUv9ktN/4EDQH6Nwlf00iU9+3Kex+QUBoPf0Wo\nBOXIaXT8XSpz/GToNhqiUdj+hgsI+YaR/loNpDLLfRtCU/cAP4aD70BoDQGgNAaA0BoDQGgNAaA0\nBoDQGgNAaA0BoDQGgNAaA0BoDQGgNAaA0BoDQJlzU52rW/UKawAXZDLjbee24jp+/QYI9SrYYbbF\nIc3pSkKU480gFQHXsVHvoMntNzOe7BjNftyVr/wtjQHLulfd6GyPk064fzK0/wANAfV1fWcuVcI+\nTUZsf4yvQBokpwYfq0pfx2Ftv/AgHQH6OQ1f00iU98lynsfkFDQAtW3wdyoSHD8XCpw/8xOg2WqJ\nRmP6GCwj5hpH+Wg2kMstjDaEp+4Afw0H3oDQGgNAaA0BoDQGgNAaA0BoDQGgNAaA0BoDQGgNAaA0\nBoDQGgNAaA0H/9k=\n", |
|
532 | 532 | "output_type": "pyout", |
|
533 | 533 | "prompt_number": 7, |
|
534 | 534 | "text": [ |
|
535 | 535 | "<IPython.core.display.Image at 0x107deaad0>" |
|
536 | 536 | ] |
|
537 | 537 | } |
|
538 | 538 | ], |
|
539 | 539 | "prompt_number": 7 |
|
540 | 540 | }, |
|
541 | 541 | { |
|
542 | 542 | "cell_type": "markdown", |
|
543 | 543 | "source": [ |
|
544 | 544 | "Today's Google doodle, visible only with an active internet connexion, that should be different from the previous one. This will not work on Qtconsole.", |
|
545 | 545 | "Notebook saved with this kind of image will be lighter and always reflect the current version of the source, but the image won't display offline." |
|
546 | 546 | ] |
|
547 | 547 | }, |
|
548 | 548 | { |
|
549 | 549 | "cell_type": "code", |
|
550 | 550 | "collapsed": false, |
|
551 | 551 | "input": [ |
|
552 | 552 | "SoftLinked" |
|
553 | 553 | ], |
|
554 | 554 | "language": "python", |
|
555 | 555 | "outputs": [ |
|
556 | 556 | { |
|
557 | 557 | "html": [ |
|
558 | 558 | "<img src=\"http://www.google.fr/images/srpr/logo3w.png\" />" |
|
559 | 559 | ], |
|
560 | 560 | "output_type": "pyout", |
|
561 | 561 | "prompt_number": 5, |
|
562 | 562 | "text": [ |
|
563 | 563 | "<IPython.core.display.Image at 0x107dea890>" |
|
564 | 564 | ] |
|
565 | 565 | } |
|
566 | 566 | ], |
|
567 | 567 | "prompt_number": 5 |
|
568 | 568 | }, |
|
569 | 569 | { |
|
570 | 570 | "cell_type": "markdown", |
|
571 | 571 | "source": [ |
|
572 | 572 | "Of course, if you re-run this notebook, the two doodles will be the same again.", |
|
573 | 573 | "<!-- well actually I cheated a little, by setting Embed Url to http://www.google.com/logos/2012/doisneau12-hp.jpg then editing the ipynb myself and replacing it by the other url -->" |
|
574 | 574 | ] |
|
575 | 575 | }, |
|
576 | 576 | { |
|
577 | 577 | "cell_type": "markdown", |
|
578 | 578 | "source": [ |
|
579 | 579 | "### Video" |
|
580 | 580 | ] |
|
581 | 581 | }, |
|
582 | 582 | { |
|
583 | 583 | "cell_type": "markdown", |
|
584 | 584 | "source": [ |
|
585 | 585 | "And more exotic objects can also be displayed, as long as their representation supports ", |
|
586 | 586 | "the IPython display protocol.", |
|
587 | 587 | "", |
|
588 | 588 | "For example, videos hosted externally on YouTube are easy to load (and writing a similar wrapper for other", |
|
589 | 589 | "hosted content is trivial):" |
|
590 | 590 | ] |
|
591 | 591 | }, |
|
592 | 592 | { |
|
593 | 593 | "cell_type": "code", |
|
594 | 594 | "collapsed": false, |
|
595 | 595 | "input": [ |
|
596 | 596 | "from IPython.lib.display import YouTubeVideo", |
|
597 | 597 | "# a talk about IPython at Sage Days at U. Washington, Seattle.", |
|
598 | 598 | "# Video credit: William Stein.", |
|
599 | 599 | "YouTubeVideo('1j_HxD4iLn8')" |
|
600 | 600 | ], |
|
601 | 601 | "language": "python", |
|
602 | 602 | "outputs": [ |
|
603 | 603 | { |
|
604 | 604 | "html": [ |
|
605 | 605 | "", |
|
606 | 606 | " <iframe", |
|
607 | 607 | " width=\"400\"", |
|
608 | 608 | " height=\"300\"", |
|
609 | 609 | " src=\"http://www.youtube.com/embed/1j_HxD4iLn8\"", |
|
610 | 610 | " frameborder=\"0\"", |
|
611 | 611 | " allowfullscreen", |
|
612 | 612 | " ></iframe>", |
|
613 | 613 | " " |
|
614 | 614 | ], |
|
615 | 615 | "output_type": "pyout", |
|
616 | 616 | "prompt_number": 4, |
|
617 | 617 | "text": [ |
|
618 | 618 | "<IPython.lib.display.YouTubeVideo at 0x41d4310>" |
|
619 | 619 | ] |
|
620 | 620 | } |
|
621 | 621 | ], |
|
622 | 622 | "prompt_number": 4 |
|
623 | 623 | }, |
|
624 | 624 | { |
|
625 | 625 | "cell_type": "markdown", |
|
626 | 626 | "source": [ |
|
627 | 627 | "Using the nascent video capabilities of modern browsers, you may also be able to display local", |
|
628 | 628 | "videos. At the moment this doesn't work very well in all browsers, so it may or may not work for you;", |
|
629 | 629 | "we will continue testing this and looking for ways to make it more robust. ", |
|
630 | 630 | "", |
|
631 | 631 | "The following cell loads a local file called `animation.m4v`, encodes the raw video as base64 for http", |
|
632 | 632 | "transport, and uses the HTML5 video tag to load it. On Chrome 15 it works correctly, displaying a control", |
|
633 | 633 | "bar at the bottom with a play/pause button and a location slider." |
|
634 | 634 | ] |
|
635 | 635 | }, |
|
636 | 636 | { |
|
637 | 637 | "cell_type": "code", |
|
638 | 638 | "collapsed": false, |
|
639 | 639 | "input": [ |
|
640 | 640 | "from IPython.core.display import HTML", |
|
641 | 641 | "video = open(\"animation.m4v\", \"rb\").read()", |
|
642 | 642 | "video_encoded = video.encode(\"base64\")", |
|
643 | 643 | "video_tag = '<video controls alt=\"test\" src=\"data:video/x-m4v;base64,{0}\">'.format(video_encoded)", |
|
644 | 644 | "HTML(data=video_tag)" |
|
645 | 645 | ], |
|
646 | 646 | "language": "python", |
|
647 | 647 | "outputs": [ |
|
648 | 648 | { |
|
649 | 649 | "html": [ |
|
650 | 650 | "<video controls alt=\"test\" src=\"data:video/x-m4v;base64,AAAAHGZ0eXBNNFYgAAACAGlzb21pc28yYXZjMQAAAAhmcmVlAAAqiW1kYXQAAAKMBgX//4jcRem9", |
|
651 | 651 | "5tlIt5Ys2CDZI+7veDI2NCAtIGNvcmUgMTE4IC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENv", |
|
652 | 652 | "cHlsZWZ0IDIwMDMtMjAxMSAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9w", |
|
653 | 653 | "dGlvbnM6IGNhYmFjPTEgcmVmPTMgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MzoweDExMyBtZT1o", |
|
654 | 654 | "ZXggc3VibWU9NyBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0xIG1lX3JhbmdlPTE2", |
|
655 | 655 | "IGNocm9tYV9tZT0xIHRyZWxsaXM9MSA4eDhkY3Q9MSBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0", |
|
656 | 656 | "X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0tMiB0aHJlYWRzPTEgc2xpY2VkX3RocmVhZHM9MCBu", |
|
657 | 657 | "cj0wIGRlY2ltYXRlPTEgaW50ZXJsYWNlZD0wIGJsdXJheV9jb21wYXQ9MCBjb25zdHJhaW5lZF9p", |
|
658 | 658 | "bnRyYT0wIGJmcmFtZXM9MyBiX3B5cmFtaWQ9MiBiX2FkYXB0PTEgYl9iaWFzPTAgZGlyZWN0PTEg", |
|
659 | 659 | "d2VpZ2h0Yj0xIG9wZW5fZ29wPTAgd2VpZ2h0cD0yIGtleWludD0yNTAga2V5aW50X21pbj0yNSBz", |
|
660 | 660 | "Y2VuZWN1dD00MCBpbnRyYV9yZWZyZXNoPTAgcmNfbG9va2FoZWFkPTQwIHJjPWNyZiBtYnRyZWU9", |
|
661 | 661 | "MSBjcmY9MjMuMCBxY29tcD0wLjYwIHFwbWluPTAgcXBtYXg9NjkgcXBzdGVwPTQgaXBfcmF0aW89", |
|
662 | 662 | "MS40MCBhcT0xOjEuMDAAgAAACqVliIQAV/0TAAI/3gU2tIW7KawwaCmQGTGHKmuYAAADACBcshU+", |
|
663 | 663 | "yICkgAA14AHowiEeT6ei7v7h3Hu0i2fpUBLGBIkbCMP3Vfz+9BVGCDXnw9Uv5o3iN030tb7eq6rs", |
|
664 | 664 | "EEhHs2azbdTiE9Csz5Zm6SiUWRdmB43hbD5i6syATuODUJd7LM3d9cbFpc7zFlu5y3vUmNGd6urp", |
|
665 | 665 | "vKKT9iyleIyTuR1sVS431DhevGfkUllVeIznYUe2USoMW1tufETjyRdmGldN6eNlhAOsGAH4z+Hk", |
|
666 | 666 | "rwKecPPU7Q5T4gDAIxj9hW84jVExMTSTHxkPTq1I4OotgUxURCGTsw60k/ezPNmNg38j1bqaGmPc", |
|
667 | 667 | "ruDKEIBDsK5qEytFB90Q68s0h2wmlf2KXd5bleBefiK+/p47ZsyUO4IdlW25rRy+HLjt6wQXfYee", |
|
668 | 668 | "3IkiQOoOK+U7u/lxcl78zfxwIoEMjUUSKNZjkp8clnmecDDJ3Kz+viF7bPklk7N6QRyizAKPIIpn", |
|
669 | 669 | "NJUuMWQmqeL2Or6cr4D0/0tOym+4tficxmhuEONKUtO2pPn3hRjMllkd12tXp70fLTfxy0dwB70M", |
|
670 | 670 | "L9iLEcItHb7zVupHlP5RxdvecpREw+OsIPr9KWilIesNE19jgIbT+TkiRBjOoKvUuwcQnKg7fOTH", |
|
671 | 671 | "VoLvnKuAfea+oujEdm1Rwd2tEOnkF+ZC11WaNQsiNR/eJ9EnUXjXDYGfhB+Oe7qj8nYTT+eOXg1c", |
|
672 | 672 | "uJNgLXEs4vOheWEjQOqfIWMQc3DmTof5s0ksBmUQ3PQ+UHPxZSnmOEZB+j6xT3wbm7HGzDjWtSg1", |
|
673 | 673 | "SjTxd1EiJ8xA4SIxxR8WIKLg+TwFxJNS7Laxq7Uglu3AkXe82P1JCdJX5PsbFbxuDbuJgakzRcTw", |
|
674 | 674 | "MLLSKCiizS/eCW0uJed/lev9yb80kKlVET4S219cn/zhkpeDV83cHYOr+sJQKDRk/Wh2c7fsuxfx", |
|
675 | 675 | "aEH/6reSmvFDsAnXAyPXliJ3G4VG3OkEM5K5WyGGrBizZbTrdGsBnzj5VSGGOJdCKuRrUluw/8es", |
|
676 | 676 | "2vYRPs9BcTqAqvHk9M52SSIf+1T6L53EZP8VbtXB+G29CMW4xVCK/B/YDjaNmqMwJ61dapugjnWJ", |
|
677 | 677 | "fqeXlGGa3Ch3aA7gi30T8PucNRBjLK3lF67ZDDvkWXRQXd+VMnKWHkBbCkQ/F/fMuNpHO3C00Y2p", |
|
678 | 678 | "ljna1qImBhVMvPe0F7Qx7G/YyxLRzhyUU8e23HGzp0agtNJRbydbrPV+TqJMSifJMNcZIf8wkdnC", |
|
679 | 679 | "3/xdpcXnLf2Ye3Kbd0o7utciTG+q5h6WTEk+PaNbXLLA0YyZ2VnLTcyV1QTS76aNCbV9Q1/OQ7QU", |
|
680 | 680 | "81Gg0hPa9aSiscGary6jLVwDQaik4zLsi7jPqgPVdup7pwx7uJDqRCVcVi5QoZFp/GHdex5sJTF6", |
|
681 | 681 | "9A6sja69/NLkFIWNSIeRcuGahXpF+wZeYIrqJv975s1TKYKAvp1WtzgtgWNkcbzCtROqf8rPtlAI", |
|
682 | 682 | "xkX8GLcEo9zfExyfimeXQ64qfFxEy0IMy2Hsxau9fSMqUnIjntuVVjCQtBL+94gx1RZLndE6wROV", |
|
683 | 683 | "Tq/wHwHrQzo9QL9cpPqPFJjiZ/NGZIFuudS+wsBFe6Hu8Oitf5zToLqLdtU4Smwh4ne3JsiT9lOz", |
|
684 | 684 | "N+4PPw3VSx9l5FppVwdKUWELw1dYpCOppyVWlJ3YQ8H4FQQM8EcYMG9N3Bxu79y1J1ikuvuhMmLQ", |
|
685 | 685 | "lehLTbguhbix74hd1VIQC8EjHmOZSSWbssulYwPbr6FF49tifk6PymJvulR9/u+2585HkRfbxveG", |
|
686 | 686 | "eWCz0ix1pIVfaNpESKmtLy/0mcbMg9hYDz2werz9oe0lT2BiMV6uAin6RaQcT8Vk9MPctfwae+gk", |
|
687 | 687 | "vtnZA/sOBk8MbpylaHqc0KIVHhhLFMNnkOFiucjtGo/JWTa/F6g8wWeow5ZuIJUORaYHWqegZbTg", |
|
688 | 688 | "M9dCsYYsfZGjjVMuSlDIvpYvIvFFooGPC7Ye2Jfawmq4Ut7EL/nv/dyAd2HRc5msmUhzeu/XpX3r", |
|
689 | 689 | "VlzRmf9/Qan8Dbve3QfW1Ym0o5J/KAc3z1VBho7JBr5PgCL68RiD9jZHN0VvsT4gzsEjNlW3D91U", |
|
690 | 690 | "y4RduaodBFoNTzXwlfUYULBzdiTbH75l/UmVMC4TKeTWhNzw2UezaqeGd8at3WSY7W/VR3+hvZHD", |
|
691 | 691 | "pkIjgKuNNH0DsCRa/Kk56XQoHIyvvUH/eNekNvziReqS4qgLnXUT4BRGt2BOtCifI6+X/DGHUOmW", |
|
692 | 692 | "lX7TN5b4pw5U7jwfwshtbhGZM49T8JMk15Mzrc7tM6J11TYxb5R3mQhZ8TZumJ0bMJXPM69HFyih", |
|
693 | 693 | "r5dJSEJMycxJVUh6NTQALUOoRTHIOwE+FpWI6feTv1SiZ0YpYe5DbkYJJbN7zAHbAKw25XvqR2mA", |
|
694 | 694 | "jQmOlsfX/tK8DPjP/8h5/xgAF4EUbj1tOnQCBQL8jk9vHtfsXncsprww4Z+P/Z/UrKifuFyEpBWN", |
|
695 | 695 | "8kLpF7yywE2iYdDruV9+/qKR8rC9ozNKyqQNIwtxrzYkWpE5t8K7gG4JFnrHona/Rp8dOX6VW41+", |
|
696 | 696 | "jb5LB1LEtE8MwjLp3RCUOq/+6yLzaOEgBTqzvEjDeFpg/u9DMHMr4/2TOchfjg7dl+uQ6Gsx+4Ia", |
|
697 | 697 | "9W7vivG95027p25eKL0nHvx/OqmAQEZYJL/JO58lOj0zPdJxrQ5dZksjMISzVZNn7DsxqE3zgBBu", |
|
698 | 698 | "Nzk50R8lTK3U8P12QiOAQYSTeGlYlkvfeofrfO1AitEj02m9aUkxTFd1ZZJoLQT2d3zEU5PmE4lx", |
|
699 | 699 | "MVfL5ttNnIbqfcIU2RJKNWqdw77xfjfrNc/eNpRKPZ/6z50LzBprgjzBHRfKgSWWkDxHrX0aTbgw", |
|
700 | 700 | "QFwd51+PoUWH4DkQg26uGslF5Hn3hB58+fkeLTosTANOIBNAeFZtTc4PIaLHw759zae7scY55xcT", |
|
701 | 701 | "abzlilYIftst2RZ6ntsRC3zFxduCKvL6wLfYT+TiIWJn5P7sTwZwXuSzXY+9Q3xMZ5o4Xcpz6vD9", |
|
702 | 702 | "FtTjzS69iefEYt4pXiDrZUo4ePGiLeoIFIwYB/v6GXdmG5VLLk+eKbOc9AmsX2zmvqtcvDRGQbzu", |
|
703 | 703 | "gXbH/kTH/lkNPBTmqN3ZJODUEXVohPEJ6th0xna0EVleB73Q3eNvaVUvhlJbjs3D/T17FRCebN7A", |
|
704 | 704 | "OXvzzbLE/I5kNfEmJcv4dxtIeo2uQ/z9ohSpiZzbDj1u40nJRyJxUK60wEv0nA9f/NuJ6/PEyU0b", |
|
705 | 705 | "kK16z2KH12k3Lc4+1f5fawIzkK2qJRB4wnj8VHhUW9mbJhs9vgfFmU3xrXSShY67Ygb+gYNPxxtn", |
|
706 | 706 | "4K/9eTSwIA9fv/nR33lA2lZoXALRUTmOZIl3R0gAM5h6oX1y1thIyqViBK95VZc8Pvy7G3O90M9S", |
|
707 | 707 | "4zkpyFQ36jrMazvMveMA4d39fvoaC7p90quiJfjI4yrl+ECVkCJL5MxRSa+iVcIL7Xbl0jVaGhZI", |
|
708 | 708 | "cMYmcGOBbLzhJgloM1x1zFnnj3ggJRFAM8yNnXxhavk+mA18JC+y3lqGsp6vPReRxGlGHMou17L4", |
|
709 | 709 | "It070LzkoeCzarpv8Apw59smdS5KN9qVN1WgeL7OSN8BHg94ubCvS7DW6H3/PbtRB62jFLsBhUV5", |
|
710 | 710 | "YqCIbIN5VZ81AAACpUGaIWxFfwAru8x8uT3FuOjrAeSWXmAWqq9jCNGE+N5AOv//9//xjk4uBAcA", |
|
711 | 711 | "DN96c97AVGmzRtnWwPsgcCbLrVdQJgbKp4QSmPwQnVhv0hXyBjeFWWlcvx70urEN3FK6/lvk2tQe", |
|
712 | 712 | "ZgbtlbzXluvTfnSj/Ctz7vZ+O1FjhDzzdpL7uLzewzCIW5VWLAEKUVuS2J6wNk6MR7UblcEd4EtO", |
|
713 | 713 | "Y+R4/qJgfojCsfRvA0oC5dc41Vd0erZbSkrmPTjLCn815bxlchUJMS8gQD5hJNwoKHvNLNwn7XKu", |
|
714 | 714 | "TtYIhH2wVNZvDWgzCjlPeQajnrcMsb6bZYJvNJU8HuGHvm50r7VG8qifEwmuyegAZXojh5Ul5Vvj", |
|
715 | 715 | "DW7kSAZyw8a7I6mHY3FZHd+OA3V4JZMbNliI3Tj1L6+MKTmilVialmyZagRtEMeKRdtxUPd3vVEt", |
|
716 | 716 | "rOBVIVYWdgAGA7HmZiHQUQNxLkWxbLyWVlrh5EM0Do2NdbclHxxArz90d+MSVeUOIXQ/4V9quq8C", |
|
717 | 717 | "8qVflo1gPtPMkjO2/UrdOYqhY404ReObOu/fdp4hAEDq6jhy64vOeT7XUK/Onq0rXTldtA6kvgQa", |
|
718 | 718 | "Jg+mgYSR9hfXtMbOUSLgLj/RmBSO8aAMHuJJZqf1tCM5pZ9eYUsrHmy+/z2NGalon0//uF6+33bQ", |
|
719 | 719 | "zT/RLRfBbYTjy9QrJqHLlw46lggWPGkHuPKSqk/CB7U4pNPXUbR0DdcJy9Db00wCzVzxVc6h7jfC", |
|
720 | 720 | "FgiL2Y0HVqd6bgIaVUqn/gJCEyCDVplnzebv0gg3XwMJAGu639lHu7rEvxTp1smIYjWp9R5L4Ssp", |
|
721 | 721 | "VvS07Nb+Smk1FgsMp1K3EMUT8X2Fty4VG54/Ec6bE8tNVw4/QV1VzBw7Px2/2eEhhUS+FMfbHAlD", |
|
722 | 722 | "28x00jRgAAACW0GaQjwhkymEVwArOUkEOhoFqiELtH8wgecFLiUq6WqmwAP7iGEwbYzfnHacfqUN", |
|
723 | 723 | "XAfD+CGR2ap0lAHL25ipuYtd5j2O0PU/MpaWPG/n2y5OkfTzaOpotaR5tWjN55B2XblVVqsFfBC/", |
|
724 | 724 | "mvsiPvCBWUHFChacdY5whj5mP5rqQ0dqLJCsWjrs4TWnIbL2V/Iwfj3hwI35jfo1JkTOeR+8GhOd", |
|
725 | 725 | "ma9rgiKWafCbQyhYMTDmVdvhND60Flm97EDSTjF0OC+0gD9b8Yn4tNeHipCa/aWyt0n79bMmjfcj", |
|
726 | 726 | "ntBCPjrcB5ecRTpfGHbEHy1IRj2cjkGXKC+VYoYJXBp4rd4cMd8ygLCk5nBSd8/cTaKNRjdBscOe", |
|
727 | 727 | "TXG6QEjSxj9/2pVwx9DMRVtWQR0BSaAcQcZ8W2KPSaeRC4QwmNMu2xx25CSyrDiq2rFSK/JJtmvo", |
|
728 | 728 | "IjAKq0ciEXoOgw+Ke+Ylb7ULKCS3k1p/613UNRp450uSq5b7CAHo7S0b7fBMLfNmwSjRYEhLlo0H", |
|
729 | 729 | "UaRe/I+IX2Z6XdZH9Hty/399ZA1PwZGC6EfvUJIf7CBeaxv7cu6IT2/s0zPRGthpvXpYw6A7P4Ww", |
|
730 | 730 | "z5C4V98KnIUNUanadqabKP6eXWhvbvcQHxAjiOOiKZgXZplZW2g+B2NNyJSLiR+g48DqvWR6t9S2", |
|
731 | 731 | "aGfFjdOW1Gi6oTtZ1d4p5XIslAr8mryeZ6+htSSQe4AcfVt7k+V6mOthBCYtr/LEU4ZHtl0mW987", |
|
732 | 732 | "6PK8mRFAaT8DJOUFVz1lPfzRApuPggkkyq+UMvyfKTUbCk7/DpfX8Y4s4QAAAg9BmmNJ4Q8mUwIr", |
|
733 | 733 | "/wAsWUPjZw3ksgRsxZ6n4fQjprPbkj2aUh30y0bZJnLmiXnWskvOGnCPwBnG9dEhatwX3hoxk7BN", |
|
734 | 734 | "yG+wQ4emZUpcVzcWl2T9nKQB1euucuZWHTg7TCtM/iHyfPO2vbmGsfzs70b/egIbywUH4y4BQSL1", |
|
735 | 735 | "nWc1SmpHm2zHMBcUjYLDZ5gL5vdfxn0V8FFw66G88c/LN4I5icUa7xf4fcSBKywU0ajbp1P+aJYj", |
|
736 | 736 | "BgWT6Ggu0MDLDNl54tfqd42lKosQtM1aif4WXAZFP5Ww3vrQ1rH9+utSYxqZd6N6gGtNbSNMcVia", |
|
737 | 737 | "Kn5LcnjsbBi3T3EmGqshEbcme8VHKwR3kSfBOAprrIsv6K8R+X6az+MD23rWka/2v64m1qM69D7X", |
|
738 | 738 | "a+Kcs/n0KLCJdTilyaGadopLeaAn3eYvWTeHcucMM1Fp1KgHD1tiFeO6HvobLkZlRximsA3/7Mio", |
|
739 | 739 | "hYklLIcJrZL22BH+6W9d6kZsYIsej9RM681nU6mWNjepBAfAfTbrGRrVB/h2DxC5B8YyRjgSIzQj", |
|
740 | 740 | "NYrse0rzChqbrsLl7mQ7W+1bsNKze5//9ZIa8rSsF+BXh/vgoRTDkPW/ws95B7VPCZEFChfX0icw", |
|
741 | 741 | "+tpcpN/q7NY87tUn4vESdSiMMlyhKklMjQu/G51J69ZRQLs2oUO6YfoJFqliy4qCFCrf8SZE9Fc6", |
|
742 | 742 | "DcCagAAAAodBmoRJ4Q8mUwIr/wArPWF/KOw78THwadfPqhJO0CnmR/M74/XYZLqVYKlNcEaYauf+", |
|
743 | 743 | "vrRUDJPmu75sMKy2Y+Bnslc/iAISSyWtw/h/3CF8fE5ZrbrwSNst+MSyCoNWP+8imtoX2eyojpdC", |
|
744 | 744 | "k8YP5K+cbK4SJPCkZXbYqSXYk7hO8AdSemBHgXKWiZ+UOr802aJo+98ZOIjX9hWL9bo31Gqx7cy4", |
|
745 | 745 | "ZG+W/ar/WGlzDa1xPWnPRsEdrIcZlEVGV/jGmbirkxw1lyUYoqj8Vv7Bxube9XPQlBkXOV6Lc1LT", |
|
746 | 746 | "2IzNq0V7WwVhF0kA6yxfAsFxc9krNEH8vGGntTWI608ovjatXc/CKKXw7AjJSftlTcLI0hIIGXbR", |
|
747 | 747 | "Ur0NCYNp7M4cVd/n73Rjetnixz4SAKpcz/P47UsijZG7T3SxzK2D79WS42aEalc12hQwCZ01LfmF", |
|
748 | 748 | "/H2mmGEvOzPBie1D0YT7Jh19vxa4Dd3SQ1FrDfmSUpvv4DjbYcZ2PrPpFpWtMjWqHBeoyMiZf6RP", |
|
749 | 749 | "3EfYR6z9jsVNIIHxM0bzzBQF8eeYkPgDySydxPXv9Izo+QUY94N8kWi16fI6eZSDc1G0Yo0L91jc", |
|
750 | 750 | "RQuDMGGS7B2zuf/0GbJyRhUO48UbMrqnILMrbQg1LF00Q3pH9nbGEK/RRQpRN3T/J/4IZQjwW2Ft", |
|
751 | 751 | "2ipWGztg1Jn9I4DmffKS60QC+JQcyakdVON6zDcKttIKlqeTcmAi4xzmo4QXa2dRKleS+fs3EtTd", |
|
752 | 752 | "BBtony2wK9T2Imj+NCziOSEL7Q7VuIU8kclUHrJJsSneFcxGRgIgGGUEQM8/pklwTOqab7mMmJeR", |
|
753 | 753 | "iaBrjJDEnDpkR4Vz3qXxgyn4/5x24FuTMNVPwQAAAhtBmqVJ4Q8mUwIr/wApcLwPT0/Xh9UdWqWX", |
|
754 | 754 | "Is8Wbj5K1hivmN6qIQnq+aolcegdlM/63MbHsdC6xYZC1e/Q8UjQCt9N/Ejqwms8DzeWv2qxskel", |
|
755 | 755 | "iZH0kt1QWkErWSEodq7V0ZNksctLkMGWayX33gBT368EehfIeGDolBZoqIbJfb4nqcfU+ev4OzVv", |
|
756 | 756 | "9zVqWyLck315GFmXxQKIM8pICQc8Q5es34LH1+DmnMnW8kQpVGrztQcDXhjCU3F0fOgoSsXSVWCj", |
|
757 | 757 | "c6XKqGbCwQDfJUxCfXfIT6YmQoPpVp1mpGy1wQypXus9z0bScDpyDu23hViYDntdj1O45ea0znKZ", |
|
758 | 758 | "kj1+tLHbBtqAGJ1WTcbGlF6Vya6hQhEsiiZUIC2fRxIj8/wEXCICIbr0gZ/m6gcOhE10tenvE7iy", |
|
759 | 759 | "+BKY81wLWrnzos3S6FWxYtmCRes+LLhNGOKWRuQo6SyePH2OZ90xZm8oA1MuTe3V59euVNxjAt0F", |
|
760 | 760 | "LkAc9TEiFhP/8CB+gA8mF+A8h1U01f4DVX55GzCH51jHI2xUS0L9GtsHoBxLPLK/NNel8zcnwG4X", |
|
761 | 761 | "+UusfcfEb5hh+ffnXteCE9vRGbs2n9wYW0xA3ZicklfadmWKUtMiHYBfkMSULWnkBQr4CXxjpYOs", |
|
762 | 762 | "6ygeEoA5+5B0B1SZObgZ42wWqddyyYE0NfwQAl75tfdJGqOa7OMHwBYNeatJaJK0zT2+bFaw2qWC", |
|
763 | 763 | "WwAAAitBmsZJ4Q8mUwIr/wAstkdsayRXchoFk703izqzduZ5WsyXriI9cfUdMUWvm0iGHwYIrUuj", |
|
764 | 764 | "vz3Yjou+JLwv9df2kt7MJo8u+3P5CjEKbwlz4vkE5AHTAbgXn3+Xc/MMJLgW5cm7iX3KiGNnBpbp", |
|
765 | 765 | "hhwJRlb3u91NRDr0d1IR2up/z7lKxE7XPAPFe0siPMYVlIqWNSn5KqLABPeuxxbOsvMEb27/nH1L", |
|
766 | 766 | "UVM8I2F95c1I3Lv1SpkhZXjs1JsmS9X7gsoTxkXyShGC2+zRJSGUbhCPo/q1XSFMHQyMWJ79FKPQ", |
|
767 | 767 | "SL/RpVsacN2bYwdKo4TFBw1SsKq/L1iOmqMI+4Gxnbbjojdk0ek0JIcDb4bHv1czxchF7FX1Ym8H", |
|
768 | 768 | "6IpPuE8CeNKjzQ1a1wqhEu+wl1N0x3Y37ZryCCKJRkxj0FT7bOoH3L38/yMUuh/v3aCmxY4eCkyk", |
|
769 | 769 | "b2p6ZrYMFE044anM/nMjmbErMibfRFuCz58Io1rBlF7JfkIz0R2/5vjUMVskcdbX2mm7DntncOsW", |
|
770 | 770 | "DIdg/XVmgsC9CzVzUyq4VsS/sk97lJggcddpWLNw/29egz8iLyzWHOAXCvl2fTIPkviYAOQXfVhZ", |
|
771 | 771 | "UQdxsyJUNFMTiALrZCmoQLMp2LmDbfbW8JQriDeR3fVz6P1sjT8C2yEDvzkCn7sh0aTBK+sx7BKH", |
|
772 | 772 | "1nb4320+caQepQj4TCJtCeNXjdrVcNEnjvwlcRJwFT1pT+Y7HREbHnT71XYNh4EAAAGEQZrnSeEP", |
|
773 | 773 | "JlMCK/8AKIjxcI58rm/ML255fOJW1zbznFna7lfgMQrka7OTPPsvVAV4EJXye/Uxiu9dlftmRypJ", |
|
774 | 774 | "qfDot3xwDe8lX/qAVf6pBkSlUsaLyBYtww/SUSa1bGl1JvrJCN7FXCCXbLd5R4PoYlPiDIm/DQH2", |
|
775 | 775 | "puO0StIWmrR77Isc/J1pRvdu5+mQa/n0SEHUeM2KkoRzCznfD9zaaRO7BDtvC9SYIT0uYZxrwTjx", |
|
776 | 776 | "Q7N7UERTrYG0P+vRLAhxkfohFIYl3HXyjPOvnlbUFP2oiiy6nkUFuaIyQcJawJv3GU8k4ObcKsC1", |
|
777 | 777 | "cNDXjSpsyQRrxLFaCCjke4mikyt7vs0iN0bnrNWv9HXruG9zOFEOer1ggIFTsT1Eos5CXRkgja5H", |
|
778 | 778 | "N4QUM6MhWpc5du/HgBIH8ANFcoo2kJpqcadw9r/0qk25X91MQSDJQiH8Hny2dQhqR+LFWEawiW75", |
|
779 | 779 | "3SJhn0ngZcv/mPj3mwcHv1SL9ErBqAjm4JGiDetPKYtFwANYY11OyQAAAVdBmwhJ4Q8mUwIr/wAr", |
|
780 | 780 | "Ox5HV2505jRePGgMxptW4PGIHEszV1xGZS+flSkF+aq30AaqO7u6XK9jJsuWXTfYCRQTn1bZfFQ2", |
|
781 | 781 | "2DbO5DXAxK/TUmbQleCflFzeS6/czxkL4PJ8AwOs2U+oehekgCZC8gZyHHaQSaKbNJ46gTjNsLy8", |
|
782 | 782 | "4ACQ5uNt11TPuCPqPTuh+schdw9S+/lU/6m+EyaqGZ49wDFPiBFBYXglQQBjyP9k/rqq0xL7SiLj", |
|
783 | 783 | "pe4riYg8SFUuUtOzPdWHyvxnI7Ug/0VLPGAAhgMISUnqe01d5QFf36yHpwMAHexjAZFIGQHAFaut", |
|
784 | 784 | "uMuEw6HzUZVzNdeHYxvEYOGkTo007bLwbuf/nxzrywGOxlRTYJLRdYI0mk0SdN3+LeTv1RIJwv21", |
|
785 | 785 | "+e9rT5iFOTCgzeQoekEWXLYz0X8YLq5bVCtijP7/T7w1Ck71j0aqfrEn6wtIAAABNUGbKUnhDyZT", |
|
786 | 786 | "Aiv/ACcySi7VBgOid6qZNXvhh/JsllHkMLLq0yNbQTqv/Wk2EBoSKICZwFwAD0WRzhvvReCGirep", |
|
787 | 787 | "1Fe4bxjm49/UR+OYrXRmHR18T0C83AUVeBk7KvDZmb/eHzuzEN4yfXucr/NWFJl+USVMY4r4UQ9C", |
|
788 | 788 | "ayrfEY9v6AQ6mzAdLy2UMfFxrRJ99g/Rfl8qx+m4jIZNjlrTaThzJ/3OpVmAliDfxVyg8+CVIlI3", |
|
789 | 789 | "1IykiwQrXcebgajG+av8XU1SfyAG5ibvwbtdSAxkGBcJWL387V+uTdY56w3KN2vBtoQpVKD2zb3y", |
|
790 | 790 | "azIcATZ02upwIytNcM/rpaLCdMb1myWcikE25agzLhDhOS+4zwjYz2DnW6VY0gFBAPsphhsUMnau", |
|
791 | 791 | "VVdUVHzCTSdvzEve/H8q4AAAAVdBm0pJ4Q8mUwIr/wAo+x5XKuiN1am7SkJKSMonFZDPU3f5XFcD", |
|
792 | 792 | "QSs0FLVq2idfsKwuIkt1mxIq8NgMHpzofTnDHqs/WedvAmhBgL0N5azdQa5MNKG2rJ4IAvGQY/uF", |
|
793 | 793 | "m3jKQAKzvhSS01gO1oIfizF817z9IShS4QK2WT0PeFPELqLSpED8eNOpVTR96vmwpk/WBKRVJdTQ", |
|
794 | 794 | "JzjiCQ5pgEwjtvk7KqoS0+lwXSbvIrXkYm8DignEts3DLNoLHrPjXlQmbIop76JZSyJEtB+91GrL", |
|
795 | 795 | "wo6Km5GeebyA2E6qGL3xSkpppej/ruoFprSKrH60UMbrq/SK7eCo+1QFoySPQmqDFsMGiQFqvtld", |
|
796 | 796 | "5BXDYdVI4yRaoyN7Y7wi83HRC6eVazuHU9OtIY3xJJApBWq1aJOsYwc38aTC3ee863Aa/4n9Lk4D", |
|
797 | 797 | "AtyFYHNZjB5m2e2vk8G2Gny9YFlBAAABQEGba0nhDyZTAiv/ACoZSZQfHxhfQxEqOBQrP+L3Dmgv", |
|
798 | 798 | "HSJQtB1iVkcLTxm+vagLHBLG91OGnopwrr7gT/loDypIhoRxjcwAAOeg/jN4WBbXzCJtnWGGllUC", |
|
799 | 799 | "SdtUZQzKOSp9iM4yX18C6jrY4Sq6R9PUV/lEGNveJR4gw4FMve7110XdEPL1O2VTdHvdqeANyaq0", |
|
800 | 800 | "nLdEmtXnrzvdrFlBaUvmaR4EdlkqGkvkZKWJej8Vq+msbKa7JdbxjwZtRufiyGfD/NVqMgSrYRzw", |
|
801 | 801 | "9z/a8Zwbr+9+19CxlWD5bCuAEfPmjY6kZJE2L/CQI6+tnCBTXOmWZtZMBoCLGOf7G2uAC3+kFlbo", |
|
802 | 802 | "h9as5WCkO6+iqXq29dyhKnsHInorRYsPlgxIXyU1Om/Kyhj1DJV0Am9WJK3Dln0zNUH0q6ZTOnZc", |
|
803 | 803 | "FD36AAABYkGbjEnhDyZTAiv/ACcwdIOLRFfoGK2ZkKsvgMwG0m0qsY0vMLPSzefc+ebp/aztyF7M", |
|
804 | 804 | "lsBz/fBeNtxFBcsKgR4pf65GvdfOMHah0ltZ918sMDmXUEZMeRHy/xpnWpTLeGz6uTs/7MATPmU5", |
|
805 | 805 | "BgHbT/DkD8QeaZnFAzidyFCXDz2l/jaKhEdgqipbB2pH0+fQ039r05z9axxEWGmaLQjg6x9+po1o", |
|
806 | 806 | "24yhkVO7m03YwWmPyCgy8cOwrvRyJkXJpRN4m8ZBS1zwY80HeN/VyMQQJSMwsTo7R1XMerSFuyx0", |
|
807 | 807 | "nz+8qOuhiqykc2ohCCsXia/+kIKbJ5Vs+cbWtvkqBKIDSfU7FhAd3GjcY/xar0EVmi6wWFTugAog", |
|
808 | 808 | "R3I7mTrQDdlTAqYgqO7Gn5NMXQVHu2i1zhFSdo9GjMbeGnbkJwsFbQ2XkoKRIDpuW7AewC9AEBt0", |
|
809 | 809 | "Ox/Ah6dGXfXO1jl8pEApj2RFmgAAAPlBm61J4Q8mUwIr/wAlR+eW/VZ7bSrmwwMA62G05DZ7p/5F", |
|
810 | 810 | "UugsSsQdonUq6abtbU5hjFr+I1lPgoiV5c3CkTQZS+K5zivdo+Ti2P4K90xXANp8dSMAu85uJIOC", |
|
811 | 811 | "Qn2TXbEnNDifLB+3V84ht5tj4lvTaZx317BcliV8D5v2zZQW8RO1mUbuJEBItst8E7hfE+ZXj7tf", |
|
812 | 812 | "DxNZPTvtpFyUv0fH1cTg1pr2VLy0d0zQLiA58dg+GkRvR1/hs2LyifBgHcj6eTWz0vsypVn9iPXR", |
|
813 | 813 | "H/unJ6i8cfFL69NO24tQ9QQB+nDFhoP2cRhkAvhHwn56n5PppBD/oxni2f8AAAE9QZvOSeEPJlMC", |
|
814 | 814 | "K/8AJjAXVGf+Kj2XNJnFeKC/gr7dJDTC2ngpd4WeAHlg04GuJKnn9hAmiECxxo9qM1IYMRiB85t6", |
|
815 | 815 | "gALnlm9sRqGmioyzAm18RJndc9Ah8RlpGzr+44a6ntRaPx0cIwNIWAA8buL2JP00dmfjNqEiAlCa", |
|
816 | 816 | "8OdV8FQxjp1vDXsGcAGF3Qbd62KEpkimeI3wH2nuXpbDHm8/ZKOR49s5ifUCkxCoJpfp43aC0lTz", |
|
817 | 817 | "h2NXpcfVw6h0QnK8G60R4ZAxOxaJB7c0nn8ixXSU2JVY24EtGMF53nxJnHfzUheewUfBOGYSxeo8", |
|
818 | 818 | "oK7oUCqX4rztzDwoc2QywNqQUJUkFrqIN+sb5ecYvX24Zujn+ZzTW6UDAF3R6WdNyJyRAremgC8s", |
|
819 | 819 | "pSflTqygQNGfHyGkfIEEJJaFo/pBCBkAAAEWQZvvSeEPJlMCK/8AKI41fuekXG59Knbw4Y6YJrit", |
|
820 | 820 | "sh9VtQgc3QKvVmxrzzo7f4aXn8N74eyP4b2lV1Z2Q+rohxps7EHTkOY9jLdqxI3MXe7je4g2qepz", |
|
821 | 821 | "71+hY+jYdX+9LO0kA0Zg3NfyAlIRX7k6c/YHAZNtNaGZgTBMqiPgmEjiJH9Luk7shbgr+srfwiYw", |
|
822 | 822 | "BX9rdS3fQNNFwcT8orQC+F60LAY9+GbFo2Sw3Ld4Tw9jq9yJtrY8RtHAdzytyek/mv2+j2TbTvAQ", |
|
823 | 823 | "KbbCYtdC8E/KtR4V5ZTSScr5Wb63vmbw7UpddEXYvl55pARyyvMxWNSh3Li4GF8Jk5JBi5B5ASQw", |
|
824 | 824 | "xCMYpX5hkAMc+d8tl2bT+IEvUTsAAAElQZoQSeEPJlMCK/8AJIAzFZs00JJ0yfm8CZiew4xWdArL", |
|
825 | 825 | "klEvBVXo/+ukPLu3XP9HFOfsme3T6BJEKmPPgZw/Lxnraq6Sl2kLVW19YU1qmqgfv+80LkZaWU5g", |
|
826 | 826 | "RAH4hqyo3bFYcbuY2SC3IW5Wm69gtYyAXOdbAYSEHA16fvCeRQjHEsxKVndJdrRAlrGHsKgUBQ3U", |
|
827 | 827 | "p/ZXIy1vkdFOfKSjpuZnswkuqr8NZI5tJ/dnBSErBTNWPaNwWV7nNomC0EYVGo+geGBhLXzaLw0U", |
|
828 | 828 | "AOCYGjiPc3803BDw1GLoLIXjrIFJxwRfBNIAXYZAglu30oYzhpAfRWSprkeULMWYJTlWvbUQ5CNe", |
|
829 | 829 | "wSZssuDWIRAc3w8AcFaywwn+YSGhtR8VI1OGjYkfBbcAAAD8QZoxSeEPJlMCK/8AJdokjCUETRw/", |
|
830 | 830 | "nciVPtaZQSBP/VxAQSITASEzlJBl9Na1r0DJhLOz279+KQLtl/xHZ8vAKc528mTMTqtWs4sFbeVg", |
|
831 | 831 | "HWyBpHcHEtgTzjIqEinp/MPuUXF5poo8YLSSMFn9Ozx2FbU5/Kh9A39oN9NHQflVxV1NA6yT/84H", |
|
832 | 832 | "HyfMtfdSMS8KTvAEE2lDs14VQayNs5ctjXboQT7xMBf5OLj6thhPvgaDrFB2o/PV9ouK147lruWT", |
|
833 | 833 | "P2mkoA9oDIMYW1pcBx4yyV/t9GOPZ3aXneMUb2fFmUCX43BjXfUDMaa4GO2/Ankj3UEQwDxA7ZlN", |
|
834 | 834 | "UQK2AAAA4UGaUknhDyZTAiv/ACJHv33I08bkhybYiJ/JiiheW5zMPBu4n5CxGr3frhE7TkLh0vPk", |
|
835 | 835 | "tM8m/AhaDiJisdk5QXNe/4WmxEDSAyaVi4eUVu0iHT2ly/KNTGqiORqA2oKpTjh84nYbrpXwnGv9", |
|
836 | 836 | "SOf/34Z06xN6Yo3t35UZrP8nlcs/63GtnEmnUwVZHBYfPM6bs5M5AeBfAQ/9mIqu7vnEst+5O2wp", |
|
837 | 837 | "PjzdItjwGCZ2ApHVjGnYYFomlA9nm6AXnxNIWHIsDgxCk3zx+6QbXipu/CWLG1Wf0WIbt4C0JPVl", |
|
838 | 838 | "3TEb0QAAAMlBmnNJ4Q8mUwIr/wAVV64OfTKmlktYOqZHH1W1DhPy/X/6sD4T6hRdzfOgNtTOX2Ic", |
|
839 | 839 | "kRJHshfBQVkJIzns079io6kpJFCcS3VD4zrWCn/dNaGV0kWTpFBRuusfn8F0C0R/EhsQeyTsdZft", |
|
840 | 840 | "EkLGb5tq+nrir3vfmeb7rjmWJRXkIrTEKu8pIuAd+4FBGp8ARgGe80Jqpp//s1433HqBFqXsIFJT", |
|
841 | 841 | "mU8j/toF9HyueI1Ea4uvsQ6NANGcYCbOAKCmbNiwABMCFaiUTMAAAAPSbW9vdgAAAGxtdmhkAAAA", |
|
842 | 842 | "AHwlsIB8JbCAAAAD6AAAAyAAAQAAAQAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAA", |
|
843 | 843 | "AAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAv10cmFrAAAAXHRraGQA", |
|
844 | 844 | "AAAPfCWwgHwlsIAAAAABAAAAAAAAAyAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAB", |
|
845 | 845 | "AAAAAAAAAAAAAAAAAABAAAAAAY4AAAGGAAAAAAAkZWR0cwAAABxlbHN0AAAAAAAAAAEAAAMgAAAA", |
|
846 | 846 | "AgABAAAAAAJ1bWRpYQAAACBtZGhkAAAAAHwlsIB8JbCAAAAAGQAAABRVxAAAAAAALWhkbHIAAAAA", |
|
847 | 847 | "AAAAAHZpZGUAAAAAAAAAAAAAAABWaWRlb0hhbmRsZXIAAAACIG1pbmYAAAAUdm1oZAAAAAEAAAAA", |
|
848 | 848 | "AAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAeBzdGJsAAAAtHN0c2QA", |
|
849 | 849 | "AAAAAAAAAQAAAKRhdmMxAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAY4BhgBIAAAASAAAAAAAAAAB", |
|
850 | 850 | "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGP//AAAAMmF2Y0MBZAAV/+EAGWdkABWs", |
|
851 | 851 | "2UGQz6mhAAADAAEAAAMAMg8WLZYBAAZo6+PLIsAAAAAcdXVpZGtoQPJfJE/FujmlG88DI/MAAAAA", |
|
852 | 852 | "AAAAGHN0dHMAAAAAAAAAAQAAABQAAAABAAAAFHN0c3MAAAAAAAAAAQAAAAEAAAAYY3R0cwAAAAAA", |
|
853 | 853 | "AAABAAAAFAAAAAIAAAAcc3RzYwAAAAAAAAABAAAAAQAAAAEAAAABAAAAZHN0c3oAAAAAAAAAAAAA", |
|
854 | 854 | "ABQAAA05AAACqQAAAl8AAAITAAACiwAAAh8AAAIvAAABiAAAAVsAAAE5AAABWwAAAUQAAAFmAAAA", |
|
855 | 855 | "/QAAAUEAAAEaAAABKQAAAQAAAADlAAAAzQAAAGBzdGNvAAAAAAAAABQAAAAsAAANZQAAEA4AABJt", |
|
856 | 856 | "AAAUgAAAFwsAABkqAAAbWQAAHOEAAB48AAAfdQAAINAAACIUAAAjegAAJHcAACW4AAAm0gAAJ/sA", |
|
857 | 857 | "ACj7AAAp4AAAAGF1ZHRhAAAAWW1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAA", |
|
858 | 858 | "AAAAAAAALGlsc3QAAAAkqXRvbwAAABxkYXRhAAAAAQAAAABMYXZmNTIuMTExLjA=", |
|
859 | 859 | "\">" |
|
860 | 860 | ], |
|
861 | 861 | "output_type": "pyout", |
|
862 | 862 | "prompt_number": 5, |
|
863 | 863 | "text": [ |
|
864 | 864 | "<IPython.core.display.HTML at 0x423a550>" |
|
865 | 865 | ] |
|
866 | 866 | } |
|
867 | 867 | ], |
|
868 | 868 | "prompt_number": 5 |
|
869 | 869 | }, |
|
870 | 870 | { |
|
871 | 871 | "cell_type": "markdown", |
|
872 | 872 | "source": [ |
|
873 | 873 | "## Local Files", |
|
874 | 874 | "", |
|
875 | 875 | "The above examples embed images and video from the notebook filesystem in the output", |
|
876 | 876 | "areas of code cells. It is also possible to request these files directly in markdown cells", |
|
877 | 877 | "if they reside in the notebook directory via relative urls prefixed with `files/`:", |
|
878 | 878 | "", |
|
879 | 879 | " files/[subdirectory/]<filename>", |
|
880 | 880 | "", |
|
881 | 881 | "", |
|
882 | 882 | "For example, in the example notebook folder, we have the Python logo, addressed as:", |
|
883 | 883 | "", |
|
884 | 884 | " <img src=\"files/python-logo.svg\" />", |
|
885 | 885 | "", |
|
886 | 886 | "<img src=\"/files/python-logo.svg\" />", |
|
887 | 887 | "", |
|
888 | 888 | "and a video with the HTML5 video tag:", |
|
889 | 889 | "", |
|
890 | 890 | " <video controls src=\"files/animation.m4v\" />", |
|
891 | 891 | "", |
|
892 | 892 | "<video controls src=\"/files/animation.m4v\" />", |
|
893 | 893 | "", |
|
894 | 894 | "These do not embed the data into the notebook file,", |
|
895 | 895 | "and require that the files exist when you are viewing the notebook.", |
|
896 | 896 | "", |
|
897 | 897 | "### Security of local files", |
|
898 | 898 | "", |
|
899 | 899 | "Note that this means that the IPython notebook server also acts as a generic file server", |
|
900 | 900 | "for files inside the same tree as your notebooks. Access is not granted outside the", |
|
901 | 901 | "notebook folder so you have strict control over what files are visible, but for this", |
|
902 | 902 | "reason it is highly recommended that you do not run the notebook server with a notebook", |
|
903 | 903 | "directory at a high level in your filesystem (e.g. your home directory).", |
|
904 | 904 | "", |
|
905 | 905 | "When you run the notebook in a password-protected manner, local file access is restricted", |
|
906 | 906 | "to authenticated users unless read-only views are active." |
|
907 | 907 | ] |
|
908 | 908 | }, |
|
909 | 909 | { |
|
910 | 910 | "cell_type": "markdown", |
|
911 | 911 | "source": [ |
|
912 | 912 | "### External sites", |
|
913 | 913 | "", |
|
914 | 914 | "You can even embed an entire page from another site in an iframe; for example this is today's Wikipedia", |
|
915 | 915 | "page for mobile users:" |
|
916 | 916 | ] |
|
917 | 917 | }, |
|
918 | 918 | { |
|
919 | 919 | "cell_type": "code", |
|
920 | 920 | "collapsed": false, |
|
921 | 921 | "input": [ |
|
922 | 922 | "HTML('<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350>')" |
|
923 | 923 | ], |
|
924 | 924 | "language": "python", |
|
925 | 925 | "outputs": [ |
|
926 | 926 | { |
|
927 | 927 | "html": [ |
|
928 | 928 | "<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350>" |
|
929 | 929 | ], |
|
930 | 930 | "output_type": "pyout", |
|
931 | 931 | "prompt_number": 6, |
|
932 | 932 | "text": [ |
|
933 | 933 | "<IPython.core.display.HTML at 0x41d4710>" |
|
934 | 934 | ] |
|
935 | 935 | } |
|
936 | 936 | ], |
|
937 | 937 | "prompt_number": 6 |
|
938 | 938 | }, |
|
939 | 939 | { |
|
940 | 940 | "cell_type": "markdown", |
|
941 | 941 | "source": [ |
|
942 | 942 | "### Mathematics", |
|
943 | 943 | "", |
|
944 | 944 | "And we also support the display of mathematical expressions typeset in LaTeX, which is rendered", |
|
945 | 945 | "in the browser thanks to the [MathJax library](http://mathjax.org). ", |
|
946 | 946 | "", |
|
947 | 947 | "Note that this is *different* from the above examples. Above we were typing mathematical expressions", |
|
948 | 948 | "in Markdown cells (along with normal text) and letting the browser render them; now we are displaying", |
|
949 | 949 | "the output of a Python computation as a LaTeX expression wrapped by the `Math()` object so the browser", |
|
950 | 950 | "renders it. The `Math` object will add the needed LaTeX delimiters (`$$`) if they are not provided:" |
|
951 | 951 | ] |
|
952 | 952 | }, |
|
953 | 953 | { |
|
954 | 954 | "cell_type": "code", |
|
955 | 955 | "collapsed": false, |
|
956 | 956 | "input": [ |
|
957 | 957 | "from IPython.core.display import Math", |
|
958 | 958 | "Math(r'F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx')" |
|
959 | 959 | ], |
|
960 | 960 | "language": "python", |
|
961 | 961 | "outputs": [ |
|
962 | 962 | { |
|
963 | 963 | "latex": [ |
|
964 | 964 | "$$F(k) = \\int_{-\\infty}^{\\infty} f(x) e^{2\\pi i k} dx$$" |
|
965 | 965 | ], |
|
966 | 966 | "output_type": "pyout", |
|
967 | 967 | "prompt_number": 1, |
|
968 | 968 | "text": [ |
|
969 | 969 | "<IPython.core.display.Math object at 0x10ad35e90>" |
|
970 | 970 | ] |
|
971 | 971 | } |
|
972 | 972 | ], |
|
973 | 973 | "prompt_number": 1 |
|
974 | 974 | }, |
|
975 | 975 | { |
|
976 | 976 | "cell_type": "markdown", |
|
977 | 977 | "source": [ |
|
978 | 978 | "With the `Latex` class, you have to include the delimiters yourself. This allows you to use other LaTeX modes such as `eqnarray`:" |
|
979 | 979 | ] |
|
980 | 980 | }, |
|
981 | 981 | { |
|
982 | 982 | "cell_type": "code", |
|
983 | 983 | "collapsed": false, |
|
984 | 984 | "input": [ |
|
985 | 985 | "from IPython.core.display import Latex", |
|
986 | 986 | "Latex(r\"\"\"\\begin{eqnarray}", |
|
987 | 987 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\", |
|
988 | 988 | "\\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\", |
|
989 | 989 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\", |
|
990 | 990 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 ", |
|
991 | 991 | "\\end{eqnarray}\"\"\")" |
|
992 | 992 | ], |
|
993 | 993 | "language": "python", |
|
994 | 994 | "outputs": [ |
|
995 | 995 | { |
|
996 | 996 | "latex": [ |
|
997 | 997 | "\\begin{eqnarray}", |
|
998 | 998 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\", |
|
999 | 999 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\", |
|
1000 | 1000 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 ", |
|
1001 | 1001 | "\\end{eqnarray}" |
|
1002 | 1002 | ], |
|
1003 | 1003 | "output_type": "pyout", |
|
1004 | 1004 | "prompt_number": 5, |
|
1005 | 1005 | "text": [ |
|
1006 | 1006 | "<IPython.core.display.Latex object at 0x109a38790>" |
|
1007 | 1007 | ] |
|
1008 | 1008 | } |
|
1009 | 1009 | ], |
|
1010 | 1010 | "prompt_number": 5 |
|
1011 | 1011 | }, |
|
1012 | 1012 | { |
|
1013 | 1013 | "cell_type": "markdown", |
|
1014 | 1014 | "source": [ |
|
1015 | 1015 | "# Loading external codes", |
|
1016 | 1016 | "* Drag and drop a ``.py`` in the dashboard", |
|
1017 |
"* Use ``%load |
|
|
1017 | "* Use ``%load`` with any local or remote url: [the Matplotlib Gallery!](http://matplotlib.sourceforge.net/gallery.html)", | |
|
1018 | 1018 | "", |
|
1019 | 1019 | "In this notebook we've kept the output saved so you can see the result, but you should run the next", |
|
1020 | 1020 | "cell yourself (with an active internet connection)." |
|
1021 | 1021 | ] |
|
1022 | 1022 | }, |
|
1023 | 1023 | { |
|
1024 | 1024 | "cell_type": "code", |
|
1025 | 1025 | "collapsed": true, |
|
1026 | 1026 | "input": [ |
|
1027 |
"%load |
|
|
1027 | "%load http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/integral_demo.py" | |
|
1028 | 1028 | ], |
|
1029 | 1029 | "language": "python", |
|
1030 | 1030 | "outputs": [], |
|
1031 | 1031 | "prompt_number": 8 |
|
1032 | 1032 | }, |
|
1033 | 1033 | { |
|
1034 | 1034 | "cell_type": "code", |
|
1035 | 1035 | "collapsed": false, |
|
1036 | 1036 | "input": [ |
|
1037 | 1037 | "#!/usr/bin/env python", |
|
1038 | 1038 | "", |
|
1039 | 1039 | "# implement the example graphs/integral from pyx", |
|
1040 | 1040 | "from pylab import *", |
|
1041 | 1041 | "from matplotlib.patches import Polygon", |
|
1042 | 1042 | "", |
|
1043 | 1043 | "def func(x):", |
|
1044 | 1044 | " return (x-3)*(x-5)*(x-7)+85", |
|
1045 | 1045 | "", |
|
1046 | 1046 | "ax = subplot(111)", |
|
1047 | 1047 | "", |
|
1048 | 1048 | "a, b = 2, 9 # integral area", |
|
1049 | 1049 | "x = arange(0, 10, 0.01)", |
|
1050 | 1050 | "y = func(x)", |
|
1051 | 1051 | "plot(x, y, linewidth=1)", |
|
1052 | 1052 | "", |
|
1053 | 1053 | "# make the shaded region", |
|
1054 | 1054 | "ix = arange(a, b, 0.01)", |
|
1055 | 1055 | "iy = func(ix)", |
|
1056 | 1056 | "verts = [(a,0)] + zip(ix,iy) + [(b,0)]", |
|
1057 | 1057 | "poly = Polygon(verts, facecolor='0.8', edgecolor='k')", |
|
1058 | 1058 | "ax.add_patch(poly)", |
|
1059 | 1059 | "", |
|
1060 | 1060 | "text(0.5 * (a + b), 30,", |
|
1061 | 1061 | " r\"$\\int_a^b f(x)\\mathrm{d}x$\", horizontalalignment='center',", |
|
1062 | 1062 | " fontsize=20)", |
|
1063 | 1063 | "", |
|
1064 | 1064 | "axis([0,10, 0, 180])", |
|
1065 | 1065 | "figtext(0.9, 0.05, 'x')", |
|
1066 | 1066 | "figtext(0.1, 0.9, 'y')", |
|
1067 | 1067 | "ax.set_xticks((a,b))", |
|
1068 | 1068 | "ax.set_xticklabels(('a','b'))", |
|
1069 | 1069 | "ax.set_yticks([])", |
|
1070 | 1070 | "show()" |
|
1071 | 1071 | ], |
|
1072 | 1072 | "language": "python", |
|
1073 | 1073 | "outputs": [ |
|
1074 | 1074 | { |
|
1075 | 1075 | "output_type": "display_data", |
|
1076 | 1076 | "png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAADzCAYAAAAl6cWdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VNXdx/HPZCU7CQQIgQSMICCBALILBUXrVjFU+xIp\nbvAgj7gUwSDUBYogFa1QsbhUK2KhSkUNIPpUiiwKQhDCmhAIYUsIexLINsnM88cAAmbPTG5u5vt+\nvfyDZOaenxK/+c2555xrmTx5sn3mzJmIiIjrWQ4cOGBv06aN0XWIiLgFi91utxtdhIiIu/AwugAR\nEXei0BURqUMKXRGROuRV0TctFktd1SEi0qCUd7uswtCt6I3uZurUqUydOtXoMkSkEnX1/2p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URqVMK3UrEx8fTo0cPbrrp\nJj7//HOjyxGRMmRkZBAbG2t0GVXi8kewm90HH3xAaGgoubm5DBo0iPj4eKNLEhETU6dbiX/961/c\nfPPN9O/fn/T0dLZv3250SSJSBpvNxqhRo+jYsSPTpk2jqKjI6JLKpNCtQHp6OvPnz2fJkiXs2LGD\ntm3bcvbsWaPLEpEy7Nmzh7vuuott27axfft2li9fbnRJZVLoViAzM5Pw8HDCwsL4/vvvSU5ONrok\nESlHSEgI8fHx+Pr6Mnz4cL7++mujSyqT5nQrcOONNxIdHU3Hjh3p3LkzQ4YMMbokETE5hW4lPvjg\nA6NLEJEqyMnJ4YsvvuD222/nk08+Yfjw4UaXVCZNL4iI6VksFjp06EBiYiJxcXF07tyZO++80+iy\nylTh2QsiIuJc6nRFROqQQldEpA4pdEVE6pBCV0TEyTZv3kzXrl0pKiri/PnzdO7cmd27dwO6kSYi\n4hIvvPAChYWFFBQU0Lp1ayZNmgQodEVEXMJqtXLDDTfg5+fHhg0bLj2J5/8B9qXioKa743wAAAAA\nSUVORK5CYII=\n" |
|
1077 | 1077 | } |
|
1078 | 1078 | ], |
|
1079 | 1079 | "prompt_number": 9 |
|
1080 | 1080 | }, |
|
1081 | 1081 | { |
|
1082 | 1082 | "cell_type": "code", |
|
1083 | 1083 | "collapsed": true, |
|
1084 | 1084 | "input": [ |
|
1085 | 1085 | "" |
|
1086 | 1086 | ], |
|
1087 | 1087 | "language": "python", |
|
1088 | 1088 | "outputs": [] |
|
1089 | 1089 | } |
|
1090 | 1090 | ] |
|
1091 | 1091 | } |
|
1092 | 1092 | ] |
|
1093 | 1093 | } |
@@ -1,31 +1,31 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Run this script in the qtconsole with one of: |
|
3 | 3 | |
|
4 |
%load |
|
|
4 | %load hb_gil.py | |
|
5 | 5 | |
|
6 | 6 | or |
|
7 | 7 | %run hb_gil.py |
|
8 | 8 | |
|
9 | 9 | Holding the GIL for too long could disrupt the heartbeat. |
|
10 | 10 | |
|
11 | 11 | See Issue #1260: https://github.com/ipython/ipython/issues/1260 |
|
12 | 12 | |
|
13 | 13 | """ |
|
14 | 14 | |
|
15 | 15 | import sys |
|
16 | 16 | import time |
|
17 | 17 | |
|
18 | 18 | from cython import inline |
|
19 | 19 | |
|
20 | 20 | def gilsleep(t): |
|
21 | 21 | """gil-holding sleep with cython.inline""" |
|
22 | 22 | code = '\n'.join([ |
|
23 | 23 | 'from posix cimport unistd', |
|
24 | 24 | 'unistd.sleep(t)', |
|
25 | 25 | ]) |
|
26 | 26 | while True: |
|
27 | 27 | inline(code, quiet=True, t=t) |
|
28 | 28 | print(time.time()) |
|
29 | 29 | sys.stdout.flush() # this is important |
|
30 | 30 | |
|
31 | 31 | gilsleep(5) |
@@ -1,609 +1,609 b'' | |||
|
1 | 1 | .. _qtconsole: |
|
2 | 2 | |
|
3 | 3 | ========================= |
|
4 | 4 | A Qt Console for IPython |
|
5 | 5 | ========================= |
|
6 | 6 | |
|
7 | 7 | We now have a version of IPython, using the new two-process :ref:`ZeroMQ Kernel |
|
8 | 8 | <ipythonzmq>`, running in a PyQt_ GUI. This is a very lightweight widget that |
|
9 | 9 | largely feels like a terminal, but provides a number of enhancements only |
|
10 | 10 | possible in a GUI, such as inline figures, proper multiline editing with syntax |
|
11 | 11 | highlighting, graphical calltips, and much more. |
|
12 | 12 | |
|
13 | 13 | .. figure:: ../_static/qtconsole.png |
|
14 | 14 | :width: 400px |
|
15 | 15 | :alt: IPython Qt console with embedded plots |
|
16 | 16 | :align: center |
|
17 | 17 | :target: ../_static/qtconsole.png |
|
18 | 18 | |
|
19 | 19 | The Qt console for IPython, using inline matplotlib plots. |
|
20 | 20 | |
|
21 | 21 | To get acquainted with the Qt console, type `%guiref` to see a quick |
|
22 | 22 | introduction of its main features. |
|
23 | 23 | |
|
24 | 24 | The Qt frontend has hand-coded emacs-style bindings for text navigation. This |
|
25 | 25 | is not yet configurable. |
|
26 | 26 | |
|
27 | 27 | .. tip:: |
|
28 | 28 | |
|
29 | 29 | Since the Qt console tries hard to behave like a terminal, by default it |
|
30 | 30 | immediately executes single lines of input that are complete. If you want |
|
31 | 31 | to force multiline input, hit :kbd:`Ctrl-Enter` at the end of the first line |
|
32 | 32 | instead of :kbd:`Enter`, and it will open a new line for input. At any |
|
33 | 33 | point in a multiline block, you can force its execution (without having to |
|
34 | 34 | go to the bottom) with :kbd:`Shift-Enter`. |
|
35 | 35 | |
|
36 |
``%load |
|
|
37 |
========= |
|
|
36 | ``%load`` | |
|
37 | ========= | |
|
38 | 38 | |
|
39 | The new ``%loadpy`` magic takes any python script (must end in '.py'), and | |
|
40 |
|
|
|
41 |
|
|
|
42 |
and it will download the script from the web. This is particularly useful |
|
|
43 | playing with examples from documentation, such as matplotlib. | |
|
39 | The new ``%load`` magic (previously ``%loadpy``) takes any script, and pastes | |
|
40 | its contents as your next input, so you can edit it before executing. The | |
|
41 | script may be on your machine, but you can also specify an history range, or a | |
|
42 | url, and it will download the script from the web. This is particularly useful | |
|
43 | for playing with examples from documentation, such as matplotlib. | |
|
44 | 44 | |
|
45 | 45 | .. sourcecode:: ipython |
|
46 | 46 | |
|
47 |
In [6]: %load |
|
|
47 | In [6]: %load http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/contour3d_demo.py | |
|
48 | 48 | |
|
49 | 49 | In [7]: from mpl_toolkits.mplot3d import axes3d |
|
50 | 50 | ...: import matplotlib.pyplot as plt |
|
51 | 51 | ...: |
|
52 | 52 | ...: fig = plt.figure() |
|
53 | 53 | ...: ax = fig.add_subplot(111, projection='3d') |
|
54 | 54 | ...: X, Y, Z = axes3d.get_test_data(0.05) |
|
55 | 55 | ...: cset = ax.contour(X, Y, Z) |
|
56 | 56 | ...: ax.clabel(cset, fontsize=9, inline=1) |
|
57 | 57 | ...: |
|
58 | 58 | ...: plt.show() |
|
59 | 59 | |
|
60 | 60 | Pylab |
|
61 | 61 | ===== |
|
62 | 62 | |
|
63 | 63 | One of the most exciting features of the new console is embedded matplotlib |
|
64 | 64 | figures. You can use any standard matplotlib GUI backend |
|
65 | 65 | to draw the figures, and since there is now a two-process model, there is no |
|
66 | 66 | longer a conflict between user input and the drawing eventloop. |
|
67 | 67 | |
|
68 | 68 | .. image:: figs/besselj.png |
|
69 | 69 | :width: 519px |
|
70 | 70 | |
|
71 | 71 | .. display: |
|
72 | 72 | |
|
73 | 73 | :func:`display` |
|
74 | 74 | *************** |
|
75 | 75 | |
|
76 | 76 | An additional function, :func:`display`, will be added to the global namespace |
|
77 | 77 | if you specify the ``--pylab`` option at the command line. The IPython display |
|
78 | 78 | system provides a mechanism for specifying PNG or SVG (and more) |
|
79 | 79 | representations of objects for GUI frontends. By default, IPython registers |
|
80 | 80 | convenient PNG and SVG renderers for matplotlib figures, so you can embed them |
|
81 | 81 | in your document by calling :func:`display` on one or more of them. This is |
|
82 | 82 | especially useful for saving_ your work. |
|
83 | 83 | |
|
84 | 84 | .. sourcecode:: ipython |
|
85 | 85 | |
|
86 | 86 | In [5]: plot(range(5)) # plots in the matplotlib window |
|
87 | 87 | |
|
88 | 88 | In [6]: display(gcf()) # embeds the current figure in the qtconsole |
|
89 | 89 | |
|
90 | 90 | In [7]: display(*getfigs()) # embeds all active figures in the qtconsole |
|
91 | 91 | |
|
92 | 92 | If you have a reference to a matplotlib figure object, you can always display |
|
93 | 93 | that specific figure: |
|
94 | 94 | |
|
95 | 95 | .. sourcecode:: ipython |
|
96 | 96 | |
|
97 | 97 | In [1]: f = figure() |
|
98 | 98 | |
|
99 | 99 | In [2]: plot(rand(100)) |
|
100 | 100 | Out[2]: [<matplotlib.lines.Line2D at 0x7fc6ac03dd90>] |
|
101 | 101 | |
|
102 | 102 | In [3]: display(f) |
|
103 | 103 | |
|
104 | 104 | # Plot is shown here |
|
105 | 105 | |
|
106 | 106 | In [4]: title('A title') |
|
107 | 107 | Out[4]: <matplotlib.text.Text at 0x7fc6ac023450> |
|
108 | 108 | |
|
109 | 109 | In [5]: display(f) |
|
110 | 110 | |
|
111 | 111 | # Updated plot with title is shown here. |
|
112 | 112 | |
|
113 | 113 | .. _inline: |
|
114 | 114 | |
|
115 | 115 | ``--pylab=inline`` |
|
116 | 116 | ****************** |
|
117 | 117 | |
|
118 | 118 | If you want to have all of your figures embedded in your session, instead of |
|
119 | 119 | calling :func:`display`, you can specify ``--pylab=inline`` when you start the |
|
120 | 120 | console, and each time you make a plot, it will show up in your document, as if |
|
121 | 121 | you had called :func:`display(fig)`. |
|
122 | 122 | |
|
123 | 123 | The inline backend can use either SVG or PNG figures (PNG being the default). |
|
124 | 124 | To switch between them, set the ``InlineBackend.figure_format`` configurable |
|
125 | 125 | in a config file, or via the ``%config`` magic: |
|
126 | 126 | |
|
127 | 127 | .. sourcecode:: ipython |
|
128 | 128 | |
|
129 | 129 | In [10]: %config InlineBackend.figure_format = 'svg' |
|
130 | 130 | |
|
131 | 131 | .. note:: |
|
132 | 132 | |
|
133 | 133 | Changing the inline figure format also affects calls to :func:`display` above, |
|
134 | 134 | even if you are not using the inline backend for all figures. |
|
135 | 135 | |
|
136 | 136 | By default, IPython closes all figures at the completion of each execution. This means you |
|
137 | 137 | don't have to manually close figures, which is less convenient when figures aren't attached |
|
138 | 138 | to windows with an obvious close button. It also means that the first matplotlib call in |
|
139 | 139 | each cell will always create a new figure: |
|
140 | 140 | |
|
141 | 141 | .. sourcecode:: ipython |
|
142 | 142 | |
|
143 | 143 | In [11]: plot(range(100)) |
|
144 | 144 | <single-line plot> |
|
145 | 145 | |
|
146 | 146 | In [12]: plot([1,3,2]) |
|
147 | 147 | <another single-line plot> |
|
148 | 148 | |
|
149 | 149 | |
|
150 | 150 | However, it does prevent the list of active figures surviving from one input cell to the |
|
151 | 151 | next, so if you want to continue working with a figure, you must hold on to a reference to |
|
152 | 152 | it: |
|
153 | 153 | |
|
154 | 154 | .. sourcecode:: ipython |
|
155 | 155 | |
|
156 | 156 | In [11]: fig = gcf() |
|
157 | 157 | ....: fig.plot(rand(100)) |
|
158 | 158 | <plot> |
|
159 | 159 | In [12]: fig.title('Random Title') |
|
160 | 160 | <redraw plot with title> |
|
161 | 161 | |
|
162 | 162 | This behavior is controlled by the :attr:`InlineBackend.close_figures` configurable, and |
|
163 | 163 | if you set it to False, via %config or config file, then IPython will *not* close figures, |
|
164 | 164 | and tools like :func:`gcf`, :func:`gca`, :func:`getfigs` will behave the same as they |
|
165 | 165 | do with other backends. You will, however, have to manually close figures: |
|
166 | 166 | |
|
167 | 167 | .. sourcecode:: ipython |
|
168 | 168 | |
|
169 | 169 | # close all active figures: |
|
170 | 170 | In [13]: [ fig.close() for fig in getfigs() ] |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | |
|
174 | 174 | .. _saving: |
|
175 | 175 | |
|
176 | 176 | Saving and Printing |
|
177 | 177 | =================== |
|
178 | 178 | |
|
179 | 179 | IPythonQt has the ability to save your current session, as either HTML or |
|
180 | 180 | XHTML. If you have been using :func:`display` or inline_ pylab, your figures |
|
181 | 181 | will be PNG in HTML, or inlined as SVG in XHTML. PNG images have the option to |
|
182 | 182 | be either in an external folder, as in many browsers' "Webpage, Complete" |
|
183 | 183 | option, or inlined as well, for a larger, but more portable file. |
|
184 | 184 | |
|
185 | 185 | .. note:: |
|
186 | 186 | |
|
187 | 187 | Export to SVG+XHTML requires that you are using SVG figures, which is *not* |
|
188 | 188 | the default. To switch the inline figure format to use SVG during an active |
|
189 | 189 | session, do: |
|
190 | 190 | |
|
191 | 191 | .. sourcecode:: ipython |
|
192 | 192 | |
|
193 | 193 | In [10]: %config InlineBackend.figure_format = 'svg' |
|
194 | 194 | |
|
195 | 195 | Or, you can add the same line (c.Inline... instead of %config Inline...) to |
|
196 | 196 | your config files. |
|
197 | 197 | |
|
198 | 198 | This will only affect figures plotted after making this call |
|
199 | 199 | |
|
200 | 200 | |
|
201 | 201 | The widget also exposes the ability to print directly, via the default print |
|
202 | 202 | shortcut or context menu. |
|
203 | 203 | |
|
204 | 204 | |
|
205 | 205 | .. Note:: |
|
206 | 206 | |
|
207 | 207 | Saving is only available to richtext Qt widgets, which are used by default, |
|
208 | 208 | but if you pass the ``--plain`` flag, saving will not be available to you. |
|
209 | 209 | |
|
210 | 210 | |
|
211 | 211 | See these examples of :download:`png/html<figs/jn.html>` and |
|
212 | 212 | :download:`svg/xhtml <figs/jn.xhtml>` output. Note that syntax highlighting |
|
213 | 213 | does not survive export. This is a known issue, and is being investigated. |
|
214 | 214 | |
|
215 | 215 | |
|
216 | 216 | Colors and Highlighting |
|
217 | 217 | ======================= |
|
218 | 218 | |
|
219 | 219 | Terminal IPython has always had some coloring, but never syntax |
|
220 | 220 | highlighting. There are a few simple color choices, specified by the ``colors`` |
|
221 | 221 | flag or ``%colors`` magic: |
|
222 | 222 | |
|
223 | 223 | * LightBG for light backgrounds |
|
224 | 224 | * Linux for dark backgrounds |
|
225 | 225 | * NoColor for a simple colorless terminal |
|
226 | 226 | |
|
227 | 227 | The Qt widget has full support for the ``colors`` flag used in the terminal shell. |
|
228 | 228 | |
|
229 | 229 | The Qt widget, however, has full syntax highlighting as you type, handled by |
|
230 | 230 | the `pygments`_ library. The ``style`` argument exposes access to any style by |
|
231 | 231 | name that can be found by pygments, and there are several already |
|
232 | 232 | installed. The ``colors`` argument, if unspecified, will be guessed based on |
|
233 | 233 | the chosen style. Similarly, there are default styles associated with each |
|
234 | 234 | ``colors`` option. |
|
235 | 235 | |
|
236 | 236 | |
|
237 | 237 | Screenshot of ``ipython qtconsole --colors=linux``, which uses the 'monokai' |
|
238 | 238 | theme by default: |
|
239 | 239 | |
|
240 | 240 | .. image:: figs/colors_dark.png |
|
241 | 241 | :width: 627px |
|
242 | 242 | |
|
243 | 243 | .. Note:: |
|
244 | 244 | |
|
245 | 245 | Calling ``ipython qtconsole -h`` will show all the style names that |
|
246 | 246 | pygments can find on your system. |
|
247 | 247 | |
|
248 | 248 | You can also pass the filename of a custom CSS stylesheet, if you want to do |
|
249 | 249 | your own coloring, via the ``stylesheet`` argument. The default LightBG |
|
250 | 250 | stylesheet: |
|
251 | 251 | |
|
252 | 252 | .. sourcecode:: css |
|
253 | 253 | |
|
254 | 254 | QPlainTextEdit, QTextEdit { background-color: white; |
|
255 | 255 | color: black ; |
|
256 | 256 | selection-background-color: #ccc} |
|
257 | 257 | .error { color: red; } |
|
258 | 258 | .in-prompt { color: navy; } |
|
259 | 259 | .in-prompt-number { font-weight: bold; } |
|
260 | 260 | .out-prompt { color: darkred; } |
|
261 | 261 | .out-prompt-number { font-weight: bold; } |
|
262 | 262 | |
|
263 | 263 | Fonts |
|
264 | 264 | ===== |
|
265 | 265 | |
|
266 | 266 | The QtConsole has configurable via the ConsoleWidget. To change these, set the |
|
267 | 267 | ``font_family`` or ``font_size`` traits of the ConsoleWidget. For instance, to |
|
268 | 268 | use 9pt Anonymous Pro:: |
|
269 | 269 | |
|
270 | 270 | $> ipython qtconsole --ConsoleWidget.font_family="Anonymous Pro" --ConsoleWidget.font_size=9 |
|
271 | 271 | |
|
272 | 272 | Process Management |
|
273 | 273 | ================== |
|
274 | 274 | |
|
275 | 275 | With the two-process ZMQ model, the frontend does not block input during |
|
276 | 276 | execution. This means that actions can be taken by the frontend while the |
|
277 | 277 | Kernel is executing, or even after it crashes. The most basic such command is |
|
278 | 278 | via 'Ctrl-.', which restarts the kernel. This can be done in the middle of a |
|
279 | 279 | blocking execution. The frontend can also know, via a heartbeat mechanism, that |
|
280 | 280 | the kernel has died. This means that the frontend can safely restart the |
|
281 | 281 | kernel. |
|
282 | 282 | |
|
283 | 283 | .. _multiple_consoles: |
|
284 | 284 | |
|
285 | 285 | Multiple Consoles |
|
286 | 286 | ***************** |
|
287 | 287 | |
|
288 | 288 | Since the Kernel listens on the network, multiple frontends can connect to it. |
|
289 | 289 | These do not have to all be qt frontends - any IPython frontend can connect and |
|
290 | 290 | run code. When you start ipython qtconsole, there will be an output line, |
|
291 | 291 | like:: |
|
292 | 292 | |
|
293 | 293 | [IPKernelApp] To connect another client to this kernel, use: |
|
294 | 294 | [IPKernelApp] --existing kernel-12345.json |
|
295 | 295 | |
|
296 | 296 | Other frontends can connect to your kernel, and share in the execution. This is |
|
297 | 297 | great for collaboration. The ``--existing`` flag means connect to a kernel |
|
298 | 298 | that already exists. Starting other consoles |
|
299 | 299 | with that flag will not try to start their own kernel, but rather connect to |
|
300 | 300 | yours. :file:`kernel-12345.json` is a small JSON file with the ip, port, and |
|
301 | 301 | authentication information necessary to connect to your kernel. By default, this file |
|
302 | 302 | will be in your default profile's security directory. If it is somewhere else, |
|
303 | 303 | the output line will print the full path of the connection file, rather than |
|
304 | 304 | just its filename. |
|
305 | 305 | |
|
306 | 306 | If you need to find the connection info to send, and don't know where your connection file |
|
307 | 307 | lives, there are a couple of ways to get it. If you are already running an IPython console |
|
308 | 308 | connected to the kernel, you can use the ``%connect_info`` magic to display the information |
|
309 | 309 | necessary to connect another frontend to the kernel. |
|
310 | 310 | |
|
311 | 311 | .. sourcecode:: ipython |
|
312 | 312 | |
|
313 | 313 | In [2]: %connect_info |
|
314 | 314 | { |
|
315 | 315 | "stdin_port":50255, |
|
316 | 316 | "ip":"127.0.0.1", |
|
317 | 317 | "hb_port":50256, |
|
318 | 318 | "key":"70be6f0f-1564-4218-8cda-31be40a4d6aa", |
|
319 | 319 | "shell_port":50253, |
|
320 | 320 | "iopub_port":50254 |
|
321 | 321 | } |
|
322 | 322 | |
|
323 | 323 | Paste the above JSON into a file, and connect with: |
|
324 | 324 | $> ipython <app> --existing <file> |
|
325 | 325 | or, if you are local, you can connect with just: |
|
326 | 326 | $> ipython <app> --existing kernel-12345.json |
|
327 | 327 | or even just: |
|
328 | 328 | $> ipython <app> --existing |
|
329 | 329 | if this is the most recent IPython session you have started. |
|
330 | 330 | |
|
331 | 331 | Otherwise, you can find a connection file by name (and optionally profile) with |
|
332 | 332 | :func:`IPython.lib.kernel.find_connection_file`: |
|
333 | 333 | |
|
334 | 334 | .. sourcecode:: bash |
|
335 | 335 | |
|
336 | 336 | $> python -c "from IPython.lib.kernel import find_connection_file;\ |
|
337 | 337 | print find_connection_file('kernel-12345.json')" |
|
338 | 338 | /home/you/.ipython/profile_default/security/kernel-12345.json |
|
339 | 339 | |
|
340 | 340 | And if you are using a particular IPython profile: |
|
341 | 341 | |
|
342 | 342 | .. sourcecode:: bash |
|
343 | 343 | |
|
344 | 344 | $> python -c "from IPython.lib.kernel import find_connection_file;\ |
|
345 | 345 | print find_connection_file('kernel-12345.json', profile='foo')" |
|
346 | 346 | /home/you/.ipython/profile_foo/security/kernel-12345.json |
|
347 | 347 | |
|
348 | 348 | You can even launch a standalone kernel, and connect and disconnect Qt Consoles |
|
349 | 349 | from various machines. This lets you keep the same running IPython session |
|
350 | 350 | on your work machine (with matplotlib plots and everything), logging in from home, |
|
351 | 351 | cafΓ©s, etc.:: |
|
352 | 352 | |
|
353 | 353 | $> ipython kernel |
|
354 | 354 | [IPKernelApp] To connect another client to this kernel, use: |
|
355 | 355 | [IPKernelApp] --existing kernel-12345.json |
|
356 | 356 | |
|
357 | 357 | This is actually exactly the same as the subprocess launched by the qtconsole, so |
|
358 | 358 | all the information about connecting to a standalone kernel is identical to that |
|
359 | 359 | of connecting to the kernel attached to a running console. |
|
360 | 360 | |
|
361 | 361 | .. _kernel_security: |
|
362 | 362 | |
|
363 | 363 | Security |
|
364 | 364 | -------- |
|
365 | 365 | |
|
366 | 366 | .. warning:: |
|
367 | 367 | |
|
368 | 368 | Since the ZMQ code currently has no encryption, listening on an |
|
369 | 369 | external-facing IP is dangerous. You are giving any computer that can see |
|
370 | 370 | you on the network the ability to connect to your kernel, and view your traffic. |
|
371 | 371 | Read the rest of this section before listening on external ports |
|
372 | 372 | or running an IPython kernel on a shared machine. |
|
373 | 373 | |
|
374 | 374 | By default (for security reasons), the kernel only listens on localhost, so you |
|
375 | 375 | can only connect multiple frontends to the kernel from your local machine. You |
|
376 | 376 | can specify to listen on an external interface by specifying the ``ip`` |
|
377 | 377 | argument:: |
|
378 | 378 | |
|
379 | 379 | $> ipython qtconsole --ip=192.168.1.123 |
|
380 | 380 | |
|
381 | 381 | If you specify the ip as 0.0.0.0 or '*', that means all interfaces, so any |
|
382 | 382 | computer that can see yours on the network can connect to the kernel. |
|
383 | 383 | |
|
384 | 384 | Messages are not encrypted, so users with access to the ports your kernel is using will be |
|
385 | 385 | able to see any output of the kernel. They will **NOT** be able to issue shell commands as |
|
386 | 386 | you due to message signatures, which are enabled by default as of IPython 0.12. |
|
387 | 387 | |
|
388 | 388 | .. warning:: |
|
389 | 389 | |
|
390 | 390 | If you disable message signatures, then any user with access to the ports your |
|
391 | 391 | kernel is listening on can issue arbitrary code as you. **DO NOT** disable message |
|
392 | 392 | signatures unless you have a lot of trust in your environment. |
|
393 | 393 | |
|
394 | 394 | The one security feature IPython does provide is protection from unauthorized execution. |
|
395 | 395 | IPython's messaging system will sign messages with HMAC digests using a shared-key. The key |
|
396 | 396 | is never sent over the network, it is only used to generate a unique hash for each message, |
|
397 | 397 | based on its content. When IPython receives a message, it will check that the digest |
|
398 | 398 | matches, and discard the message. You can use any file that only you have access to to |
|
399 | 399 | generate this key, but the default is just to generate a new UUID. You can generate a random |
|
400 | 400 | private key with:: |
|
401 | 401 | |
|
402 | 402 | # generate 1024b of random data, and store in a file only you can read: |
|
403 | 403 | # (assumes IPYTHONDIR is defined, otherwise use your IPython directory) |
|
404 | 404 | $> python -c "import os; print os.urandom(128).encode('base64')" > $IPYTHONDIR/sessionkey |
|
405 | 405 | $> chmod 600 $IPYTHONDIR/sessionkey |
|
406 | 406 | |
|
407 | 407 | The *contents* of this file will be stored in the JSON connection file, so that file |
|
408 | 408 | contains everything you need to connect to and use a kernel. |
|
409 | 409 | |
|
410 | 410 | To use this generated key, simply specify the ``Session.keyfile`` configurable |
|
411 | 411 | in :file:`ipython_config.py` or at the command-line, as in:: |
|
412 | 412 | |
|
413 | 413 | # instruct IPython to sign messages with that key, instead of a new UUID |
|
414 | 414 | $> ipython qtconsole --Session.keyfile=$IPYTHONDIR/sessionkey |
|
415 | 415 | |
|
416 | 416 | .. _ssh_tunnels: |
|
417 | 417 | |
|
418 | 418 | SSH Tunnels |
|
419 | 419 | ----------- |
|
420 | 420 | |
|
421 | 421 | Sometimes you want to connect to machines across the internet, or just across |
|
422 | 422 | a LAN that either doesn't permit open ports or you don't trust the other |
|
423 | 423 | machines on the network. To do this, you can use SSH tunnels. SSH tunnels |
|
424 | 424 | are a way to securely forward ports on your local machine to ports on another |
|
425 | 425 | machine, to which you have SSH access. |
|
426 | 426 | |
|
427 | 427 | In simple cases, IPython's tools can forward ports over ssh by simply adding the |
|
428 | 428 | ``--ssh=remote`` argument to the usual ``--existing...`` set of flags for connecting |
|
429 | 429 | to a running kernel, after copying the JSON connection file (or its contents) to |
|
430 | 430 | the second computer. |
|
431 | 431 | |
|
432 | 432 | .. warning:: |
|
433 | 433 | |
|
434 | 434 | Using SSH tunnels does *not* increase localhost security. In fact, when |
|
435 | 435 | tunneling from one machine to another *both* machines have open |
|
436 | 436 | ports on localhost available for connections to the kernel. |
|
437 | 437 | |
|
438 | 438 | There are two primary models for using SSH tunnels with IPython. The first |
|
439 | 439 | is to have the Kernel listen only on localhost, and connect to it from |
|
440 | 440 | another machine on the same LAN. |
|
441 | 441 | |
|
442 | 442 | First, let's start a kernel on machine **worker**, listening only |
|
443 | 443 | on loopback:: |
|
444 | 444 | |
|
445 | 445 | user@worker $> ipython kernel |
|
446 | 446 | [IPKernelApp] To connect another client to this kernel, use: |
|
447 | 447 | [IPKernelApp] --existing kernel-12345.json |
|
448 | 448 | |
|
449 | 449 | In this case, the IP that you would connect |
|
450 | 450 | to would still be 127.0.0.1, but you want to specify the additional ``--ssh`` argument |
|
451 | 451 | with the hostname of the kernel (in this example, it's 'worker'):: |
|
452 | 452 | |
|
453 | 453 | user@client $> ipython qtconsole --ssh=worker --existing /path/to/kernel-12345.json |
|
454 | 454 | |
|
455 | 455 | Which will write a new connection file with the forwarded ports, so you can reuse them:: |
|
456 | 456 | |
|
457 | 457 | [IPythonQtConsoleApp] To connect another client via this tunnel, use: |
|
458 | 458 | [IPythonQtConsoleApp] --existing kernel-12345-ssh.json |
|
459 | 459 | |
|
460 | 460 | Note again that this opens ports on the *client* machine that point to your kernel. |
|
461 | 461 | |
|
462 | 462 | .. note:: |
|
463 | 463 | |
|
464 | 464 | the ssh argument is simply passed to openssh, so it can be fully specified ``user@host:port`` |
|
465 | 465 | but it will also respect your aliases, etc. in :file:`.ssh/config` if you have any. |
|
466 | 466 | |
|
467 | 467 | The second pattern is for connecting to a machine behind a firewall across the internet |
|
468 | 468 | (or otherwise wide network). This time, we have a machine **login** that you have ssh access |
|
469 | 469 | to, which can see **kernel**, but **client** is on another network. The important difference |
|
470 | 470 | now is that **client** can see **login**, but *not* **worker**. So we need to forward ports from |
|
471 | 471 | client to worker *via* login. This means that the kernel must be started listening |
|
472 | 472 | on external interfaces, so that its ports are visible to `login`:: |
|
473 | 473 | |
|
474 | 474 | user@worker $> ipython kernel --ip=0.0.0.0 |
|
475 | 475 | [IPKernelApp] To connect another client to this kernel, use: |
|
476 | 476 | [IPKernelApp] --existing kernel-12345.json |
|
477 | 477 | |
|
478 | 478 | Which we can connect to from the client with:: |
|
479 | 479 | |
|
480 | 480 | user@client $> ipython qtconsole --ssh=login --ip=192.168.1.123 --existing /path/to/kernel-12345.json |
|
481 | 481 | |
|
482 | 482 | .. note:: |
|
483 | 483 | |
|
484 | 484 | The IP here is the address of worker as seen from *login*, and need only be specified if |
|
485 | 485 | the kernel used the ambiguous 0.0.0.0 (all interfaces) address. If it had used |
|
486 | 486 | 192.168.1.123 to start with, it would not be needed. |
|
487 | 487 | |
|
488 | 488 | |
|
489 | 489 | Manual SSH tunnels |
|
490 | 490 | ------------------ |
|
491 | 491 | |
|
492 | 492 | It's possible that IPython's ssh helper functions won't work for you, for various |
|
493 | 493 | reasons. You can still connect to remote machines, as long as you set up the tunnels |
|
494 | 494 | yourself. The basic format of forwarding a local port to a remote one is:: |
|
495 | 495 | |
|
496 | 496 | [client] $> ssh <server> <localport>:<remoteip>:<remoteport> -f -N |
|
497 | 497 | |
|
498 | 498 | This will forward local connections to **localport** on client to **remoteip:remoteport** |
|
499 | 499 | *via* **server**. Note that remoteip is interpreted relative to *server*, not the client. |
|
500 | 500 | So if you have direct ssh access to the machine to which you want to forward connections, |
|
501 | 501 | then the server *is* the remote machine, and remoteip should be server's IP as seen from the |
|
502 | 502 | server itself, i.e. 127.0.0.1. Thus, to forward local port 12345 to remote port 54321 on |
|
503 | 503 | a machine you can see, do:: |
|
504 | 504 | |
|
505 | 505 | [client] $> ssh machine 12345:127.0.0.1:54321 -f -N |
|
506 | 506 | |
|
507 | 507 | But if your target is actually on a LAN at 192.168.1.123, behind another machine called **login**, |
|
508 | 508 | then you would do:: |
|
509 | 509 | |
|
510 | 510 | [client] $> ssh login 12345:192.168.1.16:54321 -f -N |
|
511 | 511 | |
|
512 | 512 | The ``-f -N`` on the end are flags that tell ssh to run in the background, |
|
513 | 513 | and don't actually run any commands beyond creating the tunnel. |
|
514 | 514 | |
|
515 | 515 | .. seealso:: |
|
516 | 516 | |
|
517 | 517 | A short discussion of ssh tunnels: http://www.revsys.com/writings/quicktips/ssh-tunnel.html |
|
518 | 518 | |
|
519 | 519 | |
|
520 | 520 | |
|
521 | 521 | Stopping Kernels and Consoles |
|
522 | 522 | ***************************** |
|
523 | 523 | |
|
524 | 524 | Since there can be many consoles per kernel, the shutdown mechanism and dialog |
|
525 | 525 | are probably more complicated than you are used to. Since you don't always want |
|
526 | 526 | to shutdown a kernel when you close a window, you are given the option to just |
|
527 | 527 | close the console window or also close the Kernel and *all other windows*. Note |
|
528 | 528 | that this only refers to all other *local* windows, as remote Consoles are not |
|
529 | 529 | allowed to shutdown the kernel, and shutdowns do not close Remote consoles (to |
|
530 | 530 | allow for saving, etc.). |
|
531 | 531 | |
|
532 | 532 | Rules: |
|
533 | 533 | |
|
534 | 534 | * Restarting the kernel automatically clears all *local* Consoles, and prompts remote |
|
535 | 535 | Consoles about the reset. |
|
536 | 536 | * Shutdown closes all *local* Consoles, and notifies remotes that |
|
537 | 537 | the Kernel has been shutdown. |
|
538 | 538 | * Remote Consoles may not restart or shutdown the kernel. |
|
539 | 539 | |
|
540 | 540 | Qt and the QtConsole |
|
541 | 541 | ==================== |
|
542 | 542 | |
|
543 | 543 | An important part of working with the QtConsole when you are writing your own |
|
544 | 544 | Qt code is to remember that user code (in the kernel) is *not* in the same |
|
545 | 545 | process as the frontend. This means that there is not necessarily any Qt code |
|
546 | 546 | running in the kernel, and under most normal circumstances there isn't. If, |
|
547 | 547 | however, you specify ``--pylab=qt`` at the command-line, then there *will* be a |
|
548 | 548 | :class:`QCoreApplication` instance running in the kernel process along with |
|
549 | 549 | user-code. To get a reference to this application, do: |
|
550 | 550 | |
|
551 | 551 | .. sourcecode:: python |
|
552 | 552 | |
|
553 | 553 | from PyQt4 import QtCore |
|
554 | 554 | app = QtCore.QCoreApplication.instance() |
|
555 | 555 | # app will be None if there is no such instance |
|
556 | 556 | |
|
557 | 557 | A common problem listed in the PyQt4 Gotchas_ is the fact that Python's garbage |
|
558 | 558 | collection will destroy Qt objects (Windows, etc.) once there is no longer a |
|
559 | 559 | Python reference to them, so you have to hold on to them. For instance, in: |
|
560 | 560 | |
|
561 | 561 | .. sourcecode:: python |
|
562 | 562 | |
|
563 | 563 | def make_window(): |
|
564 | 564 | win = QtGui.QMainWindow() |
|
565 | 565 | |
|
566 | 566 | def make_and_return_window(): |
|
567 | 567 | win = QtGui.QMainWindow() |
|
568 | 568 | return win |
|
569 | 569 | |
|
570 | 570 | :func:`make_window` will never draw a window, because garbage collection will |
|
571 | 571 | destroy it before it is drawn, whereas :func:`make_and_return_window` lets the |
|
572 | 572 | caller decide when the window object should be destroyed. If, as a developer, |
|
573 | 573 | you know that you always want your objects to last as long as the process, you |
|
574 | 574 | can attach them to the QApplication instance itself: |
|
575 | 575 | |
|
576 | 576 | .. sourcecode:: python |
|
577 | 577 | |
|
578 | 578 | # do this just once: |
|
579 | 579 | app = QtCore.QCoreApplication.instance() |
|
580 | 580 | app.references = set() |
|
581 | 581 | # then when you create Windows, add them to the set |
|
582 | 582 | def make_window(): |
|
583 | 583 | win = QtGui.QMainWindow() |
|
584 | 584 | app.references.add(win) |
|
585 | 585 | |
|
586 | 586 | Now the QApplication itself holds a reference to ``win``, so it will never be |
|
587 | 587 | garbage collected until the application itself is destroyed. |
|
588 | 588 | |
|
589 | 589 | .. _Gotchas: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/gotchas.html#garbage-collection |
|
590 | 590 | |
|
591 | 591 | Regressions |
|
592 | 592 | =========== |
|
593 | 593 | |
|
594 | 594 | There are some features, where the qt console lags behind the Terminal |
|
595 | 595 | frontend: |
|
596 | 596 | |
|
597 | 597 | * !cmd input: Due to our use of pexpect, we cannot pass input to subprocesses |
|
598 | 598 | launched using the '!' escape, so you should never call a command that |
|
599 | 599 | requires interactive input. For such cases, use the terminal IPython. This |
|
600 | 600 | will not be fixed, as abandoning pexpect would significantly degrade the |
|
601 | 601 | console experience. |
|
602 | 602 | |
|
603 | 603 | * Use of ``\b`` and ``\r`` characters in the console: these are control |
|
604 | 604 | characters that allow the cursor to move backwards on a line, and are used to |
|
605 | 605 | display things like in-place progress bars in a terminal. We currently do |
|
606 | 606 | not support this, but it is being tracked as issue :ghissue:`629`. |
|
607 | 607 | |
|
608 | 608 | .. _PyQt: http://www.riverbankcomputing.co.uk/software/pyqt/download |
|
609 | 609 | .. _pygments: http://pygments.org/ |
General Comments 0
You need to be logged in to leave comments.
Login now