##// END OF EJS Templates
Update various references to IPython's homepage.
Thomas Kluyver -
Show More
@@ -1,123 +1,123 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project."""
3 3
4 4 #-----------------------------------------------------------------------------
5 5 # Copyright (c) 2008-2010, IPython Development Team.
6 6 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
7 7 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
8 8 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
9 9 #
10 10 # Distributed under the terms of the Modified BSD License.
11 11 #
12 12 # The full license is in the file COPYING.txt, distributed with this software.
13 13 #-----------------------------------------------------------------------------
14 14
15 15 # Name of the package for release purposes. This is the name which labels
16 16 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
17 17 name = 'ipython'
18 18
19 19 # IPython version information. An empty _version_extra corresponds to a full
20 20 # release. 'dev' as a _version_extra string means this is a development
21 21 # version
22 22 _version_major = 0
23 23 _version_minor = 11
24 24 _version_micro = '' # use '' for first of series, number for 1 and above
25 25 _version_extra = 'dev'
26 26 #_version_extra = '' # Uncomment this for full releases
27 27
28 28 # Construct full version string from these.
29 29 _ver = [_version_major, _version_minor]
30 30 if _version_micro:
31 31 _ver.append(_version_micro)
32 32 if _version_extra:
33 33 _ver.append(_version_extra)
34 34
35 35 __version__ = '.'.join(map(str, _ver))
36 36
37 37 version = __version__ # backwards compatibility name
38 38
39 39 description = "An interactive computing environment for Python"
40 40
41 41 long_description = \
42 42 """
43 43 The goal of IPython is to create a comprehensive environment for
44 44 interactive and exploratory computing. To support this goal, IPython
45 45 has two main components:
46 46
47 47 * An enhanced interactive Python shell.
48 48
49 49 * An architecture for interactive parallel computing.
50 50
51 51 The enhanced interactive Python shell has the following main features:
52 52
53 53 * Comprehensive object introspection.
54 54
55 55 * Input history, persistent across sessions.
56 56
57 57 * Caching of output results during a session with automatically generated
58 58 references.
59 59
60 60 * Readline based name completion.
61 61
62 62 * Extensible system of 'magic' commands for controlling the environment and
63 63 performing many tasks related either to IPython or the operating system.
64 64
65 65 * Configuration system with easy switching between different setups (simpler
66 66 than changing $PYTHONSTARTUP environment variables every time).
67 67
68 68 * Session logging and reloading.
69 69
70 70 * Extensible syntax processing for special purpose situations.
71 71
72 72 * Access to the system shell with user-extensible alias system.
73 73
74 74 * Easily embeddable in other Python programs and wxPython GUIs.
75 75
76 76 * Integrated access to the pdb debugger and the Python profiler.
77 77
78 78 The parallel computing architecture has the following main features:
79 79
80 80 * Quickly parallelize Python code from an interactive Python/IPython session.
81 81
82 82 * A flexible and dynamic process model that be deployed on anything from
83 83 multicore workstations to supercomputers.
84 84
85 85 * An architecture that supports many different styles of parallelism, from
86 86 message passing to task farming.
87 87
88 88 * Both blocking and fully asynchronous interfaces.
89 89
90 90 * High level APIs that enable many things to be parallelized in a few lines
91 91 of code.
92 92
93 93 * Share live parallel jobs with other users securely.
94 94
95 95 * Dynamically load balanced task farming system.
96 96
97 97 * Robust error handling in parallel code.
98 98
99 99 The latest development version is always available from IPython's `GitHub
100 100 site <http://github.com/ipython>`_.
101 101 """
102 102
103 103 license = 'BSD'
104 104
105 105 authors = {'Fernando' : ('Fernando Perez','fperez.net@gmail.com'),
106 106 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
107 107 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'),
108 108 'Ville' : ('Ville Vainio','vivainio@gmail.com'),
109 109 'Brian' : ('Brian E Granger', 'ellisonbg@gmail.com'),
110 110 'Min' : ('Min Ragan-Kelley', 'benjaminrk@gmail.com')
111 111 }
112 112
113 113 author = 'The IPython Development Team'
114 114
115 115 author_email = 'ipython-dev@scipy.org'
116 116
117 url = 'http://ipython.scipy.org'
117 url = 'http://ipython.org'
118 118
119 119 download_url = 'http://ipython.scipy.org/dist'
120 120
121 121 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
122 122
123 123 keywords = ['Interactive','Interpreter','Shell','Parallel','Distributed']
@@ -1,509 +1,509 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Usage information for the main IPython applications.
3 3 """
4 4 #-----------------------------------------------------------------------------
5 5 # Copyright (C) 2008-2010 The IPython Development Team
6 6 # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
7 7 #
8 8 # Distributed under the terms of the BSD License. The full license is in
9 9 # the file COPYING, distributed as part of this software.
10 10 #-----------------------------------------------------------------------------
11 11
12 12 import sys
13 13 from IPython.core import release
14 14
15 15 cl_usage = """\
16 16 ipython [options] [files]
17 17
18 18 IPython: an enhanced interactive Python shell.
19 19
20 20 A Python shell with automatic history (input and output), dynamic object
21 21 introspection, easier configuration, command completion, access to the
22 22 system shell and more. IPython can also be embedded in running programs.
23 23
24 24 If invoked with no options, it executes all the files listed in sequence
25 25 and exits, use -i to enter interactive mode after running the files. Files
26 26 ending in .py will be treated as normal Python, but files ending in .ipy
27 27 can contain special IPython syntax (magic commands, shell expansions, etc.)
28 28
29 29 Please note that some of the configuration options are not available at the
30 30 command line, simply because they are not practical here. Look into your
31 31 ipython_config.py configuration file for details on those.
32 32
33 33 This file is typically installed in the IPYTHON_DIR directory. For Linux
34 34 users, this will be $HOME/.config/ipython, and for other users it will be
35 35 $HOME/.ipython. For Windows users, $HOME resolves to C:\\Documents and
36 36 Settings\\YourUserName in most instances.
37 37
38 38 In IPython's documentation, we will refer to this directory as IPYTHON_DIR,
39 39 you can change its default location by setting any path you want in this
40 40 environment variable.
41 41
42 42 For more information, see the manual available in HTML and PDF in your
43 installation, or online at http://ipython.scipy.org.
43 installation, or online at http://ipython.org/documentation.html.
44 44 """
45 45
46 46 interactive_usage = """
47 47 IPython -- An enhanced Interactive Python
48 48 =========================================
49 49
50 50 IPython offers a combination of convenient shell features, special commands
51 51 and a history mechanism for both input (command history) and output (results
52 52 caching, similar to Mathematica). It is intended to be a fully compatible
53 53 replacement for the standard Python interpreter, while offering vastly
54 54 improved functionality and flexibility.
55 55
56 56 At your system command line, type 'ipython -help' to see the command line
57 57 options available. This document only describes interactive features.
58 58
59 59 Warning: IPython relies on the existence of a global variable called __IP which
60 60 controls the shell itself. If you redefine __IP to anything, bizarre behavior
61 61 will quickly occur.
62 62
63 63 MAIN FEATURES
64 64
65 65 * Access to the standard Python help. As of Python 2.1, a help system is
66 66 available with access to object docstrings and the Python manuals. Simply
67 67 type 'help' (no quotes) to access it.
68 68
69 69 * Magic commands: type %magic for information on the magic subsystem.
70 70
71 71 * System command aliases, via the %alias command or the ipythonrc config file.
72 72
73 73 * Dynamic object information:
74 74
75 75 Typing ?word or word? prints detailed information about an object. If
76 76 certain strings in the object are too long (docstrings, code, etc.) they get
77 77 snipped in the center for brevity.
78 78
79 79 Typing ??word or word?? gives access to the full information without
80 80 snipping long strings. Long strings are sent to the screen through the less
81 81 pager if longer than the screen, printed otherwise.
82 82
83 83 The ?/?? system gives access to the full source code for any object (if
84 84 available), shows function prototypes and other useful information.
85 85
86 86 If you just want to see an object's docstring, type '%pdoc object' (without
87 87 quotes, and without % if you have automagic on).
88 88
89 89 Both %pdoc and ?/?? give you access to documentation even on things which are
90 90 not explicitely defined. Try for example typing {}.get? or after import os,
91 91 type os.path.abspath??. The magic functions %pdef, %source and %file operate
92 92 similarly.
93 93
94 94 * Completion in the local namespace, by typing TAB at the prompt.
95 95
96 96 At any time, hitting tab will complete any available python commands or
97 97 variable names, and show you a list of the possible completions if there's
98 98 no unambiguous one. It will also complete filenames in the current directory.
99 99
100 100 This feature requires the readline and rlcomplete modules, so it won't work
101 101 if your Python lacks readline support (such as under Windows).
102 102
103 103 * Search previous command history in two ways (also requires readline):
104 104
105 105 - Start typing, and then use Ctrl-p (previous,up) and Ctrl-n (next,down) to
106 106 search through only the history items that match what you've typed so
107 107 far. If you use Ctrl-p/Ctrl-n at a blank prompt, they just behave like
108 108 normal arrow keys.
109 109
110 110 - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches
111 111 your history for lines that match what you've typed so far, completing as
112 112 much as it can.
113 113
114 114 * Persistent command history across sessions (readline required).
115 115
116 116 * Logging of input with the ability to save and restore a working session.
117 117
118 118 * System escape with !. Typing !ls will run 'ls' in the current directory.
119 119
120 120 * The reload command does a 'deep' reload of a module: changes made to the
121 121 module since you imported will actually be available without having to exit.
122 122
123 123 * Verbose and colored exception traceback printouts. See the magic xmode and
124 124 xcolor functions for details (just type %magic).
125 125
126 126 * Input caching system:
127 127
128 128 IPython offers numbered prompts (In/Out) with input and output caching. All
129 129 input is saved and can be retrieved as variables (besides the usual arrow
130 130 key recall).
131 131
132 132 The following GLOBAL variables always exist (so don't overwrite them!):
133 133 _i: stores previous input.
134 134 _ii: next previous.
135 135 _iii: next-next previous.
136 136 _ih : a list of all input _ih[n] is the input from line n.
137 137
138 138 Additionally, global variables named _i<n> are dynamically created (<n>
139 139 being the prompt counter), such that _i<n> == _ih[<n>]
140 140
141 141 For example, what you typed at prompt 14 is available as _i14 and _ih[14].
142 142
143 143 You can create macros which contain multiple input lines from this history,
144 144 for later re-execution, with the %macro function.
145 145
146 146 The history function %hist allows you to see any part of your input history
147 147 by printing a range of the _i variables. Note that inputs which contain
148 148 magic functions (%) appear in the history with a prepended comment. This is
149 149 because they aren't really valid Python code, so you can't exec them.
150 150
151 151 * Output caching system:
152 152
153 153 For output that is returned from actions, a system similar to the input
154 154 cache exists but using _ instead of _i. Only actions that produce a result
155 155 (NOT assignments, for example) are cached. If you are familiar with
156 156 Mathematica, IPython's _ variables behave exactly like Mathematica's %
157 157 variables.
158 158
159 159 The following GLOBAL variables always exist (so don't overwrite them!):
160 160 _ (one underscore): previous output.
161 161 __ (two underscores): next previous.
162 162 ___ (three underscores): next-next previous.
163 163
164 164 Global variables named _<n> are dynamically created (<n> being the prompt
165 165 counter), such that the result of output <n> is always available as _<n>.
166 166
167 167 Finally, a global dictionary named _oh exists with entries for all lines
168 168 which generated output.
169 169
170 170 * Directory history:
171 171
172 172 Your history of visited directories is kept in the global list _dh, and the
173 173 magic %cd command can be used to go to any entry in that list.
174 174
175 175 * Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
176 176
177 177 1. Auto-parentheses
178 178 Callable objects (i.e. functions, methods, etc) can be invoked like
179 179 this (notice the commas between the arguments):
180 180 >>> callable_ob arg1, arg2, arg3
181 181 and the input will be translated to this:
182 182 --> callable_ob(arg1, arg2, arg3)
183 183 You can force auto-parentheses by using '/' as the first character
184 184 of a line. For example:
185 185 >>> /globals # becomes 'globals()'
186 186 Note that the '/' MUST be the first character on the line! This
187 187 won't work:
188 188 >>> print /globals # syntax error
189 189
190 190 In most cases the automatic algorithm should work, so you should
191 191 rarely need to explicitly invoke /. One notable exception is if you
192 192 are trying to call a function with a list of tuples as arguments (the
193 193 parenthesis will confuse IPython):
194 194 In [1]: zip (1,2,3),(4,5,6) # won't work
195 195 but this will work:
196 196 In [2]: /zip (1,2,3),(4,5,6)
197 197 ------> zip ((1,2,3),(4,5,6))
198 198 Out[2]= [(1, 4), (2, 5), (3, 6)]
199 199
200 200 IPython tells you that it has altered your command line by
201 201 displaying the new command line preceded by -->. e.g.:
202 202 In [18]: callable list
203 203 -------> callable (list)
204 204
205 205 2. Auto-Quoting
206 206 You can force auto-quoting of a function's arguments by using ',' as
207 207 the first character of a line. For example:
208 208 >>> ,my_function /home/me # becomes my_function("/home/me")
209 209
210 210 If you use ';' instead, the whole argument is quoted as a single
211 211 string (while ',' splits on whitespace):
212 212 >>> ,my_function a b c # becomes my_function("a","b","c")
213 213 >>> ;my_function a b c # becomes my_function("a b c")
214 214
215 215 Note that the ',' MUST be the first character on the line! This
216 216 won't work:
217 217 >>> x = ,my_function /home/me # syntax error
218 218 """
219 219
220 220 interactive_usage_min = """\
221 221 An enhanced console for Python.
222 222 Some of its features are:
223 223 - Readline support if the readline library is present.
224 224 - Tab completion in the local namespace.
225 225 - Logging of input, see command-line options.
226 226 - System shell escape via ! , eg !ls.
227 227 - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
228 228 - Keeps track of locally defined variables via %who, %whos.
229 229 - Show object information with a ? eg ?x or x? (use ?? for more info).
230 230 """
231 231
232 232 quick_reference = r"""
233 233 IPython -- An enhanced Interactive Python - Quick Reference Card
234 234 ================================================================
235 235
236 236 obj?, obj?? : Get help, or more help for object (also works as
237 237 ?obj, ??obj).
238 238 ?foo.*abc* : List names in 'foo' containing 'abc' in them.
239 239 %magic : Information about IPython's 'magic' % functions.
240 240
241 241 Magic functions are prefixed by %, and typically take their arguments without
242 242 parentheses, quotes or even commas for convenience.
243 243
244 244 Example magic function calls:
245 245
246 246 %alias d ls -F : 'd' is now an alias for 'ls -F'
247 247 alias d ls -F : Works if 'alias' not a python name
248 248 alist = %alias : Get list of aliases to 'alist'
249 249 cd /usr/share : Obvious. cd -<tab> to choose from visited dirs.
250 250 %cd?? : See help AND source for magic %cd
251 251
252 252 System commands:
253 253
254 254 !cp a.txt b/ : System command escape, calls os.system()
255 255 cp a.txt b/ : after %rehashx, most system commands work without !
256 256 cp ${f}.txt $bar : Variable expansion in magics and system commands
257 257 files = !ls /usr : Capture sytem command output
258 258 files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'
259 259
260 260 History:
261 261
262 262 _i, _ii, _iii : Previous, next previous, next next previous input
263 263 _i4, _ih[2:5] : Input history line 4, lines 2-4
264 264 exec _i81 : Execute input history line #81 again
265 265 %rep 81 : Edit input history line #81
266 266 _, __, ___ : previous, next previous, next next previous output
267 267 _dh : Directory history
268 268 _oh : Output history
269 269 %hist : Command history. '%hist -g foo' search history for 'foo'
270 270
271 271 Autocall:
272 272
273 273 f 1,2 : f(1,2)
274 274 /f 1,2 : f(1,2) (forced autoparen)
275 275 ,f 1 2 : f("1","2")
276 276 ;f 1 2 : f("1 2")
277 277
278 278 Remember: TAB completion works in many contexts, not just file names
279 279 or python names.
280 280
281 281 The following magic functions are currently available:
282 282
283 283 """
284 284
285 285 gui_reference = """\
286 286 ===============================
287 287 The graphical IPython console
288 288 ===============================
289 289
290 290 This console is designed to emulate the look, feel and workflow of a terminal
291 291 environment, while adding a number of enhancements that are simply not possible
292 292 in a real terminal, such as inline syntax highlighting, true multiline editing,
293 293 inline graphics and much more.
294 294
295 295 This quick reference document contains the basic information you'll need to
296 296 know to make the most efficient use of it. For the various command line
297 297 options available at startup, type ``--help`` at the command line.
298 298
299 299
300 300 Multiline editing
301 301 =================
302 302
303 303 The graphical console is capable of true multiline editing, but it also tries
304 304 to behave intuitively like a terminal when possible. If you are used to
305 305 IPyhton's old terminal behavior, you should find the transition painless, and
306 306 once you learn a few basic keybindings it will be a much more efficient
307 307 environment.
308 308
309 309 For single expressions or indented blocks, the console behaves almost like the
310 310 terminal IPython: single expressions are immediately evaluated, and indented
311 311 blocks are evaluated once a single blank line is entered::
312 312
313 313 In [1]: print "Hello IPython!" # Enter was pressed at the end of the line
314 314 Hello IPython!
315 315
316 316 In [2]: for i in range(10):
317 317 ...: print i,
318 318 ...:
319 319 0 1 2 3 4 5 6 7 8 9
320 320
321 321 If you want to enter more than one expression in a single input block
322 322 (something not possible in the terminal), you can use ``Control-Enter`` at the
323 323 end of your first line instead of ``Enter``. At that point the console goes
324 324 into 'cell mode' and even if your inputs are not indented, it will continue
325 325 accepting arbitrarily many lines until either you enter an extra blank line or
326 326 you hit ``Shift-Enter`` (the key binding that forces execution). When a
327 327 multiline cell is entered, IPython analyzes it and executes its code producing
328 328 an ``Out[n]`` prompt only for the last expression in it, while the rest of the
329 329 cell is executed as if it was a script. An example should clarify this::
330 330
331 331 In [3]: x=1 # Hit C-Enter here
332 332 ...: y=2 # from now on, regular Enter is sufficient
333 333 ...: z=3
334 334 ...: x**2 # This does *not* produce an Out[] value
335 335 ...: x+y+z # Only the last expression does
336 336 ...:
337 337 Out[3]: 6
338 338
339 339 The behavior where an extra blank line forces execution is only active if you
340 340 are actually typing at the keyboard each line, and is meant to make it mimic
341 341 the IPython terminal behavior. If you paste a long chunk of input (for example
342 342 a long script copied form an editor or web browser), it can contain arbitrarily
343 343 many intermediate blank lines and they won't cause any problems. As always,
344 344 you can then make it execute by appending a blank line *at the end* or hitting
345 345 ``Shift-Enter`` anywhere within the cell.
346 346
347 347 With the up arrow key, you can retrieve previous blocks of input that contain
348 348 multiple lines. You can move inside of a multiline cell like you would in any
349 349 text editor. When you want it executed, the simplest thing to do is to hit the
350 350 force execution key, ``Shift-Enter`` (though you can also navigate to the end
351 351 and append a blank line by using ``Enter`` twice).
352 352
353 353 If you've edited a multiline cell and accidentally navigate out of it with the
354 354 up or down arrow keys, IPython will clear the cell and replace it with the
355 355 contents of the one above or below that you navigated to. If this was an
356 356 accident and you want to retrieve the cell you were editing, use the Undo
357 357 keybinding, ``Control-z``.
358 358
359 359
360 360 Key bindings
361 361 ============
362 362
363 363 The IPython console supports most of the basic Emacs line-oriented keybindings,
364 364 in addition to some of its own.
365 365
366 366 The keybinding prefixes mean:
367 367
368 368 - ``C``: Control
369 369 - ``S``: Shift
370 370 - ``M``: Meta (typically the Alt key)
371 371
372 372 The keybindings themselves are:
373 373
374 374 - ``Enter``: insert new line (may cause execution, see above).
375 375 - ``C-Enter``: force new line, *never* causes execution.
376 376 - ``S-Enter``: *force* execution regardless of where cursor is, no newline added.
377 377 - ``C-c``: copy highlighted text to clipboard (prompts are automatically stripped).
378 378 - ``C-S-c``: copy highlighted text to clipboard (prompts are not stripped).
379 379 - ``C-v``: paste text from clipboard.
380 380 - ``C-z``: undo (retrieves lost text if you move out of a cell with the arrows).
381 381 - ``C-S-z``: redo.
382 382 - ``C-o``: move to 'other' area, between pager and terminal.
383 383 - ``C-l``: clear terminal.
384 384 - ``C-a``: go to beginning of line.
385 385 - ``C-e``: go to end of line.
386 386 - ``C-k``: kill from cursor to the end of the line.
387 387 - ``C-y``: yank (paste)
388 388 - ``C-p``: previous line (like up arrow)
389 389 - ``C-n``: next line (like down arrow)
390 390 - ``C-f``: forward (like right arrow)
391 391 - ``C-b``: back (like left arrow)
392 392 - ``C-d``: delete next character.
393 393 - ``M-<``: move to the beginning of the input region.
394 394 - ``M->``: move to the end of the input region.
395 395 - ``M-d``: delete next word.
396 396 - ``M-Backspace``: delete previous word.
397 397 - ``C-.``: force a kernel restart (a confirmation dialog appears).
398 398 - ``C-+``: increase font size.
399 399 - ``C--``: decrease font size.
400 400
401 401 The IPython pager
402 402 =================
403 403
404 404 IPython will show long blocks of text from many sources using a builtin pager.
405 405 You can control where this pager appears with the ``--paging`` command-line
406 406 flag:
407 407
408 408 - ``inside`` [default]: the pager is overlaid on top of the main terminal. You
409 409 must quit the pager to get back to the terminal (similar to how a pager such
410 410 as ``less`` or ``more`` works).
411 411
412 412 - ``vsplit``: the console is made double-tall, and the pager appears on the
413 413 bottom area when needed. You can view its contents while using the terminal.
414 414
415 415 - ``hsplit``: the console is made double-wide, and the pager appears on the
416 416 right area when needed. You can view its contents while using the terminal.
417 417
418 418 - ``none``: the console never pages output.
419 419
420 420 If you use the vertical or horizontal paging modes, you can navigate between
421 421 terminal and pager as follows:
422 422
423 423 - Tab key: goes from pager to terminal (but not the other way around).
424 424 - Control-o: goes from one to another always.
425 425 - Mouse: click on either.
426 426
427 427 In all cases, the ``q`` or ``Escape`` keys quit the pager (when used with the
428 428 focus on the pager area).
429 429
430 430 Running subprocesses
431 431 ====================
432 432
433 433 The graphical IPython console uses the ``pexpect`` module to run subprocesses
434 434 when you type ``!command``. This has a number of advantages (true asynchronous
435 435 output from subprocesses as well as very robust termination of rogue
436 436 subprocesses with ``Control-C``), as well as some limitations. The main
437 437 limitation is that you can *not* interact back with the subprocess, so anything
438 438 that invokes a pager or expects you to type input into it will block and hang
439 439 (you can kill it with ``Control-C``).
440 440
441 441 We have provided as magics ``%less`` to page files (aliased to ``%more``),
442 442 ``%clear`` to clear the terminal, and ``%man`` on Linux/OSX. These cover the
443 443 most common commands you'd want to call in your subshell and that would cause
444 444 problems if invoked via ``!cmd``, but you need to be aware of this limitation.
445 445
446 446 Display
447 447 =======
448 448
449 449 The IPython console can now display objects in a variety of formats, including
450 450 HTML, PNG and SVG. This is accomplished using the display functions in
451 451 ``IPython.core.display``::
452 452
453 453 In [4]: from IPython.core.display import display, display_html
454 454
455 455 In [5]: from IPython.core.display import display_png, display_svg
456 456
457 457 Python objects can simply be passed to these functions and the appropriate
458 458 representations will be displayed in the console as long as the objects know
459 459 how to compute those representations. The easiest way of teaching objects how
460 460 to format themselves in various representations is to define special methods
461 461 such as: ``_repr_html_``, ``_repr_svg_`` and ``_repr_png_``. IPython's display formatters
462 462 can also be given custom formatter functions for various types::
463 463
464 464 In [6]: ip = get_ipython()
465 465
466 466 In [7]: html_formatter = ip.display_formatter.formatters['text/html']
467 467
468 468 In [8]: html_formatter.for_type(Foo, foo_to_html)
469 469
470 470 For further details, see ``IPython.core.formatters``.
471 471
472 472 Inline matplotlib graphics
473 473 ==========================
474 474
475 475 The IPython console is capable of displaying matplotlib figures inline, in SVG
476 476 format. If started with the ``--pylab inline`` flag, then all figures are
477 477 rendered inline automatically. If started with ``--pylab`` or ``--pylab <your
478 478 backend>``, then a GUI backend will be used, but IPython's ``display()`` and
479 479 ``getfigs()`` functions can be used to view plots inline::
480 480
481 481 In [9]: display(*getfigs()) # display all figures inline
482 482
483 483 In[10]: display(*getfigs(1,2)) # display figures 1 and 2 inline
484 484 """
485 485
486 486
487 487 quick_guide = """\
488 488 ? -> Introduction and overview of IPython's features.
489 489 %quickref -> Quick reference.
490 490 help -> Python's own help system.
491 491 object? -> Details about 'object', use 'object??' for extra details.
492 492 """
493 493
494 494 gui_note = """\
495 495 %guiref -> A brief reference about the graphical user interface.
496 496 """
497 497
498 498 default_banner_parts = [
499 499 'Python %s\n' % (sys.version.split('\n')[0],),
500 500 'Type "copyright", "credits" or "license" for more information.\n\n',
501 501 'IPython %s -- An enhanced Interactive Python.\n' % (release.version,),
502 502 quick_guide
503 503 ]
504 504
505 505 default_gui_banner_parts = default_banner_parts + [gui_note]
506 506
507 507 default_banner = ''.join(default_banner_parts)
508 508
509 509 default_gui_banner = ''.join(default_gui_banner_parts)
@@ -1,492 +1,492 b''
1 1 ;;; ipython.el --- Adds support for IPython to python-mode.el
2 2
3 3 ;; Copyright (C) 2002, 2003, 2004, 2005 Alexander Schmolck
4 4 ;; Author: Alexander Schmolck
5 5 ;; Keywords: ipython python languages oop
6 ;; URL: http://ipython.scipy.org
6 ;; URL: http://ipython.org
7 7 ;; Compatibility: Emacs21, XEmacs21
8 8 ;; FIXME: #$@! INPUT RING
9 9 (defconst ipython-version "0.11"
10 10 "Tied to IPython main version number.")
11 11
12 12 ;;; Commentary
13 13 ;; This library makes all the functionality python-mode has when running with
14 14 ;; the normal python-interpreter available for ipython, too. It also enables a
15 15 ;; persistent py-shell command history across sessions (if you exit python
16 16 ;; with C-d in py-shell) and defines the command `ipython-to-doctest', which
17 17 ;; can be used to convert bits of a ipython session into something that can be
18 18 ;; used for doctests. To install, put this file somewhere in your emacs
19 19 ;; `load-path' [1] and add the following line to your ~/.emacs file (the first
20 20 ;; line only needed if the default (``"ipython"``) is wrong)::
21 21 ;;
22 22 ;; (setq ipython-command "/SOME-PATH/ipython")
23 23 ;; (require 'ipython)
24 24 ;;
25 25 ;; Ipython will be set as the default python shell, but only if the ipython
26 26 ;; executable is in the path. For ipython sessions autocompletion with <tab>
27 27 ;; is also enabled (experimental feature!). Please also note that all the
28 28 ;; terminal functions in py-shell are handled by emacs's comint, **not** by
29 29 ;; (i)python, so importing readline etc. will have 0 effect.
30 30 ;;
31 31 ;; To start an interactive ipython session run `py-shell' with ``M-x py-shell``
32 32 ;; (or the default keybinding ``C-c C-!``).
33 33 ;;
34 34 ;; You can customize the arguments passed to the IPython instance at startup by
35 35 ;; setting the ``py-python-command-args`` variable. For example, to start
36 36 ;; always in ``pylab`` mode with hardcoded light-background colors, you can
37 37 ;; use::
38 38 ;;
39 39 ;; (setq py-python-command-args '("-pylab" "--colors" "LightBG"))
40 40 ;;
41 41 ;;
42 42 ;; NOTE: This mode is currently somewhat alpha and although I hope that it
43 43 ;; will work fine for most cases, doing certain things (like the
44 44 ;; autocompletion and a decent scheme to switch between python interpreters)
45 45 ;; properly will also require changes to ipython that will likely have to wait
46 46 ;; for a larger rewrite scheduled some time in the future.
47 47 ;;
48 48 ;;
49 49 ;; Further note that I don't know whether this runs under windows or not and
50 50 ;; that if it doesn't I can't really help much, not being afflicted myself.
51 51 ;;
52 52 ;;
53 53 ;; Hints for effective usage
54 54 ;; -------------------------
55 55 ;;
56 56 ;; - IMO the best feature by far of the ipython/emacs combo is how much easier
57 57 ;; it makes it to find and fix bugs thanks to the ``%pdb on or %debug``/
58 58 ;; pdbtrack combo. Try it: first in the ipython to shell do ``%pdb on`` then
59 59 ;; do something that will raise an exception (FIXME nice example), or type
60 60 ;; ``%debug`` after the exception has been raised. YOu'll be amazed at how
61 61 ;; easy it is to inspect the live objects in each stack frames and to jump to
62 62 ;; the corresponding sourcecode locations as you walk up and down the stack
63 63 ;; trace (even without ``%pdb on`` you can always use ``C-c -``
64 64 ;; (`py-up-exception') to jump to the corresponding source code locations).
65 65 ;;
66 66 ;; - emacs gives you much more powerful commandline editing and output searching
67 67 ;; capabilities than ipython-standalone -- isearch is your friend if you
68 68 ;; quickly want to print 'DEBUG ...' to stdout out etc.
69 69 ;;
70 70 ;; - This is not really specific to ipython, but for more convenient history
71 71 ;; access you might want to add something like the following to *the beggining*
72 72 ;; of your ``.emacs`` (if you want behavior that's more similar to stand-alone
73 73 ;; ipython, you can change ``meta p`` etc. for ``control p``)::
74 74 ;;
75 75 ;; (require 'comint)
76 76 ;; (define-key comint-mode-map [(meta p)]
77 77 ;; 'comint-previous-matching-input-from-input)
78 78 ;; (define-key comint-mode-map [(meta n)]
79 79 ;; 'comint-next-matching-input-from-input)
80 80 ;; (define-key comint-mode-map [(control meta n)]
81 81 ;; 'comint-next-input)
82 82 ;; (define-key comint-mode-map [(control meta p)]
83 83 ;; 'comint-previous-input)
84 84 ;;
85 85 ;; - Be aware that if you customize py-python-command previously, this value
86 86 ;; will override what ipython.el does (because loading the customization
87 87 ;; variables comes later).
88 88 ;;
89 89 ;; Please send comments and feedback to the ipython-list
90 90 ;; (<ipython-user@scipy.org>) where I (a.s.) or someone else will try to
91 91 ;; answer them (it helps if you specify your emacs version, OS etc;
92 92 ;; familiarity with <http://www.catb.org/~esr/faqs/smart-questions.html> might
93 93 ;; speed up things further).
94 94 ;;
95 95 ;; Footnotes:
96 96 ;;
97 97 ;; [1] If you don't know what `load-path' is, C-h v load-path will tell
98 98 ;; you; if required you can also add a new directory. So assuming that
99 99 ;; ipython.el resides in ~/el/, put this in your emacs:
100 100 ;;
101 101 ;;
102 102 ;; (add-to-list 'load-path "~/el")
103 103 ;; (setq ipython-command "/some-path/ipython")
104 104 ;; (require 'ipython)
105 105 ;;
106 106 ;;
107 107 ;;
108 108 ;;
109 109 ;; TODO:
110 110 ;; - do autocompletion properly
111 111 ;; - implement a proper switching between python interpreters
112 112 ;;
113 113 ;; BUGS:
114 114 ;; - neither::
115 115 ;;
116 116 ;; (py-shell "-c print 'FOOBAR'")
117 117 ;;
118 118 ;; nor::
119 119 ;;
120 120 ;; (let ((py-python-command-args (append py-python-command-args
121 121 ;; '("-c" "print 'FOOBAR'"))))
122 122 ;; (py-shell))
123 123 ;;
124 124 ;; seem to print anything as they should
125 125 ;;
126 126 ;; - look into init priority issues with `py-python-command' (if it's set
127 127 ;; via custom)
128 128
129 129
130 130 ;;; Code
131 131 (require 'cl)
132 132 (require 'shell)
133 133 (require 'executable)
134 134 (require 'ansi-color)
135 135
136 136 (defcustom ipython-command "ipython"
137 137 "*Shell command used to start ipython."
138 138 :type 'string
139 139 :group 'python)
140 140
141 141 ;; Users can set this to nil
142 142 (defvar py-shell-initial-switch-buffers t
143 143 "If nil, don't switch to the *Python* buffer on the first call to
144 144 `py-shell'.")
145 145
146 146 (defvar ipython-backup-of-py-python-command nil
147 147 "HACK")
148 148
149 149
150 150 (defvar ipython-de-input-prompt-regexp "\\(?:
151 151 In \\[[0-9]+\\]: *.*
152 152 ----+> \\(.*
153 153 \\)[\n]?\\)\\|\\(?:
154 154 In \\[[0-9]+\\]: *\\(.*
155 155 \\)\\)\\|^[ ]\\{3\\}[.]\\{3,\\}: *\\(.*
156 156 \\)"
157 157 "A regular expression to match the IPython input prompt and the python
158 158 command after it. The first match group is for a command that is rewritten,
159 159 the second for a 'normal' command, and the third for a multiline command.")
160 160 (defvar ipython-de-output-prompt-regexp "^Out\\[[0-9]+\\]: "
161 161 "A regular expression to match the output prompt of IPython.")
162 162
163 163
164 164 (if (not (executable-find ipython-command))
165 165 (message (format "Can't find executable %s - ipython.el *NOT* activated!!!"
166 166 ipython-command))
167 167 ;; XXX load python-mode, so that we can screw around with its variables
168 168 ;; this has the disadvantage that python-mode is loaded even if no
169 169 ;; python-file is ever edited etc. but it means that `py-shell' works
170 170 ;; without loading a python-file first. Obviously screwing around with
171 171 ;; python-mode's variables like this is a mess, but well.
172 172 (require 'python-mode)
173 173 ;; turn on ansi colors for ipython and activate completion
174 174 (defun ipython-shell-hook ()
175 175 ;; the following is to synchronize dir-changes
176 176 (make-local-variable 'shell-dirstack)
177 177 (setq shell-dirstack nil)
178 178 (make-local-variable 'shell-last-dir)
179 179 (setq shell-last-dir nil)
180 180 (make-local-variable 'shell-dirtrackp)
181 181 (setq shell-dirtrackp t)
182 182 (add-hook 'comint-input-filter-functions 'shell-directory-tracker nil t)
183 183
184 184 (ansi-color-for-comint-mode-on)
185 185 (define-key py-shell-map [tab] 'ipython-complete)
186 186 ;; Add this so that tab-completion works both in X11 frames and inside
187 187 ;; terminals (such as when emacs is called with -nw).
188 188 (define-key py-shell-map "\t" 'ipython-complete)
189 189 ;;XXX this is really just a cheap hack, it only completes symbols in the
190 190 ;;interactive session -- useful nonetheless.
191 191 (define-key py-mode-map [(meta tab)] 'ipython-complete)
192 192
193 193 )
194 194 (add-hook 'py-shell-hook 'ipython-shell-hook)
195 195 ;; Regular expression that describes tracebacks for IPython in context and
196 196 ;; verbose mode.
197 197
198 198 ;;Adapt python-mode settings for ipython.
199 199 ;; (this works for %xmode 'verbose' or 'context')
200 200
201 201 ;; XXX putative regexps for syntax errors; unfortunately the
202 202 ;; current python-mode traceback-line-re scheme is too primitive,
203 203 ;; so it's either matching syntax errors, *or* everything else
204 204 ;; (XXX: should ask Fernando for a change)
205 205 ;;"^ File \"\\(.*?\\)\", line \\([0-9]+\\).*\n.*\n.*\nSyntaxError:"
206 206 ;;^ File \"\\(.*?\\)\", line \\([0-9]+\\)"
207 207
208 208 (setq py-traceback-line-re
209 209 "\\(^[^\t >].+?\\.py\\).*\n +[0-9]+[^\00]*?\n-+> \\([0-9]+\\)+")
210 210
211 211
212 212 ;; Recognize the ipython pdb, whose prompt is 'ipdb>' or 'ipydb>'
213 213 ;;instead of '(Pdb)'
214 214 (setq py-pdbtrack-input-prompt "\n[(<]*[Ii]?[Pp]y?db[>)]+ ")
215 215 (setq pydb-pydbtrack-input-prompt "\n[(]*ipydb[>)]+ ")
216 216
217 217 (setq py-shell-input-prompt-1-regexp "^In \\[[0-9]+\\]: *"
218 218 py-shell-input-prompt-2-regexp "^ [.][.][.]+: *" )
219 219 ;; select a suitable color-scheme
220 220 (unless (member "--colors" py-python-command-args)
221 221 (setq py-python-command-args
222 222 (nconc py-python-command-args
223 223 (list "--colors"
224 224 (cond
225 225 ((eq frame-background-mode 'dark)
226 226 "Linux")
227 227 ((eq frame-background-mode 'light)
228 228 "LightBG")
229 229 (t ; default (backg-mode isn't always set by XEmacs)
230 230 "LightBG"))))))
231 231 (unless (equal ipython-backup-of-py-python-command py-python-command)
232 232 (setq ipython-backup-of-py-python-command py-python-command))
233 233 (setq py-python-command ipython-command))
234 234
235 235
236 236 ;; MODIFY py-shell so that it loads the editing history
237 237 (defadvice py-shell (around py-shell-with-history)
238 238 "Add persistent command-history support (in
239 239 $PYTHONHISTORY (or \"~/.ipython/history\", if we use IPython)). Also, if
240 240 `py-shell-initial-switch-buffers' is nil, it only switches to *Python* if that
241 241 buffer already exists."
242 242 (if (comint-check-proc "*Python*")
243 243 ad-do-it
244 244 (setq comint-input-ring-file-name
245 245 (if (string-equal py-python-command ipython-command)
246 246 (concat (or (getenv "IPYTHONDIR") "~/.ipython") "/history")
247 247 (or (getenv "PYTHONHISTORY") "~/.python-history.py")))
248 248 (comint-read-input-ring t)
249 249 (let ((buf (current-buffer)))
250 250 ad-do-it
251 251 (unless py-shell-initial-switch-buffers
252 252 (switch-to-buffer-other-window buf)))))
253 253 (ad-activate 'py-shell)
254 254 ;; (defadvice py-execute-region (before py-execute-buffer-ensure-process)
255 255 ;; "HACK: test that ipython is already running before executing something.
256 256 ;; Doing this properly seems not worth the bother (unless people actually
257 257 ;; request it)."
258 258 ;; (unless (comint-check-proc "*Python*")
259 259 ;; (error "Sorry you have to first do M-x py-shell to send something to ipython.")))
260 260 ;; (ad-activate 'py-execute-region)
261 261
262 262 (defadvice py-execute-region (around py-execute-buffer-ensure-process)
263 263 "HACK: if `py-shell' is not active or ASYNC is explicitly desired, fall back
264 264 to python instead of ipython."
265 265 (let ((py-which-shell (if (and (comint-check-proc "*Python*") (not async))
266 266 py-python-command
267 267 ipython-backup-of-py-python-command)))
268 268 ad-do-it))
269 269 (ad-activate 'py-execute-region)
270 270
271 271 (defun ipython-to-doctest (start end)
272 272 "Transform a cut-and-pasted bit from an IPython session into something that
273 273 looks like it came from a normal interactive python session, so that it can
274 274 be used in doctests. Example:
275 275
276 276
277 277 In [1]: import sys
278 278
279 279 In [2]: sys.stdout.write 'Hi!\n'
280 280 ------> sys.stdout.write ('Hi!\n')
281 281 Hi!
282 282
283 283 In [3]: 3 + 4
284 284 Out[3]: 7
285 285
286 286 gets converted to:
287 287
288 288 >>> import sys
289 289 >>> sys.stdout.write ('Hi!\n')
290 290 Hi!
291 291 >>> 3 + 4
292 292 7
293 293
294 294 "
295 295 (interactive "*r\n")
296 296 ;(message (format "###DEBUG s:%de:%d" start end))
297 297 (save-excursion
298 298 (save-match-data
299 299 ;; replace ``In [3]: bla`` with ``>>> bla`` and
300 300 ;; ``... : bla`` with ``... bla``
301 301 (goto-char start)
302 302 (while (re-search-forward ipython-de-input-prompt-regexp end t)
303 303 ;(message "finding 1")
304 304 (cond ((match-string 3) ;continued
305 305 (replace-match "... \\3" t nil))
306 306 (t
307 307 (replace-match ">>> \\1\\2" t nil))))
308 308 ;; replace ``
309 309 (goto-char start)
310 310 (while (re-search-forward ipython-de-output-prompt-regexp end t)
311 311 (replace-match "" t nil)))))
312 312
313 313 (defvar ipython-completion-command-string
314 314 "print(';'.join(get_ipython().Completer.all_completions('%s'))) #PYTHON-MODE SILENT\n"
315 315 "The string send to ipython to query for all possible completions")
316 316
317 317
318 318 ;; xemacs doesn't have `comint-preoutput-filter-functions' so we'll try the
319 319 ;; following wonderful hack to work around this case
320 320 (if (featurep 'xemacs)
321 321 ;;xemacs
322 322 (defun ipython-complete ()
323 323 "Try to complete the python symbol before point. Only knows about the stuff
324 324 in the current *Python* session."
325 325 (interactive)
326 326 (let* ((ugly-return nil)
327 327 (sep ";")
328 328 (python-process (or (get-buffer-process (current-buffer))
329 329 ;XXX hack for .py buffers
330 330 (get-process py-which-bufname)))
331 331 ;; XXX currently we go backwards to find the beginning of an
332 332 ;; expression part; a more powerful approach in the future might be
333 333 ;; to let ipython have the complete line, so that context can be used
334 334 ;; to do things like filename completion etc.
335 335 (beg (save-excursion (skip-chars-backward "a-z0-9A-Z_." (point-at-bol))
336 336 (point)))
337 337 (end (point))
338 338 (pattern (buffer-substring-no-properties beg end))
339 339 (completions nil)
340 340 (completion-table nil)
341 341 completion
342 342 (comint-output-filter-functions
343 343 (append comint-output-filter-functions
344 344 '(ansi-color-filter-apply
345 345 (lambda (string)
346 346 ;(message (format "DEBUG filtering: %s" string))
347 347 (setq ugly-return (concat ugly-return string))
348 348 (delete-region comint-last-output-start
349 349 (process-mark (get-buffer-process (current-buffer)))))))))
350 350 ;(message (format "#DEBUG pattern: '%s'" pattern))
351 351 (process-send-string python-process
352 352 (format ipython-completion-command-string pattern))
353 353 (accept-process-output python-process)
354 354
355 355 ;(message (format "DEBUG return: %s" ugly-return))
356 356 (setq completions
357 357 (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep))
358 358 (setq completion-table (loop for str in completions
359 359 collect (list str nil)))
360 360 (setq completion (try-completion pattern completion-table))
361 361 (cond ((eq completion t))
362 362 ((null completion)
363 363 (message "Can't find completion for \"%s\"" pattern)
364 364 (ding))
365 365 ((not (string= pattern completion))
366 366 (delete-region beg end)
367 367 (insert completion))
368 368 (t
369 369 (message "Making completion list...")
370 370 (with-output-to-temp-buffer "*Python Completions*"
371 371 (display-completion-list (all-completions pattern completion-table)))
372 372 (message "Making completion list...%s" "done")))))
373 373 ;; emacs
374 374 (defun ipython-complete ()
375 375 "Try to complete the python symbol before point. Only knows about the stuff
376 376 in the current *Python* session."
377 377 (interactive)
378 378 (let* ((ugly-return nil)
379 379 (sep ";")
380 380 (python-process (or (get-buffer-process (current-buffer))
381 381 ;XXX hack for .py buffers
382 382 (get-process py-which-bufname)))
383 383 ;; XXX currently we go backwards to find the beginning of an
384 384 ;; expression part; a more powerful approach in the future might be
385 385 ;; to let ipython have the complete line, so that context can be used
386 386 ;; to do things like filename completion etc.
387 387 (beg (save-excursion (skip-chars-backward "a-z0-9A-Z_./" (point-at-bol))
388 388 (point)))
389 389 (end (point))
390 390 (pattern (buffer-substring-no-properties beg end))
391 391 (completions nil)
392 392 (completion-table nil)
393 393 completion
394 394 (comint-preoutput-filter-functions
395 395 (append comint-preoutput-filter-functions
396 396 '(ansi-color-filter-apply
397 397 (lambda (string)
398 398 (setq ugly-return (concat ugly-return string))
399 399 "")))))
400 400 (process-send-string python-process
401 401 (format ipython-completion-command-string pattern))
402 402 (accept-process-output python-process)
403 403 (setq completions
404 404 (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep))
405 405 ;(message (format "DEBUG completions: %S" completions))
406 406 (setq completion-table (loop for str in completions
407 407 collect (list str nil)))
408 408 (setq completion (try-completion pattern completion-table))
409 409 (cond ((eq completion t))
410 410 ((null completion)
411 411 (message "Can't find completion for \"%s\"" pattern)
412 412 (ding))
413 413 ((not (string= pattern completion))
414 414 (delete-region beg end)
415 415 (insert completion))
416 416 (t
417 417 (message "Making completion list...")
418 418 (with-output-to-temp-buffer "*IPython Completions*"
419 419 (display-completion-list (all-completions pattern completion-table)))
420 420 (message "Making completion list...%s" "done")))))
421 421 )
422 422
423 423 ;;; autoindent support: patch sent in by Jin Liu <m.liu.jin@gmail.com>,
424 424 ;;; originally written by doxgen@newsmth.net
425 425 ;;; Minor modifications by fperez for xemacs compatibility.
426 426
427 427 (defvar ipython-autoindent t
428 428 "If non-nil, enable autoindent for IPython shell through python-mode.")
429 429
430 430 (defvar ipython-indenting-buffer-name "*IPython Indentation Calculation*"
431 431 "Temporary buffer for indenting multiline statement.")
432 432
433 433 (defun ipython-get-indenting-buffer ()
434 434 "Return a temporary buffer set in python-mode. Create one if necessary."
435 435 (let ((buf (get-buffer-create ipython-indenting-buffer-name)))
436 436 (set-buffer buf)
437 437 (unless (eq major-mode 'python-mode)
438 438 (python-mode))
439 439 buf))
440 440
441 441 (defvar ipython-indentation-string nil
442 442 "Indentation for the next line in a multiline statement.")
443 443
444 444 (defun ipython-send-and-indent ()
445 445 "Send the current line to IPython, and calculate the indentation for
446 446 the next line."
447 447 (interactive)
448 448 (if ipython-autoindent
449 449 (let ((line (buffer-substring (point-at-bol) (point)))
450 450 (after-prompt1)
451 451 (after-prompt2))
452 452 (save-excursion
453 453 (comint-bol t)
454 454 (if (looking-at py-shell-input-prompt-1-regexp)
455 455 (setq after-prompt1 t)
456 456 (setq after-prompt2 (looking-at py-shell-input-prompt-2-regexp)))
457 457 (with-current-buffer (ipython-get-indenting-buffer)
458 458 (when after-prompt1
459 459 (erase-buffer))
460 460 (when (or after-prompt1 after-prompt2)
461 461 (delete-region (point-at-bol) (point))
462 462 (insert line)
463 463 (newline-and-indent))))))
464 464 ;; send input line to ipython interpreter
465 465 (comint-send-input))
466 466
467 467 (defun ipython-indentation-hook (string)
468 468 "Insert indentation string if py-shell-input-prompt-2-regexp
469 469 matches last process output."
470 470 (let* ((start-marker (or comint-last-output-start
471 471 (point-min-marker)))
472 472 (end-marker (process-mark (get-buffer-process (current-buffer))))
473 473 (text (ansi-color-filter-apply (buffer-substring start-marker end-marker))))
474 474 ;; XXX if `text' matches both pattern, it MUST be the last prompt-2
475 475 (when (and (string-match py-shell-input-prompt-2-regexp text)
476 476 (not (string-match "\n$" text)))
477 477 (with-current-buffer (ipython-get-indenting-buffer)
478 478 (setq ipython-indentation-string
479 479 (buffer-substring (point-at-bol) (point))))
480 480 (goto-char end-marker)
481 481 (insert ipython-indentation-string)
482 482 (setq ipython-indentation-string nil))))
483 483
484 484 (add-hook 'py-shell-hook
485 485 (lambda ()
486 486 (add-hook 'comint-output-filter-functions
487 487 'ipython-indentation-hook)))
488 488
489 489 (define-key py-shell-map (kbd "RET") 'ipython-send-and-indent)
490 490 ;;; / end autoindent support
491 491
492 492 (provide 'ipython)
@@ -1,67 +1,67 b''
1 1 .. This (-*- rst -*-) format file contains commonly used link targets
2 2 and name substitutions. It may be included in many files,
3 3 therefore it should only contain link targets and name
4 4 substitutions. Try grepping for "^\.\. _" to find plausible
5 5 candidates for this list.
6 6
7 7 .. NOTE: reST targets are
8 8 __not_case_sensitive__, so only one target definition is needed for
9 9 nipy, NIPY, Nipy, etc...
10 10
11 11 .. PROJECTNAME placeholders
12 12 .. _PROJECTNAME: http://neuroimaging.scipy.org
13 13 .. _`PROJECTNAME github`: http://github.com/nipy
14 14 .. _`PROJECTNAME mailing list`: http://projects.scipy.org/mailman/listinfo/nipy-devel
15 15
16 16 .. nipy
17 17 .. _nipy: http://nipy.org/nipy
18 18 .. _`nipy github`: http://github.com/nipy/nipy
19 19 .. _`nipy mailing list`: http://mail.scipy.org/mailman/listinfo/nipy-devel
20 20
21 21 .. ipython
22 .. _ipython: http://ipython.scipy.org
22 .. _ipython: http://ipython.org
23 23 .. _`ipython github`: http://github.com/ipython/ipython
24 24 .. _`ipython mailing list`: http://mail.scipy.org/mailman/listinfo/IPython-dev
25 25
26 26 .. nipy
27 27 .. _dipy: http://nipy.org/dipy
28 28 .. _`dipy github`: http://github.com/Garyfallidis/dipy
29 29 .. _`dipy mailing list`: http://mail.scipy.org/mailman/listinfo/nipy-devel
30 30
31 31 .. git stuff
32 32 .. _git: http://git-scm.com/
33 33 .. _github: http://github.com
34 34 .. _github help: http://help.github.com
35 35 .. _msysgit: http://code.google.com/p/msysgit/downloads/list
36 36 .. _git-osx-installer: http://code.google.com/p/git-osx-installer/downloads/list
37 37 .. _subversion: http://subversion.tigris.org/
38 38 .. _git cheat sheet: http://github.com/guides/git-cheat-sheet
39 39 .. _pro git book: http://progit.org/
40 40 .. _git svn crash course: http://git-scm.com/course/svn.html
41 41 .. _learn.github: http://learn.github.com/
42 42 .. _network graph visualizer: http://github.com/blog/39-say-hello-to-the-network-graph-visualizer
43 43 .. _git user manual: http://www.kernel.org/pub/software/scm/git/docs/user-manual.html
44 44 .. _git tutorial: http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
45 45 .. _git community book: http://book.git-scm.com/
46 46 .. _git ready: http://www.gitready.com/
47 47 .. _git casts: http://www.gitcasts.com/
48 48 .. _Fernando's git page: http://www.fperez.org/py4science/git.html
49 49 .. _git magic: http://www-cs-students.stanford.edu/~blynn/gitmagic/index.html
50 50 .. _git concepts: http://www.eecs.harvard.edu/~cduan/technical/git/
51 51 .. _git clone: http://www.kernel.org/pub/software/scm/git/docs/git-clone.html
52 52 .. _git checkout: http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html
53 53 .. _git commit: http://www.kernel.org/pub/software/scm/git/docs/git-commit.html
54 54 .. _git push: http://www.kernel.org/pub/software/scm/git/docs/git-push.html
55 55 .. _git pull: http://www.kernel.org/pub/software/scm/git/docs/git-pull.html
56 56 .. _git add: http://www.kernel.org/pub/software/scm/git/docs/git-add.html
57 57 .. _git status: http://www.kernel.org/pub/software/scm/git/docs/git-status.html
58 58 .. _git diff: http://www.kernel.org/pub/software/scm/git/docs/git-diff.html
59 59 .. _git log: http://www.kernel.org/pub/software/scm/git/docs/git-log.html
60 60 .. _git branch: http://www.kernel.org/pub/software/scm/git/docs/git-branch.html
61 61 .. _git remote: http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
62 62 .. _git config: http://www.kernel.org/pub/software/scm/git/docs/git-config.html
63 63 .. _why the -a flag?: http://www.gitready.com/beginner/2009/01/18/the-staging-area.html
64 64 .. _git staging area: http://www.gitready.com/beginner/2009/01/18/the-staging-area.html
65 65 .. _git management: http://kerneltrap.org/Linux/Git_Management
66 66 .. _linux git workflow: http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html
67 67 .. _git parable: http://tom.preston-werner.com/2009/05/19/the-git-parable.html
@@ -1,74 +1,74 b''
1 1 .. This (-*- rst -*-) format file contains commonly used link targets
2 2 and name substitutions. It may be included in many files,
3 3 therefore it should only contain link targets and name
4 4 substitutions. Try grepping for "^\.\. _" to find plausible
5 5 candidates for this list.
6 6
7 7 NOTE: this file must have an extension *opposite* to that of the main reST
8 8 files in the manuals, so that we can include it with ".. include::"
9 9 directives, but without triggering warnings from Sphinx for not being listed
10 10 in any toctree. Since IPython uses .txt for the main files, this wone will
11 11 use .rst.
12 12
13 13 NOTE: reST targets are
14 14 __not_case_sensitive__, so only one target definition is needed for
15 15 ipython, IPython, etc.
16 16
17 17 NOTE: Some of these were taken from the nipy links compendium.
18 18
19 19 .. Main IPython links
20 .. _ipython: http://ipython.scipy.org
21 .. _`ipython manual`: http://ipython.scipy.org/doc/manual/html
20 .. _ipython: http://ipython.org
21 .. _`ipython manual`: http://ipython.org/documentation.html
22 22 .. _ipython_github: http://github.com/ipython/ipython/
23 23 .. _ipython_github_repo: http://github.com/ipython/ipython/
24 24 .. _ipython_downloads: http://ipython.scipy.org/dist
25 25 .. _ipython_pypi: http://pypi.python.org/pypi/ipython
26 26
27 27 .. _ZeroMQ: http://zeromq.org
28 28
29 29 .. Documentation tools and related links
30 30 .. _graphviz: http://www.graphviz.org
31 31 .. _Sphinx: http://sphinx.pocoo.org
32 32 .. _`Sphinx reST`: http://sphinx.pocoo.org/rest.html
33 33 .. _sampledoc: http://matplotlib.sourceforge.net/sampledoc
34 34 .. _reST: http://docutils.sourceforge.net/rst.html
35 35 .. _docutils: http://docutils.sourceforge.net
36 36 .. _lyx: http://www.lyx.org
37 37 .. _pep8: http://www.python.org/dev/peps/pep-0008
38 38 .. _numpy_coding_guide: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
39 39
40 40 .. Licenses
41 41 .. _GPL: http://www.gnu.org/licenses/gpl.html
42 42 .. _BSD: http://www.opensource.org/licenses/bsd-license.php
43 43 .. _LGPL: http://www.gnu.org/copyleft/lesser.html
44 44
45 45 .. Other python projects
46 46 .. _numpy: http://numpy.scipy.org
47 47 .. _scipy: http://www.scipy.org
48 48 .. _scipy_conference: http://conference.scipy.org
49 49 .. _matplotlib: http://matplotlib.sourceforge.net
50 50 .. _pythonxy: http://www.pythonxy.com
51 51 .. _ETS: http://code.enthought.com/projects/tool-suite.php
52 52 .. _EPD: http://www.enthought.com/products/epd.php
53 53 .. _python: http://www.python.org
54 54 .. _mayavi: http://code.enthought.com/projects/mayavi
55 55 .. _sympy: http://code.google.com/p/sympy
56 56 .. _sage: http://sagemath.org
57 57 .. _pydy: http://code.google.com/p/pydy
58 58 .. _vpython: http://vpython.org
59 59 .. _cython: http://cython.org
60 60 .. _software carpentry: http://software-carpentry.org
61 61
62 62 .. Not so python scientific computing tools
63 63 .. _matlab: http://www.mathworks.com
64 64 .. _VTK: http://vtk.org
65 65
66 66 .. Other organizations
67 67 .. _enthought: http://www.enthought.com
68 68 .. _kitware: http://www.kitware.com
69 69 .. _netlib: http://netlib.org
70 70
71 71 .. Other tools and projects
72 72 .. _indefero: http://www.indefero.net
73 73 .. _git: http://git-scm.com
74 74 .. _github: http://github.com
@@ -1,334 +1,334 b''
1 1 ============================================
2 2 Getting started with Windows HPC Server 2008
3 3 ============================================
4 4
5 5 .. note::
6 6
7 7 Not adapted to zmq yet
8 8
9 9 Introduction
10 10 ============
11 11
12 12 The Python programming language is an increasingly popular language for
13 13 numerical computing. This is due to a unique combination of factors. First,
14 14 Python is a high-level and *interactive* language that is well matched to
15 15 interactive numerical work. Second, it is easy (often times trivial) to
16 16 integrate legacy C/C++/Fortran code into Python. Third, a large number of
17 17 high-quality open source projects provide all the needed building blocks for
18 18 numerical computing: numerical arrays (NumPy), algorithms (SciPy), 2D/3D
19 19 Visualization (Matplotlib, Mayavi, Chaco), Symbolic Mathematics (Sage, Sympy)
20 20 and others.
21 21
22 22 The IPython project is a core part of this open-source toolchain and is
23 23 focused on creating a comprehensive environment for interactive and
24 24 exploratory computing in the Python programming language. It enables all of
25 25 the above tools to be used interactively and consists of two main components:
26 26
27 27 * An enhanced interactive Python shell with support for interactive plotting
28 28 and visualization.
29 29 * An architecture for interactive parallel computing.
30 30
31 31 With these components, it is possible to perform all aspects of a parallel
32 32 computation interactively. This type of workflow is particularly relevant in
33 33 scientific and numerical computing where algorithms, code and data are
34 34 continually evolving as the user/developer explores a problem. The broad
35 35 treads in computing (commodity clusters, multicore, cloud computing, etc.)
36 36 make these capabilities of IPython particularly relevant.
37 37
38 38 While IPython is a cross platform tool, it has particularly strong support for
39 39 Windows based compute clusters running Windows HPC Server 2008. This document
40 40 describes how to get started with IPython on Windows HPC Server 2008. The
41 41 content and emphasis here is practical: installing IPython, configuring
42 42 IPython to use the Windows job scheduler and running example parallel programs
43 43 interactively. A more complete description of IPython's parallel computing
44 44 capabilities can be found in IPython's online documentation
45 (http://ipython.scipy.org/moin/Documentation).
45 (http://ipython.org/documentation.html).
46 46
47 47 Setting up your Windows cluster
48 48 ===============================
49 49
50 50 This document assumes that you already have a cluster running Windows
51 51 HPC Server 2008. Here is a broad overview of what is involved with setting up
52 52 such a cluster:
53 53
54 54 1. Install Windows Server 2008 on the head and compute nodes in the cluster.
55 55 2. Setup the network configuration on each host. Each host should have a
56 56 static IP address.
57 57 3. On the head node, activate the "Active Directory Domain Services" role
58 58 and make the head node the domain controller.
59 59 4. Join the compute nodes to the newly created Active Directory (AD) domain.
60 60 5. Setup user accounts in the domain with shared home directories.
61 61 6. Install the HPC Pack 2008 on the head node to create a cluster.
62 62 7. Install the HPC Pack 2008 on the compute nodes.
63 63
64 64 More details about installing and configuring Windows HPC Server 2008 can be
65 65 found on the Windows HPC Home Page (http://www.microsoft.com/hpc). Regardless
66 66 of what steps you follow to set up your cluster, the remainder of this
67 67 document will assume that:
68 68
69 69 * There are domain users that can log on to the AD domain and submit jobs
70 70 to the cluster scheduler.
71 71 * These domain users have shared home directories. While shared home
72 72 directories are not required to use IPython, they make it much easier to
73 73 use IPython.
74 74
75 75 Installation of IPython and its dependencies
76 76 ============================================
77 77
78 78 IPython and all of its dependencies are freely available and open source.
79 79 These packages provide a powerful and cost-effective approach to numerical and
80 80 scientific computing on Windows. The following dependencies are needed to run
81 81 IPython on Windows:
82 82
83 83 * Python 2.6 or 2.7 (http://www.python.org)
84 84 * pywin32 (http://sourceforge.net/projects/pywin32/)
85 85 * PyReadline (https://launchpad.net/pyreadline)
86 86 * pyzmq (http://github.com/zeromq/pyzmq/downloads)
87 * IPython (http://ipython.scipy.org)
87 * IPython (http://ipython.org)
88 88
89 89 In addition, the following dependencies are needed to run the demos described
90 90 in this document.
91 91
92 92 * NumPy and SciPy (http://www.scipy.org)
93 93 * Matplotlib (http://matplotlib.sourceforge.net/)
94 94
95 95 The easiest way of obtaining these dependencies is through the Enthought
96 96 Python Distribution (EPD) (http://www.enthought.com/products/epd.php). EPD is
97 97 produced by Enthought, Inc. and contains all of these packages and others in a
98 98 single installer and is available free for academic users. While it is also
99 99 possible to download and install each package individually, this is a tedious
100 100 process. Thus, we highly recommend using EPD to install these packages on
101 101 Windows.
102 102
103 103 Regardless of how you install the dependencies, here are the steps you will
104 104 need to follow:
105 105
106 106 1. Install all of the packages listed above, either individually or using EPD
107 107 on the head node, compute nodes and user workstations.
108 108
109 109 2. Make sure that :file:`C:\\Python27` and :file:`C:\\Python27\\Scripts` are
110 110 in the system :envvar:`%PATH%` variable on each node.
111 111
112 112 3. Install the latest development version of IPython. This can be done by
113 113 downloading the the development version from the IPython website
114 (http://ipython.scipy.org) and following the installation instructions.
114 (http://ipython.org) and following the installation instructions.
115 115
116 116 Further details about installing IPython or its dependencies can be found in
117 the online IPython documentation (http://ipython.scipy.org/moin/Documentation)
117 the online IPython documentation (http://ipython.org/documentation.html)
118 118 Once you are finished with the installation, you can try IPython out by
119 119 opening a Windows Command Prompt and typing ``ipython``. This will
120 120 start IPython's interactive shell and you should see something like the
121 121 following screenshot:
122 122
123 123 .. image:: ipython_shell.*
124 124
125 125 Starting an IPython cluster
126 126 ===========================
127 127
128 128 To use IPython's parallel computing capabilities, you will need to start an
129 129 IPython cluster. An IPython cluster consists of one controller and multiple
130 130 engines:
131 131
132 132 IPython controller
133 133 The IPython controller manages the engines and acts as a gateway between
134 134 the engines and the client, which runs in the user's interactive IPython
135 135 session. The controller is started using the :command:`ipcontroller`
136 136 command.
137 137
138 138 IPython engine
139 139 IPython engines run a user's Python code in parallel on the compute nodes.
140 140 Engines are starting using the :command:`ipengine` command.
141 141
142 142 Once these processes are started, a user can run Python code interactively and
143 143 in parallel on the engines from within the IPython shell using an appropriate
144 144 client. This includes the ability to interact with, plot and visualize data
145 145 from the engines.
146 146
147 147 IPython has a command line program called :command:`ipcluster` that automates
148 148 all aspects of starting the controller and engines on the compute nodes.
149 149 :command:`ipcluster` has full support for the Windows HPC job scheduler,
150 150 meaning that :command:`ipcluster` can use this job scheduler to start the
151 151 controller and engines. In our experience, the Windows HPC job scheduler is
152 152 particularly well suited for interactive applications, such as IPython. Once
153 153 :command:`ipcluster` is configured properly, a user can start an IPython
154 154 cluster from their local workstation almost instantly, without having to log
155 155 on to the head node (as is typically required by Unix based job schedulers).
156 156 This enables a user to move seamlessly between serial and parallel
157 157 computations.
158 158
159 159 In this section we show how to use :command:`ipcluster` to start an IPython
160 160 cluster using the Windows HPC Server 2008 job scheduler. To make sure that
161 161 :command:`ipcluster` is installed and working properly, you should first try
162 162 to start an IPython cluster on your local host. To do this, open a Windows
163 163 Command Prompt and type the following command::
164 164
165 165 ipcluster start n=2
166 166
167 167 You should see a number of messages printed to the screen, ending with
168 168 "IPython cluster: started". The result should look something like the following
169 169 screenshot:
170 170
171 171 .. image:: ipcluster_start.*
172 172
173 173 At this point, the controller and two engines are running on your local host.
174 174 This configuration is useful for testing and for situations where you want to
175 175 take advantage of multiple cores on your local computer.
176 176
177 177 Now that we have confirmed that :command:`ipcluster` is working properly, we
178 178 describe how to configure and run an IPython cluster on an actual compute
179 179 cluster running Windows HPC Server 2008. Here is an outline of the needed
180 180 steps:
181 181
182 182 1. Create a cluster profile using: ``ipython profile create --parallel profile=mycluster``
183 183
184 184 2. Edit configuration files in the directory :file:`.ipython\\cluster_mycluster`
185 185
186 186 3. Start the cluster using: ``ipcluser start profile=mycluster n=32``
187 187
188 188 Creating a cluster profile
189 189 --------------------------
190 190
191 191 In most cases, you will have to create a cluster profile to use IPython on a
192 192 cluster. A cluster profile is a name (like "mycluster") that is associated
193 193 with a particular cluster configuration. The profile name is used by
194 194 :command:`ipcluster` when working with the cluster.
195 195
196 196 Associated with each cluster profile is a cluster directory. This cluster
197 197 directory is a specially named directory (typically located in the
198 198 :file:`.ipython` subdirectory of your home directory) that contains the
199 199 configuration files for a particular cluster profile, as well as log files and
200 200 security keys. The naming convention for cluster directories is:
201 201 :file:`profile_<profile name>`. Thus, the cluster directory for a profile named
202 202 "foo" would be :file:`.ipython\\cluster_foo`.
203 203
204 204 To create a new cluster profile (named "mycluster") and the associated cluster
205 205 directory, type the following command at the Windows Command Prompt::
206 206
207 207 ipython profile create --parallel profile=mycluster
208 208
209 209 The output of this command is shown in the screenshot below. Notice how
210 210 :command:`ipcluster` prints out the location of the newly created cluster
211 211 directory.
212 212
213 213 .. image:: ipcluster_create.*
214 214
215 215 Configuring a cluster profile
216 216 -----------------------------
217 217
218 218 Next, you will need to configure the newly created cluster profile by editing
219 219 the following configuration files in the cluster directory:
220 220
221 221 * :file:`ipcluster_config.py`
222 222 * :file:`ipcontroller_config.py`
223 223 * :file:`ipengine_config.py`
224 224
225 225 When :command:`ipcluster` is run, these configuration files are used to
226 226 determine how the engines and controller will be started. In most cases,
227 227 you will only have to set a few of the attributes in these files.
228 228
229 229 To configure :command:`ipcluster` to use the Windows HPC job scheduler, you
230 230 will need to edit the following attributes in the file
231 231 :file:`ipcluster_config.py`::
232 232
233 233 # Set these at the top of the file to tell ipcluster to use the
234 234 # Windows HPC job scheduler.
235 235 c.IPClusterStart.controller_launcher = \
236 236 'IPython.parallel.apps.launcher.WindowsHPCControllerLauncher'
237 237 c.IPClusterEngines.engine_launcher = \
238 238 'IPython.parallel.apps.launcher.WindowsHPCEngineSetLauncher'
239 239
240 240 # Set these to the host name of the scheduler (head node) of your cluster.
241 241 c.WindowsHPCControllerLauncher.scheduler = 'HEADNODE'
242 242 c.WindowsHPCEngineSetLauncher.scheduler = 'HEADNODE'
243 243
244 244 There are a number of other configuration attributes that can be set, but
245 245 in most cases these will be sufficient to get you started.
246 246
247 247 .. warning::
248 248 If any of your configuration attributes involve specifying the location
249 249 of shared directories or files, you must make sure that you use UNC paths
250 250 like :file:`\\\\host\\share`. It is also important that you specify
251 251 these paths using raw Python strings: ``r'\\host\share'`` to make sure
252 252 that the backslashes are properly escaped.
253 253
254 254 Starting the cluster profile
255 255 ----------------------------
256 256
257 257 Once a cluster profile has been configured, starting an IPython cluster using
258 258 the profile is simple::
259 259
260 260 ipcluster start profile=mycluster n=32
261 261
262 262 The ``-n`` option tells :command:`ipcluster` how many engines to start (in
263 263 this case 32). Stopping the cluster is as simple as typing Control-C.
264 264
265 265 Using the HPC Job Manager
266 266 -------------------------
267 267
268 268 When ``ipcluster start`` is run the first time, :command:`ipcluster` creates
269 269 two XML job description files in the cluster directory:
270 270
271 271 * :file:`ipcontroller_job.xml`
272 272 * :file:`ipengineset_job.xml`
273 273
274 274 Once these files have been created, they can be imported into the HPC Job
275 275 Manager application. Then, the controller and engines for that profile can be
276 276 started using the HPC Job Manager directly, without using :command:`ipcluster`.
277 277 However, anytime the cluster profile is re-configured, ``ipcluster start``
278 278 must be run again to regenerate the XML job description files. The
279 279 following screenshot shows what the HPC Job Manager interface looks like
280 280 with a running IPython cluster.
281 281
282 282 .. image:: hpc_job_manager.*
283 283
284 284 Performing a simple interactive parallel computation
285 285 ====================================================
286 286
287 287 Once you have started your IPython cluster, you can start to use it. To do
288 288 this, open up a new Windows Command Prompt and start up IPython's interactive
289 289 shell by typing::
290 290
291 291 ipython
292 292
293 293 Then you can create a :class:`MultiEngineClient` instance for your profile and
294 294 use the resulting instance to do a simple interactive parallel computation. In
295 295 the code and screenshot that follows, we take a simple Python function and
296 296 apply it to each element of an array of integers in parallel using the
297 297 :meth:`MultiEngineClient.map` method:
298 298
299 299 .. sourcecode:: ipython
300 300
301 301 In [1]: from IPython.parallel import *
302 302
303 303 In [2]: c = MultiEngineClient(profile='mycluster')
304 304
305 305 In [3]: mec.get_ids()
306 306 Out[3]: [0, 1, 2, 3, 4, 5, 67, 8, 9, 10, 11, 12, 13, 14]
307 307
308 308 In [4]: def f(x):
309 309 ...: return x**10
310 310
311 311 In [5]: mec.map(f, range(15)) # f is applied in parallel
312 312 Out[5]:
313 313 [0,
314 314 1,
315 315 1024,
316 316 59049,
317 317 1048576,
318 318 9765625,
319 319 60466176,
320 320 282475249,
321 321 1073741824,
322 322 3486784401L,
323 323 10000000000L,
324 324 25937424601L,
325 325 61917364224L,
326 326 137858491849L,
327 327 289254654976L]
328 328
329 329 The :meth:`map` method has the same signature as Python's builtin :func:`map`
330 330 function, but runs the calculation in parallel. More involved examples of using
331 331 :class:`MultiEngineClient` are provided in the examples that follow.
332 332
333 333 .. image:: mec_simple.*
334 334
General Comments 0
You need to be logged in to leave comments. Login now