Show More
@@ -31,7 +31,7 b' reset and restore the tty state.' | |||
|
31 | 31 | |
|
32 | 32 | - The evaluation of the NAME.NAME... form may cause arbitrary |
|
33 | 33 | application defined code to be executed if an object with a |
|
34 | __getattr__ hook is found. Since it is the responsibility of the | |
|
34 | ``__getattr__`` hook is found. Since it is the responsibility of the | |
|
35 | 35 | application (or the user) to enable this feature, I consider this an |
|
36 | 36 | acceptable risk. More complicated expressions (e.g. function calls or |
|
37 | 37 | indexing operations) are *not* evaluated. |
@@ -96,18 +96,23 b' class Tracer(object):' | |||
|
96 | 96 | def __init__(self,colors=None): |
|
97 | 97 | """Create a local debugger instance. |
|
98 | 98 | |
|
99 |
|
|
|
99 | Parameters | |
|
100 | ---------- | |
|
100 | 101 | |
|
101 | - `colors` (None): a string containing the name of the color scheme to | |
|
102 | use, it must be one of IPython's valid color schemes. If not given, the | |
|
103 | function will default to the current IPython scheme when running inside | |
|
104 | IPython, and to 'NoColor' otherwise. | |
|
102 | colors : str, optional | |
|
103 | The name of the color scheme to use, it must be one of IPython's | |
|
104 | valid color schemes. If not given, the function will default to | |
|
105 | the current IPython scheme when running inside IPython, and to | |
|
106 | 'NoColor' otherwise. | |
|
105 | 107 | |
|
106 |
|
|
|
108 | Examples | |
|
109 | -------- | |
|
110 | :: | |
|
107 | 111 | |
|
108 | 112 | from IPython.core.debugger import Tracer; debug_here = Tracer() |
|
109 | 113 | |
|
110 |
|
|
|
114 | Later in your code:: | |
|
115 | ||
|
111 | 116 | debug_here() # -> will open up the debugger at that point. |
|
112 | 117 | |
|
113 | 118 | Once the debugger activates, you can use all of its regular commands to |
@@ -3036,7 +3036,8 b' class InteractiveShell(SingletonConfigurable):' | |||
|
3036 | 3036 | |
|
3037 | 3037 | N:M -> standard python form, means including items N...(M-1). |
|
3038 | 3038 | |
|
3039 |
N-M -> include items N..M (closed endpoint). |
|
|
3039 | N-M -> include items N..M (closed endpoint). | |
|
3040 | """ | |
|
3040 | 3041 | lines = self.history_manager.get_range_by_str(range_str, raw=raw) |
|
3041 | 3042 | return "\n".join(x for _, _, x in lines) |
|
3042 | 3043 |
|
1 | NO CONTENT: modified file |
|
1 | NO CONTENT: modified file |
@@ -102,7 +102,8 b' python-profiler package from non-free.""")' | |||
|
102 | 102 | |
|
103 | 103 | Options: |
|
104 | 104 | |
|
105 | -l <limit>: you can place restrictions on what or how much of the | |
|
105 | -l <limit> | |
|
106 | you can place restrictions on what or how much of the | |
|
106 | 107 | profile gets printed. The limit value can be: |
|
107 | 108 | |
|
108 | 109 | * A string: only information for function names containing this string |
@@ -114,14 +115,16 b' python-profiler package from non-free.""")' | |||
|
114 | 115 | (for example, use a limit of 0.4 to see the topmost 40% only). |
|
115 | 116 | |
|
116 | 117 | You can combine several limits with repeated use of the option. For |
|
117 |
example, |
|
|
118 | example, ``-l __init__ -l 5`` will print only the topmost 5 lines of | |
|
118 | 119 | information about class constructors. |
|
119 | 120 | |
|
120 | -r: return the pstats.Stats object generated by the profiling. This | |
|
121 | -r | |
|
122 | return the pstats.Stats object generated by the profiling. This | |
|
121 | 123 | object has all the information about the profile in it, and you can |
|
122 | 124 | later use it for further analysis or in other functions. |
|
123 | 125 | |
|
124 | -s <key>: sort profile by given key. You can provide more than one key | |
|
126 | -s <key> | |
|
127 | sort profile by given key. You can provide more than one key | |
|
125 | 128 | by using the option several times: '-s key1 -s key2 -s key3...'. The |
|
126 | 129 | default sorting key is 'time'. |
|
127 | 130 | |
@@ -136,7 +139,9 b' python-profiler package from non-free.""")' | |||
|
136 | 139 | abbreviation is unambiguous. The following are the keys currently |
|
137 | 140 | defined: |
|
138 | 141 | |
|
142 | ============ ===================== | |
|
139 | 143 |
|
|
144 | ============ ===================== | |
|
140 | 145 |
|
|
141 | 146 |
|
|
142 | 147 |
|
@@ -147,6 +152,7 b' python-profiler package from non-free.""")' | |||
|
147 | 152 |
|
|
148 | 153 |
|
|
149 | 154 |
|
|
155 | ============ ===================== | |
|
150 | 156 | |
|
151 | 157 | Note that all sorts on statistics are in descending order (placing |
|
152 | 158 | most time consuming items first), where as name, file, and line number |
@@ -159,18 +165,21 b' python-profiler package from non-free.""")' | |||
|
159 | 165 | line numbers. In fact, sort_stats("nfl") is the same as |
|
160 | 166 | sort_stats("name", "file", "line"). |
|
161 | 167 | |
|
162 | -T <filename>: save profile results as shown on screen to a text | |
|
168 | -T <filename> | |
|
169 | save profile results as shown on screen to a text | |
|
163 | 170 | file. The profile is still shown on screen. |
|
164 | 171 | |
|
165 | -D <filename>: save (via dump_stats) profile statistics to given | |
|
172 | -D <filename> | |
|
173 | save (via dump_stats) profile statistics to given | |
|
166 | 174 | filename. This data is in a format understood by the pstats module, and |
|
167 | 175 | is generated by a call to the dump_stats() method of profile |
|
168 | 176 | objects. The profile is still shown on screen. |
|
169 | 177 | |
|
170 | -q: suppress output to the pager. Best used with -T and/or -D above. | |
|
178 | -q | |
|
179 | suppress output to the pager. Best used with -T and/or -D above. | |
|
171 | 180 | |
|
172 | 181 | If you want to run complete programs under the profiler's control, use |
|
173 |
|
|
|
182 | ``%run -p [prof_opts] filename.py [args to program]`` where prof_opts | |
|
174 | 183 | contains profiler specific options as described here. |
|
175 | 184 | |
|
176 | 185 | You can read the complete documentation for the profile module with:: |
@@ -362,7 +371,8 b' python-profiler package from non-free.""")' | |||
|
362 | 371 | file_finder=get_py_filename): |
|
363 | 372 | """Run the named file inside IPython as a program. |
|
364 | 373 | |
|
365 | Usage: | |
|
374 | Usage:: | |
|
375 | ||
|
366 | 376 | %run [-n -i -e -G] |
|
367 | 377 | [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )] |
|
368 | 378 | ( -m mod | file ) [args] |
@@ -371,14 +381,13 b' python-profiler package from non-free.""")' | |||
|
371 | 381 | the program (put in sys.argv). Then, control returns to IPython's |
|
372 | 382 | prompt. |
|
373 | 383 | |
|
374 |
This is similar to running at a system prompt |
|
|
375 | $ python file args\\ | |
|
384 | This is similar to running at a system prompt ``python file args``, | |
|
376 | 385 | but with the advantage of giving you IPython's tracebacks, and of |
|
377 | 386 | loading all variables into your interactive namespace for further use |
|
378 | 387 | (unless -p is used, see below). |
|
379 | 388 | |
|
380 | 389 | The file is executed in a namespace initially consisting only of |
|
381 | __name__=='__main__' and sys.argv constructed as indicated. It thus | |
|
390 | ``__name__=='__main__'`` and sys.argv constructed as indicated. It thus | |
|
382 | 391 | sees its environment as if it were being run as a stand-alone program |
|
383 | 392 | (except for sharing global objects such as previously imported |
|
384 | 393 | modules). But after execution, the IPython interactive namespace gets |
@@ -390,33 +399,37 b' python-profiler package from non-free.""")' | |||
|
390 | 399 | '*', '?', '[seq]' and '[!seq]' can be used. Additionally, |
|
391 | 400 | tilde '~' will be expanded into user's home directory. Unlike |
|
392 | 401 | real shells, quotation does not suppress expansions. Use |
|
393 |
*two* back slashes (e.g. |
|
|
402 | *two* back slashes (e.g. ``\\\\*``) to suppress expansions. | |
|
394 | 403 | To completely disable these expansions, you can use -G flag. |
|
395 | 404 | |
|
396 | 405 | Options: |
|
397 | 406 | |
|
398 | -n: __name__ is NOT set to '__main__', but to the running file's name | |
|
407 | -n | |
|
408 | __name__ is NOT set to '__main__', but to the running file's name | |
|
399 | 409 | without extension (as python does under import). This allows running |
|
400 | 410 | scripts and reloading the definitions in them without calling code |
|
401 |
protected by an |
|
|
411 | protected by an ``if __name__ == "__main__"`` clause. | |
|
402 | 412 | |
|
403 | -i: run the file in IPython's namespace instead of an empty one. This | |
|
413 | -i | |
|
414 | run the file in IPython's namespace instead of an empty one. This | |
|
404 | 415 | is useful if you are experimenting with code written in a text editor |
|
405 | 416 | which depends on variables defined interactively. |
|
406 | 417 | |
|
407 | -e: ignore sys.exit() calls or SystemExit exceptions in the script | |
|
418 | -e | |
|
419 | ignore sys.exit() calls or SystemExit exceptions in the script | |
|
408 | 420 | being run. This is particularly useful if IPython is being used to |
|
409 | 421 | run unittests, which always exit with a sys.exit() call. In such |
|
410 | 422 | cases you are interested in the output of the test results, not in |
|
411 | 423 | seeing a traceback of the unittest module. |
|
412 | 424 | |
|
413 | -t: print timing information at the end of the run. IPython will give | |
|
425 | -t | |
|
426 | print timing information at the end of the run. IPython will give | |
|
414 | 427 | you an estimated CPU time consumption for your script, which under |
|
415 | 428 | Unix uses the resource module to avoid the wraparound problems of |
|
416 | 429 | time.clock(). Under Unix, an estimate of time spent on system tasks |
|
417 | 430 | is also given (for Windows platforms this is reported as 0.0). |
|
418 | 431 | |
|
419 | If -t is given, an additional -N<N> option can be given, where <N> | |
|
432 | If -t is given, an additional ``-N<N>`` option can be given, where <N> | |
|
420 | 433 | must be an integer indicating how many times you want the script to |
|
421 | 434 | run. The final timing report will include total and per run results. |
|
422 | 435 | |
@@ -424,21 +437,22 b' python-profiler package from non-free.""")' | |||
|
424 | 437 | |
|
425 | 438 | In [1]: run -t uniq_stable |
|
426 | 439 | |
|
427 |
IPython CPU timings (estimated): |
|
|
428 |
User : 0.19597 s. |
|
|
429 |
System: 0.0 s. |
|
|
440 | IPython CPU timings (estimated): | |
|
441 | User : 0.19597 s. | |
|
442 | System: 0.0 s. | |
|
430 | 443 | |
|
431 | 444 | In [2]: run -t -N5 uniq_stable |
|
432 | 445 | |
|
433 |
IPython CPU timings (estimated): |
|
|
434 |
Total runs performed: 5 |
|
|
435 |
Times : Total Per run |
|
|
436 |
User : 0.910862 s, 0.1821724 s. |
|
|
446 | IPython CPU timings (estimated): | |
|
447 | Total runs performed: 5 | |
|
448 | Times : Total Per run | |
|
449 | User : 0.910862 s, 0.1821724 s. | |
|
437 | 450 | System: 0.0 s, 0.0 s. |
|
438 | 451 | |
|
439 | -d: run your program under the control of pdb, the Python debugger. | |
|
452 | -d | |
|
453 | run your program under the control of pdb, the Python debugger. | |
|
440 | 454 | This allows you to execute your program step by step, watch variables, |
|
441 | etc. Internally, what IPython does is similar to calling: | |
|
455 | etc. Internally, what IPython does is similar to calling:: | |
|
442 | 456 | |
|
443 | 457 | pdb.run('execfile("YOURFILENAME")') |
|
444 | 458 | |
@@ -464,7 +478,8 b' python-profiler package from non-free.""")' | |||
|
464 | 478 | can easily see pdb's full documentation with "import pdb;pdb.help()" |
|
465 | 479 | at a prompt. |
|
466 | 480 | |
|
467 | -p: run program under the control of the Python profiler module (which | |
|
481 | -p | |
|
482 | run program under the control of the Python profiler module (which | |
|
468 | 483 | prints a detailed report of execution times, function calls, etc). |
|
469 | 484 | |
|
470 | 485 | You can pass other options after -p which affect the behavior of the |
@@ -481,7 +496,8 b' python-profiler package from non-free.""")' | |||
|
481 | 496 | if the filename ends with .ipy, the file is run as ipython script, |
|
482 | 497 | just as if the commands were written on IPython prompt. |
|
483 | 498 | |
|
484 | -m: specify module name to load instead of script path. Similar to | |
|
499 | -m | |
|
500 | specify module name to load instead of script path. Similar to | |
|
485 | 501 | the -m option for the python interpreter. Use this option last if you |
|
486 | 502 | want to combine with other %run options. Unlike the python interpreter |
|
487 | 503 | only source modules are allowed no .pyc or .pyo files. |
@@ -491,7 +507,8 b' python-profiler package from non-free.""")' | |||
|
491 | 507 | |
|
492 | 508 | will run the example module. |
|
493 | 509 | |
|
494 | -G: disable shell-like glob expansion of arguments. | |
|
510 | -G | |
|
511 | disable shell-like glob expansion of arguments. | |
|
495 | 512 | |
|
496 | 513 | """ |
|
497 | 514 |
@@ -42,16 +42,27 b' class LoggingMagics(Magics):' | |||
|
42 | 42 | history up to that point and then continues logging. |
|
43 | 43 | |
|
44 | 44 | %logstart takes a second optional parameter: logging mode. This can be one |
|
45 |
of (note that the modes are given unquoted): |
|
|
46 | append: well, that says it.\\ | |
|
47 | backup: rename (if exists) to name~ and start name.\\ | |
|
48 | global: single logfile in your home dir, appended to.\\ | |
|
49 | over : overwrite existing log.\\ | |
|
50 | rotate: create rotating logs name.1~, name.2~, etc. | |
|
45 | of (note that the modes are given unquoted): | |
|
46 | ||
|
47 | append | |
|
48 | Keep logging at the end of any existing file. | |
|
49 | ||
|
50 | backup | |
|
51 | Rename any existing file to name~ and start name. | |
|
52 | ||
|
53 | global | |
|
54 | Append to a single logfile in your home directory. | |
|
55 | ||
|
56 | over | |
|
57 | Overwrite any existing log. | |
|
58 | ||
|
59 | rotate | |
|
60 | Create rotating logs: name.1~, name.2~, etc. | |
|
51 | 61 | |
|
52 | 62 | Options: |
|
53 | 63 | |
|
54 | -o: log also IPython's output. In this mode, all commands which | |
|
64 | -o | |
|
65 | log also IPython's output. In this mode, all commands which | |
|
55 | 66 | generate an Out[NN] prompt are recorded to the logfile, right after |
|
56 | 67 |
their corresponding input line. |
|
57 | 68 | prepended with a '#[Out]# ' marker, so that the log remains valid |
@@ -62,14 +73,17 b' class LoggingMagics(Magics):' | |||
|
62 | 73 | |
|
63 | 74 | awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py |
|
64 | 75 | |
|
65 | -r: log 'raw' input. Normally, IPython's logs contain the processed | |
|
76 | -r | |
|
77 | log 'raw' input. Normally, IPython's logs contain the processed | |
|
66 | 78 | input, so that user lines are logged in their final form, converted |
|
67 | 79 | into valid Python. For example, %Exit is logged as |
|
68 | 80 | _ip.magic("Exit"). If the -r flag is given, all input is logged |
|
69 | 81 | exactly as typed, with no transformations applied. |
|
70 | 82 | |
|
71 | -t: put timestamps before each input line logged (these are put in | |
|
72 | comments).""" | |
|
83 | -t | |
|
84 | put timestamps before each input line logged (these are put in | |
|
85 | comments). | |
|
86 | """ | |
|
73 | 87 | |
|
74 | 88 | opts,par = self.parse_options(parameter_s,'ort') |
|
75 | 89 | log_output = 'o' in opts |
|
1 | NO CONTENT: modified file |
|
1 | NO CONTENT: modified file |
@@ -325,9 +325,11 b" def snip_print(str,width = 75,print_full = 0,header = ''):" | |||
|
325 | 325 | """Print a string snipping the midsection to fit in width. |
|
326 | 326 | |
|
327 | 327 | print_full: mode control: |
|
328 | ||
|
328 | 329 | - 0: only snip long strings |
|
329 | 330 | - 1: send to page() directly. |
|
330 | 331 | - 2: snip long strings and ask for full length viewing with page() |
|
332 | ||
|
331 | 333 | Return 1 if snipping was necessary, 0 otherwise.""" |
|
332 | 334 | |
|
333 | 335 | if print_full == 1: |
@@ -8,7 +8,8 b' ColorTB class is a solution to that problem. It colors the different parts of a' | |||
|
8 | 8 | traceback in a manner similar to what you would expect from a syntax-highlighting |
|
9 | 9 | text editor. |
|
10 | 10 | |
|
11 | Installation instructions for ColorTB: | |
|
11 | Installation instructions for ColorTB:: | |
|
12 | ||
|
12 | 13 | import sys,ultratb |
|
13 | 14 | sys.excepthook = ultratb.ColorTB() |
|
14 | 15 | |
@@ -21,7 +22,7 b' but kind of neat, and maybe useful for long-running programs that you believe' | |||
|
21 | 22 | are bug-free. If a crash *does* occur in that type of program you want details. |
|
22 | 23 | Give it a shot--you'll love it or you'll hate it. |
|
23 | 24 | |
|
24 | Note: | |
|
25 | .. note:: | |
|
25 | 26 | |
|
26 | 27 | The Verbose mode prints the variables currently visible where the exception |
|
27 | 28 | happened (shortening their strings if too long). This can potentially be |
@@ -36,14 +37,17 b' Note:' | |||
|
36 | 37 | Verbose). |
|
37 | 38 | |
|
38 | 39 | |
|
39 | Installation instructions for ColorTB: | |
|
40 | Installation instructions for ColorTB:: | |
|
41 | ||
|
40 | 42 | import sys,ultratb |
|
41 | 43 | sys.excepthook = ultratb.VerboseTB() |
|
42 | 44 | |
|
43 | 45 | Note: Much of the code in this module was lifted verbatim from the standard |
|
44 | 46 | library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'. |
|
45 | 47 | |
|
46 |
|
|
|
48 | Color schemes | |
|
49 | ------------- | |
|
50 | ||
|
47 | 51 | The colors are defined in the class TBTools through the use of the |
|
48 | 52 | ColorSchemeTable class. Currently the following exist: |
|
49 | 53 |
|
1 | NO CONTENT: modified file |
|
1 | NO CONTENT: modified file |
@@ -19,7 +19,8 b' def cell_preprocessor(function):' | |||
|
19 | 19 | Wrap a function to be executed on all cells of a notebook |
|
20 | 20 | |
|
21 | 21 | Wrapped Parameters |
|
22 | ---------- | |
|
22 | ------------------ | |
|
23 | ||
|
23 | 24 | cell : NotebookNode cell |
|
24 | 25 | Notebook cell being processed |
|
25 | 26 | resources : dictionary |
@@ -44,8 +44,8 b' class AvoidUNCPath(object):' | |||
|
44 | 44 | change and None otherwise, so that users can apply the necessary adjustment |
|
45 | 45 | to their system calls in the event of a change. |
|
46 | 46 | |
|
47 | Example | |
|
48 | ------- | |
|
47 | Examples | |
|
48 | -------- | |
|
49 | 49 | :: |
|
50 | 50 | cmd = 'dir' |
|
51 | 51 | with AvoidUNCPath() as path: |
@@ -161,8 +161,8 b' class AvoidUNCPath(object):' | |||
|
161 | 161 | change and None otherwise, so that users can apply the necessary adjustment |
|
162 | 162 | to their system calls in the event of a change. |
|
163 | 163 | |
|
164 | Example | |
|
165 | ------- | |
|
164 | Examples | |
|
165 | -------- | |
|
166 | 166 | :: |
|
167 | 167 | cmd = 'dir' |
|
168 | 168 | with AvoidUNCPath() as path: |
@@ -69,12 +69,12 b' class CapturedIO(object):' | |||
|
69 | 69 | |
|
70 | 70 | Each instance `c` has three attributes: |
|
71 | 71 | |
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
72 | - ``c.stdout`` : standard output as a string | |
|
73 | - ``c.stderr`` : standard error as a string | |
|
74 | - ``c.outputs``: a list of rich display outputs | |
|
75 | 75 | |
|
76 | Additionally, there's a `c.show()` method which will print all of the | |
|
77 | above in the same order, and can be invoked simply via `c()`. | |
|
76 | Additionally, there's a ``c.show()`` method which will print all of the | |
|
77 | above in the same order, and can be invoked simply via ``c()``. | |
|
78 | 78 | """ |
|
79 | 79 | |
|
80 | 80 | def __init__(self, stdout, stderr, outputs=None): |
@@ -105,8 +105,8 b' class CapturedIO(object):' | |||
|
105 | 105 | def outputs(self): |
|
106 | 106 | """A list of the captured rich display outputs, if any. |
|
107 | 107 | |
|
108 | If you have a CapturedIO object `c`, these can be displayed in IPython | |
|
109 | using: | |
|
108 | If you have a CapturedIO object ``c``, these can be displayed in IPython | |
|
109 | using:: | |
|
110 | 110 | |
|
111 | 111 | from IPython.display import display |
|
112 | 112 | for o in c.outputs: |
@@ -27,8 +27,8 b' class preserve_keys(object):' | |||
|
27 | 27 | which did not exist when entering the context manager will be |
|
28 | 28 | deleted. |
|
29 | 29 | |
|
30 | Example | |
|
31 | ------- | |
|
30 | Examples | |
|
31 | -------- | |
|
32 | 32 | |
|
33 | 33 | >>> d = {'a': 1, 'b': 2, 'c': 3} |
|
34 | 34 | >>> with preserve_keys(d, 'b', 'c', 'd'): |
@@ -98,8 +98,10 b' def pkg_info(pkg_path):' | |||
|
98 | 98 | def sys_info(): |
|
99 | 99 | """Return useful information about IPython and the system, as a string. |
|
100 | 100 | |
|
101 | Example | |
|
102 | ------- | |
|
101 | Examples | |
|
102 | -------- | |
|
103 | :: | |
|
104 | ||
|
103 | 105 | In [2]: print sys_info() |
|
104 | 106 | {'commit_hash': '144fdae', # random |
|
105 | 107 | 'commit_source': 'repository', |
General Comments 0
You need to be logged in to leave comments.
Login now