##// END OF EJS Templates
Cleanup of docs....
Brian Granger -
Show More
This diff has been collapsed as it changes many lines, (507 lines changed) Show them Hide them
@@ -0,0 +1,507 b''
1 /**
2 * Alternate Sphinx design
3 * Originally created by Armin Ronacher for Werkzeug, adapted by Georg Brandl.
4 */
5
6 body {
7 font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Geneva', 'Verdana', sans-serif;
8 font-size: 14px;
9 letter-spacing: -0.01em;
10 line-height: 150%;
11 text-align: center;
12 /*background-color: #AFC1C4; */
13 background-color: #BFD1D4;
14 color: black;
15 padding: 0;
16 border: 1px solid #aaa;
17
18 margin: 0px 80px 0px 80px;
19 min-width: 740px;
20 }
21
22 a {
23 color: #CA7900;
24 text-decoration: none;
25 }
26
27 a:hover {
28 color: #2491CF;
29 }
30
31 pre {
32 font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
33 font-size: 0.95em;
34 letter-spacing: 0.015em;
35 padding: 0.5em;
36 border: 1px solid #ccc;
37 background-color: #f8f8f8;
38 }
39
40 td.linenos pre {
41 padding: 0.5em 0;
42 border: 0;
43 background-color: transparent;
44 color: #aaa;
45 }
46
47 table.highlighttable {
48 margin-left: 0.5em;
49 }
50
51 table.highlighttable td {
52 padding: 0 0.5em 0 0.5em;
53 }
54
55 cite, code, tt {
56 font-family: 'Consolas', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;
57 font-size: 0.95em;
58 letter-spacing: 0.01em;
59 }
60
61 hr {
62 border: 1px solid #abc;
63 margin: 2em;
64 }
65
66 tt {
67 background-color: #f2f2f2;
68 border-bottom: 1px solid #ddd;
69 color: #333;
70 }
71
72 tt.descname {
73 background-color: transparent;
74 font-weight: bold;
75 font-size: 1.2em;
76 border: 0;
77 }
78
79 tt.descclassname {
80 background-color: transparent;
81 border: 0;
82 }
83
84 tt.xref {
85 background-color: transparent;
86 font-weight: bold;
87 border: 0;
88 }
89
90 a tt {
91 background-color: transparent;
92 font-weight: bold;
93 border: 0;
94 color: #CA7900;
95 }
96
97 a tt:hover {
98 color: #2491CF;
99 }
100
101 dl {
102 margin-bottom: 15px;
103 }
104
105 dd p {
106 margin-top: 0px;
107 }
108
109 dd ul, dd table {
110 margin-bottom: 10px;
111 }
112
113 dd {
114 margin-top: 3px;
115 margin-bottom: 10px;
116 margin-left: 30px;
117 }
118
119 .refcount {
120 color: #060;
121 }
122
123 dt:target,
124 .highlight {
125 background-color: #fbe54e;
126 }
127
128 dl.class, dl.function {
129 border-top: 2px solid #888;
130 }
131
132 dl.method, dl.attribute {
133 border-top: 1px solid #aaa;
134 }
135
136 dl.glossary dt {
137 font-weight: bold;
138 font-size: 1.1em;
139 }
140
141 pre {
142 line-height: 120%;
143 }
144
145 pre a {
146 color: inherit;
147 text-decoration: underline;
148 }
149
150 .first {
151 margin-top: 0 !important;
152 }
153
154 div.document {
155 background-color: white;
156 text-align: left;
157 background-image: url(contents.png);
158 background-repeat: repeat-x;
159 }
160
161 /*
162 div.documentwrapper {
163 width: 100%;
164 }
165 */
166
167 div.clearer {
168 clear: both;
169 }
170
171 div.related h3 {
172 display: none;
173 }
174
175 div.related ul {
176 background-image: url(navigation.png);
177 height: 2em;
178 list-style: none;
179 border-top: 1px solid #ddd;
180 border-bottom: 1px solid #ddd;
181 margin: 0;
182 padding-left: 10px;
183 }
184
185 div.related ul li {
186 margin: 0;
187 padding: 0;
188 height: 2em;
189 float: left;
190 }
191
192 div.related ul li.right {
193 float: right;
194 margin-right: 5px;
195 }
196
197 div.related ul li a {
198 margin: 0;
199 padding: 0 5px 0 5px;
200 line-height: 1.75em;
201 color: #EE9816;
202 }
203
204 div.related ul li a:hover {
205 color: #3CA8E7;
206 }
207
208 div.body {
209 margin: 0;
210 padding: 0.5em 20px 20px 20px;
211 }
212
213 div.bodywrapper {
214 margin: 0 240px 0 0;
215 border-right: 1px solid #ccc;
216 }
217
218 div.body a {
219 text-decoration: underline;
220 }
221
222 div.sphinxsidebar {
223 margin: 0;
224 padding: 0.5em 15px 15px 0;
225 width: 210px;
226 float: right;
227 text-align: left;
228 /* margin-left: -100%; */
229 }
230
231 div.sphinxsidebar h4, div.sphinxsidebar h3 {
232 margin: 1em 0 0.5em 0;
233 font-size: 0.9em;
234 padding: 0.1em 0 0.1em 0.5em;
235 color: white;
236 border: 1px solid #86989B;
237 background-color: #AFC1C4;
238 }
239
240 div.sphinxsidebar ul {
241 padding-left: 1.5em;
242 margin-top: 7px;
243 list-style: none;
244 padding: 0;
245 line-height: 130%;
246 }
247
248 div.sphinxsidebar ul ul {
249 list-style: square;
250 margin-left: 20px;
251 }
252
253 p {
254 margin: 0.8em 0 0.5em 0;
255 }
256
257 p.rubric {
258 font-weight: bold;
259 }
260
261 h1 {
262 margin: 0;
263 padding: 0.7em 0 0.3em 0;
264 font-size: 1.5em;
265 color: #11557C;
266 }
267
268 h2 {
269 margin: 1.3em 0 0.2em 0;
270 font-size: 1.35em;
271 padding: 0;
272 }
273
274 h3 {
275 margin: 1em 0 -0.3em 0;
276 font-size: 1.2em;
277 }
278
279 h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
280 color: black!important;
281 }
282
283 h1 a.anchor, h2 a.anchor, h3 a.anchor, h4 a.anchor, h5 a.anchor, h6 a.anchor {
284 display: none;
285 margin: 0 0 0 0.3em;
286 padding: 0 0.2em 0 0.2em;
287 color: #aaa!important;
288 }
289
290 h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor,
291 h5:hover a.anchor, h6:hover a.anchor {
292 display: inline;
293 }
294
295 h1 a.anchor:hover, h2 a.anchor:hover, h3 a.anchor:hover, h4 a.anchor:hover,
296 h5 a.anchor:hover, h6 a.anchor:hover {
297 color: #777;
298 background-color: #eee;
299 }
300
301 table {
302 border-collapse: collapse;
303 margin: 0 -0.5em 0 -0.5em;
304 }
305
306 table td, table th {
307 padding: 0.2em 0.5em 0.2em 0.5em;
308 }
309
310 div.footer {
311 background-color: #E3EFF1;
312 color: #86989B;
313 padding: 3px 8px 3px 0;
314 clear: both;
315 font-size: 0.8em;
316 text-align: right;
317 }
318
319 div.footer a {
320 color: #86989B;
321 text-decoration: underline;
322 }
323
324 div.pagination {
325 margin-top: 2em;
326 padding-top: 0.5em;
327 border-top: 1px solid black;
328 text-align: center;
329 }
330
331 div.sphinxsidebar ul.toc {
332 margin: 1em 0 1em 0;
333 padding: 0 0 0 0.5em;
334 list-style: none;
335 }
336
337 div.sphinxsidebar ul.toc li {
338 margin: 0.5em 0 0.5em 0;
339 font-size: 0.9em;
340 line-height: 130%;
341 }
342
343 div.sphinxsidebar ul.toc li p {
344 margin: 0;
345 padding: 0;
346 }
347
348 div.sphinxsidebar ul.toc ul {
349 margin: 0.2em 0 0.2em 0;
350 padding: 0 0 0 1.8em;
351 }
352
353 div.sphinxsidebar ul.toc ul li {
354 padding: 0;
355 }
356
357 div.admonition, div.warning {
358 font-size: 0.9em;
359 margin: 1em 0 0 0;
360 border: 1px solid #86989B;
361 background-color: #f7f7f7;
362 }
363
364 div.admonition p, div.warning p {
365 margin: 0.5em 1em 0.5em 1em;
366 padding: 0;
367 }
368
369 div.admonition pre, div.warning pre {
370 margin: 0.4em 1em 0.4em 1em;
371 }
372
373 div.admonition p.admonition-title,
374 div.warning p.admonition-title {
375 margin: 0;
376 padding: 0.1em 0 0.1em 0.5em;
377 color: white;
378 border-bottom: 1px solid #86989B;
379 font-weight: bold;
380 background-color: #AFC1C4;
381 }
382
383 div.warning {
384 border: 1px solid #940000;
385 }
386
387 div.warning p.admonition-title {
388 background-color: #CF0000;
389 border-bottom-color: #940000;
390 }
391
392 div.admonition ul, div.admonition ol,
393 div.warning ul, div.warning ol {
394 margin: 0.1em 0.5em 0.5em 3em;
395 padding: 0;
396 }
397
398 div.versioninfo {
399 margin: 1em 0 0 0;
400 border: 1px solid #ccc;
401 background-color: #DDEAF0;
402 padding: 8px;
403 line-height: 1.3em;
404 font-size: 0.9em;
405 }
406
407
408 a.headerlink {
409 color: #c60f0f!important;
410 font-size: 1em;
411 margin-left: 6px;
412 padding: 0 4px 0 4px;
413 text-decoration: none!important;
414 visibility: hidden;
415 }
416
417 h1:hover > a.headerlink,
418 h2:hover > a.headerlink,
419 h3:hover > a.headerlink,
420 h4:hover > a.headerlink,
421 h5:hover > a.headerlink,
422 h6:hover > a.headerlink,
423 dt:hover > a.headerlink {
424 visibility: visible;
425 }
426
427 a.headerlink:hover {
428 background-color: #ccc;
429 color: white!important;
430 }
431
432 table.indextable td {
433 text-align: left;
434 vertical-align: top;
435 }
436
437 table.indextable dl, table.indextable dd {
438 margin-top: 0;
439 margin-bottom: 0;
440 }
441
442 table.indextable tr.pcap {
443 height: 10px;
444 }
445
446 table.indextable tr.cap {
447 margin-top: 10px;
448 background-color: #f2f2f2;
449 }
450
451 img.toggler {
452 margin-right: 3px;
453 margin-top: 3px;
454 cursor: pointer;
455 }
456
457 img.inheritance {
458 border: 0px
459 }
460
461 form.pfform {
462 margin: 10px 0 20px 0;
463 }
464
465 table.contentstable {
466 width: 90%;
467 }
468
469 table.contentstable p.biglink {
470 line-height: 150%;
471 }
472
473 a.biglink {
474 font-size: 1.3em;
475 }
476
477 span.linkdescr {
478 font-style: italic;
479 padding-top: 5px;
480 font-size: 90%;
481 }
482
483 ul.search {
484 margin: 10px 0 0 20px;
485 padding: 0;
486 }
487
488 ul.search li {
489 padding: 5px 0 5px 20px;
490 background-image: url(file.png);
491 background-repeat: no-repeat;
492 background-position: 0 7px;
493 }
494
495 ul.search li a {
496 font-weight: bold;
497 }
498
499 ul.search li div.context {
500 color: #888;
501 margin: 2px 0 0 30px;
502 text-align: left;
503 }
504
505 ul.keywordmatches li.goodmatch a {
506 font-weight: bold;
507 }
@@ -0,0 +1,23 b''
1 {% extends "!layout.html" %}
2
3
4 {% block rootrellink %}
5 <li><a href="{{ pathto('index') }}">home</a>|&nbsp;</li>
6 <li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
7 <li><a href="{{ pathto('whatsnew/index') }}">what's new </a> &raquo;</li>
8 {% endblock %}
9
10
11 {% block relbar1 %}
12
13 <div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
14 <a href="{{ pathto('index') }}"><img src="{{
15 pathto("_static/logo.png", 1) }}" border="0" alt="IPython Documentation"/></a>
16 </div>
17 {{ super() }}
18 {% endblock %}
19
20 {# put the sidebar before the body #}
21 {% block sidebar1 %}{{ sidebar() }}{% endblock %}
22 {% block sidebar2 %}{% endblock %}
23
@@ -0,0 +1,13 b''
1 .. _about_index:
2
3 =============
4 About IPython
5 =============
6
7 .. toctree::
8 :maxdepth: 1
9
10 credits
11 history
12 license_and_copyright
13
@@ -0,0 +1,49 b''
1 ================================================
2 Development version
3 ================================================
4
5 Main `ipython` branch
6 =====================
7
8 New features
9 ------------
10
11 * Added a new module :mod:`IPython.lib.inputhook` to manage the integration
12 with GUI event loops using `PyOS_InputHook`. See the docstrings in this
13 module or the main IPython docs for details.
14 * For users, GUI event loop integration is now handled through the new
15 :command:`%gui` magic command. Type ``%gui?`` at an IPython prompt for
16 documentation.
17 * For developers :mod:`IPython.lib.inputhook` provides a simple interface
18 for managing the event loops in their interactive GUI applications.
19 Examples can be found in our :file:`docs/examples/lib` directory.
20
21 Bug fixes
22 ---------
23
24 * Keyboard interrupts now work with GUI support enabled across all platforms
25 and all GUI toolkits reliably.
26
27 Backwards incompatible changes
28 ------------------------------
29
30 * Support for ``qt3`` has been dropped. User's who need this should use
31 previous versions of IPython.
32 * Removed :mod:`shellglobals` as it was obsolete.
33 * Removed all the threaded shells in :mod:`IPython.core.shell`. These are no
34 longer needed because of the new capabilities in
35 :mod:`IPython.lib.inputhook`.
36 * The old threading command line flags (pylab/wthread/etc.) have been
37 deprecated. Use :mod:`IPython.inputhook` or the new :command:`%gui` magic
38 command instead.
39 * New top-level sub-packages have been created: :mod:`IPython.core`,
40 :mod:`IPython.lib`, :mod:`IPython.utils`, :mod:`IPython.deathrow`,
41 :mod:`IPython.quarantine`. All existing top-level modules have been
42 moved to appropriate sub-packages. All internal import statements
43 have been updated and tests have been added. The build system (setup.py
44 and friends) have been updated.
45 * Compatability modules have been created for :mod:`IPython.Shell`,
46 :mod:`IPython.ipapi` and :mod:`IPython.iplib` that display warnings
47 and then load the actual implementation from :mod:`IPython.core`.
48 * :mod:`Extensions` has been moved to :mod:`extensions`.
49
@@ -0,0 +1,23 b''
1 .. Developers should add in this file, during each release cycle, information
2 .. about important changes they've made, in a summary format that's meant for
3 .. end users. For each release we normally have three sections: features, bug
4 .. fixes and api breakage.
5 .. Please remember to credit the authors of the contributions by name,
6 .. especially when they are new users or developers who do not regularly
7 .. participate in IPython's development.
8
9 .. _whatsnew_index:
10
11 =====================
12 What's new in IPython
13 =====================
14
15 .. toctree::
16 :maxdepth: 1
17
18 development
19 version0.10
20 version0.9
21 version0.8
22
23
@@ -0,0 +1,223 b''
1 ========================================
2 0.10 series
3 ========================================
4
5 Release 0.10
6 ============
7
8 This release brings months of slow but steady development, and will be the last
9 before a major restructuring and cleanup of IPython's internals that is already
10 under way. For this reason, we hope that 0.10 will be a stable and robust
11 release so that while users adapt to some of the API changes that will come
12 with the refactoring that will become IPython 0.11, they can safely use 0.10 in
13 all existing projects with minimal changes (if any).
14
15 IPython 0.10 is now a medium-sized project, with roughly (as reported by David
16 Wheeler's :command:`sloccount` utility) 40750 lines of Python code, and a diff
17 between 0.9.1 and this release that contains almost 28000 lines of code and
18 documentation. Our documentation, in PDF format, is a 495-page long PDF
19 document (also available in HTML format, both generated from the same sources).
20
21 Many users and developers contributed code, features, bug reports and ideas to
22 this release. Please do not hesitate in contacting us if we've failed to
23 acknowledge your contribution here. In particular, for this release we have
24 contribution from the following people, a mix of new and regular names (in
25 alphabetical order by first name):
26
27 * Alexander Clausen: fix #341726.
28 * Brian Granger: lots of work everywhere (features, bug fixes, etc).
29 * Daniel Ashbrook: bug report on MemoryError during compilation, now fixed.
30 * Darren Dale: improvements to documentation build system, feedback, design
31 ideas.
32 * Fernando Perez: various places.
33 * Gaël Varoquaux: core code, ipythonx GUI, design discussions, etc. Lots...
34 * John Hunter: suggestions, bug fixes, feedback.
35 * Jorgen Stenarson: work on many fronts, tests, fixes, win32 support, etc.
36 * Laurent Dufréchou: many improvements to ipython-wx standalone app.
37 * Lukasz Pankowski: prefilter, `%edit`, demo improvements.
38 * Matt Foster: TextMate support in `%edit`.
39 * Nathaniel Smith: fix #237073.
40 * Pauli Virtanen: fixes and improvements to extensions, documentation.
41 * Prabhu Ramachandran: improvements to `%timeit`.
42 * Robert Kern: several extensions.
43 * Sameer D'Costa: help on critical bug #269966.
44 * Stephan Peijnik: feedback on Debian compliance and many man pages.
45 * Steven Bethard: we are now shipping his :mod:`argparse` module.
46 * Tom Fetherston: many improvements to :mod:`IPython.demo` module.
47 * Ville Vainio: lots of work everywhere (features, bug fixes, etc).
48 * Vishal Vasta: ssh support in ipcluster.
49 * Walter Doerwald: work on the :mod:`IPython.ipipe` system.
50
51 Below we give an overview of new features, bug fixes and backwards-incompatible
52 changes. For a detailed account of every change made, feel free to view the
53 project log with :command:`bzr log`.
54
55 New features
56 ------------
57
58 * New `%paste` magic automatically extracts current contents of clipboard and
59 pastes it directly, while correctly handling code that is indented or
60 prepended with `>>>` or `...` python prompt markers. A very useful new
61 feature contributed by Robert Kern.
62
63 * IPython 'demos', created with the :mod:`IPython.demo` module, can now be
64 created from files on disk or strings in memory. Other fixes and
65 improvements to the demo system, by Tom Fetherston.
66
67 * Added :func:`find_cmd` function to :mod:`IPython.platutils` module, to find
68 commands in a cross-platform manner.
69
70 * Many improvements and fixes to Gaël Varoquaux's :command:`ipythonx`, a
71 WX-based lightweight IPython instance that can be easily embedded in other WX
72 applications. These improvements have made it possible to now have an
73 embedded IPython in Mayavi and other tools.
74
75 * :class:`MultiengineClient` objects now have a :meth:`benchmark` method.
76
77 * The manual now includes a full set of auto-generated API documents from the
78 code sources, using Sphinx and some of our own support code. We are now
79 using the `Numpy Documentation Standard`_ for all docstrings, and we have
80 tried to update as many existing ones as possible to this format.
81
82 * The new :mod:`IPython.Extensions.ipy_pretty` extension by Robert Kern
83 provides configurable pretty-printing.
84
85 * Many improvements to the :command:`ipython-wx` standalone WX-based IPython
86 application by Laurent Dufréchou. It can optionally run in a thread, and
87 this can be toggled at runtime (allowing the loading of Matplotlib in a
88 running session without ill effects).
89
90 * IPython includes a copy of Steven Bethard's argparse_ in the
91 :mod:`IPython.external` package, so we can use it internally and it is also
92 available to any IPython user. By installing it in this manner, we ensure
93 zero conflicts with any system-wide installation you may already have while
94 minimizing external dependencies for new users. In IPython 0.10, We ship
95 argparse version 1.0.
96
97 * An improved and much more robust test suite, that runs groups of tests in
98 separate subprocesses using either Nose or Twisted's :command:`trial` runner
99 to ensure proper management of Twisted-using code. The test suite degrades
100 gracefully if optional dependencies are not available, so that the
101 :command:`iptest` command can be run with only Nose installed and nothing
102 else. We also have more and cleaner test decorators to better select tests
103 depending on runtime conditions, do setup/teardown, etc.
104
105 * The new ipcluster now has a fully working ssh mode that should work on
106 Linux, Unix and OS X. Thanks to Vishal Vatsa for implementing this!
107
108 * The wonderful TextMate editor can now be used with %edit on OS X. Thanks
109 to Matt Foster for this patch.
110
111 * The documentation regarding parallel uses of IPython, including MPI and PBS,
112 has been significantly updated and improved.
113
114 * The developer guidelines in the documentation have been updated to explain
115 our workflow using :command:`bzr` and Launchpad.
116
117 * Fully refactored :command:`ipcluster` command line program for starting
118 IPython clusters. This new version is a complete rewrite and 1) is fully
119 cross platform (we now use Twisted's process management), 2) has much
120 improved performance, 3) uses subcommands for different types of clusters, 4)
121 uses argparse for parsing command line options, 5) has better support for
122 starting clusters using :command:`mpirun`, 6) has experimental support for
123 starting engines using PBS. It can also reuse FURL files, by appropriately
124 passing options to its subcommands. However, this new version of ipcluster
125 should be considered a technology preview. We plan on changing the API in
126 significant ways before it is final.
127
128 * Full description of the security model added to the docs.
129
130 * cd completer: show bookmarks if no other completions are available.
131
132 * sh profile: easy way to give 'title' to prompt: assign to variable
133 '_prompt_title'. It looks like this::
134
135 [~]|1> _prompt_title = 'sudo!'
136 sudo![~]|2>
137
138 * %edit: If you do '%edit pasted_block', pasted_block variable gets updated
139 with new data (so repeated editing makes sense)
140
141 .. _Numpy Documentation Standard: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines#docstring-standard
142
143 .. _argparse: http://code.google.com/p/argparse/
144
145 Bug fixes
146 ---------
147
148 * Fix #368719, removed top-level debian/ directory to make the job of Debian
149 packagers easier.
150
151 * Fix #291143 by including man pages contributed by Stephan Peijnik from the
152 Debian project.
153
154 * Fix #358202, effectively a race condition, by properly synchronizing file
155 creation at cluster startup time.
156
157 * `%timeit` now handles correctly functions that take a long time to execute
158 even the first time, by not repeating them.
159
160 * Fix #239054, releasing of references after exiting.
161
162 * Fix #341726, thanks to Alexander Clausen.
163
164 * Fix #269966. This long-standing and very difficult bug (which is actually a
165 problem in Python itself) meant long-running sessions would inevitably grow
166 in memory size, often with catastrophic consequences if users had large
167 objects in their scripts. Now, using `%run` repeatedly should not cause any
168 memory leaks. Special thanks to John Hunter and Sameer D'Costa for their
169 help with this bug.
170
171 * Fix #295371, bug in `%history`.
172
173 * Improved support for py2exe.
174
175 * Fix #270856: IPython hangs with PyGTK
176
177 * Fix #270998: A magic with no docstring breaks the '%magic magic'
178
179 * fix #271684: -c startup commands screw up raw vs. native history
180
181 * Numerous bugs on Windows with the new ipcluster have been fixed.
182
183 * The ipengine and ipcontroller scripts now handle missing furl files
184 more gracefully by giving better error messages.
185
186 * %rehashx: Aliases no longer contain dots. python3.0 binary
187 will create alias python30. Fixes:
188 #259716 "commands with dots in them don't work"
189
190 * %cpaste: %cpaste -r repeats the last pasted block.
191 The block is assigned to pasted_block even if code
192 raises exception.
193
194 * Bug #274067 'The code in get_home_dir is broken for py2exe' was
195 fixed.
196
197 * Many other small bug fixes not listed here by number (see the bzr log for
198 more info).
199
200 Backwards incompatible changes
201 ------------------------------
202
203 * `ipykit` and related files were unmaintained and have been removed.
204
205 * The :func:`IPython.genutils.doctest_reload` does not actually call
206 `reload(doctest)` anymore, as this was causing many problems with the test
207 suite. It still resets `doctest.master` to None.
208
209 * While we have not deliberately broken Python 2.4 compatibility, only minor
210 testing was done with Python 2.4, while 2.5 and 2.6 were fully tested. But
211 if you encounter problems with 2.4, please do report them as bugs.
212
213 * The :command:`ipcluster` now requires a mode argument; for example to start a
214 cluster on the local machine with 4 engines, you must now type::
215
216 $ ipcluster local -n 4
217
218 * The controller now has a ``-r`` flag that needs to be used if you want to
219 reuse existing furl files. Otherwise they are deleted (the default).
220
221 * Remove ipy_leo.py. You can use :command:`easy_install ipython-extension` to
222 get it. (done to decouple it from ipython release cycle)
223
@@ -0,0 +1,34 b''
1 ========================================
2 0.8 series
3 ========================================
4
5 Release 0.8.4
6 =============
7
8 This was a quick release to fix an unfortunate bug that slipped into the 0.8.3
9 release. The ``--twisted`` option was disabled, as it turned out to be broken
10 across several platforms.
11
12
13 Release 0.8.3
14 =============
15
16 * pydb is now disabled by default (due to %run -d problems). You can enable
17 it by passing -pydb command line argument to IPython. Note that setting
18 it in config file won't work.
19
20
21 Release 0.8.2
22 =============
23
24 * %pushd/%popd behave differently; now "pushd /foo" pushes CURRENT directory
25 and jumps to /foo. The current behaviour is closer to the documented
26 behaviour, and should not trip anyone.
27
28
29 Older releases
30 ==============
31
32 Changes in earlier releases of IPython are described in the older file
33 ``ChangeLog``. Please refer to this document for details.
34
@@ -0,0 +1,283 b''
1 ========================================
2 0.9 series
3 ========================================
4
5 Release 0.9.1
6 =============
7
8 This release was quickly made to restore compatibility with Python 2.4, which
9 version 0.9 accidentally broke. No new features were introduced, other than
10 some additional testing support for internal use.
11
12
13 Release 0.9
14 ===========
15
16 New features
17 ------------
18
19 * All furl files and security certificates are now put in a read-only
20 directory named ~./ipython/security.
21
22 * A single function :func:`get_ipython_dir`, in :mod:`IPython.genutils` that
23 determines the user's IPython directory in a robust manner.
24
25 * Laurent's WX application has been given a top-level script called
26 ipython-wx, and it has received numerous fixes. We expect this code to be
27 architecturally better integrated with Gael's WX 'ipython widget' over the
28 next few releases.
29
30 * The Editor synchronization work by Vivian De Smedt has been merged in. This
31 code adds a number of new editor hooks to synchronize with editors under
32 Windows.
33
34 * A new, still experimental but highly functional, WX shell by Gael Varoquaux.
35 This work was sponsored by Enthought, and while it's still very new, it is
36 based on a more cleanly organized arhictecture of the various IPython
37 components. We will continue to develop this over the next few releases as a
38 model for GUI components that use IPython.
39
40 * Another GUI frontend, Cocoa based (Cocoa is the OSX native GUI framework),
41 authored by Barry Wark. Currently the WX and the Cocoa ones have slightly
42 different internal organizations, but the whole team is working on finding
43 what the right abstraction points are for a unified codebase.
44
45 * As part of the frontend work, Barry Wark also implemented an experimental
46 event notification system that various ipython components can use. In the
47 next release the implications and use patterns of this system regarding the
48 various GUI options will be worked out.
49
50 * IPython finally has a full test system, that can test docstrings with
51 IPython-specific functionality. There are still a few pieces missing for it
52 to be widely accessible to all users (so they can run the test suite at any
53 time and report problems), but it now works for the developers. We are
54 working hard on continuing to improve it, as this was probably IPython's
55 major Achilles heel (the lack of proper test coverage made it effectively
56 impossible to do large-scale refactoring). The full test suite can now
57 be run using the :command:`iptest` command line program.
58
59 * The notion of a task has been completely reworked. An `ITask` interface has
60 been created. This interface defines the methods that tasks need to
61 implement. These methods are now responsible for things like submitting
62 tasks and processing results. There are two basic task types:
63 :class:`IPython.kernel.task.StringTask` (this is the old `Task` object, but
64 renamed) and the new :class:`IPython.kernel.task.MapTask`, which is based on
65 a function.
66
67 * A new interface, :class:`IPython.kernel.mapper.IMapper` has been defined to
68 standardize the idea of a `map` method. This interface has a single `map`
69 method that has the same syntax as the built-in `map`. We have also defined
70 a `mapper` factory interface that creates objects that implement
71 :class:`IPython.kernel.mapper.IMapper` for different controllers. Both the
72 multiengine and task controller now have mapping capabilties.
73
74 * The parallel function capabilities have been reworks. The major changes are
75 that i) there is now an `@parallel` magic that creates parallel functions,
76 ii) the syntax for mulitple variable follows that of `map`, iii) both the
77 multiengine and task controller now have a parallel function implementation.
78
79 * All of the parallel computing capabilities from `ipython1-dev` have been
80 merged into IPython proper. This resulted in the following new subpackages:
81 :mod:`IPython.kernel`, :mod:`IPython.kernel.core`, :mod:`IPython.config`,
82 :mod:`IPython.tools` and :mod:`IPython.testing`.
83
84 * As part of merging in the `ipython1-dev` stuff, the `setup.py` script and
85 friends have been completely refactored. Now we are checking for
86 dependencies using the approach that matplotlib uses.
87
88 * The documentation has been completely reorganized to accept the
89 documentation from `ipython1-dev`.
90
91 * We have switched to using Foolscap for all of our network protocols in
92 :mod:`IPython.kernel`. This gives us secure connections that are both
93 encrypted and authenticated.
94
95 * We have a brand new `COPYING.txt` files that describes the IPython license
96 and copyright. The biggest change is that we are putting "The IPython
97 Development Team" as the copyright holder. We give more details about
98 exactly what this means in this file. All developer should read this and use
99 the new banner in all IPython source code files.
100
101 * sh profile: ./foo runs foo as system command, no need to do !./foo anymore
102
103 * String lists now support ``sort(field, nums = True)`` method (to easily sort
104 system command output). Try it with ``a = !ls -l ; a.sort(1, nums=1)``.
105
106 * '%cpaste foo' now assigns the pasted block as string list, instead of string
107
108 * The ipcluster script now run by default with no security. This is done
109 because the main usage of the script is for starting things on localhost.
110 Eventually when ipcluster is able to start things on other hosts, we will put
111 security back.
112
113 * 'cd --foo' searches directory history for string foo, and jumps to that dir.
114 Last part of dir name is checked first. If no matches for that are found,
115 look at the whole path.
116
117
118 Bug fixes
119 ---------
120
121 * The Windows installer has been fixed. Now all IPython scripts have ``.bat``
122 versions created. Also, the Start Menu shortcuts have been updated.
123
124 * The colors escapes in the multiengine client are now turned off on win32 as
125 they don't print correctly.
126
127 * The :mod:`IPython.kernel.scripts.ipengine` script was exec'ing
128 mpi_import_statement incorrectly, which was leading the engine to crash when
129 mpi was enabled.
130
131 * A few subpackages had missing ``__init__.py`` files.
132
133 * The documentation is only created if Sphinx is found. Previously, the
134 ``setup.py`` script would fail if it was missing.
135
136 * Greedy ``cd`` completion has been disabled again (it was enabled in 0.8.4) as
137 it caused problems on certain platforms.
138
139
140 Backwards incompatible changes
141 ------------------------------
142
143 * The ``clusterfile`` options of the :command:`ipcluster` command has been
144 removed as it was not working and it will be replaced soon by something much
145 more robust.
146
147 * The :mod:`IPython.kernel` configuration now properly find the user's
148 IPython directory.
149
150 * In ipapi, the :func:`make_user_ns` function has been replaced with
151 :func:`make_user_namespaces`, to support dict subclasses in namespace
152 creation.
153
154 * :class:`IPython.kernel.client.Task` has been renamed
155 :class:`IPython.kernel.client.StringTask` to make way for new task types.
156
157 * The keyword argument `style` has been renamed `dist` in `scatter`, `gather`
158 and `map`.
159
160 * Renamed the values that the rename `dist` keyword argument can have from
161 `'basic'` to `'b'`.
162
163 * IPython has a larger set of dependencies if you want all of its capabilities.
164 See the `setup.py` script for details.
165
166 * The constructors for :class:`IPython.kernel.client.MultiEngineClient` and
167 :class:`IPython.kernel.client.TaskClient` no longer take the (ip,port) tuple.
168 Instead they take the filename of a file that contains the FURL for that
169 client. If the FURL file is in your IPYTHONDIR, it will be found automatically
170 and the constructor can be left empty.
171
172 * The asynchronous clients in :mod:`IPython.kernel.asyncclient` are now created
173 using the factory functions :func:`get_multiengine_client` and
174 :func:`get_task_client`. These return a `Deferred` to the actual client.
175
176 * The command line options to `ipcontroller` and `ipengine` have changed to
177 reflect the new Foolscap network protocol and the FURL files. Please see the
178 help for these scripts for details.
179
180 * The configuration files for the kernel have changed because of the Foolscap
181 stuff. If you were using custom config files before, you should delete them
182 and regenerate new ones.
183
184 Changes merged in from IPython1
185 -------------------------------
186
187 New features
188 ............
189
190 * Much improved ``setup.py`` and ``setupegg.py`` scripts. Because Twisted and
191 zope.interface are now easy installable, we can declare them as dependencies
192 in our setupegg.py script.
193
194 * IPython is now compatible with Twisted 2.5.0 and 8.x.
195
196 * Added a new example of how to use :mod:`ipython1.kernel.asynclient`.
197
198 * Initial draft of a process daemon in :mod:`ipython1.daemon`. This has not
199 been merged into IPython and is still in `ipython1-dev`.
200
201 * The ``TaskController`` now has methods for getting the queue status.
202
203 * The ``TaskResult`` objects not have information about how long the task
204 took to run.
205
206 * We are attaching additional attributes to exceptions ``(_ipython_*)`` that
207 we use to carry additional info around.
208
209 * New top-level module :mod:`asyncclient` that has asynchronous versions (that
210 return deferreds) of the client classes. This is designed to users who want
211 to run their own Twisted reactor.
212
213 * All the clients in :mod:`client` are now based on Twisted. This is done by
214 running the Twisted reactor in a separate thread and using the
215 :func:`blockingCallFromThread` function that is in recent versions of Twisted.
216
217 * Functions can now be pushed/pulled to/from engines using
218 :meth:`MultiEngineClient.push_function` and
219 :meth:`MultiEngineClient.pull_function`.
220
221 * Gather/scatter are now implemented in the client to reduce the work load
222 of the controller and improve performance.
223
224 * Complete rewrite of the IPython docuementation. All of the documentation
225 from the IPython website has been moved into docs/source as restructured
226 text documents. PDF and HTML documentation are being generated using
227 Sphinx.
228
229 * New developer oriented documentation: development guidelines and roadmap.
230
231 * Traditional ``ChangeLog`` has been changed to a more useful ``changes.txt``
232 file that is organized by release and is meant to provide something more
233 relevant for users.
234
235 Bug fixes
236 .........
237
238 * Created a proper ``MANIFEST.in`` file to create source distributions.
239
240 * Fixed a bug in the ``MultiEngine`` interface. Previously, multi-engine
241 actions were being collected with a :class:`DeferredList` with
242 ``fireononeerrback=1``. This meant that methods were returning
243 before all engines had given their results. This was causing extremely odd
244 bugs in certain cases. To fix this problem, we have 1) set
245 ``fireononeerrback=0`` to make sure all results (or exceptions) are in
246 before returning and 2) introduced a :exc:`CompositeError` exception
247 that wraps all of the engine exceptions. This is a huge change as it means
248 that users will have to catch :exc:`CompositeError` rather than the actual
249 exception.
250
251 Backwards incompatible changes
252 ..............................
253
254 * All names have been renamed to conform to the lowercase_with_underscore
255 convention. This will require users to change references to all names like
256 ``queueStatus`` to ``queue_status``.
257
258 * Previously, methods like :meth:`MultiEngineClient.push` and
259 :meth:`MultiEngineClient.push` used ``*args`` and ``**kwargs``. This was
260 becoming a problem as we weren't able to introduce new keyword arguments into
261 the API. Now these methods simple take a dict or sequence. This has also
262 allowed us to get rid of the ``*All`` methods like :meth:`pushAll` and
263 :meth:`pullAll`. These things are now handled with the ``targets`` keyword
264 argument that defaults to ``'all'``.
265
266 * The :attr:`MultiEngineClient.magicTargets` has been renamed to
267 :attr:`MultiEngineClient.targets`.
268
269 * All methods in the MultiEngine interface now accept the optional keyword
270 argument ``block``.
271
272 * Renamed :class:`RemoteController` to :class:`MultiEngineClient` and
273 :class:`TaskController` to :class:`TaskClient`.
274
275 * Renamed the top-level module from :mod:`api` to :mod:`client`.
276
277 * Most methods in the multiengine interface now raise a :exc:`CompositeError`
278 exception that wraps the user's exceptions, rather than just raising the raw
279 user's exception.
280
281 * Changed the ``setupNS`` and ``resultNames`` in the ``Task`` class to ``push``
282 and ``pull``.
283
@@ -1,36 +1,42 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """Script to auto-generate our API docs.
2 """Script to auto-generate our API docs.
3 """
3 """
4 # stdlib imports
4 # stdlib imports
5 import os
5 import os
6 import sys
6 import sys
7
7
8 # local imports
8 # local imports
9 sys.path.append(os.path.abspath('sphinxext'))
9 sys.path.append(os.path.abspath('sphinxext'))
10 from apigen import ApiDocWriter
10 from apigen import ApiDocWriter
11
11
12 #*****************************************************************************
12 #*****************************************************************************
13 if __name__ == '__main__':
13 if __name__ == '__main__':
14 pjoin = os.path.join
14 pjoin = os.path.join
15 package = 'IPython'
15 package = 'IPython'
16 outdir = pjoin('source','api','generated')
16 outdir = pjoin('source','api','generated')
17 docwriter = ApiDocWriter(package,rst_extension='.txt')
17 docwriter = ApiDocWriter(package,rst_extension='.txt')
18 # You have to escape the . here because . is a special char for regexps.
19 # You must do make clean if you change this!
18 docwriter.package_skip_patterns += [r'\.fixes$',
20 docwriter.package_skip_patterns += [r'\.fixes$',
19 r'\.externals$',
21 r'\.external$',
20 r'\.extensions',
22 r'\.extensions',
21 r'\.kernel.config',
23 r'\.kernel\.config',
22 r'\.attic',
24 r'\.attic',
23 r'\.quarantine',
25 r'\.quarantine',
24 r'\.deathrow'
26 r'\.deathrow',
27 r'\.config\.default',
28 r'\.config\.profile',
29 r'\.frontend',
30 r'\.gui'
25 ]
31 ]
26 docwriter.module_skip_patterns += [ r'\.core.fakemodule',
32 docwriter.module_skip_patterns += [ r'\.core\.fakemodule',
27 r'\.cocoa',
33 r'\.cocoa',
28 r'\.ipdoctest',
34 r'\.ipdoctest',
29 r'\.Gnuplot',
35 r'\.Gnuplot',
30 r'\.frontend.process.winprocess',
36 r'\.frontend\.process\.winprocess',
31 ]
37 ]
32 docwriter.write_api_docs(outdir)
38 docwriter.write_api_docs(outdir)
33 docwriter.write_index(outdir, 'gen',
39 docwriter.write_index(outdir, 'gen',
34 relative_to = pjoin('source','api')
40 relative_to = pjoin('source','api')
35 )
41 )
36 print '%d files written' % len(docwriter.written_modules)
42 print '%d files written' % len(docwriter.written_modules)
@@ -1,207 +1,208 b''
1 .. _credits:
1 .. _credits:
2
2
3 =======
3 =======
4 Credits
4 Credits
5 =======
5 =======
6
6
7 IPython is led by Fernando Pérez.
7 IPython is led by Fernando Pérez.
8
8
9 As of this writing, the following developers have joined the core team:
9 As of this writing, the following developers have joined the core team:
10
10
11 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
11 * [Robert Kern] <rkern-AT-enthought.com>: co-mentored the 2005
12 Google Summer of Code project to develop python interactive
12 Google Summer of Code project to develop python interactive
13 notebooks (XML documents) and graphical interface. This project
13 notebooks (XML documents) and graphical interface. This project
14 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
14 was awarded to the students Tzanko Matev <tsanko-AT-gmail.com> and
15 Toni Alatalo <antont-AT-an.org>.
15 Toni Alatalo <antont-AT-an.org>.
16
16
17 * [Brian Granger] <ellisonbg-AT-gmail.com>: extending IPython to allow
17 * [Brian Granger] <ellisonbg-AT-gmail.com>: extending IPython to allow
18 support for interactive parallel computing.
18 support for interactive parallel computing.
19
19
20 * [Benjamin (Min) Ragan-Kelley]: key work on IPython's parallel
20 * [Benjamin (Min) Ragan-Kelley]: key work on IPython's parallel
21 computing infrastructure.
21 computing infrastructure.
22
22
23 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville has made many improvements
23 * [Ville Vainio] <vivainio-AT-gmail.com>: Ville has made many improvements
24 to the core of IPython and was the maintainer of the main IPython
24 to the core of IPython and was the maintainer of the main IPython
25 trunk from version 0.7.1 to 0.8.4.
25 trunk from version 0.7.1 to 0.8.4.
26
26
27 * [Gael Varoquaux] <gael.varoquaux-AT-normalesup.org>: work on the merged
27 * [Gael Varoquaux] <gael.varoquaux-AT-normalesup.org>: work on the merged
28 architecture for the interpreter as of version 0.9, implementing a new WX GUI
28 architecture for the interpreter as of version 0.9, implementing a new WX GUI
29 based on this system.
29 based on this system.
30
30
31 * [Barry Wark] <barrywark-AT-gmail.com>: implementing a new Cocoa GUI, as well
31 * [Barry Wark] <barrywark-AT-gmail.com>: implementing a new Cocoa GUI, as well
32 as work on the new interpreter architecture and Twisted support.
32 as work on the new interpreter architecture and Twisted support.
33
33
34 * [Laurent Dufrechou] <laurent.dufrechou-AT-gmail.com>: development of the WX
34 * [Laurent Dufrechou] <laurent.dufrechou-AT-gmail.com>: development of the WX
35 GUI support.
35 GUI support.
36
36
37 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu>: maintainer of the
37 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu>: maintainer of the
38 PyReadline project, necessary for IPython under windows.
38 PyReadline project, necessary for IPython under windows.
39
39
40
40
41 The IPython project is also very grateful to:
41 The IPython project is also very grateful to:
42
42
43 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
43 Bill Bumgarner <bbum-AT-friday.com>: for providing the DPyGetOpt module
44 which gives very powerful and convenient handling of command-line
44 which gives very powerful and convenient handling of command-line
45 options (light years ahead of what Python 2.1.1's getopt module does).
45 options (light years ahead of what Python 2.1.1's getopt module does).
46
46
47 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
47 Ka-Ping Yee <ping-AT-lfw.org>: for providing the Itpl module for
48 convenient and powerful string interpolation with a much nicer syntax
48 convenient and powerful string interpolation with a much nicer syntax
49 than formatting through the '%' operator.
49 than formatting through the '%' operator.
50
50
51 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
51 Arnd Baecker <baecker-AT-physik.tu-dresden.de>: for his many very useful
52 suggestions and comments, and lots of help with testing and
52 suggestions and comments, and lots of help with testing and
53 documentation checking. Many of IPython's newer features are a result of
53 documentation checking. Many of IPython's newer features are a result of
54 discussions with him (bugs are still my fault, not his).
54 discussions with him (bugs are still my fault, not his).
55
55
56 Obviously Guido van Rossum and the whole Python development team, that
56 Obviously Guido van Rossum and the whole Python development team, that
57 goes without saying.
57 goes without saying.
58
58
59 IPython's website is generously hosted at http://ipython.scipy.orgby
59 IPython's website is generously hosted at http://ipython.scipy.orgby
60 Enthought (http://www.enthought.com). I am very grateful to them and all
60 Enthought (http://www.enthought.com). I am very grateful to them and all
61 of the SciPy team for their contribution.
61 of the SciPy team for their contribution.
62
62
63 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
63 Fernando would also like to thank Stephen Figgins <fig-AT-monitor.net>,
64 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
64 an O'Reilly Python editor. His Oct/11/2001 article about IPP and
65 LazyPython, was what got this project started. You can read it at:
65 LazyPython, was what got this project started. You can read it at:
66 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
66 http://www.onlamp.com/pub/a/python/2001/10/11/pythonnews.html.
67
67
68 And last but not least, all the kind IPython users who have emailed new code,
68 And last but not least, all the kind IPython users who have emailed new code,
69 bug reports, fixes, comments and ideas. A brief list follows, please let us
69 bug reports, fixes, comments and ideas. A brief list follows, please let us
70 know if we have ommitted your name by accident:
70 know if we have ommitted your name by accident:
71
71
72 * Dan Milstein <danmil-AT-comcast.net>. A bold refactoring of the
72 * Dan Milstein <danmil-AT-comcast.net>. A bold refactoring of the
73 core prefilter stuff in the IPython interpreter.
73 core prefilter stuff in the IPython interpreter.
74
74
75 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
75 * [Jack Moffit] <jack-AT-xiph.org> Bug fixes, including the infamous
76 color problem. This bug alone caused many lost hours and
76 color problem. This bug alone caused many lost hours and
77 frustration, many thanks to him for the fix. I've always been a
77 frustration, many thanks to him for the fix. I've always been a
78 fan of Ogg & friends, now I have one more reason to like these folks.
78 fan of Ogg & friends, now I have one more reason to like these folks.
79 Jack is also contributing with Debian packaging and many other
79 Jack is also contributing with Debian packaging and many other
80 things.
80 things.
81
81
82 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
82 * [Alexander Schmolck] <a.schmolck-AT-gmx.net> Emacs work, bug
83 reports, bug fixes, ideas, lots more. The ipython.el mode for
83 reports, bug fixes, ideas, lots more. The ipython.el mode for
84 (X)Emacs is Alex's code, providing full support for IPython under
84 (X)Emacs is Alex's code, providing full support for IPython under
85 (X)Emacs.
85 (X)Emacs.
86
86
87 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
87 * [Andrea Riciputi] <andrea.riciputi-AT-libero.it> Mac OSX
88 information, Fink package management.
88 information, Fink package management.
89
89
90 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
90 * [Gary Bishop] <gb-AT-cs.unc.edu> Bug reports, and patches to work
91 around the exception handling idiosyncracies of WxPython. Readline
91 around the exception handling idiosyncracies of WxPython. Readline
92 and color support for Windows.
92 and color support for Windows.
93
93
94 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
94 * [Jeffrey Collins] <Jeff.Collins-AT-vexcel.com> Bug reports. Much
95 improved readline support, including fixes for Python 2.3.
95 improved readline support, including fixes for Python 2.3.
96
96
97 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
97 * [Dryice Liu] <dryice-AT-liu.com.cn> FreeBSD port.
98
98
99 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
99 * [Mike Heeter] <korora-AT-SDF.LONESTAR.ORG>
100
100
101 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
101 * [Christopher Hart] <hart-AT-caltech.edu> PDB integration.
102
102
103 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
103 * [Milan Zamazal] <pdm-AT-zamazal.org> Emacs info.
104
104
105 * [Philip Hisley] <compsys-AT-starpower.net>
105 * [Philip Hisley] <compsys-AT-starpower.net>
106
106
107 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
107 * [Holger Krekel] <pyth-AT-devel.trillke.net> Tab completion, lots
108 more.
108 more.
109
109
110 * [Robin Siebler] <robinsiebler-AT-starband.net>
110 * [Robin Siebler] <robinsiebler-AT-starband.net>
111
111
112 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
112 * [Ralf Ahlbrink] <ralf_ahlbrink-AT-web.de>
113
113
114 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
114 * [Thorsten Kampe] <thorsten-AT-thorstenkampe.de>
115
115
116 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
116 * [Fredrik Kant] <fredrik.kant-AT-front.com> Windows setup.
117
117
118 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
118 * [Syver Enstad] <syver-en-AT-online.no> Windows setup.
119
119
120 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
120 * [Richard] <rxe-AT-renre-europe.com> Global embedding.
121
121
122 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
122 * [Hayden Callow] <h.callow-AT-elec.canterbury.ac.nz> Gnuplot.py 1.6
123 compatibility.
123 compatibility.
124
124
125 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
125 * [Leonardo Santagada] <retype-AT-terra.com.br> Fixes for Windows
126 installation.
126 installation.
127
127
128 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
128 * [Christopher Armstrong] <radix-AT-twistedmatrix.com> Bugfixes.
129
129
130 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
130 * [Francois Pinard] <pinard-AT-iro.umontreal.ca> Code and
131 documentation fixes.
131 documentation fixes.
132
132
133 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
133 * [Cory Dodt] <cdodt-AT-fcoe.k12.ca.us> Bug reports and Windows
134 ideas. Patches for Windows installer.
134 ideas. Patches for Windows installer.
135
135
136 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
136 * [Olivier Aubert] <oaubert-AT-bat710.univ-lyon1.fr> New magics.
137
137
138 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
138 * [King C. Shu] <kingshu-AT-myrealbox.com> Autoindent patch.
139
139
140 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
140 * [Chris Drexler] <chris-AT-ac-drexler.de> Readline packages for
141 Win32/CygWin.
141 Win32/CygWin.
142
142
143 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
143 * [Gustavo Cordova Avila] <gcordova-AT-sismex.com> EvalDict code for
144 nice, lightweight string interpolation.
144 nice, lightweight string interpolation.
145
145
146 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
146 * [Kasper Souren] <Kasper.Souren-AT-ircam.fr> Bug reports, ideas.
147
147
148 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
148 * [Gever Tulley] <gever-AT-helium.com> Code contributions.
149
149
150 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
150 * [Ralf Schmitt] <ralf-AT-brainbot.com> Bug reports & fixes.
151
151
152 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
152 * [Oliver Sander] <osander-AT-gmx.de> Bug reports.
153
153
154 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
154 * [Rod Holland] <rhh-AT-structurelabs.com> Bug reports and fixes to
155 logging module.
155 logging module.
156
156
157 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
157 * [Daniel 'Dang' Griffith] <pythondev-dang-AT-lazytwinacres.net>
158 Fixes, enhancement suggestions for system shell use.
158 Fixes, enhancement suggestions for system shell use.
159
159
160 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
160 * [Viktor Ransmayr] <viktor.ransmayr-AT-t-online.de> Tests and
161 reports on Windows installation issues. Contributed a true Windows
161 reports on Windows installation issues. Contributed a true Windows
162 binary installer.
162 binary installer.
163
163
164 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
164 * [Mike Salib] <msalib-AT-mit.edu> Help fixing a subtle bug related
165 to traceback printing.
165 to traceback printing.
166
166
167 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
167 * [W.J. van der Laan] <gnufnork-AT-hetdigitalegat.nl> Bash-like
168 prompt specials.
168 prompt specials.
169
169
170 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
170 * [Antoon Pardon] <Antoon.Pardon-AT-rece.vub.ac.be> Critical fix for
171 the multithreaded IPython.
171 the multithreaded IPython.
172
172
173 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
173 * [John Hunter] <jdhunter-AT-nitace.bsd.uchicago.edu> Matplotlib
174 author, helped with all the development of support for matplotlib
174 author, helped with all the development of support for matplotlib
175 in IPyhton, including making necessary changes to matplotlib itself.
175 in IPyhton, including making necessary changes to matplotlib itself.
176
176
177 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
177 * [Matthew Arnison] <maffew-AT-cat.org.au> Bug reports, '%run -d' idea.
178
178
179 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
179 * [Prabhu Ramachandran] <prabhu_r-AT-users.sourceforge.net> Help
180 with (X)Emacs support, threading patches, ideas...
180 with (X)Emacs support, threading patches, ideas...
181
181
182 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
182 * [Norbert Tretkowski] <tretkowski-AT-inittab.de> help with Debian
183 packaging and distribution.
183 packaging and distribution.
184
184
185 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
185 * [George Sakkis] <gsakkis-AT-eden.rutgers.edu> New matcher for
186 tab-completing named arguments of user-defined functions.
186 tab-completing named arguments of user-defined functions.
187
187
188 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
188 * [Jörgen Stenarson] <jorgen.stenarson-AT-bostream.nu> Wildcard
189 support implementation for searching namespaces.
189 support implementation for searching namespaces.
190
190
191 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
191 * [Vivian De Smedt] <vivian-AT-vdesmedt.com> Debugger enhancements,
192 so that when pdb is activated from within IPython, coloring, tab
192 so that when pdb is activated from within IPython, coloring, tab
193 completion and other features continue to work seamlessly.
193 completion and other features continue to work seamlessly.
194
194
195 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
195 * [Scott Tsai] <scottt958-AT-yahoo.com.tw> Support for automatic
196 editor invocation on syntax errors (see
196 editor invocation on syntax errors (see
197 http://www.scipy.net/roundup/ipython/issue36).
197 http://www.scipy.net/roundup/ipython/issue36).
198
198
199 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
199 * [Alexander Belchenko] <bialix-AT-ukr.net> Improvements for win32
200 paging system.
200 paging system.
201
201
202 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
202 * [Will Maier] <willmaier-AT-ml1.net> Official OpenBSD port.
203
203
204 * [Ondrej Certik] <ondrej-AT-certik.cz>: set up the IPython docs to use the new
204 * [Ondrej Certik] <ondrej-AT-certik.cz>: set up the IPython docs to use the new
205 Sphinx system used by Python, Matplotlib and many more projects.
205 Sphinx system used by Python, Matplotlib and many more projects.
206
206
207 * [Stefan van der Walt] <stefan-AT-sun.ac.za>: support for the new config system.
207 * [Stefan van der Walt] <stefan-AT-sun.ac.za>: support for the new config system.
208
1 NO CONTENT: file renamed from docs/source/history.txt to docs/source/about/history.txt
NO CONTENT: file renamed from docs/source/history.txt to docs/source/about/history.txt
@@ -1,91 +1,92 b''
1 .. _license:
1 .. _license:
2
2
3 =====================
3 =====================
4 License and Copyright
4 License and Copyright
5 =====================
5 =====================
6
6
7 License
7 License
8 =======
8 =======
9
9
10 IPython is licensed under the terms of the new or revised BSD license, as follows::
10 IPython is licensed under the terms of the new or revised BSD license, as follows::
11
11
12 Copyright (c) 2008, IPython Development Team
12 Copyright (c) 2008, IPython Development Team
13
13
14 All rights reserved.
14 All rights reserved.
15
15
16 Redistribution and use in source and binary forms, with or without
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are
17 modification, are permitted provided that the following conditions are
18 met:
18 met:
19
19
20 Redistributions of source code must retain the above copyright notice,
20 Redistributions of source code must retain the above copyright notice,
21 this list of conditions and the following disclaimer.
21 this list of conditions and the following disclaimer.
22
22
23 Redistributions in binary form must reproduce the above copyright notice,
23 Redistributions in binary form must reproduce the above copyright notice,
24 this list of conditions and the following disclaimer in the documentation
24 this list of conditions and the following disclaimer in the documentation
25 and/or other materials provided with the distribution.
25 and/or other materials provided with the distribution.
26
26
27 Neither the name of the IPython Development Team nor the names of its
27 Neither the name of the IPython Development Team nor the names of its
28 contributors may be used to endorse or promote products derived from this
28 contributors may be used to endorse or promote products derived from this
29 software without specific prior written permission.
29 software without specific prior written permission.
30
30
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
32 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
42
43 About the IPython Development Team
43 About the IPython Development Team
44 ==================================
44 ==================================
45
45
46 Fernando Perez began IPython in 2001 based on code from Janko Hauser
46 Fernando Perez began IPython in 2001 based on code from Janko Hauser
47 <jhauser@zscout.de> and Nathaniel Gray <n8gray@caltech.edu>. Fernando is still
47 <jhauser@zscout.de> and Nathaniel Gray <n8gray@caltech.edu>. Fernando is still
48 the project lead.
48 the project lead.
49
49
50 The IPython Development Team is the set of all contributors to the IPython
50 The IPython Development Team is the set of all contributors to the IPython
51 project. This includes all of the IPython subprojects. Here is a list of the
51 project. This includes all of the IPython subprojects. Here is a list of the
52 currently active contributors:
52 currently active contributors:
53
53
54 * Matthieu Brucher
54 * Matthieu Brucher
55 * Ondrej Certik
55 * Ondrej Certik
56 * Laurent Dufrechou
56 * Laurent Dufrechou
57 * Robert Kern
57 * Robert Kern
58 * Brian E. Granger
58 * Brian E. Granger
59 * Fernando Perez (project leader)
59 * Fernando Perez (project leader)
60 * Benjamin Ragan-Kelley
60 * Benjamin Ragan-Kelley
61 * Ville M. Vainio
61 * Ville M. Vainio
62 * Gael Varoququx
62 * Gael Varoququx
63 * Stefan van der Walt
63 * Stefan van der Walt
64 * Tech-X Corporation
64 * Tech-X Corporation
65 * Barry Wark
65 * Barry Wark
66
66
67 If your name is missing, please add it.
67 If your name is missing, please add it.
68
68
69 Our Copyright Policy
69 Our Copyright Policy
70 ====================
70 ====================
71
71
72 IPython uses a shared copyright model. Each contributor maintains copyright
72 IPython uses a shared copyright model. Each contributor maintains copyright
73 over their contributions to IPython. But, it is important to note that these
73 over their contributions to IPython. But, it is important to note that these
74 contributions are typically only changes to the repositories. Thus, the
74 contributions are typically only changes to the repositories. Thus, the
75 IPython source code, in its entirety is not the copyright of any single person
75 IPython source code, in its entirety is not the copyright of any single person
76 or institution. Instead, it is the collective copyright of the entire IPython
76 or institution. Instead, it is the collective copyright of the entire IPython
77 Development Team. If individual contributors want to maintain a record of what
77 Development Team. If individual contributors want to maintain a record of what
78 changes/contributions they have specific copyright on, they should indicate
78 changes/contributions they have specific copyright on, they should indicate
79 their copyright in the commit message of the change, when they commit the
79 their copyright in the commit message of the change, when they commit the
80 change to one of the IPython repositories.
80 change to one of the IPython repositories.
81
81
82 Miscellaneous
82 Miscellaneous
83 =============
83 =============
84
84
85 Some files (DPyGetOpt.py, for example) may be licensed under different
85 Some files (DPyGetOpt.py, for example) may be licensed under different
86 conditions. Ultimately each file indicates clearly the conditions under which
86 conditions. Ultimately each file indicates clearly the conditions under which
87 its author/authors have decided to publish the code.
87 its author/authors have decided to publish the code.
88
88
89 Versions of IPython up to and including 0.6.3 were released under the GNU
89 Versions of IPython up to and including 0.6.3 were released under the GNU
90 Lesser General Public License (LGPL), available at
90 Lesser General Public License (LGPL), available at
91 http://www.gnu.org/copyleft/lesser.html. No newline at end of file
91 http://www.gnu.org/copyleft/lesser.html.
92
@@ -1,191 +1,192 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 #
2 #
3 # IPython documentation build configuration file.
3 # IPython documentation build configuration file.
4
4
5 # NOTE: This file has been edited manually from the auto-generated one from
5 # NOTE: This file has been edited manually from the auto-generated one from
6 # sphinx. Do NOT delete and re-generate. If any changes from sphinx are
6 # sphinx. Do NOT delete and re-generate. If any changes from sphinx are
7 # needed, generate a scratch one and merge by hand any new fields needed.
7 # needed, generate a scratch one and merge by hand any new fields needed.
8
8
9 #
9 #
10 # This file is execfile()d with the current directory set to its containing dir.
10 # This file is execfile()d with the current directory set to its containing dir.
11 #
11 #
12 # The contents of this file are pickled, so don't put values in the namespace
12 # The contents of this file are pickled, so don't put values in the namespace
13 # that aren't pickleable (module imports are okay, they're removed automatically).
13 # that aren't pickleable (module imports are okay, they're removed automatically).
14 #
14 #
15 # All configuration values have a default value; values that are commented out
15 # All configuration values have a default value; values that are commented out
16 # serve to show the default value.
16 # serve to show the default value.
17
17
18 import sys, os
18 import sys, os
19
19
20 # If your extensions are in another directory, add it here. If the directory
20 # If your extensions are in another directory, add it here. If the directory
21 # is relative to the documentation root, use os.path.abspath to make it
21 # is relative to the documentation root, use os.path.abspath to make it
22 # absolute, like shown here.
22 # absolute, like shown here.
23 sys.path.append(os.path.abspath('../sphinxext'))
23 sys.path.append(os.path.abspath('../sphinxext'))
24
24
25 # Import support for ipython console session syntax highlighting (lives
25 # Import support for ipython console session syntax highlighting (lives
26 # in the sphinxext directory defined above)
26 # in the sphinxext directory defined above)
27 import ipython_console_highlighting
27 import ipython_console_highlighting
28
28
29 # We load the ipython release info into a dict by explicit execution
29 # We load the ipython release info into a dict by explicit execution
30 iprelease = {}
30 iprelease = {}
31 execfile('../../IPython/core/release.py',iprelease)
31 execfile('../../IPython/core/release.py',iprelease)
32
32
33 # General configuration
33 # General configuration
34 # ---------------------
34 # ---------------------
35
35
36 # Add any Sphinx extension module names here, as strings. They can be extensions
36 # Add any Sphinx extension module names here, as strings. They can be extensions
37 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
37 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
38 extensions = ['sphinx.ext.autodoc',
38 extensions = [
39 'sphinx.ext.doctest',
39 # 'matplotlib.sphinxext.mathmpl',
40
40 'matplotlib.sphinxext.only_directives',
41 'only_directives',
41 # 'matplotlib.sphinxext.plot_directive',
42 'inheritance_diagram',
42 'sphinx.ext.autodoc',
43 'ipython_console_highlighting',
43 'sphinx.ext.doctest',
44 # 'plot_directive', # disabled for now, needs matplotlib
44 'inheritance_diagram',
45 'numpydoc', # to preprocess docstrings
45 'ipython_console_highlighting',
46 ]
46 'numpydoc', # to preprocess docstrings
47 ]
47
48
48 # Add any paths that contain templates here, relative to this directory.
49 # Add any paths that contain templates here, relative to this directory.
49 templates_path = ['_templates']
50 templates_path = ['_templates']
50
51
51 # The suffix of source filenames.
52 # The suffix of source filenames.
52 source_suffix = '.txt'
53 source_suffix = '.txt'
53
54
54 # The master toctree document.
55 # The master toctree document.
55 master_doc = 'index'
56 master_doc = 'index'
56
57
57 # General substitutions.
58 # General substitutions.
58 project = 'IPython'
59 project = 'IPython'
59 copyright = '2008, The IPython Development Team'
60 copyright = '2008, The IPython Development Team'
60
61
61 # The default replacements for |version| and |release|, also used in various
62 # The default replacements for |version| and |release|, also used in various
62 # other places throughout the built documents.
63 # other places throughout the built documents.
63 #
64 #
64 # The full version, including alpha/beta/rc tags.
65 # The full version, including alpha/beta/rc tags.
65 release = iprelease['version']
66 release = iprelease['version']
66 # The short X.Y version.
67 # The short X.Y version.
67 version = '.'.join(release.split('.',2)[:2])
68 version = '.'.join(release.split('.',2)[:2])
68
69
69
70
70 # There are two options for replacing |today|: either, you set today to some
71 # There are two options for replacing |today|: either, you set today to some
71 # non-false value, then it is used:
72 # non-false value, then it is used:
72 #today = ''
73 #today = ''
73 # Else, today_fmt is used as the format for a strftime call.
74 # Else, today_fmt is used as the format for a strftime call.
74 today_fmt = '%B %d, %Y'
75 today_fmt = '%B %d, %Y'
75
76
76 # List of documents that shouldn't be included in the build.
77 # List of documents that shouldn't be included in the build.
77 #unused_docs = []
78 #unused_docs = []
78
79
79 # List of directories, relative to source directories, that shouldn't be searched
80 # List of directories, relative to source directories, that shouldn't be searched
80 # for source files.
81 # for source files.
81 exclude_dirs = ['attic']
82 exclude_dirs = ['attic']
82
83
83 # If true, '()' will be appended to :func: etc. cross-reference text.
84 # If true, '()' will be appended to :func: etc. cross-reference text.
84 #add_function_parentheses = True
85 #add_function_parentheses = True
85
86
86 # If true, the current module name will be prepended to all description
87 # If true, the current module name will be prepended to all description
87 # unit titles (such as .. function::).
88 # unit titles (such as .. function::).
88 #add_module_names = True
89 #add_module_names = True
89
90
90 # If true, sectionauthor and moduleauthor directives will be shown in the
91 # If true, sectionauthor and moduleauthor directives will be shown in the
91 # output. They are ignored by default.
92 # output. They are ignored by default.
92 #show_authors = False
93 #show_authors = False
93
94
94 # The name of the Pygments (syntax highlighting) style to use.
95 # The name of the Pygments (syntax highlighting) style to use.
95 pygments_style = 'sphinx'
96 pygments_style = 'sphinx'
96
97
97
98
98 # Options for HTML output
99 # Options for HTML output
99 # -----------------------
100 # -----------------------
100
101
101 # The style sheet to use for HTML and HTML Help pages. A file of that name
102 # The style sheet to use for HTML and HTML Help pages. A file of that name
102 # must exist either in Sphinx' static/ path, or in one of the custom paths
103 # must exist either in Sphinx' static/ path, or in one of the custom paths
103 # given in html_static_path.
104 # given in html_static_path.
104 html_style = 'default.css'
105 html_style = 'default.css'
105
106
106 # The name for this set of Sphinx documents. If None, it defaults to
107 # The name for this set of Sphinx documents. If None, it defaults to
107 # "<project> v<release> documentation".
108 # "<project> v<release> documentation".
108 #html_title = None
109 #html_title = None
109
110
110 # The name of an image file (within the static path) to place at the top of
111 # The name of an image file (within the static path) to place at the top of
111 # the sidebar.
112 # the sidebar.
112 #html_logo = None
113 #html_logo = None
113
114
114 # Add any paths that contain custom static files (such as style sheets) here,
115 # Add any paths that contain custom static files (such as style sheets) here,
115 # relative to this directory. They are copied after the builtin static files,
116 # relative to this directory. They are copied after the builtin static files,
116 # so a file named "default.css" will overwrite the builtin "default.css".
117 # so a file named "default.css" will overwrite the builtin "default.css".
117 html_static_path = ['_static']
118 html_static_path = ['_static']
118
119
119 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
120 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
120 # using the given strftime format.
121 # using the given strftime format.
121 html_last_updated_fmt = '%b %d, %Y'
122 html_last_updated_fmt = '%b %d, %Y'
122
123
123 # If true, SmartyPants will be used to convert quotes and dashes to
124 # If true, SmartyPants will be used to convert quotes and dashes to
124 # typographically correct entities.
125 # typographically correct entities.
125 #html_use_smartypants = True
126 #html_use_smartypants = True
126
127
127 # Custom sidebar templates, maps document names to template names.
128 # Custom sidebar templates, maps document names to template names.
128 #html_sidebars = {}
129 #html_sidebars = {}
129
130
130 # Additional templates that should be rendered to pages, maps page names to
131 # Additional templates that should be rendered to pages, maps page names to
131 # template names.
132 # template names.
132 #html_additional_pages = {}
133 #html_additional_pages = {}
133
134
134 # If false, no module index is generated.
135 # If false, no module index is generated.
135 #html_use_modindex = True
136 #html_use_modindex = True
136
137
137 # If true, the reST sources are included in the HTML build as _sources/<name>.
138 # If true, the reST sources are included in the HTML build as _sources/<name>.
138 #html_copy_source = True
139 #html_copy_source = True
139
140
140 # If true, an OpenSearch description file will be output, and all pages will
141 # If true, an OpenSearch description file will be output, and all pages will
141 # contain a <link> tag referring to it. The value of this option must be the
142 # contain a <link> tag referring to it. The value of this option must be the
142 # base URL from which the finished HTML is served.
143 # base URL from which the finished HTML is served.
143 #html_use_opensearch = ''
144 #html_use_opensearch = ''
144
145
145 # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
146 # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
146 #html_file_suffix = ''
147 #html_file_suffix = ''
147
148
148 # Output file base name for HTML help builder.
149 # Output file base name for HTML help builder.
149 htmlhelp_basename = 'ipythondoc'
150 htmlhelp_basename = 'ipythondoc'
150
151
151
152
152 # Options for LaTeX output
153 # Options for LaTeX output
153 # ------------------------
154 # ------------------------
154
155
155 # The paper size ('letter' or 'a4').
156 # The paper size ('letter' or 'a4').
156 latex_paper_size = 'letter'
157 latex_paper_size = 'letter'
157
158
158 # The font size ('10pt', '11pt' or '12pt').
159 # The font size ('10pt', '11pt' or '12pt').
159 latex_font_size = '11pt'
160 latex_font_size = '11pt'
160
161
161 # Grouping the document tree into LaTeX files. List of tuples
162 # Grouping the document tree into LaTeX files. List of tuples
162 # (source start file, target name, title, author, document class [howto/manual]).
163 # (source start file, target name, title, author, document class [howto/manual]).
163
164
164 latex_documents = [ ('index', 'ipython.tex', 'IPython Documentation',
165 latex_documents = [ ('index', 'ipython.tex', 'IPython Documentation',
165 ur"""The IPython Development Team""",
166 ur"""The IPython Development Team""",
166 'manual'),
167 'manual'),
167 ]
168 ]
168
169
169 # The name of an image file (relative to this directory) to place at the top of
170 # The name of an image file (relative to this directory) to place at the top of
170 # the title page.
171 # the title page.
171 #latex_logo = None
172 #latex_logo = None
172
173
173 # For "manual" documents, if this is true, then toplevel headings are parts,
174 # For "manual" documents, if this is true, then toplevel headings are parts,
174 # not chapters.
175 # not chapters.
175 #latex_use_parts = False
176 #latex_use_parts = False
176
177
177 # Additional stuff for the LaTeX preamble.
178 # Additional stuff for the LaTeX preamble.
178 #latex_preamble = ''
179 #latex_preamble = ''
179
180
180 # Documents to append as an appendix to all manuals.
181 # Documents to append as an appendix to all manuals.
181 #latex_appendices = []
182 #latex_appendices = []
182
183
183 # If false, no module index is generated.
184 # If false, no module index is generated.
184 #latex_use_modindex = True
185 #latex_use_modindex = True
185
186
186
187
187 # Cleanup
188 # Cleanup
188 # -------
189 # -------
189 # delete release info to avoid pickling errors from sphinx
190 # delete release info to avoid pickling errors from sphinx
190
191
191 del iprelease
192 del iprelease
@@ -1,286 +1,287 b''
1 .. _customization:
1 .. _customization:
2
2
3 ========================
3 ========================
4 Customization of IPython
4 Customization of IPython
5 ========================
5 ========================
6
6
7 There are 2 ways to configure IPython - the old way of using ipythonrc
7 There are 2 ways to configure IPython - the old way of using ipythonrc
8 files (an INI-file like format), and the new way that involves editing
8 files (an INI-file like format), and the new way that involves editing
9 your ipy_user_conf.py. Both configuration systems work at the same
9 your ipy_user_conf.py. Both configuration systems work at the same
10 time, so you can set your options in both, but if you are hesitating
10 time, so you can set your options in both, but if you are hesitating
11 about which alternative to choose, we recommend the ipy_user_conf.py
11 about which alternative to choose, we recommend the ipy_user_conf.py
12 approach, as it will give you more power and control in the long
12 approach, as it will give you more power and control in the long
13 run. However, there are few options such as pylab_import_all that can
13 run. However, there are few options such as pylab_import_all that can
14 only be specified in ipythonrc file or command line - the reason for
14 only be specified in ipythonrc file or command line - the reason for
15 this is that they are needed before IPython has been started up, and
15 this is that they are needed before IPython has been started up, and
16 the IPApi object used in ipy_user_conf.py is not yet available at that
16 the IPApi object used in ipy_user_conf.py is not yet available at that
17 time. A hybrid approach of specifying a few options in ipythonrc and
17 time. A hybrid approach of specifying a few options in ipythonrc and
18 doing the more advanced configuration in ipy_user_conf.py is also
18 doing the more advanced configuration in ipy_user_conf.py is also
19 possible.
19 possible.
20
20
21 .. _ipythonrc:
21 .. _ipythonrc:
22
22
23 The ipythonrc approach
23 The ipythonrc approach
24 ======================
24 ======================
25
25
26 As we've already mentioned, IPython reads a configuration file which can
26 As we've already mentioned, IPython reads a configuration file which can
27 be specified at the command line (-rcfile) or which by default is
27 be specified at the command line (-rcfile) or which by default is
28 assumed to be called ipythonrc. Such a file is looked for in the current
28 assumed to be called ipythonrc. Such a file is looked for in the current
29 directory where IPython is started and then in your IPYTHONDIR, which
29 directory where IPython is started and then in your IPYTHONDIR, which
30 allows you to have local configuration files for specific projects. In
30 allows you to have local configuration files for specific projects. In
31 this section we will call these types of configuration files simply
31 this section we will call these types of configuration files simply
32 rcfiles (short for resource configuration file).
32 rcfiles (short for resource configuration file).
33
33
34 The syntax of an rcfile is one of key-value pairs separated by
34 The syntax of an rcfile is one of key-value pairs separated by
35 whitespace, one per line. Lines beginning with a # are ignored as
35 whitespace, one per line. Lines beginning with a # are ignored as
36 comments, but comments can not be put on lines with data (the parser is
36 comments, but comments can not be put on lines with data (the parser is
37 fairly primitive). Note that these are not python files, and this is
37 fairly primitive). Note that these are not python files, and this is
38 deliberate, because it allows us to do some things which would be quite
38 deliberate, because it allows us to do some things which would be quite
39 tricky to implement if they were normal python files.
39 tricky to implement if they were normal python files.
40
40
41 First, an rcfile can contain permanent default values for almost all command
41 First, an rcfile can contain permanent default values for almost all command
42 line options (except things like -help or -Version). :ref:`This section
42 line options (except things like -help or -Version). :ref:`This section
43 <command_line_options>` contains a description of all command-line
43 <command_line_options>` contains a description of all command-line
44 options. However, values you explicitly specify at the command line override
44 options. However, values you explicitly specify at the command line override
45 the values defined in the rcfile.
45 the values defined in the rcfile.
46
46
47 Besides command line option values, the rcfile can specify values for
47 Besides command line option values, the rcfile can specify values for
48 certain extra special options which are not available at the command
48 certain extra special options which are not available at the command
49 line. These options are briefly described below.
49 line. These options are briefly described below.
50
50
51 Each of these options may appear as many times as you need it in the file.
51 Each of these options may appear as many times as you need it in the file.
52
52
53 * include <file1> <file2> ...: you can name other rcfiles you want
53 * include <file1> <file2> ...: you can name other rcfiles you want
54 to recursively load up to 15 levels (don't use the <> brackets in
54 to recursively load up to 15 levels (don't use the <> brackets in
55 your names!). This feature allows you to define a 'base' rcfile
55 your names!). This feature allows you to define a 'base' rcfile
56 with general options and special-purpose files which can be loaded
56 with general options and special-purpose files which can be loaded
57 only when needed with particular configuration options. To make
57 only when needed with particular configuration options. To make
58 this more convenient, IPython accepts the -profile <name> option
58 this more convenient, IPython accepts the -profile <name> option
59 (abbreviates to -p <name>) which tells it to look for an rcfile
59 (abbreviates to -p <name>) which tells it to look for an rcfile
60 named ipythonrc-<name>.
60 named ipythonrc-<name>.
61 * import_mod <mod1> <mod2> ...: import modules with 'import
61 * import_mod <mod1> <mod2> ...: import modules with 'import
62 <mod1>,<mod2>,...'
62 <mod1>,<mod2>,...'
63 * import_some <mod> <f1> <f2> ...: import functions with 'from
63 * import_some <mod> <f1> <f2> ...: import functions with 'from
64 <mod> import <f1>,<f2>,...'
64 <mod> import <f1>,<f2>,...'
65 * import_all <mod1> <mod2> ...: for each module listed import
65 * import_all <mod1> <mod2> ...: for each module listed import
66 functions with ``from <mod> import *``.
66 functions with ``from <mod> import *``.
67 * execute <python code>: give any single-line python code to be
67 * execute <python code>: give any single-line python code to be
68 executed.
68 executed.
69 * execfile <filename>: execute the python file given with an
69 * execfile <filename>: execute the python file given with an
70 'execfile(filename)' command. Username expansion is performed on
70 'execfile(filename)' command. Username expansion is performed on
71 the given names. So if you need any amount of extra fancy
71 the given names. So if you need any amount of extra fancy
72 customization that won't fit in any of the above 'canned' options,
72 customization that won't fit in any of the above 'canned' options,
73 you can just put it in a separate python file and execute it.
73 you can just put it in a separate python file and execute it.
74 * alias <alias_def>: this is equivalent to calling
74 * alias <alias_def>: this is equivalent to calling
75 '%alias <alias_def>' at the IPython command line. This way, from
75 '%alias <alias_def>' at the IPython command line. This way, from
76 within IPython you can do common system tasks without having to
76 within IPython you can do common system tasks without having to
77 exit it or use the ! escape. IPython isn't meant to be a shell
77 exit it or use the ! escape. IPython isn't meant to be a shell
78 replacement, but it is often very useful to be able to do things
78 replacement, but it is often very useful to be able to do things
79 with files while testing code. This gives you the flexibility to
79 with files while testing code. This gives you the flexibility to
80 have within IPython any aliases you may be used to under your
80 have within IPython any aliases you may be used to under your
81 normal system shell.
81 normal system shell.
82
82
83 ipy_user_conf.py
83 ipy_user_conf.py
84 ================
84 ================
85
85
86 There should be a simple template ipy_user_conf.py file in your
86 There should be a simple template ipy_user_conf.py file in your
87 ~/.ipython directory. It is a plain python module that is imported
87 ~/.ipython directory. It is a plain python module that is imported
88 during IPython startup, so you can do pretty much what you want there
88 during IPython startup, so you can do pretty much what you want there
89 - import modules, configure extensions, change options, define magic
89 - import modules, configure extensions, change options, define magic
90 commands, put variables and functions in the IPython namespace,
90 commands, put variables and functions in the IPython namespace,
91 etc. You use the IPython extension api object, acquired by
91 etc. You use the IPython extension api object, acquired by
92 IPython.ipapi.get() and documented in the "IPython extension API"
92 IPython.ipapi.get() and documented in the "IPython extension API"
93 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
93 chapter, to interact with IPython. A sample ipy_user_conf.py is listed
94 below for reference::
94 below for reference::
95
95
96 # Most of your config files and extensions will probably start
96 # Most of your config files and extensions will probably start
97 # with this import
97 # with this import
98
98
99 import IPython.ipapi
99 import IPython.ipapi
100 ip = IPython.ipapi.get()
100 ip = IPython.ipapi.get()
101
101
102 # You probably want to uncomment this if you did %upgrade -nolegacy
102 # You probably want to uncomment this if you did %upgrade -nolegacy
103 # import ipy_defaults
103 # import ipy_defaults
104
104
105 import os
105 import os
106
106
107 def main():
107 def main():
108
108
109 #ip.dbg.debugmode = True
109 #ip.dbg.debugmode = True
110 ip.dbg.debug_stack()
110 ip.dbg.debug_stack()
111
111
112 # uncomment if you want to get ipython -p sh behaviour
112 # uncomment if you want to get ipython -p sh behaviour
113 # without having to use command line switches
113 # without having to use command line switches
114 import ipy_profile_sh
114 import ipy_profile_sh
115 import jobctrl
115 import jobctrl
116
116
117 # Configure your favourite editor?
117 # Configure your favourite editor?
118 # Good idea e.g. for %edit os.path.isfile
118 # Good idea e.g. for %edit os.path.isfile
119
119
120 #import ipy_editors
120 #import ipy_editors
121
121
122 # Choose one of these:
122 # Choose one of these:
123
123
124 #ipy_editors.scite()
124 #ipy_editors.scite()
125 #ipy_editors.scite('c:/opt/scite/scite.exe')
125 #ipy_editors.scite('c:/opt/scite/scite.exe')
126 #ipy_editors.komodo()
126 #ipy_editors.komodo()
127 #ipy_editors.idle()
127 #ipy_editors.idle()
128 # ... or many others, try 'ipy_editors??' after import to see them
128 # ... or many others, try 'ipy_editors??' after import to see them
129
129
130 # Or roll your own:
130 # Or roll your own:
131 #ipy_editors.install_editor("c:/opt/jed +$line $file")
131 #ipy_editors.install_editor("c:/opt/jed +$line $file")
132
132
133
133
134 o = ip.options
134 o = ip.options
135 # An example on how to set options
135 # An example on how to set options
136 #o.autocall = 1
136 #o.autocall = 1
137 o.system_verbose = 0
137 o.system_verbose = 0
138
138
139 #import_all("os sys")
139 #import_all("os sys")
140 #execf('~/_ipython/ns.py')
140 #execf('~/_ipython/ns.py')
141
141
142
142
143 # -- prompt
143 # -- prompt
144 # A different, more compact set of prompts from the default ones, that
144 # A different, more compact set of prompts from the default ones, that
145 # always show your current location in the filesystem:
145 # always show your current location in the filesystem:
146
146
147 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
147 #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
148 #o.prompt_in2 = r'.\D: '
148 #o.prompt_in2 = r'.\D: '
149 #o.prompt_out = r'[\#] '
149 #o.prompt_out = r'[\#] '
150
150
151 # Try one of these color settings if you can't read the text easily
151 # Try one of these color settings if you can't read the text easily
152 # autoexec is a list of IPython commands to execute on startup
152 # autoexec is a list of IPython commands to execute on startup
153 #o.autoexec.append('%colors LightBG')
153 #o.autoexec.append('%colors LightBG')
154 #o.autoexec.append('%colors NoColor')
154 #o.autoexec.append('%colors NoColor')
155 o.autoexec.append('%colors Linux')
155 o.autoexec.append('%colors Linux')
156
156
157
157
158 # some config helper functions you can use
158 # some config helper functions you can use
159 def import_all(modules):
159 def import_all(modules):
160 """ Usage: import_all("os sys") """
160 """ Usage: import_all("os sys") """
161 for m in modules.split():
161 for m in modules.split():
162 ip.ex("from %s import *" % m)
162 ip.ex("from %s import *" % m)
163
163
164 def execf(fname):
164 def execf(fname):
165 """ Execute a file in user namespace """
165 """ Execute a file in user namespace """
166 ip.ex('execfile("%s")' % os.path.expanduser(fname))
166 ip.ex('execfile("%s")' % os.path.expanduser(fname))
167
167
168 main()
168 main()
169
169
170 .. _Prompts:
170 .. _Prompts:
171
171
172 Fine-tuning your prompt
172 Fine-tuning your prompt
173 =======================
173 =======================
174
174
175 IPython's prompts can be customized using a syntax similar to that of
175 IPython's prompts can be customized using a syntax similar to that of
176 the bash shell. Many of bash's escapes are supported, as well as a few
176 the bash shell. Many of bash's escapes are supported, as well as a few
177 additional ones. We list them below::
177 additional ones. We list them below::
178
178
179 \#
179 \#
180 the prompt/history count number. This escape is automatically
180 the prompt/history count number. This escape is automatically
181 wrapped in the coloring codes for the currently active color scheme.
181 wrapped in the coloring codes for the currently active color scheme.
182 \N
182 \N
183 the 'naked' prompt/history count number: this is just the number
183 the 'naked' prompt/history count number: this is just the number
184 itself, without any coloring applied to it. This lets you produce
184 itself, without any coloring applied to it. This lets you produce
185 numbered prompts with your own colors.
185 numbered prompts with your own colors.
186 \D
186 \D
187 the prompt/history count, with the actual digits replaced by dots.
187 the prompt/history count, with the actual digits replaced by dots.
188 Used mainly in continuation prompts (prompt_in2)
188 Used mainly in continuation prompts (prompt_in2)
189 \w
189 \w
190 the current working directory
190 the current working directory
191 \W
191 \W
192 the basename of current working directory
192 the basename of current working directory
193 \Xn
193 \Xn
194 where $n=0\ldots5.$ The current working directory, with $HOME
194 where $n=0\ldots5.$ The current working directory, with $HOME
195 replaced by ~, and filtered out to contain only $n$ path elements
195 replaced by ~, and filtered out to contain only $n$ path elements
196 \Yn
196 \Yn
197 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
197 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
198 is similar to the behavior of the %cn escapes in tcsh)
198 is similar to the behavior of the %cn escapes in tcsh)
199 \u
199 \u
200 the username of the current user
200 the username of the current user
201 \$
201 \$
202 if the effective UID is 0, a #, otherwise a $
202 if the effective UID is 0, a #, otherwise a $
203 \h
203 \h
204 the hostname up to the first '.'
204 the hostname up to the first '.'
205 \H
205 \H
206 the hostname
206 the hostname
207 \n
207 \n
208 a newline
208 a newline
209 \r
209 \r
210 a carriage return
210 a carriage return
211 \v
211 \v
212 IPython version string
212 IPython version string
213
213
214 In addition to these, ANSI color escapes can be insterted into the
214 In addition to these, ANSI color escapes can be insterted into the
215 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
215 prompts, as \C_ColorName. The list of valid color names is: Black, Blue,
216 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
216 Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray,
217 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
217 LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White,
218 Yellow.
218 Yellow.
219
219
220 Finally, IPython supports the evaluation of arbitrary expressions in
220 Finally, IPython supports the evaluation of arbitrary expressions in
221 your prompt string. The prompt strings are evaluated through the syntax
221 your prompt string. The prompt strings are evaluated through the syntax
222 of PEP 215, but basically you can use $x.y to expand the value of x.y,
222 of PEP 215, but basically you can use $x.y to expand the value of x.y,
223 and for more complicated expressions you can use braces: ${foo()+x} will
223 and for more complicated expressions you can use braces: ${foo()+x} will
224 call function foo and add to it the value of x, before putting the
224 call function foo and add to it the value of x, before putting the
225 result into your prompt. For example, using
225 result into your prompt. For example, using
226 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
226 prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: '
227 will print the result of the uptime command on each prompt (assuming the
227 will print the result of the uptime command on each prompt (assuming the
228 commands module has been imported in your ipythonrc file).
228 commands module has been imported in your ipythonrc file).
229
229
230
230
231 Prompt examples
231 Prompt examples
232
232
233 The following options in an ipythonrc file will give you IPython's
233 The following options in an ipythonrc file will give you IPython's
234 default prompts::
234 default prompts::
235
235
236 prompt_in1 'In [\#]:'
236 prompt_in1 'In [\#]:'
237 prompt_in2 ' .\D.:'
237 prompt_in2 ' .\D.:'
238 prompt_out 'Out[\#]:'
238 prompt_out 'Out[\#]:'
239
239
240 which look like this::
240 which look like this::
241
241
242 In [1]: 1+2
242 In [1]: 1+2
243 Out[1]: 3
243 Out[1]: 3
244
244
245 In [2]: for i in (1,2,3):
245 In [2]: for i in (1,2,3):
246 ...: print i,
246 ...: print i,
247 ...:
247 ...:
248 1 2 3
248 1 2 3
249
249
250 These will give you a very colorful prompt with path information::
250 These will give you a very colorful prompt with path information::
251
251
252 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
252 #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>'
253 prompt_in2 ' ..\D>'
253 prompt_in2 ' ..\D>'
254 prompt_out '<\#>'
254 prompt_out '<\#>'
255
255
256 which look like this::
256 which look like this::
257
257
258 fperez[~/ipython]1> 1+2
258 fperez[~/ipython]1> 1+2
259 <1> 3
259 <1> 3
260 fperez[~/ipython]2> for i in (1,2,3):
260 fperez[~/ipython]2> for i in (1,2,3):
261 ...> print i,
261 ...> print i,
262 ...>
262 ...>
263 1 2 3
263 1 2 3
264
264
265
265
266 .. _Profiles:
266 .. _Profiles:
267
267
268 IPython profiles
268 IPython profiles
269 ================
269 ================
270
270
271 As we already mentioned, IPython supports the -profile command-line option (see
271 As we already mentioned, IPython supports the -profile command-line option (see
272 :ref:`here <command_line_options>`). A profile is nothing more than a
272 :ref:`here <command_line_options>`). A profile is nothing more than a
273 particular configuration file like your basic ipythonrc one, but with
273 particular configuration file like your basic ipythonrc one, but with
274 particular customizations for a specific purpose. When you start IPython with
274 particular customizations for a specific purpose. When you start IPython with
275 'ipython -profile <name>', it assumes that in your IPYTHONDIR there is a file
275 'ipython -profile <name>', it assumes that in your IPYTHONDIR there is a file
276 called ipythonrc-<name> or ipy_profile_<name>.py, and loads it instead of the
276 called ipythonrc-<name> or ipy_profile_<name>.py, and loads it instead of the
277 normal ipythonrc.
277 normal ipythonrc.
278
278
279 This system allows you to maintain multiple configurations which load
279 This system allows you to maintain multiple configurations which load
280 modules, set options, define functions, etc. suitable for different
280 modules, set options, define functions, etc. suitable for different
281 tasks and activate them in a very simple manner. In order to avoid
281 tasks and activate them in a very simple manner. In order to avoid
282 having to repeat all of your basic options (common things that don't
282 having to repeat all of your basic options (common things that don't
283 change such as your color preferences, for example), any profile can
283 change such as your color preferences, for example), any profile can
284 include another configuration file. The most common way to use profiles
284 include another configuration file. The most common way to use profiles
285 is then to have each one include your basic ipythonrc file as a starting
285 is then to have each one include your basic ipythonrc file as a starting
286 point, and then add further customizations. No newline at end of file
286 point, and then add further customizations.
287
@@ -1,10 +1,11 b''
1 ===============================
1 ===============================
2 Configuration and customization
2 Configuration and customization
3 ===============================
3 ===============================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 2
6 :maxdepth: 2
7
7
8 initial_config.txt
8 initial_config.txt
9 customization.txt
9 customization.txt
10 new_config.txt
10 new_config.txt
11
@@ -1,249 +1,250 b''
1 .. _initial config:
1 .. _initial config:
2
2
3 =========================================
3 =========================================
4 Initial configuration of your environment
4 Initial configuration of your environment
5 =========================================
5 =========================================
6
6
7 This section will help you set various things in your environment for
7 This section will help you set various things in your environment for
8 your IPython sessions to be as efficient as possible. All of IPython's
8 your IPython sessions to be as efficient as possible. All of IPython's
9 configuration information, along with several example files, is stored
9 configuration information, along with several example files, is stored
10 in a directory named by default $HOME/.ipython. You can change this by
10 in a directory named by default $HOME/.ipython. You can change this by
11 defining the environment variable IPYTHONDIR, or at runtime with the
11 defining the environment variable IPYTHONDIR, or at runtime with the
12 command line option -ipythondir.
12 command line option -ipythondir.
13
13
14 If all goes well, the first time you run IPython it should automatically create
14 If all goes well, the first time you run IPython it should automatically create
15 a user copy of the config directory for you, based on its builtin defaults. You
15 a user copy of the config directory for you, based on its builtin defaults. You
16 can look at the files it creates to learn more about configuring the
16 can look at the files it creates to learn more about configuring the
17 system. The main file you will modify to configure IPython's behavior is called
17 system. The main file you will modify to configure IPython's behavior is called
18 ipythonrc (with a .ini extension under Windows), included for reference
18 ipythonrc (with a .ini extension under Windows), included for reference
19 :ref:`here <ipythonrc>`. This file is very commented and has many variables you
19 :ref:`here <ipythonrc>`. This file is very commented and has many variables you
20 can change to suit your taste, you can find more details :ref:`here
20 can change to suit your taste, you can find more details :ref:`here
21 <customization>`. Here we discuss the basic things you will want to make sure
21 <customization>`. Here we discuss the basic things you will want to make sure
22 things are working properly from the beginning.
22 things are working properly from the beginning.
23
23
24
24
25 .. _accessing_help:
25 .. _accessing_help:
26
26
27 Access to the Python help system
27 Access to the Python help system
28 ================================
28 ================================
29
29
30 This is true for Python in general (not just for IPython): you should have an
30 This is true for Python in general (not just for IPython): you should have an
31 environment variable called PYTHONDOCS pointing to the directory where your
31 environment variable called PYTHONDOCS pointing to the directory where your
32 HTML Python documentation lives. In my system it's
32 HTML Python documentation lives. In my system it's
33 :file:`/usr/share/doc/python-doc/html`, check your local details or ask your
33 :file:`/usr/share/doc/python-doc/html`, check your local details or ask your
34 systems administrator.
34 systems administrator.
35
35
36 This is the directory which holds the HTML version of the Python
36 This is the directory which holds the HTML version of the Python
37 manuals. Unfortunately it seems that different Linux distributions
37 manuals. Unfortunately it seems that different Linux distributions
38 package these files differently, so you may have to look around a bit.
38 package these files differently, so you may have to look around a bit.
39 Below I show the contents of this directory on my system for reference::
39 Below I show the contents of this directory on my system for reference::
40
40
41 [html]> ls
41 [html]> ls
42 about.html dist/ icons/ lib/ python2.5.devhelp.gz whatsnew/
42 about.html dist/ icons/ lib/ python2.5.devhelp.gz whatsnew/
43 acks.html doc/ index.html mac/ ref/
43 acks.html doc/ index.html mac/ ref/
44 api/ ext/ inst/ modindex.html tut/
44 api/ ext/ inst/ modindex.html tut/
45
45
46 You should really make sure this variable is correctly set so that
46 You should really make sure this variable is correctly set so that
47 Python's pydoc-based help system works. It is a powerful and convenient
47 Python's pydoc-based help system works. It is a powerful and convenient
48 system with full access to the Python manuals and all modules accessible
48 system with full access to the Python manuals and all modules accessible
49 to you.
49 to you.
50
50
51 Under Windows it seems that pydoc finds the documentation automatically,
51 Under Windows it seems that pydoc finds the documentation automatically,
52 so no extra setup appears necessary.
52 so no extra setup appears necessary.
53
53
54
54
55 Editor
55 Editor
56 ======
56 ======
57
57
58 The %edit command (and its alias %ed) will invoke the editor set in your
58 The %edit command (and its alias %ed) will invoke the editor set in your
59 environment as EDITOR. If this variable is not set, it will default to
59 environment as EDITOR. If this variable is not set, it will default to
60 vi under Linux/Unix and to notepad under Windows. You may want to set
60 vi under Linux/Unix and to notepad under Windows. You may want to set
61 this variable properly and to a lightweight editor which doesn't take
61 this variable properly and to a lightweight editor which doesn't take
62 too long to start (that is, something other than a new instance of
62 too long to start (that is, something other than a new instance of
63 Emacs). This way you can edit multi-line code quickly and with the power
63 Emacs). This way you can edit multi-line code quickly and with the power
64 of a real editor right inside IPython.
64 of a real editor right inside IPython.
65
65
66 If you are a dedicated Emacs user, you should set up the Emacs server so
66 If you are a dedicated Emacs user, you should set up the Emacs server so
67 that new requests are handled by the original process. This means that
67 that new requests are handled by the original process. This means that
68 almost no time is spent in handling the request (assuming an Emacs
68 almost no time is spent in handling the request (assuming an Emacs
69 process is already running). For this to work, you need to set your
69 process is already running). For this to work, you need to set your
70 EDITOR environment variable to 'emacsclient'. The code below, supplied
70 EDITOR environment variable to 'emacsclient'. The code below, supplied
71 by Francois Pinard, can then be used in your .emacs file to enable the
71 by Francois Pinard, can then be used in your .emacs file to enable the
72 server::
72 server::
73
73
74 (defvar server-buffer-clients)
74 (defvar server-buffer-clients)
75 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
75 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
76 (server-start)
76 (server-start)
77 (defun fp-kill-server-with-buffer-routine ()
77 (defun fp-kill-server-with-buffer-routine ()
78 (and server-buffer-clients (server-done)))
78 (and server-buffer-clients (server-done)))
79 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
79 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
80
80
81 You can also set the value of this editor via the commmand-line option
81 You can also set the value of this editor via the commmand-line option
82 '-editor' or in your ipythonrc file. This is useful if you wish to use
82 '-editor' or in your ipythonrc file. This is useful if you wish to use
83 specifically for IPython an editor different from your typical default
83 specifically for IPython an editor different from your typical default
84 (and for Windows users who tend to use fewer environment variables).
84 (and for Windows users who tend to use fewer environment variables).
85
85
86
86
87 Color
87 Color
88 =====
88 =====
89
89
90 The default IPython configuration has most bells and whistles turned on
90 The default IPython configuration has most bells and whistles turned on
91 (they're pretty safe). But there's one that may cause problems on some
91 (they're pretty safe). But there's one that may cause problems on some
92 systems: the use of color on screen for displaying information. This is
92 systems: the use of color on screen for displaying information. This is
93 very useful, since IPython can show prompts and exception tracebacks
93 very useful, since IPython can show prompts and exception tracebacks
94 with various colors, display syntax-highlighted source code, and in
94 with various colors, display syntax-highlighted source code, and in
95 general make it easier to visually parse information.
95 general make it easier to visually parse information.
96
96
97 The following terminals seem to handle the color sequences fine:
97 The following terminals seem to handle the color sequences fine:
98
98
99 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
99 * Linux main text console, KDE Konsole, Gnome Terminal, E-term,
100 rxvt, xterm.
100 rxvt, xterm.
101 * CDE terminal (tested under Solaris). This one boldfaces light colors.
101 * CDE terminal (tested under Solaris). This one boldfaces light colors.
102 * (X)Emacs buffers. See the emacs_ section for more details on
102 * (X)Emacs buffers. See the emacs_ section for more details on
103 using IPython with (X)Emacs.
103 using IPython with (X)Emacs.
104 * A Windows (XP/2k) command prompt with pyreadline_.
104 * A Windows (XP/2k) command prompt with pyreadline_.
105 * A Windows (XP/2k) CygWin shell. Although some users have reported
105 * A Windows (XP/2k) CygWin shell. Although some users have reported
106 problems; it is not clear whether there is an issue for everyone
106 problems; it is not clear whether there is an issue for everyone
107 or only under specific configurations. If you have full color
107 or only under specific configurations. If you have full color
108 support under cygwin, please post to the IPython mailing list so
108 support under cygwin, please post to the IPython mailing list so
109 this issue can be resolved for all users.
109 this issue can be resolved for all users.
110
110
111 .. _pyreadline: https://code.launchpad.net/pyreadline
111 .. _pyreadline: https://code.launchpad.net/pyreadline
112
112
113 These have shown problems:
113 These have shown problems:
114
114
115 * Windows command prompt in WinXP/2k logged into a Linux machine via
115 * Windows command prompt in WinXP/2k logged into a Linux machine via
116 telnet or ssh.
116 telnet or ssh.
117 * Windows native command prompt in WinXP/2k, without Gary Bishop's
117 * Windows native command prompt in WinXP/2k, without Gary Bishop's
118 extensions. Once Gary's readline library is installed, the normal
118 extensions. Once Gary's readline library is installed, the normal
119 WinXP/2k command prompt works perfectly.
119 WinXP/2k command prompt works perfectly.
120
120
121 Currently the following color schemes are available:
121 Currently the following color schemes are available:
122
122
123 * NoColor: uses no color escapes at all (all escapes are empty '' ''
123 * NoColor: uses no color escapes at all (all escapes are empty '' ''
124 strings). This 'scheme' is thus fully safe to use in any terminal.
124 strings). This 'scheme' is thus fully safe to use in any terminal.
125 * Linux: works well in Linux console type environments: dark
125 * Linux: works well in Linux console type environments: dark
126 background with light fonts. It uses bright colors for
126 background with light fonts. It uses bright colors for
127 information, so it is difficult to read if you have a light
127 information, so it is difficult to read if you have a light
128 colored background.
128 colored background.
129 * LightBG: the basic colors are similar to those in the Linux scheme
129 * LightBG: the basic colors are similar to those in the Linux scheme
130 but darker. It is easy to read in terminals with light backgrounds.
130 but darker. It is easy to read in terminals with light backgrounds.
131
131
132 IPython uses colors for two main groups of things: prompts and
132 IPython uses colors for two main groups of things: prompts and
133 tracebacks which are directly printed to the terminal, and the object
133 tracebacks which are directly printed to the terminal, and the object
134 introspection system which passes large sets of data through a pager.
134 introspection system which passes large sets of data through a pager.
135
135
136
136
137 Input/Output prompts and exception tracebacks
137 Input/Output prompts and exception tracebacks
138 =============================================
138 =============================================
139
139
140 You can test whether the colored prompts and tracebacks work on your
140 You can test whether the colored prompts and tracebacks work on your
141 system interactively by typing '%colors Linux' at the prompt (use
141 system interactively by typing '%colors Linux' at the prompt (use
142 '%colors LightBG' if your terminal has a light background). If the input
142 '%colors LightBG' if your terminal has a light background). If the input
143 prompt shows garbage like::
143 prompt shows garbage like::
144
144
145 [0;32mIn [[1;32m1[0;32m]: [0;00m
145 [0;32mIn [[1;32m1[0;32m]: [0;00m
146
146
147 instead of (in color) something like::
147 instead of (in color) something like::
148
148
149 In [1]:
149 In [1]:
150
150
151 this means that your terminal doesn't properly handle color escape
151 this means that your terminal doesn't properly handle color escape
152 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
152 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
153
153
154 You can try using a different terminal emulator program (Emacs users,
154 You can try using a different terminal emulator program (Emacs users,
155 see below). To permanently set your color preferences, edit the file
155 see below). To permanently set your color preferences, edit the file
156 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
156 $HOME/.ipython/ipythonrc and set the colors option to the desired value.
157
157
158
158
159 Object details (types, docstrings, source code, etc.)
159 Object details (types, docstrings, source code, etc.)
160 =====================================================
160 =====================================================
161
161
162 IPython has a set of special functions for studying the objects you are working
162 IPython has a set of special functions for studying the objects you are working
163 with, discussed in detail :ref:`here <dynamic_object_info>`. But this system
163 with, discussed in detail :ref:`here <dynamic_object_info>`. But this system
164 relies on passing information which is longer than your screen through a data
164 relies on passing information which is longer than your screen through a data
165 pager, such as the common Unix less and more programs. In order to be able to
165 pager, such as the common Unix less and more programs. In order to be able to
166 see this information in color, your pager needs to be properly configured. I
166 see this information in color, your pager needs to be properly configured. I
167 strongly recommend using less instead of more, as it seems that more simply can
167 strongly recommend using less instead of more, as it seems that more simply can
168 not understand colored text correctly.
168 not understand colored text correctly.
169
169
170 In order to configure less as your default pager, do the following:
170 In order to configure less as your default pager, do the following:
171
171
172 1. Set the environment PAGER variable to less.
172 1. Set the environment PAGER variable to less.
173 2. Set the environment LESS variable to -r (plus any other options
173 2. Set the environment LESS variable to -r (plus any other options
174 you always want to pass to less by default). This tells less to
174 you always want to pass to less by default). This tells less to
175 properly interpret control sequences, which is how color
175 properly interpret control sequences, which is how color
176 information is given to your terminal.
176 information is given to your terminal.
177
177
178 For the bash shell, add to your ~/.bashrc file the lines::
178 For the bash shell, add to your ~/.bashrc file the lines::
179
179
180 export PAGER=less
180 export PAGER=less
181 export LESS=-r
181 export LESS=-r
182
182
183 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
183 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
184
184
185 setenv PAGER less
185 setenv PAGER less
186 setenv LESS -r
186 setenv LESS -r
187
187
188 There is similar syntax for other Unix shells, look at your system
188 There is similar syntax for other Unix shells, look at your system
189 documentation for details.
189 documentation for details.
190
190
191 If you are on a system which lacks proper data pagers (such as Windows),
191 If you are on a system which lacks proper data pagers (such as Windows),
192 IPython will use a very limited builtin pager.
192 IPython will use a very limited builtin pager.
193
193
194 .. _emacs:
194 .. _emacs:
195
195
196 (X)Emacs configuration
196 (X)Emacs configuration
197 ======================
197 ======================
198
198
199 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
199 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
200 currently (X)Emacs and IPython get along very well.
200 currently (X)Emacs and IPython get along very well.
201
201
202 Important note: You will need to use a recent enough version of
202 Important note: You will need to use a recent enough version of
203 python-mode.el, along with the file ipython.el. You can check that the
203 python-mode.el, along with the file ipython.el. You can check that the
204 version you have of python-mode.el is new enough by either looking at
204 version you have of python-mode.el is new enough by either looking at
205 the revision number in the file itself, or asking for it in (X)Emacs via
205 the revision number in the file itself, or asking for it in (X)Emacs via
206 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
206 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
207 proper IPython support.
207 proper IPython support.
208
208
209 The file ipython.el is included with the IPython distribution, in the
209 The file ipython.el is included with the IPython distribution, in the
210 documentation directory (where this manual resides in PDF and HTML
210 documentation directory (where this manual resides in PDF and HTML
211 formats).
211 formats).
212
212
213 Once you put these files in your Emacs path, all you need in your .emacs
213 Once you put these files in your Emacs path, all you need in your .emacs
214 file is::
214 file is::
215
215
216 (require 'ipython)
216 (require 'ipython)
217
217
218 This should give you full support for executing code snippets via
218 This should give you full support for executing code snippets via
219 IPython, opening IPython as your Python shell via ``C-c !``, etc.
219 IPython, opening IPython as your Python shell via ``C-c !``, etc.
220
220
221 You can customize the arguments passed to the IPython instance at startup by
221 You can customize the arguments passed to the IPython instance at startup by
222 setting the ``py-python-command-args`` variable. For example, to start always
222 setting the ``py-python-command-args`` variable. For example, to start always
223 in ``pylab`` mode with hardcoded light-background colors, you can use::
223 in ``pylab`` mode with hardcoded light-background colors, you can use::
224
224
225 (setq py-python-command-args '("-pylab" "-colors" "LightBG"))
225 (setq py-python-command-args '("-pylab" "-colors" "LightBG"))
226
226
227 If you happen to get garbage instead of colored prompts as described in
227 If you happen to get garbage instead of colored prompts as described in
228 the previous section, you may need to set also in your .emacs file::
228 the previous section, you may need to set also in your .emacs file::
229
229
230 (setq ansi-color-for-comint-mode t)
230 (setq ansi-color-for-comint-mode t)
231
231
232 Notes:
232 Notes:
233
233
234 * There is one caveat you should be aware of: you must start the
234 * There is one caveat you should be aware of: you must start the
235 IPython shell before attempting to execute any code regions via
235 IPython shell before attempting to execute any code regions via
236 ``C-c |``. Simply type C-c ! to start IPython before passing any code
236 ``C-c |``. Simply type C-c ! to start IPython before passing any code
237 regions to the interpreter, and you shouldn't experience any
237 regions to the interpreter, and you shouldn't experience any
238 problems.
238 problems.
239 This is due to a bug in Python itself, which has been fixed for
239 This is due to a bug in Python itself, which has been fixed for
240 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
240 Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [
241 737947 ]).
241 737947 ]).
242 * The (X)Emacs support is maintained by Alexander Schmolck, so all
242 * The (X)Emacs support is maintained by Alexander Schmolck, so all
243 comments/requests should be directed to him through the IPython
243 comments/requests should be directed to him through the IPython
244 mailing lists.
244 mailing lists.
245 * This code is still somewhat experimental so it's a bit rough
245 * This code is still somewhat experimental so it's a bit rough
246 around the edges (although in practice, it works quite well).
246 around the edges (although in practice, it works quite well).
247 * Be aware that if you customize py-python-command previously, this
247 * Be aware that if you customize py-python-command previously, this
248 value will override what ipython.el does (because loading the
248 value will override what ipython.el does (because loading the
249 customization variables comes later).
249 customization variables comes later).
250
@@ -1,27 +1,28 b''
1 ========================
1 ========================
2 New configuration system
2 New configuration system
3 ========================
3 ========================
4
4
5 IPython has a configuration system. When running IPython for the first time,
5 IPython has a configuration system. When running IPython for the first time,
6 reasonable defaults are used for the configuration. The configuration of IPython
6 reasonable defaults are used for the configuration. The configuration of IPython
7 can be changed in two ways:
7 can be changed in two ways:
8
8
9 * Configuration files
9 * Configuration files
10 * Commands line options (which override the configuration files)
10 * Commands line options (which override the configuration files)
11
11
12 IPython has a separate configuration file for each subpackage. Thus, the main
12 IPython has a separate configuration file for each subpackage. Thus, the main
13 configuration files are (in your ``~/.ipython`` directory):
13 configuration files are (in your ``~/.ipython`` directory):
14
14
15 * ``ipython1.core.ini``
15 * ``ipython1.core.ini``
16 * ``ipython1.kernel.ini``
16 * ``ipython1.kernel.ini``
17 * ``ipython1.notebook.ini``
17 * ``ipython1.notebook.ini``
18
18
19 To create these files for the first time, do the following::
19 To create these files for the first time, do the following::
20
20
21 from IPython.kernel.config import config_manager as kernel_config
21 from IPython.kernel.config import config_manager as kernel_config
22 kernel_config.write_default_config_file()
22 kernel_config.write_default_config_file()
23
23
24 But, you should only need to do this if you need to modify the defaults. If needed
24 But, you should only need to do this if you need to modify the defaults. If needed
25 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
25 repeat this process with the ``notebook`` and ``core`` configuration as well. If you
26 are running into problems with IPython, you might try deleting these configuration
26 are running into problems with IPython, you might try deleting these configuration
27 files. No newline at end of file
27 files.
28
@@ -1,141 +1,142 b''
1 ==============
1 ==============
2 Coding guide
2 Coding guide
3 ==============
3 ==============
4
4
5
5
6 Coding conventions
6 Coding conventions
7 ==================
7 ==================
8
8
9 In general, we'll try to follow the standard Python style conventions as
9 In general, we'll try to follow the standard Python style conventions as
10 described in Python's `PEP 8`_, the official Python Style Guide.
10 described in Python's `PEP 8`_, the official Python Style Guide.
11
11
12 .. _PEP 8: http://www.python.org/peps/pep-0008.html
12 .. _PEP 8: http://www.python.org/peps/pep-0008.html
13
13
14 Other comments:
14 Other comments:
15
15
16 - In a large file, top level classes and functions should be separated by 2-3
16 - In a large file, top level classes and functions should be separated by 2-3
17 lines to make it easier to separate them visually.
17 lines to make it easier to separate them visually.
18
18
19 - Use 4 spaces for indentation, *never* use hard tabs.
19 - Use 4 spaces for indentation, *never* use hard tabs.
20
20
21 - Keep the ordering of methods the same in classes that have the same methods.
21 - Keep the ordering of methods the same in classes that have the same methods.
22 This is particularly true for classes that implement similar interfaces and
22 This is particularly true for classes that implement similar interfaces and
23 for interfaces that are similar.
23 for interfaces that are similar.
24
24
25 Naming conventions
25 Naming conventions
26 ------------------
26 ------------------
27
27
28 In terms of naming conventions, we'll follow the guidelines of PEP 8. Some of
28 In terms of naming conventions, we'll follow the guidelines of PEP 8. Some of
29 the existing code doesn't honor this perfectly, but for all new IPython code
29 the existing code doesn't honor this perfectly, but for all new IPython code
30 (and much existing code is being refactored), we'll use:
30 (and much existing code is being refactored), we'll use:
31
31
32 - All ``lowercase`` module names.
32 - All ``lowercase`` module names.
33
33
34 - ``CamelCase`` for class names.
34 - ``CamelCase`` for class names.
35
35
36 - ``lowercase_with_underscores`` for methods, functions, variables and
36 - ``lowercase_with_underscores`` for methods, functions, variables and
37 attributes.
37 attributes.
38
38
39 This may be confusing as some of the existing codebase uses a different
39 This may be confusing as some of the existing codebase uses a different
40 convention (``lowerCamelCase`` for methods and attributes). Slowly, we will
40 convention (``lowerCamelCase`` for methods and attributes). Slowly, we will
41 move IPython over to the new convention, providing shadow names for backward
41 move IPython over to the new convention, providing shadow names for backward
42 compatibility in public interfaces.
42 compatibility in public interfaces.
43
43
44 There are, however, some important exceptions to these rules. In some cases,
44 There are, however, some important exceptions to these rules. In some cases,
45 IPython code will interface with packages (Twisted, Wx, Qt) that use other
45 IPython code will interface with packages (Twisted, Wx, Qt) that use other
46 conventions. At some level this makes it impossible to adhere to our own
46 conventions. At some level this makes it impossible to adhere to our own
47 standards at all times. In particular, when subclassing classes that use other
47 standards at all times. In particular, when subclassing classes that use other
48 naming conventions, you must follow their naming conventions. To deal with
48 naming conventions, you must follow their naming conventions. To deal with
49 cases like this, we propose the following policy:
49 cases like this, we propose the following policy:
50
50
51 - If you are subclassing a class that uses different conventions, use its
51 - If you are subclassing a class that uses different conventions, use its
52 naming conventions throughout your subclass. Thus, if you are creating a
52 naming conventions throughout your subclass. Thus, if you are creating a
53 Twisted Protocol class, used Twisted's
53 Twisted Protocol class, used Twisted's
54 ``namingSchemeForMethodsAndAttributes.``
54 ``namingSchemeForMethodsAndAttributes.``
55
55
56 - All IPython's official interfaces should use our conventions. In some cases
56 - All IPython's official interfaces should use our conventions. In some cases
57 this will mean that you need to provide shadow names (first implement
57 this will mean that you need to provide shadow names (first implement
58 ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all
58 ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all
59 costs, but it will probably be necessary at times. But, please use this
59 costs, but it will probably be necessary at times. But, please use this
60 sparingly!
60 sparingly!
61
61
62 Implementation-specific *private* methods will use
62 Implementation-specific *private* methods will use
63 ``_single_underscore_prefix``. Names with a leading double underscore will
63 ``_single_underscore_prefix``. Names with a leading double underscore will
64 *only* be used in special cases, as they makes subclassing difficult (such
64 *only* be used in special cases, as they makes subclassing difficult (such
65 names are not easily seen by child classes).
65 names are not easily seen by child classes).
66
66
67 Occasionally some run-in lowercase names are used, but mostly for very short
67 Occasionally some run-in lowercase names are used, but mostly for very short
68 names or where we are implementing methods very similar to existing ones in a
68 names or where we are implementing methods very similar to existing ones in a
69 base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had
69 base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had
70 established precedent).
70 established precedent).
71
71
72 The old IPython codebase has a big mix of classes and modules prefixed with an
72 The old IPython codebase has a big mix of classes and modules prefixed with an
73 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned
73 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned
74 upon, as namespaces offer cleaner prefixing. The only case where this approach
74 upon, as namespaces offer cleaner prefixing. The only case where this approach
75 is justified is for classes which are expected to be imported into external
75 is justified is for classes which are expected to be imported into external
76 namespaces and a very generic name (like Shell) is too likely to clash with
76 namespaces and a very generic name (like Shell) is too likely to clash with
77 something else. We'll need to revisit this issue as we clean up and refactor
77 something else. We'll need to revisit this issue as we clean up and refactor
78 the code, but in general we should remove as many unnecessary ``IP``/``ip``
78 the code, but in general we should remove as many unnecessary ``IP``/``ip``
79 prefixes as possible. However, if a prefix seems absolutely necessary the more
79 prefixes as possible. However, if a prefix seems absolutely necessary the more
80 specific ``IPY`` or ``ipy`` are preferred.
80 specific ``IPY`` or ``ipy`` are preferred.
81
81
82
82
83 .. _devel-testing:
83 .. _devel-testing:
84
84
85 Testing system
85 Testing system
86 ==============
86 ==============
87
87
88 It is extremely important that all code contributed to IPython has tests. Tests
88 It is extremely important that all code contributed to IPython has tests. Tests
89 should be written as unittests, doctests or as entities that the `Nose`_
89 should be written as unittests, doctests or as entities that the `Nose`_
90 testing package will find. Regardless of how the tests are written, we will use
90 testing package will find. Regardless of how the tests are written, we will use
91 `Nose`_ for discovering and running the tests. `Nose`_ will be required to run
91 `Nose`_ for discovering and running the tests. `Nose`_ will be required to run
92 the IPython test suite, but will not be required to simply use IPython.
92 the IPython test suite, but will not be required to simply use IPython.
93
93
94 .. _Nose: http://code.google.com/p/python-nose/
94 .. _Nose: http://code.google.com/p/python-nose/
95
95
96 Tests of `Twisted`__ using code should be written by subclassing the
96 Tests of `Twisted`__ using code should be written by subclassing the
97 ``TestCase`` class that comes with ``twisted.trial.unittest``. When this is
97 ``TestCase`` class that comes with ``twisted.trial.unittest``. When this is
98 done, `Nose`_ will be able to run the tests and the twisted reactor will be
98 done, `Nose`_ will be able to run the tests and the twisted reactor will be
99 handled correctly.
99 handled correctly.
100
100
101 .. __: http://www.twistedmatrix.com
101 .. __: http://www.twistedmatrix.com
102
102
103 Each subpackage in IPython should have its own ``tests`` directory that
103 Each subpackage in IPython should have its own ``tests`` directory that
104 contains all of the tests for that subpackage. This allows each subpackage to
104 contains all of the tests for that subpackage. This allows each subpackage to
105 be self-contained. If a subpackage has any dependencies beyond the Python
105 be self-contained. If a subpackage has any dependencies beyond the Python
106 standard library, the tests for that subpackage should be skipped if the
106 standard library, the tests for that subpackage should be skipped if the
107 dependencies are not found. This is very important so users don't get tests
107 dependencies are not found. This is very important so users don't get tests
108 failing simply because they don't have dependencies.
108 failing simply because they don't have dependencies.
109
109
110 We also need to look into use Noses ability to tag tests to allow a more
110 We also need to look into use Noses ability to tag tests to allow a more
111 modular approach of running tests.
111 modular approach of running tests.
112
112
113 .. _devel-config:
113 .. _devel-config:
114
114
115 Configuration system
115 Configuration system
116 ====================
116 ====================
117
117
118 IPython uses `.ini`_ files for configuration purposes. This represents a huge
118 IPython uses `.ini`_ files for configuration purposes. This represents a huge
119 improvement over the configuration system used in IPython. IPython works with
119 improvement over the configuration system used in IPython. IPython works with
120 these files using the `ConfigObj`_ package, which IPython includes as
120 these files using the `ConfigObj`_ package, which IPython includes as
121 ``ipython1/external/configobj.py``.
121 ``ipython1/external/configobj.py``.
122
122
123 Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of
123 Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of
124 IPython should contain a ``config`` subdirectory that contains all of the
124 IPython should contain a ``config`` subdirectory that contains all of the
125 configuration information for the subpackage. To see how configuration
125 configuration information for the subpackage. To see how configuration
126 information is defined (along with defaults) see at the examples in
126 information is defined (along with defaults) see at the examples in
127 ``ipython1/kernel/config`` and ``ipython1/core/config``. Likewise, to see how
127 ``ipython1/kernel/config`` and ``ipython1/core/config``. Likewise, to see how
128 the configuration information is used, see examples in
128 the configuration information is used, see examples in
129 ``ipython1/kernel/scripts/ipengine.py``.
129 ``ipython1/kernel/scripts/ipengine.py``.
130
130
131 Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We
131 Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We
132 are calling this new layer, ``tconfig``, as it will use a `Traits`_-like
132 are calling this new layer, ``tconfig``, as it will use a `Traits`_-like
133 validation model. We won't actually use `Traits`_, but will implement
133 validation model. We won't actually use `Traits`_, but will implement
134 something similar in pure Python. But, even in this new system, we will still
134 something similar in pure Python. But, even in this new system, we will still
135 use `ConfigObj`_ and `.ini`_ files underneath the hood. Talk to Fernando if you
135 use `ConfigObj`_ and `.ini`_ files underneath the hood. Talk to Fernando if you
136 are interested in working on this part of IPython. The current prototype of
136 are interested in working on this part of IPython. The current prototype of
137 ``tconfig`` is located in the IPython sandbox.
137 ``tconfig`` is located in the IPython sandbox.
138
138
139 .. _.ini: http://docs.python.org/lib/module-ConfigParser.html
139 .. _.ini: http://docs.python.org/lib/module-ConfigParser.html
140 .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html
140 .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html
141 .. _Traits: http://code.enthought.com/traits/
141 .. _Traits: http://code.enthought.com/traits/
142
@@ -1,33 +1,34 b''
1 =========================================
1 =========================================
2 Notes on the IPython configuration system
2 Notes on the IPython configuration system
3 =========================================
3 =========================================
4
4
5 This document has some random notes on the configuration system.
5 This document has some random notes on the configuration system.
6
6
7 To start, an IPython process needs:
7 To start, an IPython process needs:
8
8
9 * Configuration files
9 * Configuration files
10 * Command line options
10 * Command line options
11 * Additional files (FURL files, extra scripts, etc.)
11 * Additional files (FURL files, extra scripts, etc.)
12
12
13 It feeds these things into the core logic of the process, and as output,
13 It feeds these things into the core logic of the process, and as output,
14 produces:
14 produces:
15
15
16 * Log files
16 * Log files
17 * Security files
17 * Security files
18
18
19 There are a number of things that complicate this:
19 There are a number of things that complicate this:
20
20
21 * A process may need to be started on a different host that doesn't have
21 * A process may need to be started on a different host that doesn't have
22 any of the config files or additional files. Those files need to be
22 any of the config files or additional files. Those files need to be
23 moved over and put in a staging area. The process then needs to be told
23 moved over and put in a staging area. The process then needs to be told
24 about them.
24 about them.
25 * The location of the output files should somehow be set by config files or
25 * The location of the output files should somehow be set by config files or
26 command line options.
26 command line options.
27 * Our config files are very hierarchical, but command line options are flat,
27 * Our config files are very hierarchical, but command line options are flat,
28 making it difficult to relate command line options to config files.
28 making it difficult to relate command line options to config files.
29 * Some processes (like ipcluster and the daemons) have to manage the input and
29 * Some processes (like ipcluster and the daemons) have to manage the input and
30 output files for multiple different subprocesses, each possibly on a
30 output files for multiple different subprocesses, each possibly on a
31 different host. Ahhhh!
31 different host. Ahhhh!
32 * Our configurations are not singletons. A given user will likely have
32 * Our configurations are not singletons. A given user will likely have
33 many different configurations for different clusters.
33 many different configurations for different clusters.
34
@@ -1,103 +1,104 b''
1 .. _documenting-ipython:
1 .. _documenting-ipython:
2
2
3 =====================
3 =====================
4 Documenting IPython
4 Documenting IPython
5 =====================
5 =====================
6
6
7 Standalone documentation
7 Standalone documentation
8 ========================
8 ========================
9
9
10 All standalone documentation should be written in plain text (``.txt``) files
10 All standalone documentation should be written in plain text (``.txt``) files
11 using `reStructuredText`_ for markup and formatting. All such documentation
11 using `reStructuredText`_ for markup and formatting. All such documentation
12 should be placed in the top level directory ``docs`` of the IPython source
12 should be placed in the top level directory ``docs`` of the IPython source
13 tree. Or, when appropriate, a suitably named subdirectory should be used. The
13 tree. Or, when appropriate, a suitably named subdirectory should be used. The
14 documentation in this location will serve as the main source for IPython
14 documentation in this location will serve as the main source for IPython
15 documentation and all existing documentation should be converted to this
15 documentation and all existing documentation should be converted to this
16 format.
16 format.
17
17
18 The actual HTML and PDF docs are built using the Sphinx_ documentation
18 The actual HTML and PDF docs are built using the Sphinx_ documentation
19 generation tool. Sphinx has been adopted as the default documentation tool for
19 generation tool. Sphinx has been adopted as the default documentation tool for
20 Python itself as of version 2.6, as well as by a number of projects that
20 Python itself as of version 2.6, as well as by a number of projects that
21 IPython is related with, such as numpy, scipy, matplotlib, sage and nipy.
21 IPython is related with, such as numpy, scipy, matplotlib, sage and nipy.
22
22
23 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
23 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
24 .. _Sphinx: http://sphinx.pocoo.org/
24 .. _Sphinx: http://sphinx.pocoo.org/
25
25
26
26
27 The rest of this document is mostly taken from the `matploblib
27 The rest of this document is mostly taken from the `matploblib
28 documentation`__; we are using a number of Sphinx tools and extensions written
28 documentation`__; we are using a number of Sphinx tools and extensions written
29 by the matplotlib team and will mostly follow their conventions, which are
29 by the matplotlib team and will mostly follow their conventions, which are
30 nicely spelled out in their guide. What follows is thus a lightly adapted
30 nicely spelled out in their guide. What follows is thus a lightly adapted
31 version of the matplotlib documentation guide, taken with permission from the
31 version of the matplotlib documentation guide, taken with permission from the
32 MPL team.
32 MPL team.
33
33
34 .. __: http://matplotlib.sourceforge.net/devel/documenting_mpl.html
34 .. __: http://matplotlib.sourceforge.net/devel/documenting_mpl.html
35
35
36
36
37 A bit of Python code::
37 A bit of Python code::
38
38
39 for i in range(10):
39 for i in range(10):
40 print i,
40 print i,
41 print "A big number:",2**34
41 print "A big number:",2**34
42
42
43 An interactive Python session::
43 An interactive Python session::
44
44
45 >>> from IPython import genutils
45 >>> from IPython import genutils
46 >>> genutils.get_ipython_dir()
46 >>> genutils.get_ipython_dir()
47 '/home/fperez/.ipython'
47 '/home/fperez/.ipython'
48
48
49
49
50 An IPython session:
50 An IPython session:
51
51
52 .. code-block:: ipython
52 .. code-block:: ipython
53
53
54 In [7]: import IPython
54 In [7]: import IPython
55
55
56 In [8]: print "This IPython is version:",IPython.__version__
56 In [8]: print "This IPython is version:",IPython.__version__
57 This IPython is version: 0.9.1
57 This IPython is version: 0.9.1
58
58
59 In [9]: 2+4
59 In [9]: 2+4
60 Out[9]: 6
60 Out[9]: 6
61
61
62
62
63 A bit of shell code:
63 A bit of shell code:
64
64
65 .. code-block:: bash
65 .. code-block:: bash
66
66
67 cd /tmp
67 cd /tmp
68 echo "My home directory is: $HOME"
68 echo "My home directory is: $HOME"
69 ls
69 ls
70
70
71
71
72 Docstring format
72 Docstring format
73 ================
73 ================
74
74
75 Good docstrings are very important. Unfortunately, Python itself only provides
75 Good docstrings are very important. Unfortunately, Python itself only provides
76 a rather loose standard for docstrings (`PEP 257`_), and there is no universally
76 a rather loose standard for docstrings (`PEP 257`_), and there is no universally
77 accepted convention for all the different parts of a complete docstring.
77 accepted convention for all the different parts of a complete docstring.
78 However, the NumPy project has established a very reasonable standard, and has
78 However, the NumPy project has established a very reasonable standard, and has
79 developed some tools to support the smooth inclusion of such docstrings in
79 developed some tools to support the smooth inclusion of such docstrings in
80 Sphinx-generated manuals. Rather than inventing yet another pseudo-standard,
80 Sphinx-generated manuals. Rather than inventing yet another pseudo-standard,
81 IPython will be henceforth documented using the NumPy conventions; we carry
81 IPython will be henceforth documented using the NumPy conventions; we carry
82 copies of some of the NumPy support tools to remain self-contained, but share
82 copies of some of the NumPy support tools to remain self-contained, but share
83 back upstream with NumPy any improvements or fixes we may make to the tools.
83 back upstream with NumPy any improvements or fixes we may make to the tools.
84
84
85 The `NumPy documentation guidelines`_ contain detailed information on this
85 The `NumPy documentation guidelines`_ contain detailed information on this
86 standard, and for a quick overview, the NumPy `example docstring`_ is a useful
86 standard, and for a quick overview, the NumPy `example docstring`_ is a useful
87 read.
87 read.
88
88
89 As in the past IPython used epydoc, currently many docstrings still use epydoc
89 As in the past IPython used epydoc, currently many docstrings still use epydoc
90 conventions. We will update them as we go, but all new code should be fully
90 conventions. We will update them as we go, but all new code should be fully
91 documented using the NumPy standard.
91 documented using the NumPy standard.
92
92
93 .. _PEP 257: http://www.python.org/peps/pep-0257.html
93 .. _PEP 257: http://www.python.org/peps/pep-0257.html
94 .. _NumPy documentation guidelines: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
94 .. _NumPy documentation guidelines: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
95
95
96 .. _example docstring: http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt
96 .. _example docstring: http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt
97
97
98 Additional PEPs of interest regarding documentation of code. While both of
98 Additional PEPs of interest regarding documentation of code. While both of
99 these were rejected, the ideas therein form much of the basis of docutils (the
99 these were rejected, the ideas therein form much of the basis of docutils (the
100 machinery to process reStructuredText):
100 machinery to process reStructuredText):
101
101
102 - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
102 - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
103 - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
103 - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
104
@@ -1,15 +1,16 b''
1 ===========================
1 ===========================
2 IPython Developer's Guide
2 IPython Developer's Guide
3 ===========================
3 ===========================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 2
6 :maxdepth: 2
7
7
8 overview.txt
8 overview.txt
9 coding_guide.txt
9 coding_guide.txt
10 doc_guide.txt
10 doc_guide.txt
11 roadmap.txt
11 roadmap.txt
12
12
13 notification_blueprint.txt
13 notification_blueprint.txt
14 config_blueprint.txt
14 config_blueprint.txt
15 reorg.txt
15 reorg.txt
16
@@ -1,83 +1,108 b''
1 .. _notification:
1 .. _notification:
2
2
3 ==========================================
3 ==========================================
4 IPython.kernel.core.notification blueprint
4 IPython.kernel.core.notification blueprint
5 ==========================================
5 ==========================================
6
6
7 Overview
7 Overview
8 ========
8 ========
9
9
10 The :mod:`IPython.kernel.core.notification` module will provide a simple
10 The :mod:`IPython.kernel.core.notification` module will provide a simple
11 implementation of a notification center and support for the observer pattern
11 implementation of a notification center and support for the observer pattern
12 within the :mod:`IPython.kernel.core`. The main intended use case is to
12 within the :mod:`IPython.kernel.core`. The main intended use case is to
13 provide notification of Interpreter events to an observing frontend during the
13 provide notification of Interpreter events to an observing frontend during the
14 execution of a single block of code.
14 execution of a single block of code.
15
15
16 Functional Requirements
16 Functional Requirements
17 =======================
17 =======================
18
18
19 The notification center must:
19 The notification center must:
20
20
21 * Provide synchronous notification of events to all registered observers.
21 * Provide synchronous notification of events to all registered observers.
22
22
23 * Provide typed or labeled notification types.
23 * Provide typed or labeled notification types.
24
24
25 * Allow observers to register callbacks for individual or all notification
25 * Allow observers to register callbacks for individual or all notification
26 types.
26 types.
27
27
28 * Allow observers to register callbacks for events from individual or all
28 * Allow observers to register callbacks for events from individual or all
29 notifying objects.
29 notifying objects.
30
30
31 * Notification to the observer consists of the notification type, notifying
31 * Notification to the observer consists of the notification type, notifying
32 object and user-supplied extra information [implementation: as keyword
32 object and user-supplied extra information [implementation: as keyword
33 parameters to the registered callback].
33 parameters to the registered callback].
34
34
35 * Perform as O(1) in the case of no registered observers.
35 * Perform as O(1) in the case of no registered observers.
36
36
37 * Permit out-of-process or cross-network extension.
37 * Permit out-of-process or cross-network extension.
38
38
39 What's not included
39 What's not included
40 ===================
40 ===================
41
41
42 As written, the :mod:`IPython.kernel.core.notificaiton` module does not:
42 As written, the :mod:`IPython.kernel.core.notificaiton` module does not:
43
43
44 * Provide out-of-process or network notifications (these should be handled by
44 * Provide out-of-process or network notifications (these should be handled by
45 a separate, Twisted aware module in :mod:`IPython.kernel`).
45 a separate, Twisted aware module in :mod:`IPython.kernel`).
46
46
47 * Provide zope.interface-style interfaces for the notification system (these
47 * Provide zope.interface-style interfaces for the notification system (these
48 should also be provided by the :mod:`IPython.kernel` module).
48 should also be provided by the :mod:`IPython.kernel` module).
49
49
50 Use Cases
50 Use Cases
51 =========
51 =========
52
52
53 The following use cases describe the main intended uses of the notificaiton module and illustrate the main success scenario for each use case:
53 The following use cases describe the main intended uses of the notificaiton module and illustrate the main success scenario for each use case:
54
54
55 1. Dwight Schroot is writing a frontend for the IPython project. His frontend is stuck in the stone age and must communicate synchronously with an IPython.kernel.core.Interpreter instance. Because code is executed in blocks by the Interpreter, Dwight's UI freezes every time he executes a long block of code. To keep track of the progress of his long running block, Dwight adds the following code to his frontend's set-up code::
55 1. Dwight Schroot is writing a frontend for the IPython project. His frontend is stuck in the stone age and must communicate synchronously with an IPython.kernel.core.Interpreter instance. Because code is executed in blocks by the Interpreter, Dwight's UI freezes every time he executes a long block of code. To keep track of the progress of his long running block, Dwight adds the following code to his frontend's set-up code::
56
56
57 from IPython.kernel.core.notification import NotificationCenter
57 from IPython.kernel.core.notification import NotificationCenter
58 center = NotificationCenter.sharedNotificationCenter
58 center = NotificationCenter.sharedNotificationCenter
59 center.registerObserver(self, type=IPython.kernel.core.Interpreter.STDOUT_NOTIFICATION_TYPE, notifying_object=self.interpreter, callback=self.stdout_notification)
59 center.registerObserver(self, type=IPython.kernel.core.Interpreter.STDOUT_NOTIFICATION_TYPE, notifying_object=self.interpreter, callback=self.stdout_notification)
60
60
61 and elsewhere in his front end::
61 and elsewhere in his front end::
62
62
63 def stdout_notification(self, type, notifying_object, out_string=None):
63 def stdout_notification(self, type, notifying_object, out_string=None):
64 self.writeStdOut(out_string)
64 self.writeStdOut(out_string)
65
65
66 If everything works, the Interpreter will (according to its published API)
66 If everything works, the Interpreter will (according to its published API)
67 fire a notification via the
67 fire a notification via the
68 :data:`IPython.kernel.core.notification.sharedCenter` of type
68 :data:`IPython.kernel.core.notification.sharedCenter` of type
69 :const:`STD_OUT_NOTIFICATION_TYPE` before writing anything to stdout [it's up
69 :const:`STD_OUT_NOTIFICATION_TYPE` before writing anything to stdout [it's up
70 to the Intereter implementation to figure out when to do this]. The
70 to the Intereter implementation to figure out when to do this]. The
71 notificaiton center will then call the registered callbacks for that event
71 notificaiton center will then call the registered callbacks for that event
72 type (in this case, Dwight's frontend's stdout_notification method). Again,
72 type (in this case, Dwight's frontend's stdout_notification method). Again,
73 according to its API, the Interpreter provides an additional keyword argument
73 according to its API, the Interpreter provides an additional keyword argument
74 when firing the notificaiton of out_string, a copy of the string it will write
74 when firing the notificaiton of out_string, a copy of the string it will write
75 to stdout.
75 to stdout.
76
76
77 Like magic, Dwight's frontend is able to provide output, even during
77 Like magic, Dwight's frontend is able to provide output, even during
78 long-running calculations. Now if Jim could just convince Dwight to use
78 long-running calculations. Now if Jim could just convince Dwight to use
79 Twisted...
79 Twisted...
80
80
81 2. Boss Hog is writing a frontend for the IPython project. Because Boss Hog is stuck in the stone age, his frontend will be written in a new Fortran-like dialect of python and will run only from the command line. Because he doesn't need any fancy notification system and is used to worrying about every cycle on his rat-wheel powered mini, Boss Hog is adamant that the new notification system not produce any performance penalty. As they say in Hazard county, there's no such thing as a free lunch. If he wanted zero overhead, he should have kept using IPython 0.8. Instead, those tricky Duke boys slide in a suped-up bridge-out jumpin' awkwardly confederate-lovin' notification module that imparts only a constant (and small) performance penalty when the Interpreter (or any other object) fires an event for which there are no registered observers. Of course, the same notificaiton-enabled Interpreter can then be used in frontends that require notifications, thus saving the IPython project from a nasty civil war.
81 2. Boss Hog is writing a frontend for the IPython project. Because Boss Hog is
82 stuck in the stone age, his frontend will be written in a new Fortran-like
83 dialect of python and will run only from the command line. Because he doesn't
84 need any fancy notification system and is used to worrying about every cycle
85 on his rat-wheel powered mini, Boss Hog is adamant that the new notification
86 system not produce any performance penalty. As they say in Hazard county,
87 there's no such thing as a free lunch. If he wanted zero overhead, he should
88 have kept using IPython 0.8. Instead, those tricky Duke boys slide in a
89 suped-up bridge-out jumpin' awkwardly confederate-lovin' notification module
90 that imparts only a constant (and small) performance penalty when the
91 Interpreter (or any other object) fires an event for which there are no
92 registered observers. Of course, the same notificaiton-enabled Interpreter can
93 then be used in frontends that require notifications, thus saving the IPython
94 project from a nasty civil war.
82
95
83 3. Barry is wrting a frontend for the IPython project. Because Barry's front end is the *new hotness*, it uses an asynchronous event model to communicate with a Twisted :mod:`~IPython.kernel.engineservice` that communicates with the IPython :class:`~IPython.kernel.core.interpreter.Interpreter`. Using the :mod:`IPython.kernel.notification` module, an asynchronous wrapper on the :mod:`IPython.kernel.core.notification` module, Barry's frontend can register for notifications from the interpreter that are delivered asynchronously. Even if Barry's frontend is running on a separate process or even host from the Interpreter, the notifications are delivered, as if by dark and twisted magic. Just like Dwight's frontend, Barry's frontend can now recieve notifications of e.g. writing to stdout/stderr, opening/closing an external file, an exception in the executing code, etc. No newline at end of file
96 3. Barry is wrting a frontend for the IPython project. Because Barry's front
97 end is the *new hotness*, it uses an asynchronous event model to communicate
98 with a Twisted :mod:`~IPython.kernel.engineservice` that communicates with the
99 IPython :class:`~IPython.kernel.core.interpreter.Interpreter`. Using the
100 :mod:`IPython.kernel.notification` module, an asynchronous wrapper on the
101 :mod:`IPython.kernel.core.notification` module, Barry's frontend can register
102 for notifications from the interpreter that are delivered asynchronously. Even
103 if Barry's frontend is running on a separate process or even host from the
104 Interpreter, the notifications are delivered, as if by dark and twisted magic.
105 Just like Dwight's frontend, Barry's frontend can now recieve notifications of
106 e.g. writing to stdout/stderr, opening/closing an external file, an exception
107 in the executing code, etc.
108
@@ -1,517 +1,518 b''
1 .. _development:
1 .. _development:
2
2
3 ==============================
3 ==============================
4 IPython development guidelines
4 IPython development guidelines
5 ==============================
5 ==============================
6
6
7
7
8 Overview
8 Overview
9 ========
9 ========
10
10
11 This document describes IPython from the perspective of developers. Most
11 This document describes IPython from the perspective of developers. Most
12 importantly, it gives information for people who want to contribute to the
12 importantly, it gives information for people who want to contribute to the
13 development of IPython. So if you want to help out, read on!
13 development of IPython. So if you want to help out, read on!
14
14
15 How to contribute to IPython
15 How to contribute to IPython
16 ============================
16 ============================
17
17
18 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
18 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
19 This makes it easy for people to contribute to the development of IPython.
19 This makes it easy for people to contribute to the development of IPython.
20 There are several ways in which you can join in.
20 There are several ways in which you can join in.
21
21
22 If you have a small change that you want to send to the team, you can edit your
22 If you have a small change that you want to send to the team, you can edit your
23 bazaar checkout of IPython (see below) in-place, and ask bazaar for the
23 bazaar checkout of IPython (see below) in-place, and ask bazaar for the
24 differences::
24 differences::
25
25
26 $ cd /path/to/your/copy/of/ipython
26 $ cd /path/to/your/copy/of/ipython
27 $ bzr diff > my_fixes.diff
27 $ bzr diff > my_fixes.diff
28
28
29 This produces a patch file with your fixes, which we can apply to the source
29 This produces a patch file with your fixes, which we can apply to the source
30 tree. This file should then be attached to a ticket in our `bug tracker
30 tree. This file should then be attached to a ticket in our `bug tracker
31 <https://bugs.launchpad.net/ipython>`_, indicating what it does.
31 <https://bugs.launchpad.net/ipython>`_, indicating what it does.
32
32
33 This model of creating small, self-contained patches works very well and there
33 This model of creating small, self-contained patches works very well and there
34 are open source projects that do their entire development this way. However,
34 are open source projects that do their entire development this way. However,
35 in IPython we have found that for tracking larger changes, making use of
35 in IPython we have found that for tracking larger changes, making use of
36 bazaar's full capabilities in conjunction with Launchpad's code hosting
36 bazaar's full capabilities in conjunction with Launchpad's code hosting
37 services makes for a much better experience.
37 services makes for a much better experience.
38
38
39 Making your own branch of IPython allows you to refine your changes over time,
39 Making your own branch of IPython allows you to refine your changes over time,
40 track the development of the main team, and propose your own full version of
40 track the development of the main team, and propose your own full version of
41 the code for others to use and review, with a minimum amount of fuss. The next
41 the code for others to use and review, with a minimum amount of fuss. The next
42 parts of this document will explain how to do this.
42 parts of this document will explain how to do this.
43
43
44 Install Bazaar and create a Launchpad account
44 Install Bazaar and create a Launchpad account
45 ---------------------------------------------
45 ---------------------------------------------
46
46
47 First make sure you have installed Bazaar (see their `website
47 First make sure you have installed Bazaar (see their `website
48 <http://bazaar-vcs.org/>`_). To see that Bazaar is installed and knows about
48 <http://bazaar-vcs.org/>`_). To see that Bazaar is installed and knows about
49 you, try the following::
49 you, try the following::
50
50
51 $ bzr whoami
51 $ bzr whoami
52 Joe Coder <jcoder@gmail.com>
52 Joe Coder <jcoder@gmail.com>
53
53
54 This should display your name and email. Next, you will want to create an
54 This should display your name and email. Next, you will want to create an
55 account on the `Launchpad website <http://www.launchpad.net>`_ and setup your
55 account on the `Launchpad website <http://www.launchpad.net>`_ and setup your
56 ssh keys. For more information of setting up your ssh keys, see `this link
56 ssh keys. For more information of setting up your ssh keys, see `this link
57 <https://help.launchpad.net/YourAccount/CreatingAnSSHKeyPair>`_.
57 <https://help.launchpad.net/YourAccount/CreatingAnSSHKeyPair>`_.
58
58
59 Get the main IPython branch from Launchpad
59 Get the main IPython branch from Launchpad
60 ------------------------------------------
60 ------------------------------------------
61
61
62 Now, you can get a copy of the main IPython development branch (we call this
62 Now, you can get a copy of the main IPython development branch (we call this
63 the "trunk")::
63 the "trunk")::
64
64
65 $ bzr branch lp:ipython
65 $ bzr branch lp:ipython
66
66
67 Create a working branch
67 Create a working branch
68 -----------------------
68 -----------------------
69
69
70 When working on IPython, you won't actually make edits directly to the
70 When working on IPython, you won't actually make edits directly to the
71 :file:`lp:ipython` branch. Instead, you will create a separate branch for your
71 :file:`lp:ipython` branch. Instead, you will create a separate branch for your
72 changes. For now, let's assume you want to do your work in a branch named
72 changes. For now, let's assume you want to do your work in a branch named
73 "ipython-mybranch". Create this branch by doing::
73 "ipython-mybranch". Create this branch by doing::
74
74
75 $ bzr branch ipython ipython-mybranch
75 $ bzr branch ipython ipython-mybranch
76
76
77 When you actually create a branch, you will want to give it a name that
77 When you actually create a branch, you will want to give it a name that
78 reflects the nature of the work that you will be doing in it, like
78 reflects the nature of the work that you will be doing in it, like
79 "install-docs-update".
79 "install-docs-update".
80
80
81 Make edits in your working branch
81 Make edits in your working branch
82 ---------------------------------
82 ---------------------------------
83
83
84 Now you are ready to actually make edits in your :file:`ipython-mybranch`
84 Now you are ready to actually make edits in your :file:`ipython-mybranch`
85 branch. Before doing this, it is helpful to install this branch so you can
85 branch. Before doing this, it is helpful to install this branch so you can
86 test your changes as you work. This is easiest if you have setuptools
86 test your changes as you work. This is easiest if you have setuptools
87 installed. Then, just do::
87 installed. Then, just do::
88
88
89 $ cd ipython-mybranch
89 $ cd ipython-mybranch
90 $ python setupegg.py develop
90 $ python setupegg.py develop
91
91
92 Now, make some changes. After a while, you will want to commit your changes.
92 Now, make some changes. After a while, you will want to commit your changes.
93 This let's Bazaar know that you like the changes you have made and gives you
93 This let's Bazaar know that you like the changes you have made and gives you
94 an opportunity to keep a nice record of what you have done. This looks like
94 an opportunity to keep a nice record of what you have done. This looks like
95 this::
95 this::
96
96
97 $ ...do work in ipython-mybranch...
97 $ ...do work in ipython-mybranch...
98 $ bzr commit -m "the commit message goes here"
98 $ bzr commit -m "the commit message goes here"
99
99
100 Please note that since we now don't use an old-style linear ChangeLog (that
100 Please note that since we now don't use an old-style linear ChangeLog (that
101 tends to cause problems with distributed version control systems), you should
101 tends to cause problems with distributed version control systems), you should
102 ensure that your log messages are reasonably detailed. Use a docstring-like
102 ensure that your log messages are reasonably detailed. Use a docstring-like
103 approach in the commit messages (including the second line being left
103 approach in the commit messages (including the second line being left
104 *blank*)::
104 *blank*)::
105
105
106 Single line summary of changes being committed.
106 Single line summary of changes being committed.
107
107
108 * more details when warranted ...
108 * more details when warranted ...
109 * including crediting outside contributors if they sent the
109 * including crediting outside contributors if they sent the
110 code/bug/idea!
110 code/bug/idea!
111
111
112 As you work, you will repeat this edit/commit cycle many times. If you work on
112 As you work, you will repeat this edit/commit cycle many times. If you work on
113 your branch for a long time, you will also want to get the latest changes from
113 your branch for a long time, you will also want to get the latest changes from
114 the :file:`lp:ipython` branch. This can be done with the following sequence of
114 the :file:`lp:ipython` branch. This can be done with the following sequence of
115 commands::
115 commands::
116
116
117 $ ls
117 $ ls
118 ipython
118 ipython
119 ipython-mybranch
119 ipython-mybranch
120
120
121 $ cd ipython
121 $ cd ipython
122 $ bzr pull
122 $ bzr pull
123 $ cd ../ipython-mybranch
123 $ cd ../ipython-mybranch
124 $ bzr merge ../ipython
124 $ bzr merge ../ipython
125 $ bzr commit -m "Merging changes from trunk"
125 $ bzr commit -m "Merging changes from trunk"
126
126
127 Along the way, you should also run the IPython test suite. You can do this
127 Along the way, you should also run the IPython test suite. You can do this
128 using the :command:`iptest` command (which is basically a customized version of
128 using the :command:`iptest` command (which is basically a customized version of
129 :command:`nosetests`)::
129 :command:`nosetests`)::
130
130
131 $ cd
131 $ cd
132 $ iptest
132 $ iptest
133
133
134 The :command:`iptest` command will also pick up and run any tests you have
134 The :command:`iptest` command will also pick up and run any tests you have
135 written. See :ref:`testing documentation <devel_testing>` for further details
135 written. See :ref:`testing documentation <devel_testing>` for further details
136 on the testing system.
136 on the testing system.
137
137
138
138
139 Post your branch and request a code review
139 Post your branch and request a code review
140 ------------------------------------------
140 ------------------------------------------
141
141
142 Once you are done with your edits, you should post your branch on Launchpad so
142 Once you are done with your edits, you should post your branch on Launchpad so
143 that other IPython developers can review the changes and help you merge your
143 that other IPython developers can review the changes and help you merge your
144 changes into the main development branch. To post your branch on Launchpad,
144 changes into the main development branch. To post your branch on Launchpad,
145 do::
145 do::
146
146
147 $ cd ipython-mybranch
147 $ cd ipython-mybranch
148 $ bzr push lp:~yourusername/ipython/ipython-mybranch
148 $ bzr push lp:~yourusername/ipython/ipython-mybranch
149
149
150 Then, go to the `IPython Launchpad site <www.launchpad.net/ipython>`_, and you
150 Then, go to the `IPython Launchpad site <www.launchpad.net/ipython>`_, and you
151 should see your branch under the "Code" tab. If you click on your branch, you
151 should see your branch under the "Code" tab. If you click on your branch, you
152 can provide a short description of the branch as well as mark its status. Most
152 can provide a short description of the branch as well as mark its status. Most
153 importantly, you should click the link that reads "Propose for merging into
153 importantly, you should click the link that reads "Propose for merging into
154 another branch". What does this do?
154 another branch". What does this do?
155
155
156 This let's the other IPython developers know that your branch is ready to be
156 This let's the other IPython developers know that your branch is ready to be
157 reviewed and merged into the main development branch. During this review
157 reviewed and merged into the main development branch. During this review
158 process, other developers will give you feedback and help you get your code
158 process, other developers will give you feedback and help you get your code
159 ready to be merged. What types of things will we be looking for:
159 ready to be merged. What types of things will we be looking for:
160
160
161 * All code is documented.
161 * All code is documented.
162 * All code has tests.
162 * All code has tests.
163 * The entire IPython test suite passes.
163 * The entire IPython test suite passes.
164
164
165 Once your changes have been reviewed and approved, someone will merge them
165 Once your changes have been reviewed and approved, someone will merge them
166 into the main development branch.
166 into the main development branch.
167
167
168
168
169 Some notes for core developers when merging third-party contributions
169 Some notes for core developers when merging third-party contributions
170 =====================================================================
170 =====================================================================
171
171
172 Core developers, who ultimately merge any approved branch (from themselves,
172 Core developers, who ultimately merge any approved branch (from themselves,
173 another developer, or any third-party contribution) will typically use
173 another developer, or any third-party contribution) will typically use
174 :command:`bzr merge` to merge the branch into the trunk and push it to the
174 :command:`bzr merge` to merge the branch into the trunk and push it to the
175 main Launcphad site. This is a short list of things to keep in mind when doing
175 main Launcphad site. This is a short list of things to keep in mind when doing
176 this process, so that the project history is easy to understand in the long
176 this process, so that the project history is easy to understand in the long
177 run, and that generating release notes is as painless and accurate as
177 run, and that generating release notes is as painless and accurate as
178 possible.
178 possible.
179
179
180 - When you merge any non-trivial functionality (from one small bug fix to a
180 - When you merge any non-trivial functionality (from one small bug fix to a
181 big feature branch), please remember to always edit the :file:`changes.txt`
181 big feature branch), please remember to always edit the :file:`changes.txt`
182 file accordingly. This file has one main section for each release, and if
182 file accordingly. This file has one main section for each release, and if
183 you edit it as you go, noting what new features, bug fixes or API changes
183 you edit it as you go, noting what new features, bug fixes or API changes
184 you have made, the release notes will be almost finished when they are
184 you have made, the release notes will be almost finished when they are
185 needed later. This is much easier if done when you merge the work, rather
185 needed later. This is much easier if done when you merge the work, rather
186 than weeks or months later by re-reading a massive Bazaar log.
186 than weeks or months later by re-reading a massive Bazaar log.
187
187
188 - When big merges are done, the practice of putting a summary commit message
188 - When big merges are done, the practice of putting a summary commit message
189 in the merge is *extremely* useful. It makes this kind of job much nicer,
189 in the merge is *extremely* useful. It makes this kind of job much nicer,
190 because that summary log message can be almost copy/pasted without changes,
190 because that summary log message can be almost copy/pasted without changes,
191 if it was well written, rather than dissecting the next-level messages from
191 if it was well written, rather than dissecting the next-level messages from
192 the individual commits.
192 the individual commits.
193
193
194 - It's important that we remember to always credit who gave us something if
194 - It's important that we remember to always credit who gave us something if
195 it's not the committer. In general, we have been fairly good on this front,
195 it's not the committer. In general, we have been fairly good on this front,
196 this is just a reminder to keep things up. As a note, if you are ever
196 this is just a reminder to keep things up. As a note, if you are ever
197 committing something that is completely (or almost so) a third-party
197 committing something that is completely (or almost so) a third-party
198 contribution, do the commit as::
198 contribution, do the commit as::
199
199
200 $ bzr commit --author="Someone Else"
200 $ bzr commit --author="Someone Else"
201
201
202 This way it will show that name separately in the log, which makes it even
202 This way it will show that name separately in the log, which makes it even
203 easier to spot. Obviously we often rework third party contributions
203 easier to spot. Obviously we often rework third party contributions
204 extensively, but this is still good to keep in mind for cases when we don't
204 extensively, but this is still good to keep in mind for cases when we don't
205 touch the code too much.
205 touch the code too much.
206
206
207
207
208 Documentation
208 Documentation
209 =============
209 =============
210
210
211 Standalone documentation
211 Standalone documentation
212 ------------------------
212 ------------------------
213
213
214 All standalone documentation should be written in plain text (``.txt``) files
214 All standalone documentation should be written in plain text (``.txt``) files
215 using reStructuredText [reStructuredText]_ for markup and formatting. All such
215 using reStructuredText [reStructuredText]_ for markup and formatting. All such
216 documentation should be placed in directory :file:`docs/source` of the IPython
216 documentation should be placed in directory :file:`docs/source` of the IPython
217 source tree. The documentation in this location will serve as the main source
217 source tree. The documentation in this location will serve as the main source
218 for IPython documentation and all existing documentation should be converted
218 for IPython documentation and all existing documentation should be converted
219 to this format.
219 to this format.
220
220
221 To build the final documentation, we use Sphinx [Sphinx]_. Once you have
221 To build the final documentation, we use Sphinx [Sphinx]_. Once you have
222 Sphinx installed, you can build the html docs yourself by doing::
222 Sphinx installed, you can build the html docs yourself by doing::
223
223
224 $ cd ipython-mybranch/docs
224 $ cd ipython-mybranch/docs
225 $ make html
225 $ make html
226
226
227 Docstring format
227 Docstring format
228 ----------------
228 ----------------
229
229
230 Good docstrings are very important. All new code should have docstrings that
230 Good docstrings are very important. All new code should have docstrings that
231 are formatted using reStructuredText for markup and formatting, since it is
231 are formatted using reStructuredText for markup and formatting, since it is
232 understood by a wide variety of tools. Details about using reStructuredText
232 understood by a wide variety of tools. Details about using reStructuredText
233 for docstrings can be found `here
233 for docstrings can be found `here
234 <http://epydoc.sourceforge.net/manual-othermarkup.html>`_.
234 <http://epydoc.sourceforge.net/manual-othermarkup.html>`_.
235
235
236 Additional PEPs of interest regarding documentation of code:
236 Additional PEPs of interest regarding documentation of code:
237
237
238 * `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_
238 * `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_
239 * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
239 * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
240 * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
240 * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
241
241
242
242
243 Coding conventions
243 Coding conventions
244 ==================
244 ==================
245
245
246 General
246 General
247 -------
247 -------
248
248
249 In general, we'll try to follow the standard Python style conventions as
249 In general, we'll try to follow the standard Python style conventions as
250 described here:
250 described here:
251
251
252 * `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_
252 * `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_
253
253
254
254
255 Other comments:
255 Other comments:
256
256
257 * In a large file, top level classes and functions should be
257 * In a large file, top level classes and functions should be
258 separated by 2-3 lines to make it easier to separate them visually.
258 separated by 2-3 lines to make it easier to separate them visually.
259 * Use 4 spaces for indentation.
259 * Use 4 spaces for indentation.
260 * Keep the ordering of methods the same in classes that have the same
260 * Keep the ordering of methods the same in classes that have the same
261 methods. This is particularly true for classes that implement an interface.
261 methods. This is particularly true for classes that implement an interface.
262
262
263 Naming conventions
263 Naming conventions
264 ------------------
264 ------------------
265
265
266 In terms of naming conventions, we'll follow the guidelines from the `Style
266 In terms of naming conventions, we'll follow the guidelines from the `Style
267 Guide for Python Code`_.
267 Guide for Python Code`_.
268
268
269 For all new IPython code (and much existing code is being refactored), we'll
269 For all new IPython code (and much existing code is being refactored), we'll
270 use:
270 use:
271
271
272 * All ``lowercase`` module names.
272 * All ``lowercase`` module names.
273
273
274 * ``CamelCase`` for class names.
274 * ``CamelCase`` for class names.
275
275
276 * ``lowercase_with_underscores`` for methods, functions, variables and
276 * ``lowercase_with_underscores`` for methods, functions, variables and
277 attributes.
277 attributes.
278
278
279 There are, however, some important exceptions to these rules. In some cases,
279 There are, however, some important exceptions to these rules. In some cases,
280 IPython code will interface with packages (Twisted, Wx, Qt) that use other
280 IPython code will interface with packages (Twisted, Wx, Qt) that use other
281 conventions. At some level this makes it impossible to adhere to our own
281 conventions. At some level this makes it impossible to adhere to our own
282 standards at all times. In particular, when subclassing classes that use other
282 standards at all times. In particular, when subclassing classes that use other
283 naming conventions, you must follow their naming conventions. To deal with
283 naming conventions, you must follow their naming conventions. To deal with
284 cases like this, we propose the following policy:
284 cases like this, we propose the following policy:
285
285
286 * If you are subclassing a class that uses different conventions, use its
286 * If you are subclassing a class that uses different conventions, use its
287 naming conventions throughout your subclass. Thus, if you are creating a
287 naming conventions throughout your subclass. Thus, if you are creating a
288 Twisted Protocol class, used Twisted's
288 Twisted Protocol class, used Twisted's
289 ``namingSchemeForMethodsAndAttributes.``
289 ``namingSchemeForMethodsAndAttributes.``
290
290
291 * All IPython's official interfaces should use our conventions. In some cases
291 * All IPython's official interfaces should use our conventions. In some cases
292 this will mean that you need to provide shadow names (first implement
292 this will mean that you need to provide shadow names (first implement
293 ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all
293 ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all
294 costs, but it will probably be necessary at times. But, please use this
294 costs, but it will probably be necessary at times. But, please use this
295 sparingly!
295 sparingly!
296
296
297 Implementation-specific *private* methods will use
297 Implementation-specific *private* methods will use
298 ``_single_underscore_prefix``. Names with a leading double underscore will
298 ``_single_underscore_prefix``. Names with a leading double underscore will
299 *only* be used in special cases, as they makes subclassing difficult (such
299 *only* be used in special cases, as they makes subclassing difficult (such
300 names are not easily seen by child classes).
300 names are not easily seen by child classes).
301
301
302 Occasionally some run-in lowercase names are used, but mostly for very short
302 Occasionally some run-in lowercase names are used, but mostly for very short
303 names or where we are implementing methods very similar to existing ones in a
303 names or where we are implementing methods very similar to existing ones in a
304 base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had
304 base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had
305 established precedent).
305 established precedent).
306
306
307 The old IPython codebase has a big mix of classes and modules prefixed with an
307 The old IPython codebase has a big mix of classes and modules prefixed with an
308 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned
308 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned
309 upon, as namespaces offer cleaner prefixing. The only case where this approach
309 upon, as namespaces offer cleaner prefixing. The only case where this approach
310 is justified is for classes which are expected to be imported into external
310 is justified is for classes which are expected to be imported into external
311 namespaces and a very generic name (like Shell) is too likely to clash with
311 namespaces and a very generic name (like Shell) is too likely to clash with
312 something else. We'll need to revisit this issue as we clean up and refactor
312 something else. We'll need to revisit this issue as we clean up and refactor
313 the code, but in general we should remove as many unnecessary ``IP``/``ip``
313 the code, but in general we should remove as many unnecessary ``IP``/``ip``
314 prefixes as possible. However, if a prefix seems absolutely necessary the more
314 prefixes as possible. However, if a prefix seems absolutely necessary the more
315 specific ``IPY`` or ``ipy`` are preferred.
315 specific ``IPY`` or ``ipy`` are preferred.
316
316
317 .. _devel_testing:
317 .. _devel_testing:
318
318
319 Testing system
319 Testing system
320 ==============
320 ==============
321
321
322 It is extremely important that all code contributed to IPython has tests.
322 It is extremely important that all code contributed to IPython has tests.
323 Tests should be written as unittests, doctests or as entities that the Nose
323 Tests should be written as unittests, doctests or as entities that the Nose
324 [Nose]_ testing package will find. Regardless of how the tests are written, we
324 [Nose]_ testing package will find. Regardless of how the tests are written, we
325 will use Nose for discovering and running the tests. Nose will be required to
325 will use Nose for discovering and running the tests. Nose will be required to
326 run the IPython test suite, but will not be required to simply use IPython.
326 run the IPython test suite, but will not be required to simply use IPython.
327
327
328 Tests of Twisted using code need to follow two additional guidelines:
328 Tests of Twisted using code need to follow two additional guidelines:
329
329
330 1. Twisted using tests should be written by subclassing the :class:`TestCase`
330 1. Twisted using tests should be written by subclassing the :class:`TestCase`
331 class that comes with :mod:`twisted.trial.unittest`.
331 class that comes with :mod:`twisted.trial.unittest`.
332
332
333 2. All :class:`Deferred` instances that are created in the test must be
333 2. All :class:`Deferred` instances that are created in the test must be
334 properly chained and the final one *must* be the return value of the test
334 properly chained and the final one *must* be the return value of the test
335 method.
335 method.
336
336
337 When these two things are done, Nose will be able to run the tests and the
337 When these two things are done, Nose will be able to run the tests and the
338 twisted reactor will be handled correctly.
338 twisted reactor will be handled correctly.
339
339
340 Each subpackage in IPython should have its own :file:`tests` directory that
340 Each subpackage in IPython should have its own :file:`tests` directory that
341 contains all of the tests for that subpackage. This allows each subpackage to
341 contains all of the tests for that subpackage. This allows each subpackage to
342 be self-contained. A good convention to follow is to have a file named
342 be self-contained. A good convention to follow is to have a file named
343 :file:`test_foo.py` for each module :file:`foo.py` in the package. This makes
343 :file:`test_foo.py` for each module :file:`foo.py` in the package. This makes
344 it easy to organize the tests, though like most conventions, it's OK to break
344 it easy to organize the tests, though like most conventions, it's OK to break
345 it if logic and common sense dictate otherwise.
345 it if logic and common sense dictate otherwise.
346
346
347 If a subpackage has any dependencies beyond the Python standard library, the
347 If a subpackage has any dependencies beyond the Python standard library, the
348 tests for that subpackage should be skipped if the dependencies are not
348 tests for that subpackage should be skipped if the dependencies are not
349 found. This is very important so users don't get tests failing simply because
349 found. This is very important so users don't get tests failing simply because
350 they don't have dependencies. We ship a set of decorators in the
350 they don't have dependencies. We ship a set of decorators in the
351 :mod:`IPython.testing` package to tag tests that may be platform-specific or
351 :mod:`IPython.testing` package to tag tests that may be platform-specific or
352 otherwise may have restrictions; if the existing ones don't fit your needs, add
352 otherwise may have restrictions; if the existing ones don't fit your needs, add
353 a new decorator in that location so other tests can reuse it.
353 a new decorator in that location so other tests can reuse it.
354
354
355 To run the IPython test suite, use the :command:`iptest` command that is
355 To run the IPython test suite, use the :command:`iptest` command that is
356 installed with IPython (if you are using IPython in-place, without installing
356 installed with IPython (if you are using IPython in-place, without installing
357 it, you can find this script in the :file:`scripts` directory)::
357 it, you can find this script in the :file:`scripts` directory)::
358
358
359 $ iptest
359 $ iptest
360
360
361 This command colects all IPython tests into separate groups, and then calls
361 This command colects all IPython tests into separate groups, and then calls
362 either Nose with the proper options and extensions, or Twisted's
362 either Nose with the proper options and extensions, or Twisted's
363 :command:`trial`. This ensures that tests that need the Twisted reactor
363 :command:`trial`. This ensures that tests that need the Twisted reactor
364 management facilities execute separate of Nose. If any individual test group
364 management facilities execute separate of Nose. If any individual test group
365 fails, :command:`iptest` will print what you need to type so you can rerun that
365 fails, :command:`iptest` will print what you need to type so you can rerun that
366 particular test group alone for debugging.
366 particular test group alone for debugging.
367
367
368 By default, :command:`iptest` runs the entire IPython test
368 By default, :command:`iptest` runs the entire IPython test
369 suite (skipping tests that may be platform-specific or which depend on tools
369 suite (skipping tests that may be platform-specific or which depend on tools
370 you may not have). But you can also use it to run only one specific test file,
370 you may not have). But you can also use it to run only one specific test file,
371 or a specific test function. For example, this will run only the
371 or a specific test function. For example, this will run only the
372 :file:`test_magic` file from the test suite::
372 :file:`test_magic` file from the test suite::
373
373
374 $ iptest IPython.tests.test_magic
374 $ iptest IPython.tests.test_magic
375 ----------------------------------------------------------------------
375 ----------------------------------------------------------------------
376 Ran 10 tests in 0.348s
376 Ran 10 tests in 0.348s
377
377
378 OK (SKIP=3)
378 OK (SKIP=3)
379 Deleting object: second_pass
379 Deleting object: second_pass
380
380
381 while the ``path:function`` syntax allows you to select a specific function in
381 while the ``path:function`` syntax allows you to select a specific function in
382 that file to run::
382 that file to run::
383
383
384 $ iptest IPython.tests.test_magic:test_obj_del
384 $ iptest IPython.tests.test_magic:test_obj_del
385 ----------------------------------------------------------------------
385 ----------------------------------------------------------------------
386 Ran 1 test in 0.204s
386 Ran 1 test in 0.204s
387
387
388 OK
388 OK
389
389
390 Since :command:`iptest` is based on nosetests, you can pass it any regular
390 Since :command:`iptest` is based on nosetests, you can pass it any regular
391 nosetests option. For example, you can use ``--pdb`` or ``--pdb-failures`` to
391 nosetests option. For example, you can use ``--pdb`` or ``--pdb-failures`` to
392 automatically activate the interactive Pdb debugger on errors or failures. See
392 automatically activate the interactive Pdb debugger on errors or failures. See
393 the nosetests documentation for further details.
393 the nosetests documentation for further details.
394
394
395
395
396 A few tips for writing tests
396 A few tips for writing tests
397 ----------------------------
397 ----------------------------
398
398
399 You can write tests either as normal test files, using all the conventions that
399 You can write tests either as normal test files, using all the conventions that
400 Nose recognizes, or as doctests. Note that *all* IPython functions should have
400 Nose recognizes, or as doctests. Note that *all* IPython functions should have
401 at least one example that serves as a doctest, whenever technically feasible.
401 at least one example that serves as a doctest, whenever technically feasible.
402 However, example doctests should only be in the main docstring if they are *a
402 However, example doctests should only be in the main docstring if they are *a
403 good example*, i.e. if they convey useful information about the function. If
403 good example*, i.e. if they convey useful information about the function. If
404 you simply would like to write a test as a doctest, put it in a separate test
404 you simply would like to write a test as a doctest, put it in a separate test
405 file and write a no-op function whose only purpose is its docstring.
405 file and write a no-op function whose only purpose is its docstring.
406
406
407 Note, however, that in a file named :file:`test_X`, functions whose only test
407 Note, however, that in a file named :file:`test_X`, functions whose only test
408 is their docstring (as a doctest) and which have no test functionality of their
408 is their docstring (as a doctest) and which have no test functionality of their
409 own, should be called *doctest_foo* instead of *test_foo*, otherwise they get
409 own, should be called *doctest_foo* instead of *test_foo*, otherwise they get
410 double-counted (the empty function call is counted as a test, which just
410 double-counted (the empty function call is counted as a test, which just
411 inflates tests numbers artificially). This restriction does not apply to
411 inflates tests numbers artificially). This restriction does not apply to
412 functions in files with other names, due to how Nose discovers tests.
412 functions in files with other names, due to how Nose discovers tests.
413
413
414 You can use IPython examples in your docstrings. Those can make full use of
414 You can use IPython examples in your docstrings. Those can make full use of
415 IPython functionality (magics, variable substitution, etc), but be careful to
415 IPython functionality (magics, variable substitution, etc), but be careful to
416 keep them generic enough that they run identically on all Operating Systems.
416 keep them generic enough that they run identically on all Operating Systems.
417
417
418 The prompts in your doctests can be either of the plain Python ``>>>`` variety
418 The prompts in your doctests can be either of the plain Python ``>>>`` variety
419 or ``In [1]:`` IPython style. Since this is the IPython system, after all, we
419 or ``In [1]:`` IPython style. Since this is the IPython system, after all, we
420 encourage you to use IPython prompts throughout, unless you are illustrating a
420 encourage you to use IPython prompts throughout, unless you are illustrating a
421 specific aspect of the normal prompts (such as the ``%doctest_mode`` magic).
421 specific aspect of the normal prompts (such as the ``%doctest_mode`` magic).
422
422
423 If a test isn't safe to run inside the main nose process (e.g. because it loads
423 If a test isn't safe to run inside the main nose process (e.g. because it loads
424 a GUI toolkit), consider running it in a subprocess and capturing its output
424 a GUI toolkit), consider running it in a subprocess and capturing its output
425 for evaluation and test decision later. Here is an example of how to do it, by
425 for evaluation and test decision later. Here is an example of how to do it, by
426 relying on the builtin ``_ip`` object that contains the public IPython api as
426 relying on the builtin ``_ip`` object that contains the public IPython api as
427 defined in :mod:`IPython.ipapi`::
427 defined in :mod:`IPython.ipapi`::
428
428
429 def test_obj_del():
429 def test_obj_del():
430 """Test that object's __del__ methods are called on exit."""
430 """Test that object's __del__ methods are called on exit."""
431 test_dir = os.path.dirname(__file__)
431 test_dir = os.path.dirname(__file__)
432 del_file = os.path.join(test_dir,'obj_del.py')
432 del_file = os.path.join(test_dir,'obj_del.py')
433 out = _ip.IP.getoutput('ipython %s' % del_file)
433 out = _ip.IP.getoutput('ipython %s' % del_file)
434 nt.assert_equals(out,'object A deleted')
434 nt.assert_equals(out,'object A deleted')
435
435
436
436
437
437
438 If a doctest contains input whose output you don't want to verify identically
438 If a doctest contains input whose output you don't want to verify identically
439 via doctest (random output, an object id, etc), you can mark a docstring with
439 via doctest (random output, an object id, etc), you can mark a docstring with
440 ``#random``. All of these test will have their code executed but no output
440 ``#random``. All of these test will have their code executed but no output
441 checking will be done::
441 checking will be done::
442
442
443 >>> 1+3
443 >>> 1+3
444 junk goes here... # random
444 junk goes here... # random
445
445
446 >>> 1+2
446 >>> 1+2
447 again, anything goes #random
447 again, anything goes #random
448 if multiline, the random mark is only needed once.
448 if multiline, the random mark is only needed once.
449
449
450 >>> 1+2
450 >>> 1+2
451 You can also put the random marker at the end:
451 You can also put the random marker at the end:
452 # random
452 # random
453
453
454 >>> 1+2
454 >>> 1+2
455 # random
455 # random
456 .. or at the beginning.
456 .. or at the beginning.
457
457
458 In a case where you want an *entire* docstring to be executed but not verified
458 In a case where you want an *entire* docstring to be executed but not verified
459 (this only serves to check that the code runs without crashing, so it should be
459 (this only serves to check that the code runs without crashing, so it should be
460 used very sparingly), you can put ``# all-random`` in the docstring.
460 used very sparingly), you can put ``# all-random`` in the docstring.
461
461
462 .. _devel_config:
462 .. _devel_config:
463
463
464 Release checklist
464 Release checklist
465 =================
465 =================
466
466
467 Most of the release process is automated by the :file:`release` script in the
467 Most of the release process is automated by the :file:`release` script in the
468 :file:`tools` directory. This is just a handy reminder for the release manager.
468 :file:`tools` directory. This is just a handy reminder for the release manager.
469
469
470 #. First, run :file:`build_release`, which does all the file checking and
470 #. First, run :file:`build_release`, which does all the file checking and
471 building that the real release script will do. This will let you do test
471 building that the real release script will do. This will let you do test
472 installations, check that the build procedure runs OK, etc. You may want to
472 installations, check that the build procedure runs OK, etc. You may want to
473 disable a few things like multi-version RPM building while testing, because
473 disable a few things like multi-version RPM building while testing, because
474 otherwise the build takes really long.
474 otherwise the build takes really long.
475
475
476 #. Run the release script, which makes the tar.gz, eggs and Win32 .exe
476 #. Run the release script, which makes the tar.gz, eggs and Win32 .exe
477 installer. It posts them to the site and registers the release with PyPI.
477 installer. It posts them to the site and registers the release with PyPI.
478
478
479 #. Updating the website with announcements and links to the updated
479 #. Updating the website with announcements and links to the updated
480 changes.txt in html form. Remember to put a short note both on the news
480 changes.txt in html form. Remember to put a short note both on the news
481 page of the site and on Launcphad.
481 page of the site and on Launcphad.
482
482
483 #. Drafting a short release announcement with i) highlights and ii) a link to
483 #. Drafting a short release announcement with i) highlights and ii) a link to
484 the html changes.txt.
484 the html changes.txt.
485
485
486 #. Make sure that the released version of the docs is live on the site.
486 #. Make sure that the released version of the docs is live on the site.
487
487
488 #. Celebrate!
488 #. Celebrate!
489
489
490 Porting to 3.0
490 Porting to 3.0
491 ==============
491 ==============
492
492
493 There are no definite plans for porting of IPython to python 3. The major
493 There are no definite plans for porting of IPython to python 3. The major
494 issue is the dependency on twisted framework for the networking/threading
494 issue is the dependency on twisted framework for the networking/threading
495 stuff. It is possible that it the traditional IPython interactive console
495 stuff. It is possible that it the traditional IPython interactive console
496 could be ported more easily since it has no such dependency. Here are a few
496 could be ported more easily since it has no such dependency. Here are a few
497 things that will need to be considered when doing such a port especially
497 things that will need to be considered when doing such a port especially
498 if we want to have a codebase that works directly on both 2.x and 3.x.
498 if we want to have a codebase that works directly on both 2.x and 3.x.
499
499
500 1. The syntax for exceptions changed (PEP 3110). The old
500 1. The syntax for exceptions changed (PEP 3110). The old
501 `except exc, var` changed to `except exc as var`. At last
501 `except exc, var` changed to `except exc as var`. At last
502 count there was 78 occurences of this usage in the codebase. This
502 count there was 78 occurences of this usage in the codebase. This
503 is a particularly problematic issue, because it's not easy to
503 is a particularly problematic issue, because it's not easy to
504 implement it in a 2.5-compatible way.
504 implement it in a 2.5-compatible way.
505
505
506 Because it is quite difficult to support simultaneously Python 2.5 and 3.x, we
506 Because it is quite difficult to support simultaneously Python 2.5 and 3.x, we
507 will likely at some point put out a release that requires strictly 2.6 and
507 will likely at some point put out a release that requires strictly 2.6 and
508 abandons 2.5 compatibility. This will then allow us to port the code to using
508 abandons 2.5 compatibility. This will then allow us to port the code to using
509 :func:`print` as a function, `except exc as var` syntax, etc. But as of
509 :func:`print` as a function, `except exc as var` syntax, etc. But as of
510 version 0.11 at least, we will retain Python 2.5 compatibility.
510 version 0.11 at least, we will retain Python 2.5 compatibility.
511
511
512
512
513 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
513 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
514 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
514 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
515 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
515 .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html
516 .. [Sphinx] Sphinx. http://sphinx.pocoo.org/
516 .. [Sphinx] Sphinx. http://sphinx.pocoo.org/
517 .. [Nose] Nose: a discovery based unittest extension. http://code.google.com/p/python-nose/
517 .. [Nose] Nose: a discovery based unittest extension. http://code.google.com/p/python-nose/
518
@@ -1,84 +1,85 b''
1 =============================
1 =============================
2 IPython module reorganization
2 IPython module reorganization
3 =============================
3 =============================
4
4
5 Currently, IPython has many top-level modules that serve many different
5 Currently, IPython has many top-level modules that serve many different
6 purposes. The lack of organization make it very difficult for developers to
6 purposes. The lack of organization make it very difficult for developers to
7 work on IPython and understand its design. This document contains notes about
7 work on IPython and understand its design. This document contains notes about
8 how we will reorganize the modules into sub-packages.
8 how we will reorganize the modules into sub-packages.
9
9
10 .. warning::
10 .. warning::
11
11
12 This effort will possibly break third party packages that use IPython as
12 This effort will possibly break third party packages that use IPython as
13 a library or hack on the IPython internals.
13 a library or hack on the IPython internals.
14
14
15 .. warning::
15 .. warning::
16
16
17 This effort will result in the removal from IPython of certain modules
17 This effort will result in the removal from IPython of certain modules
18 that are not used anymore, don't currently work, are unmaintained, etc.
18 that are not used anymore, don't currently work, are unmaintained, etc.
19
19
20
20
21 Current subpackges
21 Current subpackges
22 ==================
22 ==================
23
23
24 IPython currently has the following sub-packages:
24 IPython currently has the following sub-packages:
25
25
26 * :mod:`IPython.config`
26 * :mod:`IPython.config`
27
27
28 * :mod:`IPython.Extensions`
28 * :mod:`IPython.Extensions`
29
29
30 * :mod:`IPython.external`
30 * :mod:`IPython.external`
31
31
32 * :mod:`IPython.frontend`
32 * :mod:`IPython.frontend`
33
33
34 * :mod:`IPython.gui`
34 * :mod:`IPython.gui`
35
35
36 * :mod:`IPython.kernel`
36 * :mod:`IPython.kernel`
37
37
38 * :mod:`IPython.testing`
38 * :mod:`IPython.testing`
39
39
40 * :mod:`IPython.tests`
40 * :mod:`IPython.tests`
41
41
42 * :mod:`IPython.tools`
42 * :mod:`IPython.tools`
43
43
44 * :mod:`IPython.UserConfig`
44 * :mod:`IPython.UserConfig`
45
45
46 New Subpackages to be created
46 New Subpackages to be created
47 =============================
47 =============================
48
48
49 We propose to create the following new sub-packages:
49 We propose to create the following new sub-packages:
50
50
51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
52 interpreter, but none of its extended capabilities.
52 interpreter, but none of its extended capabilities.
53
53
54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
55 of the IPython core. These things will go here.
55 of the IPython core. These things will go here.
56
56
57 * :mod:`IPython.utils`. This sub-package will contain anything that might
57 * :mod:`IPython.utils`. This sub-package will contain anything that might
58 eventually be found in the Python standard library, like things in
58 eventually be found in the Python standard library, like things in
59 :mod:`genutils`. Each sub-module in this sub-package should contain
59 :mod:`genutils`. Each sub-module in this sub-package should contain
60 functions and classes that serve a single purpose.
60 functions and classes that serve a single purpose.
61
61
62 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
62 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
63 and needs to be removed from IPython. Eventually all this code will either
63 and needs to be removed from IPython. Eventually all this code will either
64 i) be revived by someone willing to maintain it with tests and docs and
64 i) be revived by someone willing to maintain it with tests and docs and
65 re-included into IPython or 2) be removed from IPython proper, but put into
65 re-included into IPython or 2) be removed from IPython proper, but put into
66 a separate top-level (not IPython) package that we keep around. No new code
66 a separate top-level (not IPython) package that we keep around. No new code
67 will be allowed here.
67 will be allowed here.
68
68
69 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
69 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
70 standards, but that we plan on keeping. To be moved out of this sub-package
70 standards, but that we plan on keeping. To be moved out of this sub-package
71 a module needs to have a maintainer, tests and documentation.
71 a module needs to have a maintainer, tests and documentation.
72
72
73 Procedure
73 Procedure
74 =========
74 =========
75
75
76 1. Move the file to its new location with its new name.
76 1. Move the file to its new location with its new name.
77 2. Rename all import statements to reflect the change.
77 2. Rename all import statements to reflect the change.
78 3. Run PyFlakes on each changes module.
78 3. Run PyFlakes on each changes module.
79 4. Add tests/test_imports.py to test it.
79 4. Add tests/test_imports.py to test it.
80
80
81 Status
81 Status
82 ======
82 ======
83
83
84 This branch was merged into trunk in early August of 2009.
84 This branch was merged into trunk in early August of 2009.
85
@@ -1,96 +1,94 b''
1 .. _roadmap:
1 .. _roadmap:
2
2
3 ===================
3 ===================
4 Development roadmap
4 Development roadmap
5 ===================
5 ===================
6
6
7 IPython is an ambitious project that is still under heavy development.
7 IPython is an ambitious project that is still under heavy development.
8 However, we want IPython to become useful to as many people as possible, as
8 However, we want IPython to become useful to as many people as possible, as
9 quickly as possible. To help us accomplish this, we are laying out a roadmap
9 quickly as possible. To help us accomplish this, we are laying out a roadmap
10 of where we are headed and what needs to happen to get there. Hopefully, this
10 of where we are headed and what needs to happen to get there. Hopefully, this
11 will help the IPython developers figure out the best things to work on for
11 will help the IPython developers figure out the best things to work on for
12 each upcoming release.
12 each upcoming release.
13
13
14 Work targeted to particular releases
14 Work targeted to particular releases
15 ====================================
15 ====================================
16
16
17 Release 0.11
17 Release 0.11
18 ------------
18 ------------
19
19
20 * Full module and package reorganization (done).
20 * Full module and package reorganization (done).
21
21
22 * Removal of the threaded shells and new implementation of GUI support
22 * Removal of the threaded shells and new implementation of GUI support
23 based on ``PyOSInputHook`` (done).
23 based on ``PyOSInputHook`` (done).
24
24
25 * Refactor the configuration system (done).
25 * Refactor the configuration system (done).
26
26
27 * Prepare to refactor IPython's core by creating a new component and
27 * Prepare to refactor IPython's core by creating a new component and
28 application system (done).
28 application system (done).
29
29
30 * Start to refactor IPython's core by turning everything into components
30 * Start to refactor IPython's core by turning everything into components
31 (started).
31 (started).
32
32
33 Release 0.12
33 Release 0.12
34 ------------
34 ------------
35
35
36 * Continue to refactor IPython's core by turning everything into components.
36 * Continue to refactor IPython's core by turning everything into components.
37
37
38
38
39 Major areas of work
39 Major areas of work
40 ===================
40 ===================
41
41
42 Refactoring the main IPython core
42 Refactoring the main IPython core
43 ---------------------------------
43 ---------------------------------
44
44
45 During the summer of 2009, we began refactoring IPython's core. The main
45 During the summer of 2009, we began refactoring IPython's core. The main
46 thrust in this work was make the IPython core into a set of loosely coupled
46 thrust in this work was make the IPython core into a set of loosely coupled
47 components. The base component class for this is
47 components. The base component class for this is
48 :class:`IPython.core.component.Component`. This section outlines the status
48 :class:`IPython.core.component.Component`. This section outlines the status
49 of this work.
49 of this work.
50
50
51 Parts of the IPython core that have been turned into components:
51 Parts of the IPython core that have been turned into components:
52
52
53 * The main :class:`InteractiveShell` class.
53 * The main :class:`InteractiveShell` class.
54 * The aliases (:mod:`IPython.core.aliases`).
54 * The aliases (:mod:`IPython.core.aliases`).
55 * The display and builtin traps (:mod:`IPython.core.display_trap` and
55 * The display and builtin traps (:mod:`IPython.core.display_trap` and
56 :mod:`IPython.core.builtin_trap`).
56 :mod:`IPython.core.builtin_trap`).
57 * The prefilter machinery (:mod:`IPython.core.prefilter`).
57 * The prefilter machinery (:mod:`IPython.core.prefilter`).
58
58
59 Parts of the IPythoncore that need to be turned into components:
59 Parts of the IPythoncore that need to be turned into components:
60
60
61 * Magics.
61 * Magics.
62 * Input and output history management.
62 * Input and output history management.
63 * Prompts.
63 * Prompts.
64 * Completers.
64 * Completers.
65 * Logging.
65 * Logging.
66 * Exception handling.
66 * Exception handling.
67 * Anything else.
67 * Anything else.
68
68
69 Process management for :mod:`IPython.kernel`
69 Process management for :mod:`IPython.kernel`
70 --------------------------------------------
70 --------------------------------------------
71
71
72 Performance problems
72 Performance problems
73 --------------------
73 --------------------
74
74
75 Currently, we have a number of performance issues in :mod:`IPython.kernel`:
75 Currently, we have a number of performance issues in :mod:`IPython.kernel`:
76
76
77 * The controller stores a large amount of state in Python dictionaries. Under
77 * The controller stores a large amount of state in Python dictionaries. Under
78 heavy usage, these dicts with get very large, causing memory usage problems.
78 heavy usage, these dicts with get very large, causing memory usage problems.
79 We need to develop more scalable solutions to this problem. This will also
79 We need to develop more scalable solutions to this problem. This will also
80 help the controller to be more fault tolerant.
80 help the controller to be more fault tolerant.
81
81
82 * We currently don't have a good way of handling large objects in the
82 * We currently don't have a good way of handling large objects in the
83 controller. The biggest problem is that because we don't have any way of
83 controller. The biggest problem is that because we don't have any way of
84 streaming objects, we get lots of temporary copies in the low-level buffers.
84 streaming objects, we get lots of temporary copies in the low-level buffers.
85 We need to implement a better serialization approach and true streaming
85 We need to implement a better serialization approach and true streaming
86 support.
86 support.
87
87
88 * The controller currently unpickles and repickles objects. We need to use the
88 * The controller currently unpickles and repickles objects. We need to use the
89 [push|pull]_serialized methods instead.
89 [push|pull]_serialized methods instead.
90
90
91 * Currently the controller is a bottleneck. The best approach for this is to
91 * Currently the controller is a bottleneck. The best approach for this is to
92 separate the controller itself into multiple processes, one for the core
92 separate the controller itself into multiple processes, one for the core
93 controller and one each for the controller interfaces.
93 controller and one each for the controller interfaces.
94
94
95
96
@@ -1,105 +1,96 b''
1 .. _faq:
1 .. _faq:
2
2
3 ========================================
3 ========================================
4 Frequently asked questions
4 Frequently asked questions
5 ========================================
5 ========================================
6
6
7 General questions
7 General questions
8 =================
8 =================
9
9
10 Questions about parallel computing with IPython
10 Questions about parallel computing with IPython
11 ================================================
11 ================================================
12
12
13 Will IPython speed my Python code up?
13 Will IPython speed my Python code up?
14 --------------------------------------
14 --------------------------------------
15
15
16 Yes and no. When converting a serial code to run in parallel, there often many
16 Yes and no. When converting a serial code to run in parallel, there often many
17 difficulty questions that need to be answered, such as:
17 difficulty questions that need to be answered, such as:
18
18
19 * How should data be decomposed onto the set of processors?
19 * How should data be decomposed onto the set of processors?
20
20
21 * What are the data movement patterns?
21 * What are the data movement patterns?
22
22
23 * Can the algorithm be structured to minimize data movement?
23 * Can the algorithm be structured to minimize data movement?
24
24
25 * Is dynamic load balancing important?
25 * Is dynamic load balancing important?
26
26
27 We can't answer such questions for you. This is the hard (but fun) work of parallel
27 We can't answer such questions for you. This is the hard (but fun) work of parallel
28 computing. But, once you understand these things IPython will make it easier for you to
28 computing. But, once you understand these things IPython will make it easier for you to
29 implement a good solution quickly. Most importantly, you will be able to use the
29 implement a good solution quickly. Most importantly, you will be able to use the
30 resulting parallel code interactively.
30 resulting parallel code interactively.
31
31
32 With that said, if your problem is trivial to parallelize, IPython has a number of
32 With that said, if your problem is trivial to parallelize, IPython has a number of
33 different interfaces that will enable you to parallelize things is almost no time at
33 different interfaces that will enable you to parallelize things is almost no time at
34 all. A good place to start is the ``map`` method of our :class:`MultiEngineClient`.
34 all. A good place to start is the ``map`` method of our :class:`MultiEngineClient`.
35
35
36 What is the best way to use MPI from Python?
36 What is the best way to use MPI from Python?
37 --------------------------------------------
37 --------------------------------------------
38
38
39 What about all the other parallel computing packages in Python?
39 What about all the other parallel computing packages in Python?
40 ---------------------------------------------------------------
40 ---------------------------------------------------------------
41
41
42 Some of the unique characteristic of IPython are:
42 Some of the unique characteristic of IPython are:
43
43
44 * IPython is the only architecture that abstracts out the notion of a
44 * IPython is the only architecture that abstracts out the notion of a
45 parallel computation in such a way that new models of parallel computing
45 parallel computation in such a way that new models of parallel computing
46 can be explored quickly and easily. If you don't like the models we
46 can be explored quickly and easily. If you don't like the models we
47 provide, you can simply create your own using the capabilities we provide.
47 provide, you can simply create your own using the capabilities we provide.
48
48
49 * IPython is asynchronous from the ground up (we use `Twisted`_).
49 * IPython is asynchronous from the ground up (we use `Twisted`_).
50
50
51 * IPython's architecture is designed to avoid subtle problems
51 * IPython's architecture is designed to avoid subtle problems
52 that emerge because of Python's global interpreter lock (GIL).
52 that emerge because of Python's global interpreter lock (GIL).
53
53
54 * While IPython's architecture is designed to support a wide range
54 * While IPython's architecture is designed to support a wide range
55 of novel parallel computing models, it is fully interoperable with
55 of novel parallel computing models, it is fully interoperable with
56 traditional MPI applications.
56 traditional MPI applications.
57
57
58 * IPython has been used and tested extensively on modern supercomputers.
58 * IPython has been used and tested extensively on modern supercomputers.
59
59
60 * IPython's networking layers are completely modular. Thus, is
60 * IPython's networking layers are completely modular. Thus, is
61 straightforward to replace our existing network protocols with
61 straightforward to replace our existing network protocols with
62 high performance alternatives (ones based upon Myranet/Infiniband).
62 high performance alternatives (ones based upon Myranet/Infiniband).
63
63
64 * IPython is designed from the ground up to support collaborative
64 * IPython is designed from the ground up to support collaborative
65 parallel computing. This enables multiple users to actively develop
65 parallel computing. This enables multiple users to actively develop
66 and run the *same* parallel computation.
66 and run the *same* parallel computation.
67
67
68 * Interactivity is a central goal for us. While IPython does not have
68 * Interactivity is a central goal for us. While IPython does not have
69 to be used interactivly, it can be.
69 to be used interactivly, it can be.
70
70
71 .. _Twisted: http://www.twistedmatrix.com
71 .. _Twisted: http://www.twistedmatrix.com
72
72
73 Why The IPython controller a bottleneck in my parallel calculation?
73 Why The IPython controller a bottleneck in my parallel calculation?
74 -------------------------------------------------------------------
74 -------------------------------------------------------------------
75
75
76 A golden rule in parallel computing is that you should only move data around if you
76 A golden rule in parallel computing is that you should only move data around if you
77 absolutely need to. The main reason that the controller becomes a bottleneck is that
77 absolutely need to. The main reason that the controller becomes a bottleneck is that
78 too much data is being pushed and pulled to and from the engines. If your algorithm
78 too much data is being pushed and pulled to and from the engines. If your algorithm
79 is structured in this way, you really should think about alternative ways of
79 is structured in this way, you really should think about alternative ways of
80 handling the data movement. Here are some ideas:
80 handling the data movement. Here are some ideas:
81
81
82 1. Have the engines write data to files on the locals disks of the engines.
82 1. Have the engines write data to files on the locals disks of the engines.
83
83
84 2. Have the engines write data to files on a file system that is shared by
84 2. Have the engines write data to files on a file system that is shared by
85 the engines.
85 the engines.
86
86
87 3. Have the engines write data to a database that is shared by the engines.
87 3. Have the engines write data to a database that is shared by the engines.
88
88
89 4. Simply keep data in the persistent memory of the engines and move the
89 4. Simply keep data in the persistent memory of the engines and move the
90 computation to the data (rather than the data to the computation).
90 computation to the data (rather than the data to the computation).
91
91
92 5. See if you can pass data directly between engines using MPI.
92 5. See if you can pass data directly between engines using MPI.
93
93
94 Isn't Python slow to be used for high-performance parallel computing?
94 Isn't Python slow to be used for high-performance parallel computing?
95 ---------------------------------------------------------------------
95 ---------------------------------------------------------------------
96
96
97
98
99
100
101
102
103
104
105
@@ -1,31 +1,34 b''
1 =====================
1 =====================
2 IPython Documentation
2 IPython Documentation
3 =====================
3 =====================
4
4
5 .. htmlonly::
5 .. htmlonly::
6
6
7 :Release: |release|
7 :Release: |release|
8 :Date: |today|
8 :Date: |today|
9
9
10 Contents:
10 Welcome to the official IPython documentation. This document describes the
11 various parts of IPython that are relevant to both users and developers.
12
13 Contents
14 ========
11
15
12 .. toctree::
16 .. toctree::
13 :maxdepth: 2
17 :maxdepth: 1
14
18
15 overview.txt
19 overview.txt
20 whatsnew/index.txt
16 install/index.txt
21 install/index.txt
17 interactive/index.txt
22 interactive/index.txt
18 parallel/index.txt
23 parallel/index.txt
19 config/index.txt
24 config/index.txt
20 faq.txt
21 history.txt
22 changes.txt
23 development/index.txt
25 development/index.txt
24 api/index.txt
26 api/index.txt
25 license_and_copyright.txt
27 faq.txt
26 credits.txt
28 about/index.txt
27
29
28 .. htmlonly::
30 .. htmlonly::
29 * :ref:`genindex`
31 * :ref:`genindex`
30 * :ref:`modindex`
32 * :ref:`modindex`
31 * :ref:`search`
33 * :ref:`search`
34
@@ -1,10 +1,11 b''
1 .. _install_index:
1 .. _install_index:
2
2
3 ============
3 ============
4 Installation
4 Installation
5 ============
5 ============
6
6
7 .. toctree::
7 .. toctree::
8 :maxdepth: 2
8 :maxdepth: 2
9
9
10 install.txt
10 install.txt
11
@@ -1,293 +1,294 b''
1 Overview
1 Overview
2 ========
2 ========
3
3
4 This document describes the steps required to install IPython. IPython is
4 This document describes the steps required to install IPython. IPython is
5 organized into a number of subpackages, each of which has its own dependencies.
5 organized into a number of subpackages, each of which has its own dependencies.
6 All of the subpackages come with IPython, so you don't need to download and
6 All of the subpackages come with IPython, so you don't need to download and
7 install them separately. However, to use a given subpackage, you will need to
7 install them separately. However, to use a given subpackage, you will need to
8 install all of its dependencies.
8 install all of its dependencies.
9
9
10
10
11 Please let us know if you have problems installing IPython or any of its
11 Please let us know if you have problems installing IPython or any of its
12 dependencies. Officially, IPython requires Python version 2.5 or 2.6. We
12 dependencies. Officially, IPython requires Python version 2.5 or 2.6. We
13 have *not* yet started to port IPython to Python 3.0.
13 have *not* yet started to port IPython to Python 3.0.
14
14
15 .. warning::
15 .. warning::
16
16
17 Officially, IPython supports Python versions 2.5 and 2.6.
17 Officially, IPython supports Python versions 2.5 and 2.6.
18
18
19 IPython 0.10 has only been well tested with Python 2.5 and 2.6. Parts of
19 IPython 0.10 has only been well tested with Python 2.5 and 2.6. Parts of
20 it may work with Python 2.4, but we do not officially support Python 2.4
20 it may work with Python 2.4, but we do not officially support Python 2.4
21 anymore. If you need to use 2.4, you can still run IPython 0.9.
21 anymore. If you need to use 2.4, you can still run IPython 0.9.
22
22
23 Some of the installation approaches use the :mod:`setuptools` package and its
23 Some of the installation approaches use the :mod:`setuptools` package and its
24 :command:`easy_install` command line program. In many scenarios, this provides
24 :command:`easy_install` command line program. In many scenarios, this provides
25 the most simple method of installing IPython and its dependencies. It is not
25 the most simple method of installing IPython and its dependencies. It is not
26 required though. More information about :mod:`setuptools` can be found on its
26 required though. More information about :mod:`setuptools` can be found on its
27 website.
27 website.
28
28
29 More general information about installing Python packages can be found in
29 More general information about installing Python packages can be found in
30 Python's documentation at http://www.python.org/doc/.
30 Python's documentation at http://www.python.org/doc/.
31
31
32 Quickstart
32 Quickstart
33 ==========
33 ==========
34
34
35 If you have :mod:`setuptools` installed and you are on OS X or Linux (not
35 If you have :mod:`setuptools` installed and you are on OS X or Linux (not
36 Windows), the following will download and install IPython *and* the main
36 Windows), the following will download and install IPython *and* the main
37 optional dependencies::
37 optional dependencies::
38
38
39 $ easy_install ipython[kernel,security,test]
39 $ easy_install ipython[kernel,security,test]
40
40
41 This will get Twisted, zope.interface and Foolscap, which are needed for
41 This will get Twisted, zope.interface and Foolscap, which are needed for
42 IPython's parallel computing features as well as the nose package, which will
42 IPython's parallel computing features as well as the nose package, which will
43 enable you to run IPython's test suite. To run IPython's test suite, use the
43 enable you to run IPython's test suite. To run IPython's test suite, use the
44 :command:`iptest` command::
44 :command:`iptest` command::
45
45
46 $ iptest
46 $ iptest
47
47
48 Read on for more specific details and instructions for Windows.
48 Read on for more specific details and instructions for Windows.
49
49
50 Installing IPython itself
50 Installing IPython itself
51 =========================
51 =========================
52
52
53 Given a properly built Python, the basic interactive IPython shell will work
53 Given a properly built Python, the basic interactive IPython shell will work
54 with no external dependencies. However, some Python distributions
54 with no external dependencies. However, some Python distributions
55 (particularly on Windows and OS X), don't come with a working :mod:`readline`
55 (particularly on Windows and OS X), don't come with a working :mod:`readline`
56 module. The IPython shell will work without :mod:`readline`, but will lack
56 module. The IPython shell will work without :mod:`readline`, but will lack
57 many features that users depend on, such as tab completion and command line
57 many features that users depend on, such as tab completion and command line
58 editing. See below for details of how to make sure you have a working
58 editing. See below for details of how to make sure you have a working
59 :mod:`readline`.
59 :mod:`readline`.
60
60
61 Installation using easy_install
61 Installation using easy_install
62 -------------------------------
62 -------------------------------
63
63
64 If you have :mod:`setuptools` installed, the easiest way of getting IPython is
64 If you have :mod:`setuptools` installed, the easiest way of getting IPython is
65 to simple use :command:`easy_install`::
65 to simple use :command:`easy_install`::
66
66
67 $ easy_install ipython
67 $ easy_install ipython
68
68
69 That's it.
69 That's it.
70
70
71 Installation from source
71 Installation from source
72 ------------------------
72 ------------------------
73
73
74 If you don't want to use :command:`easy_install`, or don't have it installed,
74 If you don't want to use :command:`easy_install`, or don't have it installed,
75 just grab the latest stable build of IPython from `here
75 just grab the latest stable build of IPython from `here
76 <http://ipython.scipy.org/dist/>`_. Then do the following::
76 <http://ipython.scipy.org/dist/>`_. Then do the following::
77
77
78 $ tar -xzf ipython.tar.gz
78 $ tar -xzf ipython.tar.gz
79 $ cd ipython
79 $ cd ipython
80 $ python setup.py install
80 $ python setup.py install
81
81
82 If you are installing to a location (like ``/usr/local``) that requires higher
82 If you are installing to a location (like ``/usr/local``) that requires higher
83 permissions, you may need to run the last command with :command:`sudo`.
83 permissions, you may need to run the last command with :command:`sudo`.
84
84
85 Windows
85 Windows
86 -------
86 -------
87
87
88 There are a few caveats for Windows users. The main issue is that a basic
88 There are a few caveats for Windows users. The main issue is that a basic
89 ``python setup.py install`` approach won't create ``.bat`` file or Start Menu
89 ``python setup.py install`` approach won't create ``.bat`` file or Start Menu
90 shortcuts, which most users want. To get an installation with these, you can
90 shortcuts, which most users want. To get an installation with these, you can
91 use any of the following alternatives:
91 use any of the following alternatives:
92
92
93 1. Install using :command:`easy_install`.
93 1. Install using :command:`easy_install`.
94
94
95 2. Install using our binary ``.exe`` Windows installer, which can be found at
95 2. Install using our binary ``.exe`` Windows installer, which can be found at
96 `here <http://ipython.scipy.org/dist/>`_
96 `here <http://ipython.scipy.org/dist/>`_
97
97
98 3. Install from source, but using :mod:`setuptools` (``python setupegg.py
98 3. Install from source, but using :mod:`setuptools` (``python setupegg.py
99 install``).
99 install``).
100
100
101 IPython by default runs in a termninal window, but the normal terminal
101 IPython by default runs in a termninal window, but the normal terminal
102 application supplied by Microsoft Windows is very primitive. You may want to
102 application supplied by Microsoft Windows is very primitive. You may want to
103 download the excellent and free Console_ application instead, which is a far
103 download the excellent and free Console_ application instead, which is a far
104 superior tool. You can even configure Console to give you by default an
104 superior tool. You can even configure Console to give you by default an
105 IPython tab, which is very convenient to create new IPython sessions directly
105 IPython tab, which is very convenient to create new IPython sessions directly
106 from the working terminal.
106 from the working terminal.
107
107
108 .. _Console: http://sourceforge.net/projects/console
108 .. _Console: http://sourceforge.net/projects/console
109
109
110
110
111 Installing the development version
111 Installing the development version
112 ----------------------------------
112 ----------------------------------
113
113
114 It is also possible to install the development version of IPython from our
114 It is also possible to install the development version of IPython from our
115 `Bazaar <http://bazaar-vcs.org/>`_ source code repository. To do this you will
115 `Bazaar <http://bazaar-vcs.org/>`_ source code repository. To do this you will
116 need to have Bazaar installed on your system. Then just do::
116 need to have Bazaar installed on your system. Then just do::
117
117
118 $ bzr branch lp:ipython
118 $ bzr branch lp:ipython
119 $ cd ipython
119 $ cd ipython
120 $ python setup.py install
120 $ python setup.py install
121
121
122 Again, this last step on Windows won't create ``.bat`` files or Start Menu
122 Again, this last step on Windows won't create ``.bat`` files or Start Menu
123 shortcuts, so you will have to use one of the other approaches listed above.
123 shortcuts, so you will have to use one of the other approaches listed above.
124
124
125 Some users want to be able to follow the development branch as it changes. If
125 Some users want to be able to follow the development branch as it changes. If
126 you have :mod:`setuptools` installed, this is easy. Simply replace the last
126 you have :mod:`setuptools` installed, this is easy. Simply replace the last
127 step by::
127 step by::
128
128
129 $ python setupegg.py develop
129 $ python setupegg.py develop
130
130
131 This creates links in the right places and installs the command line script to
131 This creates links in the right places and installs the command line script to
132 the appropriate places. Then, if you want to update your IPython at any time,
132 the appropriate places. Then, if you want to update your IPython at any time,
133 just do::
133 just do::
134
134
135 $ bzr pull
135 $ bzr pull
136
136
137 Basic optional dependencies
137 Basic optional dependencies
138 ===========================
138 ===========================
139
139
140 There are a number of basic optional dependencies that most users will want to
140 There are a number of basic optional dependencies that most users will want to
141 get. These are:
141 get. These are:
142
142
143 * readline (for command line editing, tab completion, etc.)
143 * readline (for command line editing, tab completion, etc.)
144 * nose (to run the IPython test suite)
144 * nose (to run the IPython test suite)
145 * pexpect (to use things like irunner)
145 * pexpect (to use things like irunner)
146
146
147 If you are comfortable installing these things yourself, have at it, otherwise
147 If you are comfortable installing these things yourself, have at it, otherwise
148 read on for more details.
148 read on for more details.
149
149
150 readline
150 readline
151 --------
151 --------
152
152
153 In principle, all Python distributions should come with a working
153 In principle, all Python distributions should come with a working
154 :mod:`readline` module. But, reality is not quite that simple. There are two
154 :mod:`readline` module. But, reality is not quite that simple. There are two
155 common situations where you won't have a working :mod:`readline` module:
155 common situations where you won't have a working :mod:`readline` module:
156
156
157 * If you are using the built-in Python on Mac OS X.
157 * If you are using the built-in Python on Mac OS X.
158
158
159 * If you are running Windows, which doesn't have a :mod:`readline` module.
159 * If you are running Windows, which doesn't have a :mod:`readline` module.
160
160
161 On OS X, the built-in Python doesn't not have :mod:`readline` because of
161 On OS X, the built-in Python doesn't not have :mod:`readline` because of
162 license issues. Starting with OS X 10.5 (Leopard), Apple's built-in Python has
162 license issues. Starting with OS X 10.5 (Leopard), Apple's built-in Python has
163 a BSD-licensed not-quite-compatible readline replacement. As of IPython 0.9,
163 a BSD-licensed not-quite-compatible readline replacement. As of IPython 0.9,
164 many of the issues related to the differences between readline and libedit have
164 many of the issues related to the differences between readline and libedit have
165 been resolved. For many users, libedit may be sufficient.
165 been resolved. For many users, libedit may be sufficient.
166
166
167 Most users on OS X will want to get the full :mod:`readline` module. To get a
167 Most users on OS X will want to get the full :mod:`readline` module. To get a
168 working :mod:`readline` module, just do (with :mod:`setuptools` installed)::
168 working :mod:`readline` module, just do (with :mod:`setuptools` installed)::
169
169
170 $ easy_install readline
170 $ easy_install readline
171
171
172 .. note:
172 .. note:
173
173
174 Other Python distributions on OS X (such as fink, MacPorts and the
174 Other Python distributions on OS X (such as fink, MacPorts and the
175 official python.org binaries) already have readline installed so
175 official python.org binaries) already have readline installed so
176 you don't have to do this step.
176 you don't have to do this step.
177
177
178 If needed, the readline egg can be build and installed from source (see the
178 If needed, the readline egg can be build and installed from source (see the
179 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard).
179 wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard).
180
180
181 On Windows, you will need the PyReadline module. PyReadline is a separate,
181 On Windows, you will need the PyReadline module. PyReadline is a separate,
182 Windows only implementation of readline that uses native Windows calls through
182 Windows only implementation of readline that uses native Windows calls through
183 :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary
183 :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary
184 installer available `here <http://ipython.scipy.org/dist/>`_. The :mod:`ctypes`
184 installer available `here <http://ipython.scipy.org/dist/>`_. The :mod:`ctypes`
185 module, which comes with Python 2.5 and greater, is required by PyReadline. It
185 module, which comes with Python 2.5 and greater, is required by PyReadline. It
186 is available for Python 2.4 at http://python.net/crew/theller/ctypes.
186 is available for Python 2.4 at http://python.net/crew/theller/ctypes.
187
187
188 nose
188 nose
189 ----
189 ----
190
190
191 To run the IPython test suite you will need the :mod:`nose` package. Nose
191 To run the IPython test suite you will need the :mod:`nose` package. Nose
192 provides a great way of sniffing out and running all of the IPython tests. The
192 provides a great way of sniffing out and running all of the IPython tests. The
193 simplest way of getting nose, is to use :command:`easy_install`::
193 simplest way of getting nose, is to use :command:`easy_install`::
194
194
195 $ easy_install nose
195 $ easy_install nose
196
196
197 Another way of getting this is to do::
197 Another way of getting this is to do::
198
198
199 $ easy_install ipython[test]
199 $ easy_install ipython[test]
200
200
201 For more installation options, see the `nose website
201 For more installation options, see the `nose website
202 <http://somethingaboutorange.com/mrl/projects/nose/>`_. Once you have nose
202 <http://somethingaboutorange.com/mrl/projects/nose/>`_. Once you have nose
203 installed, you can run IPython's test suite using the iptest command::
203 installed, you can run IPython's test suite using the iptest command::
204
204
205 $ iptest
205 $ iptest
206
206
207
207
208 pexpect
208 pexpect
209 -------
209 -------
210
210
211 The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's
211 The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's
212 :command:`irunner` script. On Unix platforms (including OS X), just do::
212 :command:`irunner` script. On Unix platforms (including OS X), just do::
213
213
214 $ easy_install pexpect
214 $ easy_install pexpect
215
215
216 Windows users are out of luck as pexpect does not run there.
216 Windows users are out of luck as pexpect does not run there.
217
217
218 Dependencies for IPython.kernel (parallel computing)
218 Dependencies for IPython.kernel (parallel computing)
219 ====================================================
219 ====================================================
220
220
221 The IPython kernel provides a nice architecture for parallel computing. The
221 The IPython kernel provides a nice architecture for parallel computing. The
222 main focus of this architecture is on interactive parallel computing. These
222 main focus of this architecture is on interactive parallel computing. These
223 features require a number of additional packages:
223 features require a number of additional packages:
224
224
225 * zope.interface (yep, we use interfaces)
225 * zope.interface (yep, we use interfaces)
226 * Twisted (asynchronous networking framework)
226 * Twisted (asynchronous networking framework)
227 * Foolscap (a nice, secure network protocol)
227 * Foolscap (a nice, secure network protocol)
228 * pyOpenSSL (security for network connections)
228 * pyOpenSSL (security for network connections)
229
229
230 On a Unix style platform (including OS X), if you want to use :mod:`setuptools`, you can just do::
230 On a Unix style platform (including OS X), if you want to use :mod:`setuptools`, you can just do::
231
231
232 $ easy_install ipython[kernel] # the first three
232 $ easy_install ipython[kernel] # the first three
233 $ easy_install ipython[security] # pyOpenSSL
233 $ easy_install ipython[security] # pyOpenSSL
234
234
235 zope.interface and Twisted
235 zope.interface and Twisted
236 --------------------------
236 --------------------------
237
237
238 Twisted [Twisted]_ and zope.interface [ZopeInterface]_ are used for networking
238 Twisted [Twisted]_ and zope.interface [ZopeInterface]_ are used for networking
239 related things. On Unix style platforms (including OS X), the simplest way of
239 related things. On Unix style platforms (including OS X), the simplest way of
240 getting the these is to use :command:`easy_install`::
240 getting the these is to use :command:`easy_install`::
241
241
242 $ easy_install zope.interface
242 $ easy_install zope.interface
243 $ easy_install Twisted
243 $ easy_install Twisted
244
244
245 Of course, you can also download the source tarballs from the `Twisted website
245 Of course, you can also download the source tarballs from the `Twisted website
246 <twistedmatrix.org>`_ and the `zope.interface page at PyPI
246 <twistedmatrix.org>`_ and the `zope.interface page at PyPI
247 <http://pypi.python.org/pypi/zope.interface>`_ and do the usual ``python
247 <http://pypi.python.org/pypi/zope.interface>`_ and do the usual ``python
248 setup.py install`` if you prefer.
248 setup.py install`` if you prefer.
249
249
250 Windows is a bit different. For zope.interface and Twisted, simply get the latest binary ``.exe`` installer from the Twisted website. This installer includes both zope.interface and Twisted and should just work.
250 Windows is a bit different. For zope.interface and Twisted, simply get the latest binary ``.exe`` installer from the Twisted website. This installer includes both zope.interface and Twisted and should just work.
251
251
252 Foolscap
252 Foolscap
253 --------
253 --------
254
254
255 Foolscap [Foolscap]_ uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features.
255 Foolscap [Foolscap]_ uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features.
256
256
257 On all platforms a simple::
257 On all platforms a simple::
258
258
259 $ easy_install foolscap
259 $ easy_install foolscap
260
260
261 should work. You can also download the source tarballs from the `Foolscap
261 should work. You can also download the source tarballs from the `Foolscap
262 website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install``
262 website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install``
263 if you prefer.
263 if you prefer.
264
264
265 pyOpenSSL
265 pyOpenSSL
266 ---------
266 ---------
267
267
268 IPython requires an older version of pyOpenSSL [pyOpenSSL]_ (0.6 rather than
268 IPython requires an older version of pyOpenSSL [pyOpenSSL]_ (0.6 rather than
269 the current 0.7). There are a couple of options for getting this:
269 the current 0.7). There are a couple of options for getting this:
270
270
271 1. Most Linux distributions have packages for pyOpenSSL.
271 1. Most Linux distributions have packages for pyOpenSSL.
272 2. The built-in Python 2.5 on OS X 10.5 already has it installed.
272 2. The built-in Python 2.5 on OS X 10.5 already has it installed.
273 3. There are source tarballs on the pyOpenSSL website. On Unix-like
273 3. There are source tarballs on the pyOpenSSL website. On Unix-like
274 platforms, these can be built using ``python seutp.py install``.
274 platforms, these can be built using ``python seutp.py install``.
275 4. There is also a binary ``.exe`` Windows installer on the `pyOpenSSL website <http://pyopenssl.sourceforge.net/>`_.
275 4. There is also a binary ``.exe`` Windows installer on the `pyOpenSSL website <http://pyopenssl.sourceforge.net/>`_.
276
276
277 Dependencies for IPython.frontend (the IPython GUI)
277 Dependencies for IPython.frontend (the IPython GUI)
278 ===================================================
278 ===================================================
279
279
280 wxPython
280 wxPython
281 --------
281 --------
282
282
283 Starting with IPython 0.9, IPython has a new IPython.frontend package that has
283 Starting with IPython 0.9, IPython has a new IPython.frontend package that has
284 a nice wxPython based IPython GUI. As you would expect, this GUI requires
284 a nice wxPython based IPython GUI. As you would expect, this GUI requires
285 wxPython. Most Linux distributions have wxPython packages available and the
285 wxPython. Most Linux distributions have wxPython packages available and the
286 built-in Python on OS X comes with wxPython preinstalled. For Windows, a
286 built-in Python on OS X comes with wxPython preinstalled. For Windows, a
287 binary installer is available on the `wxPython website
287 binary installer is available on the `wxPython website
288 <http://www.wxpython.org/>`_.
288 <http://www.wxpython.org/>`_.
289
289
290 .. [Twisted] Twisted matrix. http://twistedmatrix.org
290 .. [Twisted] Twisted matrix. http://twistedmatrix.org
291 .. [ZopeInterface] http://pypi.python.org/pypi/zope.interface
291 .. [ZopeInterface] http://pypi.python.org/pypi/zope.interface
292 .. [Foolscap] Foolscap network protocol. http://foolscap.lothar.com/trac
292 .. [Foolscap] Foolscap network protocol. http://foolscap.lothar.com/trac
293 .. [pyOpenSSL] pyOpenSSL. http://pyopenssl.sourceforge.net
293 .. [pyOpenSSL] pyOpenSSL. http://pyopenssl.sourceforge.net
294
@@ -1,252 +1,253 b''
1 =====================
1 =====================
2 IPython extension API
2 IPython extension API
3 =====================
3 =====================
4
4
5 IPython api (defined in IPython/ipapi.py) is the public api that
5 IPython api (defined in IPython/ipapi.py) is the public api that
6 should be used for
6 should be used for
7
7
8 * Configuration of user preferences (.ipython/ipy_user_conf.py)
8 * Configuration of user preferences (.ipython/ipy_user_conf.py)
9 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
9 * Creating new profiles (.ipython/ipy_profile_PROFILENAME.py)
10 * Writing extensions
10 * Writing extensions
11
11
12 Note that by using the extension api for configuration (editing
12 Note that by using the extension api for configuration (editing
13 ipy_user_conf.py instead of ipythonrc), you get better validity checks
13 ipy_user_conf.py instead of ipythonrc), you get better validity checks
14 and get richer functionality - for example, you can import an
14 and get richer functionality - for example, you can import an
15 extension and call functions in it to configure it for your purposes.
15 extension and call functions in it to configure it for your purposes.
16
16
17 For an example extension (the 'sh' profile), see
17 For an example extension (the 'sh' profile), see
18 IPython/extensions/ipy_profile_sh.py.
18 IPython/extensions/ipy_profile_sh.py.
19
19
20 For the last word on what's available, see the source code of
20 For the last word on what's available, see the source code of
21 IPython/ipapi.py.
21 IPython/ipapi.py.
22
22
23
23
24 Getting started
24 Getting started
25 ===============
25 ===============
26
26
27 If you want to define an extension, create a normal python module that
27 If you want to define an extension, create a normal python module that
28 can be imported. The module will access IPython functionality through
28 can be imported. The module will access IPython functionality through
29 the 'ip' object defined below.
29 the 'ip' object defined below.
30
30
31 If you are creating a new profile (e.g. foobar), name the module as
31 If you are creating a new profile (e.g. foobar), name the module as
32 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
32 'ipy_profile_foobar.py' and put it in your ~/.ipython directory. Then,
33 when you start ipython with the '-p foobar' argument, the module is
33 when you start ipython with the '-p foobar' argument, the module is
34 automatically imported on ipython startup.
34 automatically imported on ipython startup.
35
35
36 If you are just doing some per-user configuration, you can either
36 If you are just doing some per-user configuration, you can either
37
37
38 * Put the commands directly into ipy_user_conf.py.
38 * Put the commands directly into ipy_user_conf.py.
39
39
40 * Create a new module with your customization code and import *that*
40 * Create a new module with your customization code and import *that*
41 module in ipy_user_conf.py. This is preferable to the first approach,
41 module in ipy_user_conf.py. This is preferable to the first approach,
42 because now you can reuse and distribute your customization code.
42 because now you can reuse and distribute your customization code.
43
43
44 Getting a handle to the api
44 Getting a handle to the api
45 ===========================
45 ===========================
46
46
47 Put this in the start of your module::
47 Put this in the start of your module::
48
48
49 #!python
49 #!python
50 import IPython.ipapi
50 import IPython.ipapi
51 ip = IPython.ipapi.get()
51 ip = IPython.ipapi.get()
52
52
53 The 'ip' object will then be used for accessing IPython
53 The 'ip' object will then be used for accessing IPython
54 functionality. 'ip' will mean this api object in all the following
54 functionality. 'ip' will mean this api object in all the following
55 code snippets. The same 'ip' that we just acquired is always
55 code snippets. The same 'ip' that we just acquired is always
56 accessible in interactive IPython sessions by the name _ip - play with
56 accessible in interactive IPython sessions by the name _ip - play with
57 it like this::
57 it like this::
58
58
59 [~\_ipython]|81> a = 10
59 [~\_ipython]|81> a = 10
60 [~\_ipython]|82> _ip.e
60 [~\_ipython]|82> _ip.e
61 _ip.ev _ip.ex _ip.expose_magic
61 _ip.ev _ip.ex _ip.expose_magic
62 [~\_ipython]|82> _ip.ev('a+13')
62 [~\_ipython]|82> _ip.ev('a+13')
63 <82> 23
63 <82> 23
64
64
65 The _ip object is also used in some examples in this document - it can
65 The _ip object is also used in some examples in this document - it can
66 be substituted by 'ip' in non-interactive use.
66 be substituted by 'ip' in non-interactive use.
67
67
68 Changing options
68 Changing options
69 ================
69 ================
70
70
71 The ip object has 'options' attribute that can be used te get/set
71 The ip object has 'options' attribute that can be used te get/set
72 configuration options (just as in the ipythonrc file)::
72 configuration options (just as in the ipythonrc file)::
73
73
74 o = ip.options
74 o = ip.options
75 o.autocall = 2
75 o.autocall = 2
76 o.automagic = 1
76 o.automagic = 1
77
77
78 Executing statements in IPython namespace with 'ex' and 'ev'
78 Executing statements in IPython namespace with 'ex' and 'ev'
79 ============================================================
79 ============================================================
80
80
81 Often, you want to e.g. import some module or define something that
81 Often, you want to e.g. import some module or define something that
82 should be visible in IPython namespace. Use ``ip.ev`` to
82 should be visible in IPython namespace. Use ``ip.ev`` to
83 *evaluate* (calculate the value of) expression and ``ip.ex`` to
83 *evaluate* (calculate the value of) expression and ``ip.ex`` to
84 '''execute''' a statement::
84 '''execute''' a statement::
85
85
86 # path module will be visible to the interactive session
86 # path module will be visible to the interactive session
87 ip.ex("from path import path" )
87 ip.ex("from path import path" )
88
88
89 # define a handy function 'up' that changes the working directory
89 # define a handy function 'up' that changes the working directory
90
90
91 ip.ex('import os')
91 ip.ex('import os')
92 ip.ex("def up(): os.chdir('..')")
92 ip.ex("def up(): os.chdir('..')")
93
93
94
94
95 # _i2 has the input history entry #2, print its value in uppercase.
95 # _i2 has the input history entry #2, print its value in uppercase.
96 print ip.ev('_i2.upper()')
96 print ip.ev('_i2.upper()')
97
97
98 Accessing the IPython namespace
98 Accessing the IPython namespace
99 ===============================
99 ===============================
100
100
101 ip.user_ns attribute has a dictionary containing the IPython global
101 ip.user_ns attribute has a dictionary containing the IPython global
102 namespace (the namespace visible in the interactive session).
102 namespace (the namespace visible in the interactive session).
103
103
104 ::
104 ::
105
105
106 [~\_ipython]|84> tauno = 555
106 [~\_ipython]|84> tauno = 555
107 [~\_ipython]|85> _ip.user_ns['tauno']
107 [~\_ipython]|85> _ip.user_ns['tauno']
108 <85> 555
108 <85> 555
109
109
110 Defining new magic commands
110 Defining new magic commands
111 ===========================
111 ===========================
112
112
113 The following example defines a new magic command, %impall. What the
113 The following example defines a new magic command, %impall. What the
114 command does should be obvious::
114 command does should be obvious::
115
115
116 def doimp(self, arg):
116 def doimp(self, arg):
117 ip = self.api
117 ip = self.api
118 ip.ex("import %s; reload(%s); from %s import *" % (
118 ip.ex("import %s; reload(%s); from %s import *" % (
119 arg,arg,arg)
119 arg,arg,arg)
120 )
120 )
121
121
122 ip.expose_magic('impall', doimp)
122 ip.expose_magic('impall', doimp)
123
123
124 Things to observe in this example:
124 Things to observe in this example:
125
125
126 * Define a function that implements the magic command using the
126 * Define a function that implements the magic command using the
127 ipapi methods defined in this document
127 ipapi methods defined in this document
128 * The first argument of the function is 'self', i.e. the
128 * The first argument of the function is 'self', i.e. the
129 interpreter object. It shouldn't be used directly. however.
129 interpreter object. It shouldn't be used directly. however.
130 The interpreter object is probably *not* going to remain stable
130 The interpreter object is probably *not* going to remain stable
131 through IPython versions.
131 through IPython versions.
132 * Access the ipapi through 'self.api' instead of the global 'ip' object.
132 * Access the ipapi through 'self.api' instead of the global 'ip' object.
133 * All the text following the magic command on the command line is
133 * All the text following the magic command on the command line is
134 contained in the second argument
134 contained in the second argument
135 * Expose the magic by ip.expose_magic()
135 * Expose the magic by ip.expose_magic()
136
136
137
137
138 Calling magic functions and system commands
138 Calling magic functions and system commands
139 ===========================================
139 ===========================================
140
140
141 Use ip.magic() to execute a magic function, and ip.system() to execute
141 Use ip.magic() to execute a magic function, and ip.system() to execute
142 a system command::
142 a system command::
143
143
144 # go to a bookmark
144 # go to a bookmark
145 ip.magic('%cd -b relfiles')
145 ip.magic('%cd -b relfiles')
146
146
147 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
147 # execute 'ls -F' system command. Interchangeable with os.system('ls'), really.
148 ip.system('ls -F')
148 ip.system('ls -F')
149
149
150 Launching IPython instance from normal python code
150 Launching IPython instance from normal python code
151 ==================================================
151 ==================================================
152
152
153 Use ipapi.launch_new_instance() with an argument that specifies the
153 Use ipapi.launch_new_instance() with an argument that specifies the
154 namespace to use. This can be useful for trivially embedding IPython
154 namespace to use. This can be useful for trivially embedding IPython
155 into your program. Here's an example of normal python program test.py
155 into your program. Here's an example of normal python program test.py
156 ('''without''' an existing IPython session) that launches an IPython
156 ('''without''' an existing IPython session) that launches an IPython
157 interpreter and regains control when the interpreter is exited::
157 interpreter and regains control when the interpreter is exited::
158
158
159 [ipython]|1> cat test.py
159 [ipython]|1> cat test.py
160 my_ns = dict(
160 my_ns = dict(
161 kissa = 15,
161 kissa = 15,
162 koira = 16)
162 koira = 16)
163 import IPython.ipapi
163 import IPython.ipapi
164 print "launching IPython instance"
164 print "launching IPython instance"
165 IPython.ipapi.launch_new_instance(my_ns)
165 IPython.ipapi.launch_new_instance(my_ns)
166 print "Exited IPython instance!"
166 print "Exited IPython instance!"
167 print "New vals:",my_ns['kissa'], my_ns['koira']
167 print "New vals:",my_ns['kissa'], my_ns['koira']
168
168
169 And here's what it looks like when run (note how we don't start it
169 And here's what it looks like when run (note how we don't start it
170 from an ipython session)::
170 from an ipython session)::
171
171
172 Q:\ipython>python test.py
172 Q:\ipython>python test.py
173 launching IPython instance
173 launching IPython instance
174 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
174 Py 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] IPy 0.7.3b3.r1975
175 [ipython]|1> kissa = 444
175 [ipython]|1> kissa = 444
176 [ipython]|2> koira = 555
176 [ipython]|2> koira = 555
177 [ipython]|3> Exit
177 [ipython]|3> Exit
178 Exited IPython instance!
178 Exited IPython instance!
179 New vals: 444 555
179 New vals: 444 555
180
180
181 Accessing unexposed functionality
181 Accessing unexposed functionality
182 =================================
182 =================================
183
183
184 There are still many features that are not exposed via the ipapi. If
184 There are still many features that are not exposed via the ipapi. If
185 you can't avoid using them, you can use the functionality in
185 you can't avoid using them, you can use the functionality in
186 InteractiveShell object (central IPython session class, defined in
186 InteractiveShell object (central IPython session class, defined in
187 iplib.py) through ip.IP.
187 iplib.py) through ip.IP.
188
188
189 For example::
189 For example::
190
190
191 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
191 [~]|7> _ip.IP.expand_aliases('np','myfile.py')
192 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
192 <7> 'c:/opt/Notepad++/notepad++.exe myfile.py'
193 [~]|8>
193 [~]|8>
194
194
195 Still, it's preferable that if you encounter such a feature, contact
195 Still, it's preferable that if you encounter such a feature, contact
196 the IPython team and request that the functionality be exposed in a
196 the IPython team and request that the functionality be exposed in a
197 future version of IPython. Things not in ipapi are more likely to
197 future version of IPython. Things not in ipapi are more likely to
198 change over time.
198 change over time.
199
199
200 Provided extensions
200 Provided extensions
201 ===================
201 ===================
202
202
203 You can see the list of available extensions (and profiles) by doing
203 You can see the list of available extensions (and profiles) by doing
204 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
204 ``import ipy_<TAB>``. Some extensions don't have the ``ipy_`` prefix in
205 module name, so you may need to see the contents of IPython/extensions
205 module name, so you may need to see the contents of IPython/extensions
206 folder to see what's available.
206 folder to see what's available.
207
207
208 You can see a brief documentation of an extension by looking at the
208 You can see a brief documentation of an extension by looking at the
209 module docstring::
209 module docstring::
210
210
211 [c:p/ipython_main]|190> import ipy_fsops
211 [c:p/ipython_main]|190> import ipy_fsops
212 [c:p/ipython_main]|191> ipy_fsops?
212 [c:p/ipython_main]|191> ipy_fsops?
213
213
214 ...
214 ...
215
215
216 Docstring:
216 Docstring:
217 File system operations
217 File system operations
218
218
219 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
219 Contains: Simple variants of normal unix shell commands (icp, imv, irm,
220 imkdir, igrep).
220 imkdir, igrep).
221
221
222 You can also install your own extensions - the recommended way is to
222 You can also install your own extensions - the recommended way is to
223 just copy the module to ~/.ipython. Extensions are typically enabled
223 just copy the module to ~/.ipython. Extensions are typically enabled
224 by just importing them (e.g. in ipy_user_conf.py), but some extensions
224 by just importing them (e.g. in ipy_user_conf.py), but some extensions
225 require additional steps, for example::
225 require additional steps, for example::
226
226
227 [c:p]|192> import ipy_traits_completer
227 [c:p]|192> import ipy_traits_completer
228 [c:p]|193> ipy_traits_completer.activate()
228 [c:p]|193> ipy_traits_completer.activate()
229
229
230 Note that extensions, even if provided in the stock IPython
230 Note that extensions, even if provided in the stock IPython
231 installation, are not guaranteed to have the same requirements as the
231 installation, are not guaranteed to have the same requirements as the
232 rest of IPython - an extension may require external libraries or a
232 rest of IPython - an extension may require external libraries or a
233 newer version of Python than what IPython officially requires. An
233 newer version of Python than what IPython officially requires. An
234 extension may also be under a more restrictive license than IPython
234 extension may also be under a more restrictive license than IPython
235 (e.g. ipy_bzr is under GPL).
235 (e.g. ipy_bzr is under GPL).
236
236
237 Just for reference, the list of bundled extensions at the time of
237 Just for reference, the list of bundled extensions at the time of
238 writing is below:
238 writing is below:
239
239
240 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
240 astyle.py clearcmd.py envpersist.py ext_rescapture.py ibrowse.py
241 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
241 igrid.py InterpreterExec.py InterpreterPasteInput.py ipipe.py
242 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
242 ipy_app_completers.py ipy_autoreload.py ipy_bzr.py ipy_completers.py
243 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
243 ipy_constants.py ipy_defaults.py ipy_editors.py ipy_exportdb.py
244 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
244 ipy_extutil.py ipy_fsops.py ipy_gnuglobal.py ipy_kitcfg.py
245 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
245 ipy_legacy.py ipy_leo.py ipy_p4.py ipy_profile_doctest.py
246 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
246 ipy_profile_none.py ipy_profile_scipy.py ipy_profile_sh.py
247 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
247 ipy_profile_zope.py ipy_pydb.py ipy_rehashdir.py ipy_render.py
248 ipy_server.py ipy_signals.py ipy_stock_completers.py
248 ipy_server.py ipy_signals.py ipy_stock_completers.py
249 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
249 ipy_system_conf.py ipy_traits_completer.py ipy_vimserver.py
250 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
250 ipy_which.py ipy_workdir.py jobctrl.py ledit.py numeric_formats.py
251 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
251 PhysicalQInput.py PhysicalQInteractive.py pickleshare.py
252 pspersistence.py win32clip.py __init__.py No newline at end of file
252 pspersistence.py win32clip.py __init__.py
253
@@ -1,11 +1,12 b''
1 ==================================
1 ==================================
2 Using IPython for interactive work
2 Using IPython for interactive work
3 ==================================
3 ==================================
4
4
5 .. toctree::
5 .. toctree::
6 :maxdepth: 2
6 :maxdepth: 2
7
7
8 tutorial.txt
8 tutorial.txt
9 reference.txt
9 reference.txt
10 shell.txt
10 shell.txt
11 extension_api.txt
11 extension_api.txt
12
@@ -1,284 +1,285 b''
1 .. _ipython_as_shell:
1 .. _ipython_as_shell:
2
2
3 =========================
3 =========================
4 IPython as a system shell
4 IPython as a system shell
5 =========================
5 =========================
6
6
7 Overview
7 Overview
8 ========
8 ========
9
9
10 The 'sh' profile optimizes IPython for system shell usage. Apart from
10 The 'sh' profile optimizes IPython for system shell usage. Apart from
11 certain job control functionality that is present in unix (ctrl+z does
11 certain job control functionality that is present in unix (ctrl+z does
12 "suspend"), the sh profile should provide you with most of the
12 "suspend"), the sh profile should provide you with most of the
13 functionality you use daily in system shell, and more. Invoke IPython
13 functionality you use daily in system shell, and more. Invoke IPython
14 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
14 in 'sh' profile by doing 'ipython -p sh', or (in win32) by launching
15 the "pysh" shortcut in start menu.
15 the "pysh" shortcut in start menu.
16
16
17 If you want to use the features of sh profile as your defaults (which
17 If you want to use the features of sh profile as your defaults (which
18 might be a good idea if you use other profiles a lot of the time but
18 might be a good idea if you use other profiles a lot of the time but
19 still want the convenience of sh profile), add ``import ipy_profile_sh``
19 still want the convenience of sh profile), add ``import ipy_profile_sh``
20 to your ~/.ipython/ipy_user_conf.py.
20 to your ~/.ipython/ipy_user_conf.py.
21
21
22 The 'sh' profile is different from the default profile in that:
22 The 'sh' profile is different from the default profile in that:
23
23
24 * Prompt shows the current directory
24 * Prompt shows the current directory
25 * Spacing between prompts and input is more compact (no padding with
25 * Spacing between prompts and input is more compact (no padding with
26 empty lines). The startup banner is more compact as well.
26 empty lines). The startup banner is more compact as well.
27 * System commands are directly available (in alias table) without
27 * System commands are directly available (in alias table) without
28 requesting %rehashx - however, if you install new programs along
28 requesting %rehashx - however, if you install new programs along
29 your PATH, you might want to run %rehashx to update the persistent
29 your PATH, you might want to run %rehashx to update the persistent
30 alias table
30 alias table
31 * Macros are stored in raw format by default. That is, instead of
31 * Macros are stored in raw format by default. That is, instead of
32 '_ip.system("cat foo"), the macro will contain text 'cat foo')
32 '_ip.system("cat foo"), the macro will contain text 'cat foo')
33 * Autocall is in full mode
33 * Autocall is in full mode
34 * Calling "up" does "cd .."
34 * Calling "up" does "cd .."
35
35
36 The 'sh' profile is different from the now-obsolete (and unavailable)
36 The 'sh' profile is different from the now-obsolete (and unavailable)
37 'pysh' profile in that:
37 'pysh' profile in that:
38
38
39 * '$$var = command' and '$var = command' syntax is not supported
39 * '$$var = command' and '$var = command' syntax is not supported
40 * anymore. Use 'var = !command' instead (incidentally, this is
40 * anymore. Use 'var = !command' instead (incidentally, this is
41 * available in all IPython profiles). Note that !!command *will*
41 * available in all IPython profiles). Note that !!command *will*
42 * work.
42 * work.
43
43
44 Aliases
44 Aliases
45 =======
45 =======
46
46
47 All of your $PATH has been loaded as IPython aliases, so you should be
47 All of your $PATH has been loaded as IPython aliases, so you should be
48 able to type any normal system command and have it executed. See
48 able to type any normal system command and have it executed. See
49 %alias? and %unalias? for details on the alias facilities. See also
49 %alias? and %unalias? for details on the alias facilities. See also
50 %rehashx? for details on the mechanism used to load $PATH.
50 %rehashx? for details on the mechanism used to load $PATH.
51
51
52
52
53 Directory management
53 Directory management
54 ====================
54 ====================
55
55
56 Since each command passed by ipython to the underlying system is executed
56 Since each command passed by ipython to the underlying system is executed
57 in a subshell which exits immediately, you can NOT use !cd to navigate
57 in a subshell which exits immediately, you can NOT use !cd to navigate
58 the filesystem.
58 the filesystem.
59
59
60 IPython provides its own builtin '%cd' magic command to move in the
60 IPython provides its own builtin '%cd' magic command to move in the
61 filesystem (the % is not required with automagic on). It also maintains
61 filesystem (the % is not required with automagic on). It also maintains
62 a list of visited directories (use %dhist to see it) and allows direct
62 a list of visited directories (use %dhist to see it) and allows direct
63 switching to any of them. Type 'cd?' for more details.
63 switching to any of them. Type 'cd?' for more details.
64
64
65 %pushd, %popd and %dirs are provided for directory stack handling.
65 %pushd, %popd and %dirs are provided for directory stack handling.
66
66
67
67
68 Enabled extensions
68 Enabled extensions
69 ==================
69 ==================
70
70
71 Some extensions, listed below, are enabled as default in this profile.
71 Some extensions, listed below, are enabled as default in this profile.
72
72
73 envpersist
73 envpersist
74 ----------
74 ----------
75
75
76 %env can be used to "remember" environment variable manipulations. Examples::
76 %env can be used to "remember" environment variable manipulations. Examples::
77
77
78 %env - Show all environment variables
78 %env - Show all environment variables
79 %env VISUAL=jed - set VISUAL to jed
79 %env VISUAL=jed - set VISUAL to jed
80 %env PATH+=;/foo - append ;foo to PATH
80 %env PATH+=;/foo - append ;foo to PATH
81 %env PATH+=;/bar - also append ;bar to PATH
81 %env PATH+=;/bar - also append ;bar to PATH
82 %env PATH-=/wbin; - prepend /wbin; to PATH
82 %env PATH-=/wbin; - prepend /wbin; to PATH
83 %env -d VISUAL - forget VISUAL persistent val
83 %env -d VISUAL - forget VISUAL persistent val
84 %env -p - print all persistent env modifications
84 %env -p - print all persistent env modifications
85
85
86 ipy_which
86 ipy_which
87 ---------
87 ---------
88
88
89 %which magic command. Like 'which' in unix, but knows about ipython aliases.
89 %which magic command. Like 'which' in unix, but knows about ipython aliases.
90
90
91 Example::
91 Example::
92
92
93 [C:/ipython]|14> %which st
93 [C:/ipython]|14> %which st
94 st -> start .
94 st -> start .
95 [C:/ipython]|15> %which d
95 [C:/ipython]|15> %which d
96 d -> dir /w /og /on
96 d -> dir /w /og /on
97 [C:/ipython]|16> %which cp
97 [C:/ipython]|16> %which cp
98 cp -> cp
98 cp -> cp
99 == c:\bin\cp.exe
99 == c:\bin\cp.exe
100 c:\bin\cp.exe
100 c:\bin\cp.exe
101
101
102 ipy_app_completers
102 ipy_app_completers
103 ------------------
103 ------------------
104
104
105 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
105 Custom tab completers for some apps like svn, hg, bzr, apt-get. Try 'apt-get install <TAB>' in debian/ubuntu.
106
106
107 ipy_rehashdir
107 ipy_rehashdir
108 -------------
108 -------------
109
109
110 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
110 Allows you to add system command aliases for commands that are not along your path. Let's say that you just installed Putty and want to be able to invoke it without adding it to path, you can create the alias for it with rehashdir::
111
111
112 [~]|22> cd c:/opt/PuTTY/
112 [~]|22> cd c:/opt/PuTTY/
113 [c:opt/PuTTY]|23> rehashdir .
113 [c:opt/PuTTY]|23> rehashdir .
114 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
114 <23> ['pageant', 'plink', 'pscp', 'psftp', 'putty', 'puttygen', 'unins000']
115
115
116 Now, you can execute any of those commams directly::
116 Now, you can execute any of those commams directly::
117
117
118 [c:opt/PuTTY]|24> cd
118 [c:opt/PuTTY]|24> cd
119 [~]|25> putty
119 [~]|25> putty
120
120
121 (the putty window opens).
121 (the putty window opens).
122
122
123 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
123 If you want to store the alias so that it will always be available, do '%store putty'. If you want to %store all these aliases persistently, just do it in a for loop::
124
124
125 [~]|27> for a in _23:
125 [~]|27> for a in _23:
126 |..> %store $a
126 |..> %store $a
127 |..>
127 |..>
128 |..>
128 |..>
129 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
129 Alias stored: pageant (0, 'c:\\opt\\PuTTY\\pageant.exe')
130 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
130 Alias stored: plink (0, 'c:\\opt\\PuTTY\\plink.exe')
131 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
131 Alias stored: pscp (0, 'c:\\opt\\PuTTY\\pscp.exe')
132 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
132 Alias stored: psftp (0, 'c:\\opt\\PuTTY\\psftp.exe')
133 ...
133 ...
134
134
135 mglob
135 mglob
136 -----
136 -----
137
137
138 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
138 Provide the magic function %mglob, which makes it easier (than the 'find' command) to collect (possibly recursive) file lists. Examples::
139
139
140 [c:/ipython]|9> mglob *.py
140 [c:/ipython]|9> mglob *.py
141 [c:/ipython]|10> mglob *.py rec:*.txt
141 [c:/ipython]|10> mglob *.py rec:*.txt
142 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
142 [c:/ipython]|19> workfiles = %mglob !.svn/ !.hg/ !*_Data/ !*.bak rec:.
143
143
144 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
144 Note that the first 2 calls will put the file list in result history (_, _9, _10), and the last one will assign it to 'workfiles'.
145
145
146
146
147 Prompt customization
147 Prompt customization
148 ====================
148 ====================
149
149
150 The sh profile uses the following prompt configurations::
150 The sh profile uses the following prompt configurations::
151
151
152 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
152 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
153 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
153 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
154
154
155 You can change the prompt configuration to your liking by editing
155 You can change the prompt configuration to your liking by editing
156 ipy_user_conf.py.
156 ipy_user_conf.py.
157
157
158 String lists
158 String lists
159 ============
159 ============
160
160
161 String lists (IPython.genutils.SList) are handy way to process output
161 String lists (IPython.genutils.SList) are handy way to process output
162 from system commands. They are produced by ``var = !cmd`` syntax.
162 from system commands. They are produced by ``var = !cmd`` syntax.
163
163
164 First, we acquire the output of 'ls -l'::
164 First, we acquire the output of 'ls -l'::
165
165
166 [Q:doc/examples]|2> lines = !ls -l
166 [Q:doc/examples]|2> lines = !ls -l
167 ==
167 ==
168 ['total 23',
168 ['total 23',
169 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
169 '-rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py',
170 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
170 '-rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py',
171 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
171 '-rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py',
172 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
172 '-rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py',
173 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
173 '-rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py',
174 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
174 '-rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py',
175 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
175 '-rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc']
176
176
177 Now, let's take a look at the contents of 'lines' (the first number is
177 Now, let's take a look at the contents of 'lines' (the first number is
178 the list element number)::
178 the list element number)::
179
179
180 [Q:doc/examples]|3> lines
180 [Q:doc/examples]|3> lines
181 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
181 <3> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
182
182
183 0: total 23
183 0: total 23
184 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
184 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
185 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
185 2: -rw-rw-rw- 1 ville None 1927 Sep 30 2006 example-embed-short.py
186 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
186 3: -rwxrwxrwx 1 ville None 4606 Sep 1 17:15 example-embed.py
187 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
187 4: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
188 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
188 5: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
189 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
189 6: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
190 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
190 7: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
191
191
192 Now, let's filter out the 'embed' lines::
192 Now, let's filter out the 'embed' lines::
193
193
194 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
194 [Q:doc/examples]|4> l2 = lines.grep('embed',prune=1)
195 [Q:doc/examples]|5> l2
195 [Q:doc/examples]|5> l2
196 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
196 <5> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
197
197
198 0: total 23
198 0: total 23
199 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
199 1: -rw-rw-rw- 1 ville None 1163 Sep 30 2006 example-demo.py
200 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
200 2: -rwxrwxrwx 1 ville None 1017 Sep 30 2006 example-gnuplot.py
201 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
201 3: -rwxrwxrwx 1 ville None 339 Jun 11 18:01 extension.py
202 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
202 4: -rwxrwxrwx 1 ville None 113 Dec 20 2006 seteditor.py
203 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
203 5: -rwxrwxrwx 1 ville None 245 Dec 12 2006 seteditor.pyc
204
204
205 Now, we want strings having just file names and permissions::
205 Now, we want strings having just file names and permissions::
206
206
207 [Q:doc/examples]|6> l2.fields(8,0)
207 [Q:doc/examples]|6> l2.fields(8,0)
208 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
208 <6> SList (.p, .n, .l, .s, .grep(), .fields() available). Value:
209
209
210 0: total
210 0: total
211 1: example-demo.py -rw-rw-rw-
211 1: example-demo.py -rw-rw-rw-
212 2: example-gnuplot.py -rwxrwxrwx
212 2: example-gnuplot.py -rwxrwxrwx
213 3: extension.py -rwxrwxrwx
213 3: extension.py -rwxrwxrwx
214 4: seteditor.py -rwxrwxrwx
214 4: seteditor.py -rwxrwxrwx
215 5: seteditor.pyc -rwxrwxrwx
215 5: seteditor.pyc -rwxrwxrwx
216
216
217 Note how the line with 'total' does not raise IndexError.
217 Note how the line with 'total' does not raise IndexError.
218
218
219 If you want to split these (yielding lists), call fields() without
219 If you want to split these (yielding lists), call fields() without
220 arguments::
220 arguments::
221
221
222 [Q:doc/examples]|7> _.fields()
222 [Q:doc/examples]|7> _.fields()
223 <7>
223 <7>
224 [['total'],
224 [['total'],
225 ['example-demo.py', '-rw-rw-rw-'],
225 ['example-demo.py', '-rw-rw-rw-'],
226 ['example-gnuplot.py', '-rwxrwxrwx'],
226 ['example-gnuplot.py', '-rwxrwxrwx'],
227 ['extension.py', '-rwxrwxrwx'],
227 ['extension.py', '-rwxrwxrwx'],
228 ['seteditor.py', '-rwxrwxrwx'],
228 ['seteditor.py', '-rwxrwxrwx'],
229 ['seteditor.pyc', '-rwxrwxrwx']]
229 ['seteditor.pyc', '-rwxrwxrwx']]
230
230
231 If you want to pass these separated with spaces to a command (typical
231 If you want to pass these separated with spaces to a command (typical
232 for lists if files), use the .s property::
232 for lists if files), use the .s property::
233
233
234
234
235 [Q:doc/examples]|13> files = l2.fields(8).s
235 [Q:doc/examples]|13> files = l2.fields(8).s
236 [Q:doc/examples]|14> files
236 [Q:doc/examples]|14> files
237 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
237 <14> 'example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc'
238 [Q:doc/examples]|15> ls $files
238 [Q:doc/examples]|15> ls $files
239 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
239 example-demo.py example-gnuplot.py extension.py seteditor.py seteditor.pyc
240
240
241 SLists are inherited from normal python lists, so every list method is
241 SLists are inherited from normal python lists, so every list method is
242 available::
242 available::
243
243
244 [Q:doc/examples]|21> lines.append('hey')
244 [Q:doc/examples]|21> lines.append('hey')
245
245
246
246
247 Real world example: remove all files outside version control
247 Real world example: remove all files outside version control
248 ============================================================
248 ============================================================
249
249
250 First, capture output of "hg status"::
250 First, capture output of "hg status"::
251
251
252 [Q:/ipython]|28> out = !hg status
252 [Q:/ipython]|28> out = !hg status
253 ==
253 ==
254 ['M IPython\\extensions\\ipy_kitcfg.py',
254 ['M IPython\\extensions\\ipy_kitcfg.py',
255 'M IPython\\extensions\\ipy_rehashdir.py',
255 'M IPython\\extensions\\ipy_rehashdir.py',
256 ...
256 ...
257 '? build\\lib\\IPython\\Debugger.py',
257 '? build\\lib\\IPython\\Debugger.py',
258 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
258 '? build\\lib\\IPython\\extensions\\InterpreterExec.py',
259 '? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
259 '? build\\lib\\IPython\\extensions\\InterpreterPasteInput.py',
260 ...
260 ...
261
261
262 (lines starting with ? are not under version control).
262 (lines starting with ? are not under version control).
263
263
264 ::
264 ::
265
265
266 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
266 [Q:/ipython]|35> junk = out.grep(r'^\?').fields(1)
267 [Q:/ipython]|36> junk
267 [Q:/ipython]|36> junk
268 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
268 <36> SList (.p, .n, .l, .s, .grep(), .fields() availab
269 ...
269 ...
270 10: build\bdist.win32\winexe\temp\_ctypes.py
270 10: build\bdist.win32\winexe\temp\_ctypes.py
271 11: build\bdist.win32\winexe\temp\_hashlib.py
271 11: build\bdist.win32\winexe\temp\_hashlib.py
272 12: build\bdist.win32\winexe\temp\_socket.py
272 12: build\bdist.win32\winexe\temp\_socket.py
273
273
274 Now we can just remove these files by doing 'rm $junk.s'.
274 Now we can just remove these files by doing 'rm $junk.s'.
275
275
276 The .s, .n, .p properties
276 The .s, .n, .p properties
277 =========================
277 =========================
278
278
279 The '.s' property returns one string where lines are separated by
279 The '.s' property returns one string where lines are separated by
280 single space (for convenient passing to system commands). The '.n'
280 single space (for convenient passing to system commands). The '.n'
281 property return one string where the lines are separated by '\n'
281 property return one string where the lines are separated by '\n'
282 (i.e. the original output of the function). If the items in string
282 (i.e. the original output of the function). If the items in string
283 list are file names, '.p' can be used to get a list of "path" objects
283 list are file names, '.p' can be used to get a list of "path" objects
284 for convenient file manipulation. No newline at end of file
284 for convenient file manipulation.
285
@@ -1,315 +1,317 b''
1 .. _tutorial:
1 .. _tutorial:
2
2
3 ======================
3 ======================
4 Quick IPython tutorial
4 Quick IPython tutorial
5 ======================
5 ======================
6
6
7 IPython can be used as an improved replacement for the Python prompt,
7 IPython can be used as an improved replacement for the Python prompt,
8 and for that you don't really need to read any more of this manual. But
8 and for that you don't really need to read any more of this manual. But
9 in this section we'll try to summarize a few tips on how to make the
9 in this section we'll try to summarize a few tips on how to make the
10 most effective use of it for everyday Python development, highlighting
10 most effective use of it for everyday Python development, highlighting
11 things you might miss in the rest of the manual (which is getting long).
11 things you might miss in the rest of the manual (which is getting long).
12 We'll give references to parts in the manual which provide more detail
12 We'll give references to parts in the manual which provide more detail
13 when appropriate.
13 when appropriate.
14
14
15 The following article by Jeremy Jones provides an introductory tutorial
15 The following article by Jeremy Jones provides an introductory tutorial
16 about IPython: http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
16 about IPython: http://www.onlamp.com/pub/a/python/2005/01/27/ipython.html
17
17
18 Highlights
18 Highlights
19 ==========
19 ==========
20
20
21 Tab completion
21 Tab completion
22 --------------
22 --------------
23
23
24 TAB-completion, especially for attributes, is a convenient way to explore the
24 TAB-completion, especially for attributes, is a convenient way to explore the
25 structure of any object you're dealing with. Simply type object_name.<TAB> and
25 structure of any object you're dealing with. Simply type object_name.<TAB> and
26 a list of the object's attributes will be printed (see :ref:`the readline
26 a list of the object's attributes will be printed (see :ref:`the readline
27 section <readline>` for more). Tab completion also works on file and directory
27 section <readline>` for more). Tab completion also works on file and directory
28 names, which combined with IPython's alias system allows you to do from within
28 names, which combined with IPython's alias system allows you to do from within
29 IPython many of the things you normally would need the system shell for.
29 IPython many of the things you normally would need the system shell for.
30
30
31 Explore your objects
31 Explore your objects
32 --------------------
32 --------------------
33
33
34 Typing object_name? will print all sorts of details about any object,
34 Typing object_name? will print all sorts of details about any object,
35 including docstrings, function definition lines (for call arguments) and
35 including docstrings, function definition lines (for call arguments) and
36 constructor details for classes. The magic commands %pdoc, %pdef, %psource
36 constructor details for classes. The magic commands %pdoc, %pdef, %psource
37 and %pfile will respectively print the docstring, function definition line,
37 and %pfile will respectively print the docstring, function definition line,
38 full source code and the complete file for any object (when they can be
38 full source code and the complete file for any object (when they can be
39 found). If automagic is on (it is by default), you don't need to type the '%'
39 found). If automagic is on (it is by default), you don't need to type the '%'
40 explicitly. See :ref:`this section <dynamic_object_info>` for more.
40 explicitly. See :ref:`this section <dynamic_object_info>` for more.
41
41
42 The `%run` magic command
42 The `%run` magic command
43 ------------------------
43 ------------------------
44
44
45 The %run magic command allows you to run any python script and load all of its
45 The %run magic command allows you to run any python script and load all of its
46 data directly into the interactive namespace. Since the file is re-read from
46 data directly into the interactive namespace. Since the file is re-read from
47 disk each time, changes you make to it are reflected immediately (in contrast
47 disk each time, changes you make to it are reflected immediately (in contrast
48 to the behavior of import). I rarely use import for code I am testing, relying
48 to the behavior of import). I rarely use import for code I am testing, relying
49 on %run instead. See :ref:`this section <magic>` for more on this and other
49 on %run instead. See :ref:`this section <magic>` for more on this and other
50 magic commands, or type the name of any magic command and ? to get details on
50 magic commands, or type the name of any magic command and ? to get details on
51 it. See also :ref:`this section <dreload>` for a recursive reload command. %run
51 it. See also :ref:`this section <dreload>` for a recursive reload command. %run
52 also has special flags for timing the execution of your scripts (-t) and for
52 also has special flags for timing the execution of your scripts (-t) and for
53 executing them under the control of either Python's pdb debugger (-d) or
53 executing them under the control of either Python's pdb debugger (-d) or
54 profiler (-p). With all of these, %run can be used as the main tool for
54 profiler (-p). With all of these, %run can be used as the main tool for
55 efficient interactive development of code which you write in your editor of
55 efficient interactive development of code which you write in your editor of
56 choice.
56 choice.
57
57
58 Debug a Python script
58 Debug a Python script
59 ---------------------
59 ---------------------
60
60
61 Use the Python debugger, pdb. The %pdb command allows you to toggle on and off
61 Use the Python debugger, pdb. The %pdb command allows you to toggle on and off
62 the automatic invocation of an IPython-enhanced pdb debugger (with coloring,
62 the automatic invocation of an IPython-enhanced pdb debugger (with coloring,
63 tab completion and more) at any uncaught exception. The advantage of this is
63 tab completion and more) at any uncaught exception. The advantage of this is
64 that pdb starts inside the function where the exception occurred, with all data
64 that pdb starts inside the function where the exception occurred, with all data
65 still available. You can print variables, see code, execute statements and even
65 still available. You can print variables, see code, execute statements and even
66 walk up and down the call stack to track down the true source of the problem
66 walk up and down the call stack to track down the true source of the problem
67 (which often is many layers in the stack above where the exception gets
67 (which often is many layers in the stack above where the exception gets
68 triggered). Running programs with %run and pdb active can be an efficient to
68 triggered). Running programs with %run and pdb active can be an efficient to
69 develop and debug code, in many cases eliminating the need for print statements
69 develop and debug code, in many cases eliminating the need for print statements
70 or external debugging tools. I often simply put a 1/0 in a place where I want
70 or external debugging tools. I often simply put a 1/0 in a place where I want
71 to take a look so that pdb gets called, quickly view whatever variables I need
71 to take a look so that pdb gets called, quickly view whatever variables I need
72 to or test various pieces of code and then remove the 1/0. Note also that '%run
72 to or test various pieces of code and then remove the 1/0. Note also that '%run
73 -d' activates pdb and automatically sets initial breakpoints for you to step
73 -d' activates pdb and automatically sets initial breakpoints for you to step
74 through your code, watch variables, etc. The :ref:`output caching section
74 through your code, watch variables, etc. The :ref:`output caching section
75 <output_caching>` has more details.
75 <output_caching>` has more details.
76
76
77 Use the output cache
77 Use the output cache
78 --------------------
78 --------------------
79
79
80 All output results are automatically stored in a global dictionary named Out
80 All output results are automatically stored in a global dictionary named Out
81 and variables named _1, _2, etc. alias them. For example, the result of input
81 and variables named _1, _2, etc. alias them. For example, the result of input
82 line 4 is available either as Out[4] or as _4. Additionally, three variables
82 line 4 is available either as Out[4] or as _4. Additionally, three variables
83 named _, __ and ___ are always kept updated with the for the last three
83 named _, __ and ___ are always kept updated with the for the last three
84 results. This allows you to recall any previous result and further use it for
84 results. This allows you to recall any previous result and further use it for
85 new calculations. See :ref:`the output caching section <output_caching>` for
85 new calculations. See :ref:`the output caching section <output_caching>` for
86 more.
86 more.
87
87
88 Suppress output
88 Suppress output
89 ---------------
89 ---------------
90
90
91 Put a ';' at the end of a line to suppress the printing of output. This is
91 Put a ';' at the end of a line to suppress the printing of output. This is
92 useful when doing calculations which generate long output you are not
92 useful when doing calculations which generate long output you are not
93 interested in seeing. The _* variables and the Out[] list do get updated with
93 interested in seeing. The _* variables and the Out[] list do get updated with
94 the contents of the output, even if it is not printed. You can thus still
94 the contents of the output, even if it is not printed. You can thus still
95 access the generated results this way for further processing.
95 access the generated results this way for further processing.
96
96
97 Input cache
97 Input cache
98 -----------
98 -----------
99
99
100 A similar system exists for caching input. All input is stored in a global
100 A similar system exists for caching input. All input is stored in a global
101 list called In , so you can re-execute lines 22 through 28 plus line 34 by
101 list called In , so you can re-execute lines 22 through 28 plus line 34 by
102 typing 'exec In[22:29]+In[34]' (using Python slicing notation). If you need
102 typing 'exec In[22:29]+In[34]' (using Python slicing notation). If you need
103 to execute the same set of lines often, you can assign them to a macro with
103 to execute the same set of lines often, you can assign them to a macro with
104 the %macro function. See :ref:`here <input_caching>` for more.
104 the %macro function. See :ref:`here <input_caching>` for more.
105
105
106 Use your input history
106 Use your input history
107 ----------------------
107 ----------------------
108
108
109 The %hist command can show you all previous input, without line numbers if
109 The %hist command can show you all previous input, without line numbers if
110 desired (option -n) so you can directly copy and paste code either back in
110 desired (option -n) so you can directly copy and paste code either back in
111 IPython or in a text editor. You can also save all your history by turning on
111 IPython or in a text editor. You can also save all your history by turning on
112 logging via %logstart; these logs can later be either reloaded as IPython
112 logging via %logstart; these logs can later be either reloaded as IPython
113 sessions or used as code for your programs.
113 sessions or used as code for your programs.
114
114
115 Define your own system aliases
115 Define your own system aliases
116 ------------------------------
116 ------------------------------
117
117
118 Even though IPython gives you access to your system shell via the ! prefix,
118 Even though IPython gives you access to your system shell via the ! prefix,
119 it is convenient to have aliases to the system commands you use most often.
119 it is convenient to have aliases to the system commands you use most often.
120 This allows you to work seamlessly from inside IPython with the same commands
120 This allows you to work seamlessly from inside IPython with the same commands
121 you are used to in your system shell. IPython comes with some pre-defined
121 you are used to in your system shell. IPython comes with some pre-defined
122 aliases and a complete system for changing directories, both via a stack (see
122 aliases and a complete system for changing directories, both via a stack (see
123 %pushd, %popd and %dhist) and via direct %cd. The latter keeps a history of
123 %pushd, %popd and %dhist) and via direct %cd. The latter keeps a history of
124 visited directories and allows you to go to any previously visited one.
124 visited directories and allows you to go to any previously visited one.
125
125
126 Call system shell commands
126 Call system shell commands
127 --------------------------
127 --------------------------
128
128
129 Use Python to manipulate the results of system commands. The '!!' special
129 Use Python to manipulate the results of system commands. The '!!' special
130 syntax, and the %sc and %sx magic commands allow you to capture system output
130 syntax, and the %sc and %sx magic commands allow you to capture system output
131 into Python variables.
131 into Python variables.
132
132
133 Use Python variables when calling the shell
133 Use Python variables when calling the shell
134 -------------------------------------------
134 -------------------------------------------
135
135
136 Expand python variables when calling the shell (either via '!' and '!!' or via
136 Expand python variables when calling the shell (either via '!' and '!!' or via
137 aliases) by prepending a $ in front of them. You can also expand complete
137 aliases) by prepending a $ in front of them. You can also expand complete
138 python expressions. See :ref:`our shell section <system_shell_access>` for
138 python expressions. See :ref:`our shell section <system_shell_access>` for
139 more details.
139 more details.
140
140
141 Use profiles
141 Use profiles
142 ------------
142 ------------
143
143
144 Use profiles to maintain different configurations (modules to load, function
144 Use profiles to maintain different configurations (modules to load, function
145 definitions, option settings) for particular tasks. You can then have
145 definitions, option settings) for particular tasks. You can then have
146 customized versions of IPython for specific purposes. :ref:`This section
146 customized versions of IPython for specific purposes. :ref:`This section
147 <profiles>` has more details.
147 <profiles>` has more details.
148
148
149
149
150 Embed IPython in your programs
150 Embed IPython in your programs
151 ------------------------------
151 ------------------------------
152
152
153 A few lines of code are enough to load a complete IPython inside your own
153 A few lines of code are enough to load a complete IPython inside your own
154 programs, giving you the ability to work with your data interactively after
154 programs, giving you the ability to work with your data interactively after
155 automatic processing has been completed. See :ref:`here <embedding>` for more.
155 automatic processing has been completed. See :ref:`here <embedding>` for more.
156
156
157 Use the Python profiler
157 Use the Python profiler
158 -----------------------
158 -----------------------
159
159
160 When dealing with performance issues, the %run command with a -p option
160 When dealing with performance issues, the %run command with a -p option
161 allows you to run complete programs under the control of the Python profiler.
161 allows you to run complete programs under the control of the Python profiler.
162 The %prun command does a similar job for single Python expressions (like
162 The %prun command does a similar job for single Python expressions (like
163 function calls).
163 function calls).
164
164
165 Use IPython to present interactive demos
165 Use IPython to present interactive demos
166 ----------------------------------------
166 ----------------------------------------
167
167
168 Use the IPython.demo.Demo class to load any Python script as an interactive
168 Use the IPython.demo.Demo class to load any Python script as an interactive
169 demo. With a minimal amount of simple markup, you can control the execution of
169 demo. With a minimal amount of simple markup, you can control the execution of
170 the script, stopping as needed. See :ref:`here <interactive_demos>` for more.
170 the script, stopping as needed. See :ref:`here <interactive_demos>` for more.
171
171
172 Run doctests
172 Run doctests
173 ------------
173 ------------
174
174
175 Run your doctests from within IPython for development and debugging. The
175 Run your doctests from within IPython for development and debugging. The
176 special %doctest_mode command toggles a mode where the prompt, output and
176 special %doctest_mode command toggles a mode where the prompt, output and
177 exceptions display matches as closely as possible that of the default Python
177 exceptions display matches as closely as possible that of the default Python
178 interpreter. In addition, this mode allows you to directly paste in code that
178 interpreter. In addition, this mode allows you to directly paste in code that
179 contains leading '>>>' prompts, even if they have extra leading whitespace
179 contains leading '>>>' prompts, even if they have extra leading whitespace
180 (as is common in doctest files). This combined with the '%history -tn' call
180 (as is common in doctest files). This combined with the '%history -tn' call
181 to see your translated history (with these extra prompts removed and no line
181 to see your translated history (with these extra prompts removed and no line
182 numbers) allows for an easy doctest workflow, where you can go from doctest
182 numbers) allows for an easy doctest workflow, where you can go from doctest
183 to interactive execution to pasting into valid Python code as needed.
183 to interactive execution to pasting into valid Python code as needed.
184
184
185 Source code handling tips
185 Source code handling tips
186 =========================
186 =========================
187
187
188 IPython is a line-oriented program, without full control of the
188 IPython is a line-oriented program, without full control of the
189 terminal. Therefore, it doesn't support true multiline editing. However,
189 terminal. Therefore, it doesn't support true multiline editing. However,
190 it has a number of useful tools to help you in dealing effectively with
190 it has a number of useful tools to help you in dealing effectively with
191 more complex editing.
191 more complex editing.
192
192
193 The %edit command gives a reasonable approximation of multiline editing,
193 The %edit command gives a reasonable approximation of multiline editing,
194 by invoking your favorite editor on the spot. IPython will execute the
194 by invoking your favorite editor on the spot. IPython will execute the
195 code you type in there as if it were typed interactively. Type %edit?
195 code you type in there as if it were typed interactively. Type %edit?
196 for the full details on the edit command.
196 for the full details on the edit command.
197
197
198 If you have typed various commands during a session, which you'd like to
198 If you have typed various commands during a session, which you'd like to
199 reuse, IPython provides you with a number of tools. Start by using %hist
199 reuse, IPython provides you with a number of tools. Start by using %hist
200 to see your input history, so you can see the line numbers of all input.
200 to see your input history, so you can see the line numbers of all input.
201 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
201 Let us say that you'd like to reuse lines 10 through 20, plus lines 24
202 and 28. All the commands below can operate on these with the syntax::
202 and 28. All the commands below can operate on these with the syntax::
203
203
204 %command 10-20 24 28
204 %command 10-20 24 28
205
205
206 where the command given can be:
206 where the command given can be:
207
207
208 * %macro <macroname>: this stores the lines into a variable which,
208 * %macro <macroname>: this stores the lines into a variable which,
209 when called at the prompt, re-executes the input. Macros can be
209 when called at the prompt, re-executes the input. Macros can be
210 edited later using '%edit macroname', and they can be stored
210 edited later using '%edit macroname', and they can be stored
211 persistently across sessions with '%store macroname' (the storage
211 persistently across sessions with '%store macroname' (the storage
212 system is per-profile). The combination of quick macros,
212 system is per-profile). The combination of quick macros,
213 persistent storage and editing, allows you to easily refine
213 persistent storage and editing, allows you to easily refine
214 quick-and-dirty interactive input into permanent utilities, always
214 quick-and-dirty interactive input into permanent utilities, always
215 available both in IPython and as files for general reuse.
215 available both in IPython and as files for general reuse.
216 * %edit: this will open a text editor with those lines pre-loaded
216 * %edit: this will open a text editor with those lines pre-loaded
217 for further modification. It will then execute the resulting
217 for further modification. It will then execute the resulting
218 file's contents as if you had typed it at the prompt.
218 file's contents as if you had typed it at the prompt.
219 * %save <filename>: this saves the lines directly to a named file on
219 * %save <filename>: this saves the lines directly to a named file on
220 disk.
220 disk.
221
221
222 While %macro saves input lines into memory for interactive re-execution,
222 While %macro saves input lines into memory for interactive re-execution,
223 sometimes you'd like to save your input directly to a file. The %save
223 sometimes you'd like to save your input directly to a file. The %save
224 magic does this: its input sytnax is the same as %macro, but it saves
224 magic does this: its input sytnax is the same as %macro, but it saves
225 your input directly to a Python file. Note that the %logstart command
225 your input directly to a Python file. Note that the %logstart command
226 also saves input, but it logs all input to disk (though you can
226 also saves input, but it logs all input to disk (though you can
227 temporarily suspend it and reactivate it with %logoff/%logon); %save
227 temporarily suspend it and reactivate it with %logoff/%logon); %save
228 allows you to select which lines of input you need to save.
228 allows you to select which lines of input you need to save.
229
229
230
230
231 Lightweight 'version control'
231 Lightweight 'version control'
232 =============================
232 =============================
233
233
234 When you call %edit with no arguments, IPython opens an empty editor
234 When you call %edit with no arguments, IPython opens an empty editor
235 with a temporary file, and it returns the contents of your editing
235 with a temporary file, and it returns the contents of your editing
236 session as a string variable. Thanks to IPython's output caching
236 session as a string variable. Thanks to IPython's output caching
237 mechanism, this is automatically stored::
237 mechanism, this is automatically stored::
238
238
239 In [1]: %edit
239 In [1]: %edit
240
240
241 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
241 IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py
242
242
243 Editing... done. Executing edited code...
243 Editing... done. Executing edited code...
244
244
245 hello - this is a temporary file
245 hello - this is a temporary file
246
246
247 Out[1]: "print 'hello - this is a temporary file'\n"
247 Out[1]: "print 'hello - this is a temporary file'\n"
248
248
249 Now, if you call '%edit -p', IPython tries to open an editor with the
249 Now, if you call '%edit -p', IPython tries to open an editor with the
250 same data as the last time you used %edit. So if you haven't used %edit
250 same data as the last time you used %edit. So if you haven't used %edit
251 in the meantime, this same contents will reopen; however, it will be
251 in the meantime, this same contents will reopen; however, it will be
252 done in a new file. This means that if you make changes and you later
252 done in a new file. This means that if you make changes and you later
253 want to find an old version, you can always retrieve it by using its
253 want to find an old version, you can always retrieve it by using its
254 output number, via '%edit _NN', where NN is the number of the output
254 output number, via '%edit _NN', where NN is the number of the output
255 prompt.
255 prompt.
256
256
257 Continuing with the example above, this should illustrate this idea::
257 Continuing with the example above, this should illustrate this idea::
258
258
259 In [2]: edit -p
259 In [2]: edit -p
260
260
261 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
261 IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py
262
262
263 Editing... done. Executing edited code...
263 Editing... done. Executing edited code...
264
264
265 hello - now I made some changes
265 hello - now I made some changes
266
266
267 Out[2]: "print 'hello - now I made some changes'\n"
267 Out[2]: "print 'hello - now I made some changes'\n"
268
268
269 In [3]: edit _1
269 In [3]: edit _1
270
270
271 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
271 IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py
272
272
273 Editing... done. Executing edited code...
273 Editing... done. Executing edited code...
274
274
275 hello - this is a temporary file
275 hello - this is a temporary file
276
276
277 IPython version control at work :)
277 IPython version control at work :)
278
278
279 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
279 Out[3]: "print 'hello - this is a temporary file'\nprint 'IPython version control at work :)'\n"
280
280
281
281
282 This section was written after a contribution by Alexander Belchenko on
282 This section was written after a contribution by Alexander Belchenko on
283 the IPython user list.
283 the IPython user list.
284
284
285
285
286 Effective logging
286 Effective logging
287 =================
287 =================
288
288
289 A very useful suggestion sent in by Robert Kern follows:
289 A very useful suggestion sent in by Robert Kern follows:
290
290
291 I recently happened on a nifty way to keep tidy per-project log files. I
291 I recently happened on a nifty way to keep tidy per-project log files. I
292 made a profile for my project (which is called "parkfield")::
292 made a profile for my project (which is called "parkfield")::
293
293
294 include ipythonrc
294 include ipythonrc
295
295
296 # cancel earlier logfile invocation:
296 # cancel earlier logfile invocation:
297
297
298 logfile ''
298 logfile ''
299
299
300 execute import time
300 execute import time
301
301
302 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
302 execute __cmd = '/Users/kern/research/logfiles/parkfield-%s.log rotate'
303
303
304 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
304 execute __IP.magic_logstart(__cmd % time.strftime('%Y-%m-%d'))
305
305
306 I also added a shell alias for convenience::
306 I also added a shell alias for convenience::
307
307
308 alias parkfield="ipython -pylab -profile parkfield"
308 alias parkfield="ipython -pylab -profile parkfield"
309
309
310 Now I have a nice little directory with everything I ever type in,
310 Now I have a nice little directory with everything I ever type in,
311 organized by project and date.
311 organized by project and date.
312
312
313 Contribute your own: If you have your own favorite tip on using IPython
313 Contribute your own: If you have your own favorite tip on using IPython
314 efficiently for a certain task (especially things which can't be done in
314 efficiently for a certain task (especially things which can't be done in
315 the normal Python interpreter), don't hesitate to send it!
315 the normal Python interpreter), don't hesitate to send it!
316
317
@@ -1,232 +1,234 b''
1 .. _overview:
1 .. _overview:
2
2
3 ============
3 ============
4 Introduction
4 Introduction
5 ============
5 ============
6
6
7 Overview
7 Overview
8 ========
8 ========
9
9
10 One of Python's most useful features is its interactive interpreter.
10 One of Python's most useful features is its interactive interpreter.
11 This system allows very fast testing of ideas without the overhead of
11 This system allows very fast testing of ideas without the overhead of
12 creating test files as is typical in most programming languages.
12 creating test files as is typical in most programming languages.
13 However, the interpreter supplied with the standard Python distribution
13 However, the interpreter supplied with the standard Python distribution
14 is somewhat limited for extended interactive use.
14 is somewhat limited for extended interactive use.
15
15
16 The goal of IPython is to create a comprehensive environment for
16 The goal of IPython is to create a comprehensive environment for
17 interactive and exploratory computing. To support this goal, IPython
17 interactive and exploratory computing. To support this goal, IPython
18 has two main components:
18 has two main components:
19
19
20 * An enhanced interactive Python shell.
20 * An enhanced interactive Python shell.
21 * An architecture for interactive parallel computing.
21 * An architecture for interactive parallel computing.
22
22
23 All of IPython is open source (released under the revised BSD license).
23 All of IPython is open source (released under the revised BSD license).
24
24
25 Enhanced interactive Python shell
25 Enhanced interactive Python shell
26 =================================
26 =================================
27
27
28 IPython's interactive shell (:command:`ipython`), has the following goals,
28 IPython's interactive shell (:command:`ipython`), has the following goals,
29 amongst others:
29 amongst others:
30
30
31 1. Provide an interactive shell superior to Python's default. IPython
31 1. Provide an interactive shell superior to Python's default. IPython
32 has many features for object introspection, system shell access,
32 has many features for object introspection, system shell access,
33 and its own special command system for adding functionality when
33 and its own special command system for adding functionality when
34 working interactively. It tries to be a very efficient environment
34 working interactively. It tries to be a very efficient environment
35 both for Python code development and for exploration of problems
35 both for Python code development and for exploration of problems
36 using Python objects (in situations like data analysis).
36 using Python objects (in situations like data analysis).
37
37
38 2. Serve as an embeddable, ready to use interpreter for your own
38 2. Serve as an embeddable, ready to use interpreter for your own
39 programs. IPython can be started with a single call from inside
39 programs. IPython can be started with a single call from inside
40 another program, providing access to the current namespace. This
40 another program, providing access to the current namespace. This
41 can be very useful both for debugging purposes and for situations
41 can be very useful both for debugging purposes and for situations
42 where a blend of batch-processing and interactive exploration are
42 where a blend of batch-processing and interactive exploration are
43 needed. New in the 0.9 version of IPython is a reusable wxPython
43 needed. New in the 0.9 version of IPython is a reusable wxPython
44 based IPython widget.
44 based IPython widget.
45
45
46 3. Offer a flexible framework which can be used as the base
46 3. Offer a flexible framework which can be used as the base
47 environment for other systems with Python as the underlying
47 environment for other systems with Python as the underlying
48 language. Specifically scientific environments like Mathematica,
48 language. Specifically scientific environments like Mathematica,
49 IDL and Matlab inspired its design, but similar ideas can be
49 IDL and Matlab inspired its design, but similar ideas can be
50 useful in many fields.
50 useful in many fields.
51
51
52 4. Allow interactive testing of threaded graphical toolkits. IPython
52 4. Allow interactive testing of threaded graphical toolkits. IPython
53 has support for interactive, non-blocking control of GTK, Qt and
53 has support for interactive, non-blocking control of GTK, Qt and
54 WX applications via special threading flags. The normal Python
54 WX applications via special threading flags. The normal Python
55 shell can only do this for Tkinter applications.
55 shell can only do this for Tkinter applications.
56
56
57 Main features of the interactive shell
57 Main features of the interactive shell
58 --------------------------------------
58 --------------------------------------
59
59
60 * Dynamic object introspection. One can access docstrings, function
60 * Dynamic object introspection. One can access docstrings, function
61 definition prototypes, source code, source files and other details
61 definition prototypes, source code, source files and other details
62 of any object accessible to the interpreter with a single
62 of any object accessible to the interpreter with a single
63 keystroke (:samp:`?`, and using :samp:`??` provides additional detail).
63 keystroke (:samp:`?`, and using :samp:`??` provides additional detail).
64
64
65 * Searching through modules and namespaces with :samp:`*` wildcards, both
65 * Searching through modules and namespaces with :samp:`*` wildcards, both
66 when using the :samp:`?` system and via the :samp:`%psearch` command.
66 when using the :samp:`?` system and via the :samp:`%psearch` command.
67
67
68 * Completion in the local namespace, by typing :kbd:`TAB` at the prompt.
68 * Completion in the local namespace, by typing :kbd:`TAB` at the prompt.
69 This works for keywords, modules, methods, variables and files in the
69 This works for keywords, modules, methods, variables and files in the
70 current directory. This is supported via the readline library, and
70 current directory. This is supported via the readline library, and
71 full access to configuring readline's behavior is provided.
71 full access to configuring readline's behavior is provided.
72 Custom completers can be implemented easily for different purposes
72 Custom completers can be implemented easily for different purposes
73 (system commands, magic arguments etc.)
73 (system commands, magic arguments etc.)
74
74
75 * Numbered input/output prompts with command history (persistent
75 * Numbered input/output prompts with command history (persistent
76 across sessions and tied to each profile), full searching in this
76 across sessions and tied to each profile), full searching in this
77 history and caching of all input and output.
77 history and caching of all input and output.
78
78
79 * User-extensible 'magic' commands. A set of commands prefixed with
79 * User-extensible 'magic' commands. A set of commands prefixed with
80 :samp:`%` is available for controlling IPython itself and provides
80 :samp:`%` is available for controlling IPython itself and provides
81 directory control, namespace information and many aliases to
81 directory control, namespace information and many aliases to
82 common system shell commands.
82 common system shell commands.
83
83
84 * Alias facility for defining your own system aliases.
84 * Alias facility for defining your own system aliases.
85
85
86 * Complete system shell access. Lines starting with :samp:`!` are passed
86 * Complete system shell access. Lines starting with :samp:`!` are passed
87 directly to the system shell, and using :samp:`!!` or :samp:`var = !cmd`
87 directly to the system shell, and using :samp:`!!` or :samp:`var = !cmd`
88 captures shell output into python variables for further use.
88 captures shell output into python variables for further use.
89
89
90 * Background execution of Python commands in a separate thread.
90 * Background execution of Python commands in a separate thread.
91 IPython has an internal job manager called jobs, and a
91 IPython has an internal job manager called jobs, and a
92 convenience backgrounding magic function called :samp:`%bg`.
92 convenience backgrounding magic function called :samp:`%bg`.
93
93
94 * The ability to expand python variables when calling the system shell. In a
94 * The ability to expand python variables when calling the system shell. In a
95 shell command, any python variable prefixed with :samp:`$` is expanded. A
95 shell command, any python variable prefixed with :samp:`$` is expanded. A
96 double :samp:`$$` allows passing a literal :samp:`$` to the shell (for access
96 double :samp:`$$` allows passing a literal :samp:`$` to the shell (for access
97 to shell and environment variables like :envvar:`PATH`).
97 to shell and environment variables like :envvar:`PATH`).
98
98
99 * Filesystem navigation, via a magic :samp:`%cd` command, along with a
99 * Filesystem navigation, via a magic :samp:`%cd` command, along with a
100 persistent bookmark system (using :samp:`%bookmark`) for fast access to
100 persistent bookmark system (using :samp:`%bookmark`) for fast access to
101 frequently visited directories.
101 frequently visited directories.
102
102
103 * A lightweight persistence framework via the :samp:`%store` command, which
103 * A lightweight persistence framework via the :samp:`%store` command, which
104 allows you to save arbitrary Python variables. These get restored
104 allows you to save arbitrary Python variables. These get restored
105 automatically when your session restarts.
105 automatically when your session restarts.
106
106
107 * Automatic indentation (optional) of code as you type (through the
107 * Automatic indentation (optional) of code as you type (through the
108 readline library).
108 readline library).
109
109
110 * Macro system for quickly re-executing multiple lines of previous
110 * Macro system for quickly re-executing multiple lines of previous
111 input with a single name. Macros can be stored persistently via
111 input with a single name. Macros can be stored persistently via
112 :samp:`%store` and edited via :samp:`%edit`.
112 :samp:`%store` and edited via :samp:`%edit`.
113
113
114 * Session logging (you can then later use these logs as code in your
114 * Session logging (you can then later use these logs as code in your
115 programs). Logs can optionally timestamp all input, and also store
115 programs). Logs can optionally timestamp all input, and also store
116 session output (marked as comments, so the log remains valid
116 session output (marked as comments, so the log remains valid
117 Python source code).
117 Python source code).
118
118
119 * Session restoring: logs can be replayed to restore a previous
119 * Session restoring: logs can be replayed to restore a previous
120 session to the state where you left it.
120 session to the state where you left it.
121
121
122 * Verbose and colored exception traceback printouts. Easier to parse
122 * Verbose and colored exception traceback printouts. Easier to parse
123 visually, and in verbose mode they produce a lot of useful
123 visually, and in verbose mode they produce a lot of useful
124 debugging information (basically a terminal version of the cgitb
124 debugging information (basically a terminal version of the cgitb
125 module).
125 module).
126
126
127 * Auto-parentheses: callable objects can be executed without
127 * Auto-parentheses: callable objects can be executed without
128 parentheses: :samp:`sin 3` is automatically converted to :samp:`sin(3)`.
128 parentheses: :samp:`sin 3` is automatically converted to :samp:`sin(3)`.
129
129
130 * Auto-quoting: using :samp:`,`, or :samp:`;` as the first character forces
130 * Auto-quoting: using :samp:`,`, or :samp:`;` as the first character forces
131 auto-quoting of the rest of the line: :samp:`,my_function a b` becomes
131 auto-quoting of the rest of the line: :samp:`,my_function a b` becomes
132 automatically :samp:`my_function("a","b")`, while :samp:`;my_function a b`
132 automatically :samp:`my_function("a","b")`, while :samp:`;my_function a b`
133 becomes :samp:`my_function("a b")`.
133 becomes :samp:`my_function("a b")`.
134
134
135 * Extensible input syntax. You can define filters that pre-process
135 * Extensible input syntax. You can define filters that pre-process
136 user input to simplify input in special situations. This allows
136 user input to simplify input in special situations. This allows
137 for example pasting multi-line code fragments which start with
137 for example pasting multi-line code fragments which start with
138 :samp:`>>>` or :samp:`...` such as those from other python sessions or the
138 :samp:`>>>` or :samp:`...` such as those from other python sessions or the
139 standard Python documentation.
139 standard Python documentation.
140
140
141 * Flexible configuration system. It uses a configuration file which
141 * Flexible configuration system. It uses a configuration file which
142 allows permanent setting of all command-line options, module
142 allows permanent setting of all command-line options, module
143 loading, code and file execution. The system allows recursive file
143 loading, code and file execution. The system allows recursive file
144 inclusion, so you can have a base file with defaults and layers
144 inclusion, so you can have a base file with defaults and layers
145 which load other customizations for particular projects.
145 which load other customizations for particular projects.
146
146
147 * Embeddable. You can call IPython as a python shell inside your own
147 * Embeddable. You can call IPython as a python shell inside your own
148 python programs. This can be used both for debugging code or for
148 python programs. This can be used both for debugging code or for
149 providing interactive abilities to your programs with knowledge
149 providing interactive abilities to your programs with knowledge
150 about the local namespaces (very useful in debugging and data
150 about the local namespaces (very useful in debugging and data
151 analysis situations).
151 analysis situations).
152
152
153 * Easy debugger access. You can set IPython to call up an enhanced version of
153 * Easy debugger access. You can set IPython to call up an enhanced version of
154 the Python debugger (pdb) every time there is an uncaught exception. This
154 the Python debugger (pdb) every time there is an uncaught exception. This
155 drops you inside the code which triggered the exception with all the data
155 drops you inside the code which triggered the exception with all the data
156 live and it is possible to navigate the stack to rapidly isolate the source
156 live and it is possible to navigate the stack to rapidly isolate the source
157 of a bug. The :samp:`%run` magic command (with the :samp:`-d` option) can run
157 of a bug. The :samp:`%run` magic command (with the :samp:`-d` option) can run
158 any script under pdb's control, automatically setting initial breakpoints for
158 any script under pdb's control, automatically setting initial breakpoints for
159 you. This version of pdb has IPython-specific improvements, including
159 you. This version of pdb has IPython-specific improvements, including
160 tab-completion and traceback coloring support. For even easier debugger
160 tab-completion and traceback coloring support. For even easier debugger
161 access, try :samp:`%debug` after seeing an exception. winpdb is also
161 access, try :samp:`%debug` after seeing an exception. winpdb is also
162 supported, see ipy_winpdb extension.
162 supported, see ipy_winpdb extension.
163
163
164 * Profiler support. You can run single statements (similar to
164 * Profiler support. You can run single statements (similar to
165 :samp:`profile.run()`) or complete programs under the profiler's control.
165 :samp:`profile.run()`) or complete programs under the profiler's control.
166 While this is possible with standard cProfile or profile modules,
166 While this is possible with standard cProfile or profile modules,
167 IPython wraps this functionality with magic commands (see :samp:`%prun`
167 IPython wraps this functionality with magic commands (see :samp:`%prun`
168 and :samp:`%run -p`) convenient for rapid interactive work.
168 and :samp:`%run -p`) convenient for rapid interactive work.
169
169
170 * Doctest support. The special :samp:`%doctest_mode` command toggles a mode
170 * Doctest support. The special :samp:`%doctest_mode` command toggles a mode
171 that allows you to paste existing doctests (with leading :samp:`>>>`
171 that allows you to paste existing doctests (with leading :samp:`>>>`
172 prompts and whitespace) and uses doctest-compatible prompts and
172 prompts and whitespace) and uses doctest-compatible prompts and
173 output, so you can use IPython sessions as doctest code.
173 output, so you can use IPython sessions as doctest code.
174
174
175 Interactive parallel computing
175 Interactive parallel computing
176 ==============================
176 ==============================
177
177
178 Increasingly, parallel computer hardware, such as multicore CPUs, clusters and
178 Increasingly, parallel computer hardware, such as multicore CPUs, clusters and
179 supercomputers, is becoming ubiquitous. Over the last 3 years, we have
179 supercomputers, is becoming ubiquitous. Over the last 3 years, we have
180 developed an architecture within IPython that allows such hardware to be used
180 developed an architecture within IPython that allows such hardware to be used
181 quickly and easily from Python. Moreover, this architecture is designed to
181 quickly and easily from Python. Moreover, this architecture is designed to
182 support interactive and collaborative parallel computing.
182 support interactive and collaborative parallel computing.
183
183
184 The main features of this system are:
184 The main features of this system are:
185
185
186 * Quickly parallelize Python code from an interactive Python/IPython session.
186 * Quickly parallelize Python code from an interactive Python/IPython session.
187
187
188 * A flexible and dynamic process model that be deployed on anything from
188 * A flexible and dynamic process model that be deployed on anything from
189 multicore workstations to supercomputers.
189 multicore workstations to supercomputers.
190
190
191 * An architecture that supports many different styles of parallelism, from
191 * An architecture that supports many different styles of parallelism, from
192 message passing to task farming. And all of these styles can be handled
192 message passing to task farming. And all of these styles can be handled
193 interactively.
193 interactively.
194
194
195 * Both blocking and fully asynchronous interfaces.
195 * Both blocking and fully asynchronous interfaces.
196
196
197 * High level APIs that enable many things to be parallelized in a few lines
197 * High level APIs that enable many things to be parallelized in a few lines
198 of code.
198 of code.
199
199
200 * Write parallel code that will run unchanged on everything from multicore
200 * Write parallel code that will run unchanged on everything from multicore
201 workstations to supercomputers.
201 workstations to supercomputers.
202
202
203 * Full integration with Message Passing libraries (MPI).
203 * Full integration with Message Passing libraries (MPI).
204
204
205 * Capabilities based security model with full encryption of network connections.
205 * Capabilities based security model with full encryption of network connections.
206
206
207 * Share live parallel jobs with other users securely. We call this
207 * Share live parallel jobs with other users securely. We call this
208 collaborative parallel computing.
208 collaborative parallel computing.
209
209
210 * Dynamically load balanced task farming system.
210 * Dynamically load balanced task farming system.
211
211
212 * Robust error handling. Python exceptions raised in parallel execution are
212 * Robust error handling. Python exceptions raised in parallel execution are
213 gathered and presented to the top-level code.
213 gathered and presented to the top-level code.
214
214
215 For more information, see our :ref:`overview <parallel_index>` of using IPython
215 For more information, see our :ref:`overview <parallel_index>` of using IPython
216 for parallel computing.
216 for parallel computing.
217
217
218 Portability and Python requirements
218 Portability and Python requirements
219 -----------------------------------
219 -----------------------------------
220
220
221 As of the 0.9 release, IPython requires Python 2.4 or greater. We have
221 As of the 0.11 release, IPython works with either Python 2.5 or 2.6.
222 not begun to test IPython on Python 2.6 or 3.0, but we expect it will
222 Versions 0.9 and 0.10 worked with Python 2.4 as well. We have not begun
223 work with some minor changes.
223 the test and port IPython to 3.0. Our plan is to gradually drop Python 2.5
224 support and then begin the transition to strict 2.6 and 3.0.
224
225
225 IPython is known to work on the following operating systems:
226 IPython is known to work on the following operating systems:
226
227
227 * Linux
228 * Linux
228 * Most other Unix-like OSs (AIX, Solaris, BSD, etc.)
229 * Most other Unix-like OSs (AIX, Solaris, BSD, etc.)
229 * Mac OS X
230 * Mac OS X
230 * Windows (CygWin, XP, Vista, etc.)
231 * Windows (CygWin, XP, Vista, etc.)
231
232
232 See :ref:`here <install_index>` for instructions on how to install IPython. No newline at end of file
233 See :ref:`here <install_index>` for instructions on how to install IPython.
234
@@ -1,15 +1,17 b''
1 .. _parallel_index:
1 .. _parallel_index:
2
2
3 ====================================
3 ====================================
4 Using IPython for parallel computing
4 Using IPython for parallel computing
5 ====================================
5 ====================================
6
6
7 .. toctree::
7 .. toctree::
8 :maxdepth: 2
8 :maxdepth: 2
9
9
10 parallel_intro.txt
10 parallel_intro.txt
11 parallel_process.txt
11 parallel_process.txt
12 parallel_multiengine.txt
12 parallel_multiengine.txt
13 parallel_task.txt
13 parallel_task.txt
14 parallel_mpi.txt
14 parallel_mpi.txt
15 parallel_security.txt
15 parallel_security.txt
16
17
@@ -1,176 +1,178 b''
1 .. _parallelmpi:
1 .. _parallelmpi:
2
2
3 =======================
3 =======================
4 Using MPI with IPython
4 Using MPI with IPython
5 =======================
5 =======================
6
6
7 Often, a parallel algorithm will require moving data between the engines. One
7 Often, a parallel algorithm will require moving data between the engines. One
8 way of accomplishing this is by doing a pull and then a push using the
8 way of accomplishing this is by doing a pull and then a push using the
9 multiengine client. However, this will be slow as all the data has to go
9 multiengine client. However, this will be slow as all the data has to go
10 through the controller to the client and then back through the controller, to
10 through the controller to the client and then back through the controller, to
11 its final destination.
11 its final destination.
12
12
13 A much better way of moving data between engines is to use a message passing
13 A much better way of moving data between engines is to use a message passing
14 library, such as the Message Passing Interface (MPI) [MPI]_. IPython's
14 library, such as the Message Passing Interface (MPI) [MPI]_. IPython's
15 parallel computing architecture has been designed from the ground up to
15 parallel computing architecture has been designed from the ground up to
16 integrate with MPI. This document describes how to use MPI with IPython.
16 integrate with MPI. This document describes how to use MPI with IPython.
17
17
18 Additional installation requirements
18 Additional installation requirements
19 ====================================
19 ====================================
20
20
21 If you want to use MPI with IPython, you will need to install:
21 If you want to use MPI with IPython, you will need to install:
22
22
23 * A standard MPI implementation such as OpenMPI [OpenMPI]_ or MPICH.
23 * A standard MPI implementation such as OpenMPI [OpenMPI]_ or MPICH.
24 * The mpi4py [mpi4py]_ package.
24 * The mpi4py [mpi4py]_ package.
25
25
26 .. note::
26 .. note::
27
27
28 The mpi4py package is not a strict requirement. However, you need to
28 The mpi4py package is not a strict requirement. However, you need to
29 have *some* way of calling MPI from Python. You also need some way of
29 have *some* way of calling MPI from Python. You also need some way of
30 making sure that :func:`MPI_Init` is called when the IPython engines start
30 making sure that :func:`MPI_Init` is called when the IPython engines start
31 up. There are a number of ways of doing this and a good number of
31 up. There are a number of ways of doing this and a good number of
32 associated subtleties. We highly recommend just using mpi4py as it
32 associated subtleties. We highly recommend just using mpi4py as it
33 takes care of most of these problems. If you want to do something
33 takes care of most of these problems. If you want to do something
34 different, let us know and we can help you get started.
34 different, let us know and we can help you get started.
35
35
36 Starting the engines with MPI enabled
36 Starting the engines with MPI enabled
37 =====================================
37 =====================================
38
38
39 To use code that calls MPI, there are typically two things that MPI requires.
39 To use code that calls MPI, there are typically two things that MPI requires.
40
40
41 1. The process that wants to call MPI must be started using
41 1. The process that wants to call MPI must be started using
42 :command:`mpiexec` or a batch system (like PBS) that has MPI support.
42 :command:`mpiexec` or a batch system (like PBS) that has MPI support.
43 2. Once the process starts, it must call :func:`MPI_Init`.
43 2. Once the process starts, it must call :func:`MPI_Init`.
44
44
45 There are a couple of ways that you can start the IPython engines and get
45 There are a couple of ways that you can start the IPython engines and get
46 these things to happen.
46 these things to happen.
47
47
48 Automatic starting using :command:`mpiexec` and :command:`ipcluster`
48 Automatic starting using :command:`mpiexec` and :command:`ipcluster`
49 --------------------------------------------------------------------
49 --------------------------------------------------------------------
50
50
51 The easiest approach is to use the `mpiexec` mode of :command:`ipcluster`,
51 The easiest approach is to use the `mpiexec` mode of :command:`ipcluster`,
52 which will first start a controller and then a set of engines using
52 which will first start a controller and then a set of engines using
53 :command:`mpiexec`::
53 :command:`mpiexec`::
54
54
55 $ ipcluster mpiexec -n 4
55 $ ipcluster mpiexec -n 4
56
56
57 This approach is best as interrupting :command:`ipcluster` will automatically
57 This approach is best as interrupting :command:`ipcluster` will automatically
58 stop and clean up the controller and engines.
58 stop and clean up the controller and engines.
59
59
60 Manual starting using :command:`mpiexec`
60 Manual starting using :command:`mpiexec`
61 ----------------------------------------
61 ----------------------------------------
62
62
63 If you want to start the IPython engines using the :command:`mpiexec`, just
63 If you want to start the IPython engines using the :command:`mpiexec`, just
64 do::
64 do::
65
65
66 $ mpiexec -n 4 ipengine --mpi=mpi4py
66 $ mpiexec -n 4 ipengine --mpi=mpi4py
67
67
68 This requires that you already have a controller running and that the FURL
68 This requires that you already have a controller running and that the FURL
69 files for the engines are in place. We also have built in support for
69 files for the engines are in place. We also have built in support for
70 PyTrilinos [PyTrilinos]_, which can be used (assuming is installed) by
70 PyTrilinos [PyTrilinos]_, which can be used (assuming is installed) by
71 starting the engines with::
71 starting the engines with::
72
72
73 mpiexec -n 4 ipengine --mpi=pytrilinos
73 mpiexec -n 4 ipengine --mpi=pytrilinos
74
74
75 Automatic starting using PBS and :command:`ipcluster`
75 Automatic starting using PBS and :command:`ipcluster`
76 -----------------------------------------------------
76 -----------------------------------------------------
77
77
78 The :command:`ipcluster` command also has built-in integration with PBS. For
78 The :command:`ipcluster` command also has built-in integration with PBS. For
79 more information on this approach, see our documentation on :ref:`ipcluster
79 more information on this approach, see our documentation on :ref:`ipcluster
80 <parallel_process>`.
80 <parallel_process>`.
81
81
82 Actually using MPI
82 Actually using MPI
83 ==================
83 ==================
84
84
85 Once the engines are running with MPI enabled, you are ready to go. You can
85 Once the engines are running with MPI enabled, you are ready to go. You can
86 now call any code that uses MPI in the IPython engines. And, all of this can
86 now call any code that uses MPI in the IPython engines. And, all of this can
87 be done interactively. Here we show a simple example that uses mpi4py
87 be done interactively. Here we show a simple example that uses mpi4py
88 [mpi4py]_.
88 [mpi4py]_.
89
89
90 First, lets define a simply function that uses MPI to calculate the sum of a
90 First, lets define a simply function that uses MPI to calculate the sum of a
91 distributed array. Save the following text in a file called :file:`psum.py`:
91 distributed array. Save the following text in a file called :file:`psum.py`:
92
92
93 .. sourcecode:: python
93 .. sourcecode:: python
94
94
95 from mpi4py import MPI
95 from mpi4py import MPI
96 import numpy as np
96 import numpy as np
97
97
98 def psum(a):
98 def psum(a):
99 s = np.sum(a)
99 s = np.sum(a)
100 return MPI.COMM_WORLD.Allreduce(s,MPI.SUM)
100 return MPI.COMM_WORLD.Allreduce(s,MPI.SUM)
101
101
102 Now, start an IPython cluster in the same directory as :file:`psum.py`::
102 Now, start an IPython cluster in the same directory as :file:`psum.py`::
103
103
104 $ ipcluster mpiexec -n 4
104 $ ipcluster mpiexec -n 4
105
105
106 Finally, connect to the cluster and use this function interactively. In this
106 Finally, connect to the cluster and use this function interactively. In this
107 case, we create a random array on each engine and sum up all the random arrays
107 case, we create a random array on each engine and sum up all the random arrays
108 using our :func:`psum` function:
108 using our :func:`psum` function:
109
109
110 .. sourcecode:: ipython
110 .. sourcecode:: ipython
111
111
112 In [1]: from IPython.kernel import client
112 In [1]: from IPython.kernel import client
113
113
114 In [2]: mec = client.MultiEngineClient()
114 In [2]: mec = client.MultiEngineClient()
115
115
116 In [3]: mec.activate()
116 In [3]: mec.activate()
117
117
118 In [4]: px import numpy as np
118 In [4]: px import numpy as np
119 Parallel execution on engines: all
119 Parallel execution on engines: all
120 Out[4]:
120 Out[4]:
121 <Results List>
121 <Results List>
122 [0] In [13]: import numpy as np
122 [0] In [13]: import numpy as np
123 [1] In [13]: import numpy as np
123 [1] In [13]: import numpy as np
124 [2] In [13]: import numpy as np
124 [2] In [13]: import numpy as np
125 [3] In [13]: import numpy as np
125 [3] In [13]: import numpy as np
126
126
127 In [6]: px a = np.random.rand(100)
127 In [6]: px a = np.random.rand(100)
128 Parallel execution on engines: all
128 Parallel execution on engines: all
129 Out[6]:
129 Out[6]:
130 <Results List>
130 <Results List>
131 [0] In [15]: a = np.random.rand(100)
131 [0] In [15]: a = np.random.rand(100)
132 [1] In [15]: a = np.random.rand(100)
132 [1] In [15]: a = np.random.rand(100)
133 [2] In [15]: a = np.random.rand(100)
133 [2] In [15]: a = np.random.rand(100)
134 [3] In [15]: a = np.random.rand(100)
134 [3] In [15]: a = np.random.rand(100)
135
135
136 In [7]: px from psum import psum
136 In [7]: px from psum import psum
137 Parallel execution on engines: all
137 Parallel execution on engines: all
138 Out[7]:
138 Out[7]:
139 <Results List>
139 <Results List>
140 [0] In [16]: from psum import psum
140 [0] In [16]: from psum import psum
141 [1] In [16]: from psum import psum
141 [1] In [16]: from psum import psum
142 [2] In [16]: from psum import psum
142 [2] In [16]: from psum import psum
143 [3] In [16]: from psum import psum
143 [3] In [16]: from psum import psum
144
144
145 In [8]: px s = psum(a)
145 In [8]: px s = psum(a)
146 Parallel execution on engines: all
146 Parallel execution on engines: all
147 Out[8]:
147 Out[8]:
148 <Results List>
148 <Results List>
149 [0] In [17]: s = psum(a)
149 [0] In [17]: s = psum(a)
150 [1] In [17]: s = psum(a)
150 [1] In [17]: s = psum(a)
151 [2] In [17]: s = psum(a)
151 [2] In [17]: s = psum(a)
152 [3] In [17]: s = psum(a)
152 [3] In [17]: s = psum(a)
153
153
154 In [9]: px print s
154 In [9]: px print s
155 Parallel execution on engines: all
155 Parallel execution on engines: all
156 Out[9]:
156 Out[9]:
157 <Results List>
157 <Results List>
158 [0] In [18]: print s
158 [0] In [18]: print s
159 [0] Out[18]: 187.451545803
159 [0] Out[18]: 187.451545803
160
160
161 [1] In [18]: print s
161 [1] In [18]: print s
162 [1] Out[18]: 187.451545803
162 [1] Out[18]: 187.451545803
163
163
164 [2] In [18]: print s
164 [2] In [18]: print s
165 [2] Out[18]: 187.451545803
165 [2] Out[18]: 187.451545803
166
166
167 [3] In [18]: print s
167 [3] In [18]: print s
168 [3] Out[18]: 187.451545803
168 [3] Out[18]: 187.451545803
169
169
170 Any Python code that makes calls to MPI can be used in this manner, including
170 Any Python code that makes calls to MPI can be used in this manner, including
171 compiled C, C++ and Fortran libraries that have been exposed to Python.
171 compiled C, C++ and Fortran libraries that have been exposed to Python.
172
172
173 .. [MPI] Message Passing Interface. http://www-unix.mcs.anl.gov/mpi/
173 .. [MPI] Message Passing Interface. http://www-unix.mcs.anl.gov/mpi/
174 .. [mpi4py] MPI for Python. mpi4py: http://mpi4py.scipy.org/
174 .. [mpi4py] MPI for Python. mpi4py: http://mpi4py.scipy.org/
175 .. [OpenMPI] Open MPI. http://www.open-mpi.org/
175 .. [OpenMPI] Open MPI. http://www.open-mpi.org/
176 .. [PyTrilinos] PyTrilinos. http://trilinos.sandia.gov/packages/pytrilinos/
176 .. [PyTrilinos] PyTrilinos. http://trilinos.sandia.gov/packages/pytrilinos/
177
178
@@ -1,387 +1,389 b''
1 .. _parallel_process:
1 .. _parallel_process:
2
2
3 ===========================================
3 ===========================================
4 Starting the IPython controller and engines
4 Starting the IPython controller and engines
5 ===========================================
5 ===========================================
6
6
7 To use IPython for parallel computing, you need to start one instance of
7 To use IPython for parallel computing, you need to start one instance of
8 the controller and one or more instances of the engine. The controller
8 the controller and one or more instances of the engine. The controller
9 and each engine can run on different machines or on the same machine.
9 and each engine can run on different machines or on the same machine.
10 Because of this, there are many different possibilities.
10 Because of this, there are many different possibilities.
11
11
12 Broadly speaking, there are two ways of going about starting a controller and engines:
12 Broadly speaking, there are two ways of going about starting a controller and engines:
13
13
14 * In an automated manner using the :command:`ipcluster` command.
14 * In an automated manner using the :command:`ipcluster` command.
15 * In a more manual way using the :command:`ipcontroller` and
15 * In a more manual way using the :command:`ipcontroller` and
16 :command:`ipengine` commands.
16 :command:`ipengine` commands.
17
17
18 This document describes both of these methods. We recommend that new users
18 This document describes both of these methods. We recommend that new users
19 start with the :command:`ipcluster` command as it simplifies many common usage
19 start with the :command:`ipcluster` command as it simplifies many common usage
20 cases.
20 cases.
21
21
22 General considerations
22 General considerations
23 ======================
23 ======================
24
24
25 Before delving into the details about how you can start a controller and
25 Before delving into the details about how you can start a controller and
26 engines using the various methods, we outline some of the general issues that
26 engines using the various methods, we outline some of the general issues that
27 come up when starting the controller and engines. These things come up no
27 come up when starting the controller and engines. These things come up no
28 matter which method you use to start your IPython cluster.
28 matter which method you use to start your IPython cluster.
29
29
30 Let's say that you want to start the controller on ``host0`` and engines on
30 Let's say that you want to start the controller on ``host0`` and engines on
31 hosts ``host1``-``hostn``. The following steps are then required:
31 hosts ``host1``-``hostn``. The following steps are then required:
32
32
33 1. Start the controller on ``host0`` by running :command:`ipcontroller` on
33 1. Start the controller on ``host0`` by running :command:`ipcontroller` on
34 ``host0``.
34 ``host0``.
35 2. Move the FURL file (:file:`ipcontroller-engine.furl`) created by the
35 2. Move the FURL file (:file:`ipcontroller-engine.furl`) created by the
36 controller from ``host0`` to hosts ``host1``-``hostn``.
36 controller from ``host0`` to hosts ``host1``-``hostn``.
37 3. Start the engines on hosts ``host1``-``hostn`` by running
37 3. Start the engines on hosts ``host1``-``hostn`` by running
38 :command:`ipengine`. This command has to be told where the FURL file
38 :command:`ipengine`. This command has to be told where the FURL file
39 (:file:`ipcontroller-engine.furl`) is located.
39 (:file:`ipcontroller-engine.furl`) is located.
40
40
41 At this point, the controller and engines will be connected. By default, the
41 At this point, the controller and engines will be connected. By default, the
42 FURL files created by the controller are put into the
42 FURL files created by the controller are put into the
43 :file:`~/.ipython/security` directory. If the engines share a filesystem with
43 :file:`~/.ipython/security` directory. If the engines share a filesystem with
44 the controller, step 2 can be skipped as the engines will automatically look
44 the controller, step 2 can be skipped as the engines will automatically look
45 at that location.
45 at that location.
46
46
47 The final step required required to actually use the running controller from a
47 The final step required required to actually use the running controller from a
48 client is to move the FURL files :file:`ipcontroller-mec.furl` and
48 client is to move the FURL files :file:`ipcontroller-mec.furl` and
49 :file:`ipcontroller-tc.furl` from ``host0`` to the host where the clients will
49 :file:`ipcontroller-tc.furl` from ``host0`` to the host where the clients will
50 be run. If these file are put into the :file:`~/.ipython/security` directory
50 be run. If these file are put into the :file:`~/.ipython/security` directory
51 of the client's host, they will be found automatically. Otherwise, the full
51 of the client's host, they will be found automatically. Otherwise, the full
52 path to them has to be passed to the client's constructor.
52 path to them has to be passed to the client's constructor.
53
53
54 Using :command:`ipcluster`
54 Using :command:`ipcluster`
55 ==========================
55 ==========================
56
56
57 The :command:`ipcluster` command provides a simple way of starting a
57 The :command:`ipcluster` command provides a simple way of starting a
58 controller and engines in the following situations:
58 controller and engines in the following situations:
59
59
60 1. When the controller and engines are all run on localhost. This is useful
60 1. When the controller and engines are all run on localhost. This is useful
61 for testing or running on a multicore computer.
61 for testing or running on a multicore computer.
62 2. When engines are started using the :command:`mpirun` command that comes
62 2. When engines are started using the :command:`mpirun` command that comes
63 with most MPI [MPI]_ implementations
63 with most MPI [MPI]_ implementations
64 3. When engines are started using the PBS [PBS]_ batch system.
64 3. When engines are started using the PBS [PBS]_ batch system.
65 4. When the controller is started on localhost and the engines are started on
65 4. When the controller is started on localhost and the engines are started on
66 remote nodes using :command:`ssh`.
66 remote nodes using :command:`ssh`.
67
67
68 .. note::
68 .. note::
69
69
70 It is also possible for advanced users to add support to
70 It is also possible for advanced users to add support to
71 :command:`ipcluster` for starting controllers and engines using other
71 :command:`ipcluster` for starting controllers and engines using other
72 methods (like Sun's Grid Engine for example).
72 methods (like Sun's Grid Engine for example).
73
73
74 .. note::
74 .. note::
75
75
76 Currently :command:`ipcluster` requires that the
76 Currently :command:`ipcluster` requires that the
77 :file:`~/.ipython/security` directory live on a shared filesystem that is
77 :file:`~/.ipython/security` directory live on a shared filesystem that is
78 seen by both the controller and engines. If you don't have a shared file
78 seen by both the controller and engines. If you don't have a shared file
79 system you will need to use :command:`ipcontroller` and
79 system you will need to use :command:`ipcontroller` and
80 :command:`ipengine` directly. This constraint can be relaxed if you are
80 :command:`ipengine` directly. This constraint can be relaxed if you are
81 using the :command:`ssh` method to start the cluster.
81 using the :command:`ssh` method to start the cluster.
82
82
83 Underneath the hood, :command:`ipcluster` just uses :command:`ipcontroller`
83 Underneath the hood, :command:`ipcluster` just uses :command:`ipcontroller`
84 and :command:`ipengine` to perform the steps described above.
84 and :command:`ipengine` to perform the steps described above.
85
85
86 Using :command:`ipcluster` in local mode
86 Using :command:`ipcluster` in local mode
87 ----------------------------------------
87 ----------------------------------------
88
88
89 To start one controller and 4 engines on localhost, just do::
89 To start one controller and 4 engines on localhost, just do::
90
90
91 $ ipcluster local -n 4
91 $ ipcluster local -n 4
92
92
93 To see other command line options for the local mode, do::
93 To see other command line options for the local mode, do::
94
94
95 $ ipcluster local -h
95 $ ipcluster local -h
96
96
97 Using :command:`ipcluster` in mpiexec/mpirun mode
97 Using :command:`ipcluster` in mpiexec/mpirun mode
98 -------------------------------------------------
98 -------------------------------------------------
99
99
100 The mpiexec/mpirun mode is useful if you:
100 The mpiexec/mpirun mode is useful if you:
101
101
102 1. Have MPI installed.
102 1. Have MPI installed.
103 2. Your systems are configured to use the :command:`mpiexec` or
103 2. Your systems are configured to use the :command:`mpiexec` or
104 :command:`mpirun` commands to start MPI processes.
104 :command:`mpirun` commands to start MPI processes.
105
105
106 .. note::
106 .. note::
107
107
108 The preferred command to use is :command:`mpiexec`. However, we also
108 The preferred command to use is :command:`mpiexec`. However, we also
109 support :command:`mpirun` for backwards compatibility. The underlying
109 support :command:`mpirun` for backwards compatibility. The underlying
110 logic used is exactly the same, the only difference being the name of the
110 logic used is exactly the same, the only difference being the name of the
111 command line program that is called.
111 command line program that is called.
112
112
113 If these are satisfied, you can start an IPython cluster using::
113 If these are satisfied, you can start an IPython cluster using::
114
114
115 $ ipcluster mpiexec -n 4
115 $ ipcluster mpiexec -n 4
116
116
117 This does the following:
117 This does the following:
118
118
119 1. Starts the IPython controller on current host.
119 1. Starts the IPython controller on current host.
120 2. Uses :command:`mpiexec` to start 4 engines.
120 2. Uses :command:`mpiexec` to start 4 engines.
121
121
122 On newer MPI implementations (such as OpenMPI), this will work even if you
122 On newer MPI implementations (such as OpenMPI), this will work even if you
123 don't make any calls to MPI or call :func:`MPI_Init`. However, older MPI
123 don't make any calls to MPI or call :func:`MPI_Init`. However, older MPI
124 implementations actually require each process to call :func:`MPI_Init` upon
124 implementations actually require each process to call :func:`MPI_Init` upon
125 starting. The easiest way of having this done is to install the mpi4py
125 starting. The easiest way of having this done is to install the mpi4py
126 [mpi4py]_ package and then call ipcluster with the ``--mpi`` option::
126 [mpi4py]_ package and then call ipcluster with the ``--mpi`` option::
127
127
128 $ ipcluster mpiexec -n 4 --mpi=mpi4py
128 $ ipcluster mpiexec -n 4 --mpi=mpi4py
129
129
130 Unfortunately, even this won't work for some MPI implementations. If you are
130 Unfortunately, even this won't work for some MPI implementations. If you are
131 having problems with this, you will likely have to use a custom Python
131 having problems with this, you will likely have to use a custom Python
132 executable that itself calls :func:`MPI_Init` at the appropriate time.
132 executable that itself calls :func:`MPI_Init` at the appropriate time.
133 Fortunately, mpi4py comes with such a custom Python executable that is easy to
133 Fortunately, mpi4py comes with such a custom Python executable that is easy to
134 install and use. However, this custom Python executable approach will not work
134 install and use. However, this custom Python executable approach will not work
135 with :command:`ipcluster` currently.
135 with :command:`ipcluster` currently.
136
136
137 Additional command line options for this mode can be found by doing::
137 Additional command line options for this mode can be found by doing::
138
138
139 $ ipcluster mpiexec -h
139 $ ipcluster mpiexec -h
140
140
141 More details on using MPI with IPython can be found :ref:`here <parallelmpi>`.
141 More details on using MPI with IPython can be found :ref:`here <parallelmpi>`.
142
142
143
143
144 Using :command:`ipcluster` in PBS mode
144 Using :command:`ipcluster` in PBS mode
145 --------------------------------------
145 --------------------------------------
146
146
147 The PBS mode uses the Portable Batch System [PBS]_ to start the engines. To
147 The PBS mode uses the Portable Batch System [PBS]_ to start the engines. To
148 use this mode, you first need to create a PBS script template that will be
148 use this mode, you first need to create a PBS script template that will be
149 used to start the engines. Here is a sample PBS script template:
149 used to start the engines. Here is a sample PBS script template:
150
150
151 .. sourcecode:: bash
151 .. sourcecode:: bash
152
152
153 #PBS -N ipython
153 #PBS -N ipython
154 #PBS -j oe
154 #PBS -j oe
155 #PBS -l walltime=00:10:00
155 #PBS -l walltime=00:10:00
156 #PBS -l nodes=${n/4}:ppn=4
156 #PBS -l nodes=${n/4}:ppn=4
157 #PBS -q parallel
157 #PBS -q parallel
158
158
159 cd $$PBS_O_WORKDIR
159 cd $$PBS_O_WORKDIR
160 export PATH=$$HOME/usr/local/bin
160 export PATH=$$HOME/usr/local/bin
161 export PYTHONPATH=$$HOME/usr/local/lib/python2.4/site-packages
161 export PYTHONPATH=$$HOME/usr/local/lib/python2.4/site-packages
162 /usr/local/bin/mpiexec -n ${n} ipengine --logfile=$$PBS_O_WORKDIR/ipengine
162 /usr/local/bin/mpiexec -n ${n} ipengine --logfile=$$PBS_O_WORKDIR/ipengine
163
163
164 There are a few important points about this template:
164 There are a few important points about this template:
165
165
166 1. This template will be rendered at runtime using IPython's :mod:`Itpl`
166 1. This template will be rendered at runtime using IPython's :mod:`Itpl`
167 template engine.
167 template engine.
168
168
169 2. Instead of putting in the actual number of engines, use the notation
169 2. Instead of putting in the actual number of engines, use the notation
170 ``${n}`` to indicate the number of engines to be started. You can also uses
170 ``${n}`` to indicate the number of engines to be started. You can also uses
171 expressions like ``${n/4}`` in the template to indicate the number of
171 expressions like ``${n/4}`` in the template to indicate the number of
172 nodes.
172 nodes.
173
173
174 3. Because ``$`` is a special character used by the template engine, you must
174 3. Because ``$`` is a special character used by the template engine, you must
175 escape any ``$`` by using ``$$``. This is important when referring to
175 escape any ``$`` by using ``$$``. This is important when referring to
176 environment variables in the template.
176 environment variables in the template.
177
177
178 4. Any options to :command:`ipengine` should be given in the batch script
178 4. Any options to :command:`ipengine` should be given in the batch script
179 template.
179 template.
180
180
181 5. Depending on the configuration of you system, you may have to set
181 5. Depending on the configuration of you system, you may have to set
182 environment variables in the script template.
182 environment variables in the script template.
183
183
184 Once you have created such a script, save it with a name like
184 Once you have created such a script, save it with a name like
185 :file:`pbs.template`. Now you are ready to start your job::
185 :file:`pbs.template`. Now you are ready to start your job::
186
186
187 $ ipcluster pbs -n 128 --pbs-script=pbs.template
187 $ ipcluster pbs -n 128 --pbs-script=pbs.template
188
188
189 Additional command line options for this mode can be found by doing::
189 Additional command line options for this mode can be found by doing::
190
190
191 $ ipcluster pbs -h
191 $ ipcluster pbs -h
192
192
193 Using :command:`ipcluster` in SSH mode
193 Using :command:`ipcluster` in SSH mode
194 --------------------------------------
194 --------------------------------------
195
195
196 The SSH mode uses :command:`ssh` to execute :command:`ipengine` on remote
196 The SSH mode uses :command:`ssh` to execute :command:`ipengine` on remote
197 nodes and the :command:`ipcontroller` on localhost.
197 nodes and the :command:`ipcontroller` on localhost.
198
198
199 When using using this mode it highly recommended that you have set up SSH keys
199 When using using this mode it highly recommended that you have set up SSH keys
200 and are using ssh-agent [SSH]_ for password-less logins.
200 and are using ssh-agent [SSH]_ for password-less logins.
201
201
202 To use this mode you need a python file describing the cluster, here is an
202 To use this mode you need a python file describing the cluster, here is an
203 example of such a "clusterfile":
203 example of such a "clusterfile":
204
204
205 .. sourcecode:: python
205 .. sourcecode:: python
206
206
207 send_furl = True
207 send_furl = True
208 engines = { 'host1.example.com' : 2,
208 engines = { 'host1.example.com' : 2,
209 'host2.example.com' : 5,
209 'host2.example.com' : 5,
210 'host3.example.com' : 1,
210 'host3.example.com' : 1,
211 'host4.example.com' : 8 }
211 'host4.example.com' : 8 }
212
212
213 Since this is a regular python file usual python syntax applies. Things to
213 Since this is a regular python file usual python syntax applies. Things to
214 note:
214 note:
215
215
216 * The `engines` dict, where the keys is the host we want to run engines on and
216 * The `engines` dict, where the keys is the host we want to run engines on and
217 the value is the number of engines to run on that host.
217 the value is the number of engines to run on that host.
218 * send_furl can either be `True` or `False`, if `True` it will copy over the
218 * send_furl can either be `True` or `False`, if `True` it will copy over the
219 furl needed for :command:`ipengine` to each host.
219 furl needed for :command:`ipengine` to each host.
220
220
221 The ``--clusterfile`` command line option lets you specify the file to use for
221 The ``--clusterfile`` command line option lets you specify the file to use for
222 the cluster definition. Once you have your cluster file and you can
222 the cluster definition. Once you have your cluster file and you can
223 :command:`ssh` into the remote hosts with out an password you are ready to
223 :command:`ssh` into the remote hosts with out an password you are ready to
224 start your cluster like so:
224 start your cluster like so:
225
225
226 .. sourcecode:: bash
226 .. sourcecode:: bash
227
227
228 $ ipcluster ssh --clusterfile /path/to/my/clusterfile.py
228 $ ipcluster ssh --clusterfile /path/to/my/clusterfile.py
229
229
230
230
231 Two helper shell scripts are used to start and stop :command:`ipengine` on
231 Two helper shell scripts are used to start and stop :command:`ipengine` on
232 remote hosts:
232 remote hosts:
233
233
234 * sshx.sh
234 * sshx.sh
235 * engine_killer.sh
235 * engine_killer.sh
236
236
237 Defaults for both of these are contained in the source code for
237 Defaults for both of these are contained in the source code for
238 :command:`ipcluster`. The default scripts are written to a local file in a
238 :command:`ipcluster`. The default scripts are written to a local file in a
239 tmep directory and then copied to a temp directory on the remote host and
239 tmep directory and then copied to a temp directory on the remote host and
240 executed from there. On most Unix, Linux and OS X systems this is /tmp.
240 executed from there. On most Unix, Linux and OS X systems this is /tmp.
241
241
242 The default sshx.sh is the following:
242 The default sshx.sh is the following:
243
243
244 .. sourcecode:: bash
244 .. sourcecode:: bash
245
245
246 #!/bin/sh
246 #!/bin/sh
247 "$@" &> /dev/null &
247 "$@" &> /dev/null &
248 echo $!
248 echo $!
249
249
250 If you want to use a custom sshx.sh script you need to use the ``--sshx``
250 If you want to use a custom sshx.sh script you need to use the ``--sshx``
251 option and specify the file to use. Using a custom sshx.sh file could be
251 option and specify the file to use. Using a custom sshx.sh file could be
252 helpful when you need to setup the environment on the remote host before
252 helpful when you need to setup the environment on the remote host before
253 executing :command:`ipengine`.
253 executing :command:`ipengine`.
254
254
255 For a detailed options list:
255 For a detailed options list:
256
256
257 .. sourcecode:: bash
257 .. sourcecode:: bash
258
258
259 $ ipcluster ssh -h
259 $ ipcluster ssh -h
260
260
261 Current limitations of the SSH mode of :command:`ipcluster` are:
261 Current limitations of the SSH mode of :command:`ipcluster` are:
262
262
263 * Untested on Windows. Would require a working :command:`ssh` on Windows.
263 * Untested on Windows. Would require a working :command:`ssh` on Windows.
264 Also, we are using shell scripts to setup and execute commands on remote
264 Also, we are using shell scripts to setup and execute commands on remote
265 hosts.
265 hosts.
266 * :command:`ipcontroller` is started on localhost, with no option to start it
266 * :command:`ipcontroller` is started on localhost, with no option to start it
267 on a remote node.
267 on a remote node.
268
268
269 Using the :command:`ipcontroller` and :command:`ipengine` commands
269 Using the :command:`ipcontroller` and :command:`ipengine` commands
270 ==================================================================
270 ==================================================================
271
271
272 It is also possible to use the :command:`ipcontroller` and :command:`ipengine`
272 It is also possible to use the :command:`ipcontroller` and :command:`ipengine`
273 commands to start your controller and engines. This approach gives you full
273 commands to start your controller and engines. This approach gives you full
274 control over all aspects of the startup process.
274 control over all aspects of the startup process.
275
275
276 Starting the controller and engine on your local machine
276 Starting the controller and engine on your local machine
277 --------------------------------------------------------
277 --------------------------------------------------------
278
278
279 To use :command:`ipcontroller` and :command:`ipengine` to start things on your
279 To use :command:`ipcontroller` and :command:`ipengine` to start things on your
280 local machine, do the following.
280 local machine, do the following.
281
281
282 First start the controller::
282 First start the controller::
283
283
284 $ ipcontroller
284 $ ipcontroller
285
285
286 Next, start however many instances of the engine you want using (repeatedly)
286 Next, start however many instances of the engine you want using (repeatedly)
287 the command::
287 the command::
288
288
289 $ ipengine
289 $ ipengine
290
290
291 The engines should start and automatically connect to the controller using the
291 The engines should start and automatically connect to the controller using the
292 FURL files in :file:`~./ipython/security`. You are now ready to use the
292 FURL files in :file:`~./ipython/security`. You are now ready to use the
293 controller and engines from IPython.
293 controller and engines from IPython.
294
294
295 .. warning::
295 .. warning::
296
296
297 The order of the above operations is very important. You *must*
297 The order of the above operations is very important. You *must*
298 start the controller before the engines, since the engines connect
298 start the controller before the engines, since the engines connect
299 to the controller as they get started.
299 to the controller as they get started.
300
300
301 .. note::
301 .. note::
302
302
303 On some platforms (OS X), to put the controller and engine into the
303 On some platforms (OS X), to put the controller and engine into the
304 background you may need to give these commands in the form ``(ipcontroller
304 background you may need to give these commands in the form ``(ipcontroller
305 &)`` and ``(ipengine &)`` (with the parentheses) for them to work
305 &)`` and ``(ipengine &)`` (with the parentheses) for them to work
306 properly.
306 properly.
307
307
308 Starting the controller and engines on different hosts
308 Starting the controller and engines on different hosts
309 ------------------------------------------------------
309 ------------------------------------------------------
310
310
311 When the controller and engines are running on different hosts, things are
311 When the controller and engines are running on different hosts, things are
312 slightly more complicated, but the underlying ideas are the same:
312 slightly more complicated, but the underlying ideas are the same:
313
313
314 1. Start the controller on a host using :command:`ipcontroller`.
314 1. Start the controller on a host using :command:`ipcontroller`.
315 2. Copy :file:`ipcontroller-engine.furl` from :file:`~./ipython/security` on
315 2. Copy :file:`ipcontroller-engine.furl` from :file:`~./ipython/security` on
316 the controller's host to the host where the engines will run.
316 the controller's host to the host where the engines will run.
317 3. Use :command:`ipengine` on the engine's hosts to start the engines.
317 3. Use :command:`ipengine` on the engine's hosts to start the engines.
318
318
319 The only thing you have to be careful of is to tell :command:`ipengine` where
319 The only thing you have to be careful of is to tell :command:`ipengine` where
320 the :file:`ipcontroller-engine.furl` file is located. There are two ways you
320 the :file:`ipcontroller-engine.furl` file is located. There are two ways you
321 can do this:
321 can do this:
322
322
323 * Put :file:`ipcontroller-engine.furl` in the :file:`~./ipython/security`
323 * Put :file:`ipcontroller-engine.furl` in the :file:`~./ipython/security`
324 directory on the engine's host, where it will be found automatically.
324 directory on the engine's host, where it will be found automatically.
325 * Call :command:`ipengine` with the ``--furl-file=full_path_to_the_file``
325 * Call :command:`ipengine` with the ``--furl-file=full_path_to_the_file``
326 flag.
326 flag.
327
327
328 The ``--furl-file`` flag works like this::
328 The ``--furl-file`` flag works like this::
329
329
330 $ ipengine --furl-file=/path/to/my/ipcontroller-engine.furl
330 $ ipengine --furl-file=/path/to/my/ipcontroller-engine.furl
331
331
332 .. note::
332 .. note::
333
333
334 If the controller's and engine's hosts all have a shared file system
334 If the controller's and engine's hosts all have a shared file system
335 (:file:`~./ipython/security` is the same on all of them), then things
335 (:file:`~./ipython/security` is the same on all of them), then things
336 will just work!
336 will just work!
337
337
338 Make FURL files persistent
338 Make FURL files persistent
339 ---------------------------
339 ---------------------------
340
340
341 At fist glance it may seem that that managing the FURL files is a bit
341 At fist glance it may seem that that managing the FURL files is a bit
342 annoying. Going back to the house and key analogy, copying the FURL around
342 annoying. Going back to the house and key analogy, copying the FURL around
343 each time you start the controller is like having to make a new key every time
343 each time you start the controller is like having to make a new key every time
344 you want to unlock the door and enter your house. As with your house, you want
344 you want to unlock the door and enter your house. As with your house, you want
345 to be able to create the key (or FURL file) once, and then simply use it at
345 to be able to create the key (or FURL file) once, and then simply use it at
346 any point in the future.
346 any point in the future.
347
347
348 This is possible, but before you do this, you **must** remove any old FURL
348 This is possible, but before you do this, you **must** remove any old FURL
349 files in the :file:`~/.ipython/security` directory.
349 files in the :file:`~/.ipython/security` directory.
350
350
351 .. warning::
351 .. warning::
352
352
353 You **must** remove old FURL files before using persistent FURL files.
353 You **must** remove old FURL files before using persistent FURL files.
354
354
355 Then, The only thing you have to do is decide what ports the controller will
355 Then, The only thing you have to do is decide what ports the controller will
356 listen on for the engines and clients. This is done as follows::
356 listen on for the engines and clients. This is done as follows::
357
357
358 $ ipcontroller -r --client-port=10101 --engine-port=10102
358 $ ipcontroller -r --client-port=10101 --engine-port=10102
359
359
360 These options also work with all of the various modes of
360 These options also work with all of the various modes of
361 :command:`ipcluster`::
361 :command:`ipcluster`::
362
362
363 $ ipcluster local -n 2 -r --client-port=10101 --engine-port=10102
363 $ ipcluster local -n 2 -r --client-port=10101 --engine-port=10102
364
364
365 Then, just copy the furl files over the first time and you are set. You can
365 Then, just copy the furl files over the first time and you are set. You can
366 start and stop the controller and engines any many times as you want in the
366 start and stop the controller and engines any many times as you want in the
367 future, just make sure to tell the controller to use the *same* ports.
367 future, just make sure to tell the controller to use the *same* ports.
368
368
369 .. note::
369 .. note::
370
370
371 You may ask the question: what ports does the controller listen on if you
371 You may ask the question: what ports does the controller listen on if you
372 don't tell is to use specific ones? The default is to use high random port
372 don't tell is to use specific ones? The default is to use high random port
373 numbers. We do this for two reasons: i) to increase security through
373 numbers. We do this for two reasons: i) to increase security through
374 obscurity and ii) to multiple controllers on a given host to start and
374 obscurity and ii) to multiple controllers on a given host to start and
375 automatically use different ports.
375 automatically use different ports.
376
376
377 Log files
377 Log files
378 ---------
378 ---------
379
379
380 All of the components of IPython have log files associated with them.
380 All of the components of IPython have log files associated with them.
381 These log files can be extremely useful in debugging problems with
381 These log files can be extremely useful in debugging problems with
382 IPython and can be found in the directory :file:`~/.ipython/log`. Sending
382 IPython and can be found in the directory :file:`~/.ipython/log`. Sending
383 the log files to us will often help us to debug any problems.
383 the log files to us will often help us to debug any problems.
384
384
385
385
386 .. [PBS] Portable Batch System. http://www.openpbs.org/
386 .. [PBS] Portable Batch System. http://www.openpbs.org/
387 .. [SSH] SSH-Agent http://en.wikipedia.org/wiki/Ssh-agent
387 .. [SSH] SSH-Agent http://en.wikipedia.org/wiki/Ssh-agent
388
389
@@ -1,364 +1,366 b''
1 .. _parallelsecurity:
1 .. _parallelsecurity:
2
2
3 ===========================
3 ===========================
4 Security details of IPython
4 Security details of IPython
5 ===========================
5 ===========================
6
6
7 IPython's :mod:`IPython.kernel` package exposes the full power of the Python
7 IPython's :mod:`IPython.kernel` package exposes the full power of the Python
8 interpreter over a TCP/IP network for the purposes of parallel computing. This
8 interpreter over a TCP/IP network for the purposes of parallel computing. This
9 feature brings up the important question of IPython's security model. This
9 feature brings up the important question of IPython's security model. This
10 document gives details about this model and how it is implemented in IPython's
10 document gives details about this model and how it is implemented in IPython's
11 architecture.
11 architecture.
12
12
13 Processs and network topology
13 Processs and network topology
14 =============================
14 =============================
15
15
16 To enable parallel computing, IPython has a number of different processes that
16 To enable parallel computing, IPython has a number of different processes that
17 run. These processes are discussed at length in the IPython documentation and
17 run. These processes are discussed at length in the IPython documentation and
18 are summarized here:
18 are summarized here:
19
19
20 * The IPython *engine*. This process is a full blown Python
20 * The IPython *engine*. This process is a full blown Python
21 interpreter in which user code is executed. Multiple
21 interpreter in which user code is executed. Multiple
22 engines are started to make parallel computing possible.
22 engines are started to make parallel computing possible.
23 * The IPython *controller*. This process manages a set of
23 * The IPython *controller*. This process manages a set of
24 engines, maintaining a queue for each and presenting
24 engines, maintaining a queue for each and presenting
25 an asynchronous interface to the set of engines.
25 an asynchronous interface to the set of engines.
26 * The IPython *client*. This process is typically an
26 * The IPython *client*. This process is typically an
27 interactive Python process that is used to coordinate the
27 interactive Python process that is used to coordinate the
28 engines to get a parallel computation done.
28 engines to get a parallel computation done.
29
29
30 Collectively, these three processes are called the IPython *kernel*.
30 Collectively, these three processes are called the IPython *kernel*.
31
31
32 These three processes communicate over TCP/IP connections with a well defined
32 These three processes communicate over TCP/IP connections with a well defined
33 topology. The IPython controller is the only process that listens on TCP/IP
33 topology. The IPython controller is the only process that listens on TCP/IP
34 sockets. Upon starting, an engine connects to a controller and registers
34 sockets. Upon starting, an engine connects to a controller and registers
35 itself with the controller. These engine/controller TCP/IP connections persist
35 itself with the controller. These engine/controller TCP/IP connections persist
36 for the lifetime of each engine.
36 for the lifetime of each engine.
37
37
38 The IPython client also connects to the controller using one or more TCP/IP
38 The IPython client also connects to the controller using one or more TCP/IP
39 connections. These connections persist for the lifetime of the client only.
39 connections. These connections persist for the lifetime of the client only.
40
40
41 A given IPython controller and set of engines typically has a relatively short
41 A given IPython controller and set of engines typically has a relatively short
42 lifetime. Typically this lifetime corresponds to the duration of a single
42 lifetime. Typically this lifetime corresponds to the duration of a single
43 parallel simulation performed by a single user. Finally, the controller,
43 parallel simulation performed by a single user. Finally, the controller,
44 engines and client processes typically execute with the permissions of that
44 engines and client processes typically execute with the permissions of that
45 same user. More specifically, the controller and engines are *not* executed as
45 same user. More specifically, the controller and engines are *not* executed as
46 root or with any other superuser permissions.
46 root or with any other superuser permissions.
47
47
48 Application logic
48 Application logic
49 =================
49 =================
50
50
51 When running the IPython kernel to perform a parallel computation, a user
51 When running the IPython kernel to perform a parallel computation, a user
52 utilizes the IPython client to send Python commands and data through the
52 utilizes the IPython client to send Python commands and data through the
53 IPython controller to the IPython engines, where those commands are executed
53 IPython controller to the IPython engines, where those commands are executed
54 and the data processed. The design of IPython ensures that the client is the
54 and the data processed. The design of IPython ensures that the client is the
55 only access point for the capabilities of the engines. That is, the only way
55 only access point for the capabilities of the engines. That is, the only way
56 of addressing the engines is through a client.
56 of addressing the engines is through a client.
57
57
58 A user can utilize the client to instruct the IPython engines to execute
58 A user can utilize the client to instruct the IPython engines to execute
59 arbitrary Python commands. These Python commands can include calls to the
59 arbitrary Python commands. These Python commands can include calls to the
60 system shell, access the filesystem, etc., as required by the user's
60 system shell, access the filesystem, etc., as required by the user's
61 application code. From this perspective, when a user runs an IPython engine on
61 application code. From this perspective, when a user runs an IPython engine on
62 a host, that engine has the same capabilities and permissions as the user
62 a host, that engine has the same capabilities and permissions as the user
63 themselves (as if they were logged onto the engine's host with a terminal).
63 themselves (as if they were logged onto the engine's host with a terminal).
64
64
65 Secure network connections
65 Secure network connections
66 ==========================
66 ==========================
67
67
68 Overview
68 Overview
69 --------
69 --------
70
70
71 All TCP/IP connections between the client and controller as well as the
71 All TCP/IP connections between the client and controller as well as the
72 engines and controller are fully encrypted and authenticated. This section
72 engines and controller are fully encrypted and authenticated. This section
73 describes the details of the encryption and authentication approached used
73 describes the details of the encryption and authentication approached used
74 within IPython.
74 within IPython.
75
75
76 IPython uses the Foolscap network protocol [Foolscap]_ for all communications
76 IPython uses the Foolscap network protocol [Foolscap]_ for all communications
77 between processes. Thus, the details of IPython's security model are directly
77 between processes. Thus, the details of IPython's security model are directly
78 related to those of Foolscap. Thus, much of the following discussion is
78 related to those of Foolscap. Thus, much of the following discussion is
79 actually just a discussion of the security that is built in to Foolscap.
79 actually just a discussion of the security that is built in to Foolscap.
80
80
81 Encryption
81 Encryption
82 ----------
82 ----------
83
83
84 For encryption purposes, IPython and Foolscap use the well known Secure Socket
84 For encryption purposes, IPython and Foolscap use the well known Secure Socket
85 Layer (SSL) protocol [RFC5246]_. We use the implementation of this protocol
85 Layer (SSL) protocol [RFC5246]_. We use the implementation of this protocol
86 provided by the OpenSSL project through the pyOpenSSL [pyOpenSSL]_ Python
86 provided by the OpenSSL project through the pyOpenSSL [pyOpenSSL]_ Python
87 bindings to OpenSSL.
87 bindings to OpenSSL.
88
88
89 Authentication
89 Authentication
90 --------------
90 --------------
91
91
92 IPython clients and engines must also authenticate themselves with the
92 IPython clients and engines must also authenticate themselves with the
93 controller. This is handled in a capabilities based security model
93 controller. This is handled in a capabilities based security model
94 [Capability]_. In this model, the controller creates a strong cryptographic
94 [Capability]_. In this model, the controller creates a strong cryptographic
95 key or token that represents each set of capability that the controller
95 key or token that represents each set of capability that the controller
96 offers. Any party who has this key and presents it to the controller has full
96 offers. Any party who has this key and presents it to the controller has full
97 access to the corresponding capabilities of the controller. This model is
97 access to the corresponding capabilities of the controller. This model is
98 analogous to using a physical key to gain access to physical items
98 analogous to using a physical key to gain access to physical items
99 (capabilities) behind a locked door.
99 (capabilities) behind a locked door.
100
100
101 For a capabilities based authentication system to prevent unauthorized access,
101 For a capabilities based authentication system to prevent unauthorized access,
102 two things must be ensured:
102 two things must be ensured:
103
103
104 * The keys must be cryptographically strong. Otherwise attackers could gain
104 * The keys must be cryptographically strong. Otherwise attackers could gain
105 access by a simple brute force key guessing attack.
105 access by a simple brute force key guessing attack.
106 * The actual keys must be distributed only to authorized parties.
106 * The actual keys must be distributed only to authorized parties.
107
107
108 The keys in Foolscap are called Foolscap URL's or FURLs. The following section
108 The keys in Foolscap are called Foolscap URL's or FURLs. The following section
109 gives details about how these FURLs are created in Foolscap. The IPython
109 gives details about how these FURLs are created in Foolscap. The IPython
110 controller creates a number of FURLs for different purposes:
110 controller creates a number of FURLs for different purposes:
111
111
112 * One FURL that grants IPython engines access to the controller. Also
112 * One FURL that grants IPython engines access to the controller. Also
113 implicit in this access is permission to execute code sent by an
113 implicit in this access is permission to execute code sent by an
114 authenticated IPython client.
114 authenticated IPython client.
115 * Two or more FURLs that grant IPython clients access to the controller.
115 * Two or more FURLs that grant IPython clients access to the controller.
116 Implicit in this access is permission to give the controller's engine code
116 Implicit in this access is permission to give the controller's engine code
117 to execute.
117 to execute.
118
118
119 Upon starting, the controller creates these different FURLS and writes them
119 Upon starting, the controller creates these different FURLS and writes them
120 files in the user-read-only directory :file:`$HOME/.ipython/security`. Thus,
120 files in the user-read-only directory :file:`$HOME/.ipython/security`. Thus,
121 only the user who starts the controller has access to the FURLs.
121 only the user who starts the controller has access to the FURLs.
122
122
123 For an IPython client or engine to authenticate with a controller, it must
123 For an IPython client or engine to authenticate with a controller, it must
124 present the appropriate FURL to the controller upon connecting. If the
124 present the appropriate FURL to the controller upon connecting. If the
125 FURL matches what the controller expects for a given capability, access is
125 FURL matches what the controller expects for a given capability, access is
126 granted. If not, access is denied. The exchange of FURLs is done after
126 granted. If not, access is denied. The exchange of FURLs is done after
127 encrypted communications channels have been established to prevent attackers
127 encrypted communications channels have been established to prevent attackers
128 from capturing them.
128 from capturing them.
129
129
130 .. note::
130 .. note::
131
131
132 The FURL is similar to an unsigned private key in SSH.
132 The FURL is similar to an unsigned private key in SSH.
133
133
134 Details of the Foolscap handshake
134 Details of the Foolscap handshake
135 ---------------------------------
135 ---------------------------------
136
136
137 In this section we detail the precise security handshake that takes place at
137 In this section we detail the precise security handshake that takes place at
138 the beginning of any network connection in IPython. For the purposes of this
138 the beginning of any network connection in IPython. For the purposes of this
139 discussion, the SERVER is the IPython controller process and the CLIENT is the
139 discussion, the SERVER is the IPython controller process and the CLIENT is the
140 IPython engine or client process.
140 IPython engine or client process.
141
141
142 Upon starting, all IPython processes do the following:
142 Upon starting, all IPython processes do the following:
143
143
144 1. Create a public key x509 certificate (ISO/IEC 9594).
144 1. Create a public key x509 certificate (ISO/IEC 9594).
145 2. Create a hash of the contents of the certificate using the SHA-1 algorithm.
145 2. Create a hash of the contents of the certificate using the SHA-1 algorithm.
146 The base-32 encoded version of this hash is saved by the process as its
146 The base-32 encoded version of this hash is saved by the process as its
147 process id (actually in Foolscap, this is the Tub id, but here refer to
147 process id (actually in Foolscap, this is the Tub id, but here refer to
148 it as the process id).
148 it as the process id).
149
149
150 Upon starting, the IPython controller also does the following:
150 Upon starting, the IPython controller also does the following:
151
151
152 1. Save the x509 certificate to disk in a secure location. The CLIENT
152 1. Save the x509 certificate to disk in a secure location. The CLIENT
153 certificate is never saved to disk.
153 certificate is never saved to disk.
154 2. Create a FURL for each capability that the controller has. There are
154 2. Create a FURL for each capability that the controller has. There are
155 separate capabilities the controller offers for clients and engines. The
155 separate capabilities the controller offers for clients and engines. The
156 FURL is created using: a) the process id of the SERVER, b) the IP
156 FURL is created using: a) the process id of the SERVER, b) the IP
157 address and port the SERVER is listening on and c) a 160 bit,
157 address and port the SERVER is listening on and c) a 160 bit,
158 cryptographically secure string that represents the capability (the
158 cryptographically secure string that represents the capability (the
159 "capability id").
159 "capability id").
160 3. The FURLs are saved to disk in a secure location on the SERVER's host.
160 3. The FURLs are saved to disk in a secure location on the SERVER's host.
161
161
162 For a CLIENT to be able to connect to the SERVER and access a capability of
162 For a CLIENT to be able to connect to the SERVER and access a capability of
163 that SERVER, the CLIENT must have knowledge of the FURL for that SERVER's
163 that SERVER, the CLIENT must have knowledge of the FURL for that SERVER's
164 capability. This typically requires that the file containing the FURL be
164 capability. This typically requires that the file containing the FURL be
165 moved from the SERVER's host to the CLIENT's host. This is done by the end
165 moved from the SERVER's host to the CLIENT's host. This is done by the end
166 user who started the SERVER and wishes to have a CLIENT connect to the SERVER.
166 user who started the SERVER and wishes to have a CLIENT connect to the SERVER.
167
167
168 When a CLIENT connects to the SERVER, the following handshake protocol takes
168 When a CLIENT connects to the SERVER, the following handshake protocol takes
169 place:
169 place:
170
170
171 1. The CLIENT tells the SERVER what process (or Tub) id it expects the SERVER
171 1. The CLIENT tells the SERVER what process (or Tub) id it expects the SERVER
172 to have.
172 to have.
173 2. If the SERVER has that process id, it notifies the CLIENT that it will now
173 2. If the SERVER has that process id, it notifies the CLIENT that it will now
174 enter encrypted mode. If the SERVER has a different id, the SERVER aborts.
174 enter encrypted mode. If the SERVER has a different id, the SERVER aborts.
175 3. Both CLIENT and SERVER initiate the SSL handshake protocol.
175 3. Both CLIENT and SERVER initiate the SSL handshake protocol.
176 4. Both CLIENT and SERVER request the certificate of their peer and verify
176 4. Both CLIENT and SERVER request the certificate of their peer and verify
177 that certificate. If this succeeds, all further communications are
177 that certificate. If this succeeds, all further communications are
178 encrypted.
178 encrypted.
179 5. Both CLIENT and SERVER send a hello block containing connection parameters
179 5. Both CLIENT and SERVER send a hello block containing connection parameters
180 and their process id.
180 and their process id.
181 6. The CLIENT and SERVER check that their peer's stated process id matches the
181 6. The CLIENT and SERVER check that their peer's stated process id matches the
182 hash of the x509 certificate the peer presented. If not, the connection is
182 hash of the x509 certificate the peer presented. If not, the connection is
183 aborted.
183 aborted.
184 7. The CLIENT verifies that the SERVER's stated id matches the id of the
184 7. The CLIENT verifies that the SERVER's stated id matches the id of the
185 SERVER the CLIENT is intending to connect to. If not, the connection is
185 SERVER the CLIENT is intending to connect to. If not, the connection is
186 aborted.
186 aborted.
187 8. The CLIENT and SERVER elect a master who decides on the final connection
187 8. The CLIENT and SERVER elect a master who decides on the final connection
188 parameters.
188 parameters.
189
189
190 The public/private key pair associated with each process's x509 certificate
190 The public/private key pair associated with each process's x509 certificate
191 are completely hidden from this handshake protocol. There are however, used
191 are completely hidden from this handshake protocol. There are however, used
192 internally by OpenSSL as part of the SSL handshake protocol. Each process
192 internally by OpenSSL as part of the SSL handshake protocol. Each process
193 keeps their own private key hidden and sends its peer only the public key
193 keeps their own private key hidden and sends its peer only the public key
194 (embedded in the certificate).
194 (embedded in the certificate).
195
195
196 Finally, when the CLIENT requests access to a particular SERVER capability,
196 Finally, when the CLIENT requests access to a particular SERVER capability,
197 the following happens:
197 the following happens:
198
198
199 1. The CLIENT asks the SERVER for access to a capability by presenting that
199 1. The CLIENT asks the SERVER for access to a capability by presenting that
200 capabilities id.
200 capabilities id.
201 2. If the SERVER has a capability with that id, access is granted. If not,
201 2. If the SERVER has a capability with that id, access is granted. If not,
202 access is not granted.
202 access is not granted.
203 3. Once access has been gained, the CLIENT can use the capability.
203 3. Once access has been gained, the CLIENT can use the capability.
204
204
205 Specific security vulnerabilities
205 Specific security vulnerabilities
206 =================================
206 =================================
207
207
208 There are a number of potential security vulnerabilities present in IPython's
208 There are a number of potential security vulnerabilities present in IPython's
209 architecture. In this section we discuss those vulnerabilities and detail how
209 architecture. In this section we discuss those vulnerabilities and detail how
210 the security architecture described above prevents them from being exploited.
210 the security architecture described above prevents them from being exploited.
211
211
212 Unauthorized clients
212 Unauthorized clients
213 --------------------
213 --------------------
214
214
215 The IPython client can instruct the IPython engines to execute arbitrary
215 The IPython client can instruct the IPython engines to execute arbitrary
216 Python code with the permissions of the user who started the engines. If an
216 Python code with the permissions of the user who started the engines. If an
217 attacker were able to connect their own hostile IPython client to the IPython
217 attacker were able to connect their own hostile IPython client to the IPython
218 controller, they could instruct the engines to execute code.
218 controller, they could instruct the engines to execute code.
219
219
220 This attack is prevented by the capabilities based client authentication
220 This attack is prevented by the capabilities based client authentication
221 performed after the encrypted channel has been established. The relevant
221 performed after the encrypted channel has been established. The relevant
222 authentication information is encoded into the FURL that clients must
222 authentication information is encoded into the FURL that clients must
223 present to gain access to the IPython controller. By limiting the distribution
223 present to gain access to the IPython controller. By limiting the distribution
224 of those FURLs, a user can grant access to only authorized persons.
224 of those FURLs, a user can grant access to only authorized persons.
225
225
226 It is highly unlikely that a client FURL could be guessed by an attacker
226 It is highly unlikely that a client FURL could be guessed by an attacker
227 in a brute force guessing attack. A given instance of the IPython controller
227 in a brute force guessing attack. A given instance of the IPython controller
228 only runs for a relatively short amount of time (on the order of hours). Thus
228 only runs for a relatively short amount of time (on the order of hours). Thus
229 an attacker would have only a limited amount of time to test a search space of
229 an attacker would have only a limited amount of time to test a search space of
230 size 2**320. Furthermore, even if a controller were to run for a longer amount
230 size 2**320. Furthermore, even if a controller were to run for a longer amount
231 of time, this search space is quite large (larger for instance than that of
231 of time, this search space is quite large (larger for instance than that of
232 typical username/password pair).
232 typical username/password pair).
233
233
234 Unauthorized engines
234 Unauthorized engines
235 --------------------
235 --------------------
236
236
237 If an attacker were able to connect a hostile engine to a user's controller,
237 If an attacker were able to connect a hostile engine to a user's controller,
238 the user might unknowingly send sensitive code or data to the hostile engine.
238 the user might unknowingly send sensitive code or data to the hostile engine.
239 This attacker's engine would then have full access to that code and data.
239 This attacker's engine would then have full access to that code and data.
240
240
241 This type of attack is prevented in the same way as the unauthorized client
241 This type of attack is prevented in the same way as the unauthorized client
242 attack, through the usage of the capabilities based authentication scheme.
242 attack, through the usage of the capabilities based authentication scheme.
243
243
244 Unauthorized controllers
244 Unauthorized controllers
245 ------------------------
245 ------------------------
246
246
247 It is also possible that an attacker could try to convince a user's IPython
247 It is also possible that an attacker could try to convince a user's IPython
248 client or engine to connect to a hostile IPython controller. That controller
248 client or engine to connect to a hostile IPython controller. That controller
249 would then have full access to the code and data sent between the IPython
249 would then have full access to the code and data sent between the IPython
250 client and the IPython engines.
250 client and the IPython engines.
251
251
252 Again, this attack is prevented through the FURLs, which ensure that a
252 Again, this attack is prevented through the FURLs, which ensure that a
253 client or engine connects to the correct controller. It is also important to
253 client or engine connects to the correct controller. It is also important to
254 note that the FURLs also encode the IP address and port that the
254 note that the FURLs also encode the IP address and port that the
255 controller is listening on, so there is little chance of mistakenly connecting
255 controller is listening on, so there is little chance of mistakenly connecting
256 to a controller running on a different IP address and port.
256 to a controller running on a different IP address and port.
257
257
258 When starting an engine or client, a user must specify which FURL to use
258 When starting an engine or client, a user must specify which FURL to use
259 for that connection. Thus, in order to introduce a hostile controller, the
259 for that connection. Thus, in order to introduce a hostile controller, the
260 attacker must convince the user to use the FURLs associated with the
260 attacker must convince the user to use the FURLs associated with the
261 hostile controller. As long as a user is diligent in only using FURLs from
261 hostile controller. As long as a user is diligent in only using FURLs from
262 trusted sources, this attack is not possible.
262 trusted sources, this attack is not possible.
263
263
264 Other security measures
264 Other security measures
265 =======================
265 =======================
266
266
267 A number of other measures are taken to further limit the security risks
267 A number of other measures are taken to further limit the security risks
268 involved in running the IPython kernel.
268 involved in running the IPython kernel.
269
269
270 First, by default, the IPython controller listens on random port numbers.
270 First, by default, the IPython controller listens on random port numbers.
271 While this can be overridden by the user, in the default configuration, an
271 While this can be overridden by the user, in the default configuration, an
272 attacker would have to do a port scan to even find a controller to attack.
272 attacker would have to do a port scan to even find a controller to attack.
273 When coupled with the relatively short running time of a typical controller
273 When coupled with the relatively short running time of a typical controller
274 (on the order of hours), an attacker would have to work extremely hard and
274 (on the order of hours), an attacker would have to work extremely hard and
275 extremely *fast* to even find a running controller to attack.
275 extremely *fast* to even find a running controller to attack.
276
276
277 Second, much of the time, especially when run on supercomputers or clusters,
277 Second, much of the time, especially when run on supercomputers or clusters,
278 the controller is running behind a firewall. Thus, for engines or client to
278 the controller is running behind a firewall. Thus, for engines or client to
279 connect to the controller:
279 connect to the controller:
280
280
281 * The different processes have to all be behind the firewall.
281 * The different processes have to all be behind the firewall.
282
282
283 or:
283 or:
284
284
285 * The user has to use SSH port forwarding to tunnel the
285 * The user has to use SSH port forwarding to tunnel the
286 connections through the firewall.
286 connections through the firewall.
287
287
288 In either case, an attacker is presented with addition barriers that prevent
288 In either case, an attacker is presented with addition barriers that prevent
289 attacking or even probing the system.
289 attacking or even probing the system.
290
290
291 Summary
291 Summary
292 =======
292 =======
293
293
294 IPython's architecture has been carefully designed with security in mind. The
294 IPython's architecture has been carefully designed with security in mind. The
295 capabilities based authentication model, in conjunction with the encrypted
295 capabilities based authentication model, in conjunction with the encrypted
296 TCP/IP channels, address the core potential vulnerabilities in the system,
296 TCP/IP channels, address the core potential vulnerabilities in the system,
297 while still enabling user's to use the system in open networks.
297 while still enabling user's to use the system in open networks.
298
298
299 Other questions
299 Other questions
300 ===============
300 ===============
301
301
302 About keys
302 About keys
303 ----------
303 ----------
304
304
305 Can you clarify the roles of the certificate and its keys versus the FURL,
305 Can you clarify the roles of the certificate and its keys versus the FURL,
306 which is also called a key?
306 which is also called a key?
307
307
308 The certificate created by IPython processes is a standard public key x509
308 The certificate created by IPython processes is a standard public key x509
309 certificate, that is used by the SSL handshake protocol to setup encrypted
309 certificate, that is used by the SSL handshake protocol to setup encrypted
310 channel between the controller and the IPython engine or client. This public
310 channel between the controller and the IPython engine or client. This public
311 and private key associated with this certificate are used only by the SSL
311 and private key associated with this certificate are used only by the SSL
312 handshake protocol in setting up this encrypted channel.
312 handshake protocol in setting up this encrypted channel.
313
313
314 The FURL serves a completely different and independent purpose from the
314 The FURL serves a completely different and independent purpose from the
315 key pair associated with the certificate. When we refer to a FURL as a
315 key pair associated with the certificate. When we refer to a FURL as a
316 key, we are using the word "key" in the capabilities based security model
316 key, we are using the word "key" in the capabilities based security model
317 sense. This has nothing to do with "key" in the public/private key sense used
317 sense. This has nothing to do with "key" in the public/private key sense used
318 in the SSL protocol.
318 in the SSL protocol.
319
319
320 With that said the FURL is used as an cryptographic key, to grant
320 With that said the FURL is used as an cryptographic key, to grant
321 IPython engines and clients access to particular capabilities that the
321 IPython engines and clients access to particular capabilities that the
322 controller offers.
322 controller offers.
323
323
324 Self signed certificates
324 Self signed certificates
325 ------------------------
325 ------------------------
326
326
327 Is the controller creating a self-signed certificate? Is this created for per
327 Is the controller creating a self-signed certificate? Is this created for per
328 instance/session, one-time-setup or each-time the controller is started?
328 instance/session, one-time-setup or each-time the controller is started?
329
329
330 The Foolscap network protocol, which handles the SSL protocol details, creates
330 The Foolscap network protocol, which handles the SSL protocol details, creates
331 a self-signed x509 certificate using OpenSSL for each IPython process. The
331 a self-signed x509 certificate using OpenSSL for each IPython process. The
332 lifetime of the certificate is handled differently for the IPython controller
332 lifetime of the certificate is handled differently for the IPython controller
333 and the engines/client.
333 and the engines/client.
334
334
335 For the IPython engines and client, the certificate is only held in memory for
335 For the IPython engines and client, the certificate is only held in memory for
336 the lifetime of its process. It is never written to disk.
336 the lifetime of its process. It is never written to disk.
337
337
338 For the controller, the certificate can be created anew each time the
338 For the controller, the certificate can be created anew each time the
339 controller starts or it can be created once and reused each time the
339 controller starts or it can be created once and reused each time the
340 controller starts. If at any point, the certificate is deleted, a new one is
340 controller starts. If at any point, the certificate is deleted, a new one is
341 created the next time the controller starts.
341 created the next time the controller starts.
342
342
343 SSL private key
343 SSL private key
344 ---------------
344 ---------------
345
345
346 How the private key (associated with the certificate) is distributed?
346 How the private key (associated with the certificate) is distributed?
347
347
348 In the usual implementation of the SSL protocol, the private key is never
348 In the usual implementation of the SSL protocol, the private key is never
349 distributed. We follow this standard always.
349 distributed. We follow this standard always.
350
350
351 SSL versus Foolscap authentication
351 SSL versus Foolscap authentication
352 ----------------------------------
352 ----------------------------------
353
353
354 Many SSL connections only perform one sided authentication (the server to the
354 Many SSL connections only perform one sided authentication (the server to the
355 client). How is the client authentication in IPython's system related to SSL
355 client). How is the client authentication in IPython's system related to SSL
356 authentication?
356 authentication?
357
357
358 We perform a two way SSL handshake in which both parties request and verify
358 We perform a two way SSL handshake in which both parties request and verify
359 the certificate of their peer. This mutual authentication is handled by the
359 the certificate of their peer. This mutual authentication is handled by the
360 SSL handshake and is separate and independent from the additional
360 SSL handshake and is separate and independent from the additional
361 authentication steps that the CLIENT and SERVER perform after an encrypted
361 authentication steps that the CLIENT and SERVER perform after an encrypted
362 channel is established.
362 channel is established.
363
363
364 .. [RFC5246] <http://tools.ietf.org/html/rfc5246>
364 .. [RFC5246] <http://tools.ietf.org/html/rfc5246>
365
366
@@ -1,120 +1,121 b''
1 .. _paralleltask:
1 .. _paralleltask:
2
2
3 ==========================
3 ==========================
4 The IPython task interface
4 The IPython task interface
5 ==========================
5 ==========================
6
6
7 The task interface to the controller presents the engines as a fault tolerant,
7 The task interface to the controller presents the engines as a fault tolerant,
8 dynamic load-balanced system or workers. Unlike the multiengine interface, in
8 dynamic load-balanced system or workers. Unlike the multiengine interface, in
9 the task interface, the user have no direct access to individual engines. In
9 the task interface, the user have no direct access to individual engines. In
10 some ways, this interface is simpler, but in other ways it is more powerful.
10 some ways, this interface is simpler, but in other ways it is more powerful.
11
11
12 Best of all the user can use both of these interfaces running at the same time
12 Best of all the user can use both of these interfaces running at the same time
13 to take advantage or both of their strengths. When the user can break up the
13 to take advantage or both of their strengths. When the user can break up the
14 user's work into segments that do not depend on previous execution, the task
14 user's work into segments that do not depend on previous execution, the task
15 interface is ideal. But it also has more power and flexibility, allowing the
15 interface is ideal. But it also has more power and flexibility, allowing the
16 user to guide the distribution of jobs, without having to assign tasks to
16 user to guide the distribution of jobs, without having to assign tasks to
17 engines explicitly.
17 engines explicitly.
18
18
19 Starting the IPython controller and engines
19 Starting the IPython controller and engines
20 ===========================================
20 ===========================================
21
21
22 To follow along with this tutorial, you will need to start the IPython
22 To follow along with this tutorial, you will need to start the IPython
23 controller and four IPython engines. The simplest way of doing this is to use
23 controller and four IPython engines. The simplest way of doing this is to use
24 the :command:`ipcluster` command::
24 the :command:`ipcluster` command::
25
25
26 $ ipcluster local -n 4
26 $ ipcluster local -n 4
27
27
28 For more detailed information about starting the controller and engines, see
28 For more detailed information about starting the controller and engines, see
29 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
29 our :ref:`introduction <ip1par>` to using IPython for parallel computing.
30
30
31 Creating a ``TaskClient`` instance
31 Creating a ``TaskClient`` instance
32 =========================================
32 =========================================
33
33
34 The first step is to import the IPython :mod:`IPython.kernel.client` module
34 The first step is to import the IPython :mod:`IPython.kernel.client` module
35 and then create a :class:`TaskClient` instance:
35 and then create a :class:`TaskClient` instance:
36
36
37 .. sourcecode:: ipython
37 .. sourcecode:: ipython
38
38
39 In [1]: from IPython.kernel import client
39 In [1]: from IPython.kernel import client
40
40
41 In [2]: tc = client.TaskClient()
41 In [2]: tc = client.TaskClient()
42
42
43 This form assumes that the :file:`ipcontroller-tc.furl` is in the
43 This form assumes that the :file:`ipcontroller-tc.furl` is in the
44 :file:`~./ipython/security` directory on the client's host. If not, the
44 :file:`~./ipython/security` directory on the client's host. If not, the
45 location of the FURL file must be given as an argument to the
45 location of the FURL file must be given as an argument to the
46 constructor:
46 constructor:
47
47
48 .. sourcecode:: ipython
48 .. sourcecode:: ipython
49
49
50 In [2]: mec = client.TaskClient('/path/to/my/ipcontroller-tc.furl')
50 In [2]: mec = client.TaskClient('/path/to/my/ipcontroller-tc.furl')
51
51
52 Quick and easy parallelism
52 Quick and easy parallelism
53 ==========================
53 ==========================
54
54
55 In many cases, you simply want to apply a Python function to a sequence of
55 In many cases, you simply want to apply a Python function to a sequence of
56 objects, but *in parallel*. Like the multiengine interface, the task interface
56 objects, but *in parallel*. Like the multiengine interface, the task interface
57 provides two simple ways of accomplishing this: a parallel version of
57 provides two simple ways of accomplishing this: a parallel version of
58 :func:`map` and ``@parallel`` function decorator. However, the verions in the
58 :func:`map` and ``@parallel`` function decorator. However, the verions in the
59 task interface have one important difference: they are dynamically load
59 task interface have one important difference: they are dynamically load
60 balanced. Thus, if the execution time per item varies significantly, you
60 balanced. Thus, if the execution time per item varies significantly, you
61 should use the versions in the task interface.
61 should use the versions in the task interface.
62
62
63 Parallel map
63 Parallel map
64 ------------
64 ------------
65
65
66 The parallel :meth:`map` in the task interface is similar to that in the
66 The parallel :meth:`map` in the task interface is similar to that in the
67 multiengine interface:
67 multiengine interface:
68
68
69 .. sourcecode:: ipython
69 .. sourcecode:: ipython
70
70
71 In [63]: serial_result = map(lambda x:x**10, range(32))
71 In [63]: serial_result = map(lambda x:x**10, range(32))
72
72
73 In [64]: parallel_result = tc.map(lambda x:x**10, range(32))
73 In [64]: parallel_result = tc.map(lambda x:x**10, range(32))
74
74
75 In [65]: serial_result==parallel_result
75 In [65]: serial_result==parallel_result
76 Out[65]: True
76 Out[65]: True
77
77
78 Parallel function decorator
78 Parallel function decorator
79 ---------------------------
79 ---------------------------
80
80
81 Parallel functions are just like normal function, but they can be called on
81 Parallel functions are just like normal function, but they can be called on
82 sequences and *in parallel*. The multiengine interface provides a decorator
82 sequences and *in parallel*. The multiengine interface provides a decorator
83 that turns any Python function into a parallel function:
83 that turns any Python function into a parallel function:
84
84
85 .. sourcecode:: ipython
85 .. sourcecode:: ipython
86
86
87 In [10]: @tc.parallel()
87 In [10]: @tc.parallel()
88 ....: def f(x):
88 ....: def f(x):
89 ....: return 10.0*x**4
89 ....: return 10.0*x**4
90 ....:
90 ....:
91
91
92 In [11]: f(range(32)) # this is done in parallel
92 In [11]: f(range(32)) # this is done in parallel
93 Out[11]:
93 Out[11]:
94 [0.0,10.0,160.0,...]
94 [0.0,10.0,160.0,...]
95
95
96 More details
96 More details
97 ============
97 ============
98
98
99 The :class:`TaskClient` has many more powerful features that allow quite a bit
99 The :class:`TaskClient` has many more powerful features that allow quite a bit
100 of flexibility in how tasks are defined and run. The next places to look are
100 of flexibility in how tasks are defined and run. The next places to look are
101 in the following classes:
101 in the following classes:
102
102
103 * :class:`IPython.kernel.client.TaskClient`
103 * :class:`IPython.kernel.client.TaskClient`
104 * :class:`IPython.kernel.client.StringTask`
104 * :class:`IPython.kernel.client.StringTask`
105 * :class:`IPython.kernel.client.MapTask`
105 * :class:`IPython.kernel.client.MapTask`
106
106
107 The following is an overview of how to use these classes together:
107 The following is an overview of how to use these classes together:
108
108
109 1. Create a :class:`TaskClient`.
109 1. Create a :class:`TaskClient`.
110 2. Create one or more instances of :class:`StringTask` or :class:`MapTask`
110 2. Create one or more instances of :class:`StringTask` or :class:`MapTask`
111 to define your tasks.
111 to define your tasks.
112 3. Submit your tasks to using the :meth:`run` method of your
112 3. Submit your tasks to using the :meth:`run` method of your
113 :class:`TaskClient` instance.
113 :class:`TaskClient` instance.
114 4. Use :meth:`TaskClient.get_task_result` to get the results of the
114 4. Use :meth:`TaskClient.get_task_result` to get the results of the
115 tasks.
115 tasks.
116
116
117 We are in the process of developing more detailed information about the task
117 We are in the process of developing more detailed information about the task
118 interface. For now, the docstrings of the :class:`TaskClient`,
118 interface. For now, the docstrings of the :class:`TaskClient`,
119 :class:`StringTask` and :class:`MapTask` classes should be consulted.
119 :class:`StringTask` and :class:`MapTask` classes should be consulted.
120
120
121
@@ -1,426 +1,427 b''
1 """Attempt to generate templates for module reference with Sphinx
1 """Attempt to generate templates for module reference with Sphinx
2
2
3 XXX - we exclude extension modules
3 XXX - we exclude extension modules
4
4
5 To include extension modules, first identify them as valid in the
5 To include extension modules, first identify them as valid in the
6 ``_uri2path`` method, then handle them in the ``_parse_module`` script.
6 ``_uri2path`` method, then handle them in the ``_parse_module`` script.
7
7
8 We get functions and classes by parsing the text of .py files.
8 We get functions and classes by parsing the text of .py files.
9 Alternatively we could import the modules for discovery, and we'd have
9 Alternatively we could import the modules for discovery, and we'd have
10 to do that for extension modules. This would involve changing the
10 to do that for extension modules. This would involve changing the
11 ``_parse_module`` method to work via import and introspection, and
11 ``_parse_module`` method to work via import and introspection, and
12 might involve changing ``discover_modules`` (which determines which
12 might involve changing ``discover_modules`` (which determines which
13 files are modules, and therefore which module URIs will be passed to
13 files are modules, and therefore which module URIs will be passed to
14 ``_parse_module``).
14 ``_parse_module``).
15
15
16 NOTE: this is a modified version of a script originally shipped with the
16 NOTE: this is a modified version of a script originally shipped with the
17 PyMVPA project, which we've adapted for NIPY use. PyMVPA is an MIT-licensed
17 PyMVPA project, which we've adapted for NIPY use. PyMVPA is an MIT-licensed
18 project."""
18 project."""
19
19
20 # Stdlib imports
20 # Stdlib imports
21 import os
21 import os
22 import re
22 import re
23
23
24 # Functions and classes
24 # Functions and classes
25 class ApiDocWriter(object):
25 class ApiDocWriter(object):
26 ''' Class for automatic detection and parsing of API docs
26 ''' Class for automatic detection and parsing of API docs
27 to Sphinx-parsable reST format'''
27 to Sphinx-parsable reST format'''
28
28
29 # only separating first two levels
29 # only separating first two levels
30 rst_section_levels = ['*', '=', '-', '~', '^']
30 rst_section_levels = ['*', '=', '-', '~', '^']
31
31
32 def __init__(self,
32 def __init__(self,
33 package_name,
33 package_name,
34 rst_extension='.rst',
34 rst_extension='.rst',
35 package_skip_patterns=None,
35 package_skip_patterns=None,
36 module_skip_patterns=None,
36 module_skip_patterns=None,
37 ):
37 ):
38 ''' Initialize package for parsing
38 ''' Initialize package for parsing
39
39
40 Parameters
40 Parameters
41 ----------
41 ----------
42 package_name : string
42 package_name : string
43 Name of the top-level package. *package_name* must be the
43 Name of the top-level package. *package_name* must be the
44 name of an importable package
44 name of an importable package
45 rst_extension : string, optional
45 rst_extension : string, optional
46 Extension for reST files, default '.rst'
46 Extension for reST files, default '.rst'
47 package_skip_patterns : None or sequence of {strings, regexps}
47 package_skip_patterns : None or sequence of {strings, regexps}
48 Sequence of strings giving URIs of packages to be excluded
48 Sequence of strings giving URIs of packages to be excluded
49 Operates on the package path, starting at (including) the
49 Operates on the package path, starting at (including) the
50 first dot in the package path, after *package_name* - so,
50 first dot in the package path, after *package_name* - so,
51 if *package_name* is ``sphinx``, then ``sphinx.util`` will
51 if *package_name* is ``sphinx``, then ``sphinx.util`` will
52 result in ``.util`` being passed for earching by these
52 result in ``.util`` being passed for earching by these
53 regexps. If is None, gives default. Default is:
53 regexps. If is None, gives default. Default is:
54 ['\.tests$']
54 ['\.tests$']
55 module_skip_patterns : None or sequence
55 module_skip_patterns : None or sequence
56 Sequence of strings giving URIs of modules to be excluded
56 Sequence of strings giving URIs of modules to be excluded
57 Operates on the module name including preceding URI path,
57 Operates on the module name including preceding URI path,
58 back to the first dot after *package_name*. For example
58 back to the first dot after *package_name*. For example
59 ``sphinx.util.console`` results in the string to search of
59 ``sphinx.util.console`` results in the string to search of
60 ``.util.console``
60 ``.util.console``
61 If is None, gives default. Default is:
61 If is None, gives default. Default is:
62 ['\.setup$', '\._']
62 ['\.setup$', '\._']
63 '''
63 '''
64 if package_skip_patterns is None:
64 if package_skip_patterns is None:
65 package_skip_patterns = ['\\.tests$']
65 package_skip_patterns = ['\\.tests$']
66 if module_skip_patterns is None:
66 if module_skip_patterns is None:
67 module_skip_patterns = ['\\.setup$', '\\._']
67 module_skip_patterns = ['\\.setup$', '\\._']
68 self.package_name = package_name
68 self.package_name = package_name
69 self.rst_extension = rst_extension
69 self.rst_extension = rst_extension
70 self.package_skip_patterns = package_skip_patterns
70 self.package_skip_patterns = package_skip_patterns
71 self.module_skip_patterns = module_skip_patterns
71 self.module_skip_patterns = module_skip_patterns
72
72
73 def get_package_name(self):
73 def get_package_name(self):
74 return self._package_name
74 return self._package_name
75
75
76 def set_package_name(self, package_name):
76 def set_package_name(self, package_name):
77 ''' Set package_name
77 ''' Set package_name
78
78
79 >>> docwriter = ApiDocWriter('sphinx')
79 >>> docwriter = ApiDocWriter('sphinx')
80 >>> import sphinx
80 >>> import sphinx
81 >>> docwriter.root_path == sphinx.__path__[0]
81 >>> docwriter.root_path == sphinx.__path__[0]
82 True
82 True
83 >>> docwriter.package_name = 'docutils'
83 >>> docwriter.package_name = 'docutils'
84 >>> import docutils
84 >>> import docutils
85 >>> docwriter.root_path == docutils.__path__[0]
85 >>> docwriter.root_path == docutils.__path__[0]
86 True
86 True
87 '''
87 '''
88 # It's also possible to imagine caching the module parsing here
88 # It's also possible to imagine caching the module parsing here
89 self._package_name = package_name
89 self._package_name = package_name
90 self.root_module = __import__(package_name)
90 self.root_module = __import__(package_name)
91 self.root_path = self.root_module.__path__[0]
91 self.root_path = self.root_module.__path__[0]
92 self.written_modules = None
92 self.written_modules = None
93
93
94 package_name = property(get_package_name, set_package_name, None,
94 package_name = property(get_package_name, set_package_name, None,
95 'get/set package_name')
95 'get/set package_name')
96
96
97 def _get_object_name(self, line):
97 def _get_object_name(self, line):
98 ''' Get second token in line
98 ''' Get second token in line
99 >>> docwriter = ApiDocWriter('sphinx')
99 >>> docwriter = ApiDocWriter('sphinx')
100 >>> docwriter._get_object_name(" def func(): ")
100 >>> docwriter._get_object_name(" def func(): ")
101 'func'
101 'func'
102 >>> docwriter._get_object_name(" class Klass(object): ")
102 >>> docwriter._get_object_name(" class Klass(object): ")
103 'Klass'
103 'Klass'
104 >>> docwriter._get_object_name(" class Klass: ")
104 >>> docwriter._get_object_name(" class Klass: ")
105 'Klass'
105 'Klass'
106 '''
106 '''
107 name = line.split()[1].split('(')[0].strip()
107 name = line.split()[1].split('(')[0].strip()
108 # in case we have classes which are not derived from object
108 # in case we have classes which are not derived from object
109 # ie. old style classes
109 # ie. old style classes
110 return name.rstrip(':')
110 return name.rstrip(':')
111
111
112 def _uri2path(self, uri):
112 def _uri2path(self, uri):
113 ''' Convert uri to absolute filepath
113 ''' Convert uri to absolute filepath
114
114
115 Parameters
115 Parameters
116 ----------
116 ----------
117 uri : string
117 uri : string
118 URI of python module to return path for
118 URI of python module to return path for
119
119
120 Returns
120 Returns
121 -------
121 -------
122 path : None or string
122 path : None or string
123 Returns None if there is no valid path for this URI
123 Returns None if there is no valid path for this URI
124 Otherwise returns absolute file system path for URI
124 Otherwise returns absolute file system path for URI
125
125
126 Examples
126 Examples
127 --------
127 --------
128 >>> docwriter = ApiDocWriter('sphinx')
128 >>> docwriter = ApiDocWriter('sphinx')
129 >>> import sphinx
129 >>> import sphinx
130 >>> modpath = sphinx.__path__[0]
130 >>> modpath = sphinx.__path__[0]
131 >>> res = docwriter._uri2path('sphinx.builder')
131 >>> res = docwriter._uri2path('sphinx.builder')
132 >>> res == os.path.join(modpath, 'builder.py')
132 >>> res == os.path.join(modpath, 'builder.py')
133 True
133 True
134 >>> res = docwriter._uri2path('sphinx')
134 >>> res = docwriter._uri2path('sphinx')
135 >>> res == os.path.join(modpath, '__init__.py')
135 >>> res == os.path.join(modpath, '__init__.py')
136 True
136 True
137 >>> docwriter._uri2path('sphinx.does_not_exist')
137 >>> docwriter._uri2path('sphinx.does_not_exist')
138
138
139 '''
139 '''
140 if uri == self.package_name:
140 if uri == self.package_name:
141 return os.path.join(self.root_path, '__init__.py')
141 return os.path.join(self.root_path, '__init__.py')
142 path = uri.replace('.', os.path.sep)
142 path = uri.replace('.', os.path.sep)
143 path = path.replace(self.package_name + os.path.sep, '')
143 path = path.replace(self.package_name + os.path.sep, '')
144 path = os.path.join(self.root_path, path)
144 path = os.path.join(self.root_path, path)
145 # XXX maybe check for extensions as well?
145 # XXX maybe check for extensions as well?
146 if os.path.exists(path + '.py'): # file
146 if os.path.exists(path + '.py'): # file
147 path += '.py'
147 path += '.py'
148 elif os.path.exists(os.path.join(path, '__init__.py')):
148 elif os.path.exists(os.path.join(path, '__init__.py')):
149 path = os.path.join(path, '__init__.py')
149 path = os.path.join(path, '__init__.py')
150 else:
150 else:
151 return None
151 return None
152 return path
152 return path
153
153
154 def _path2uri(self, dirpath):
154 def _path2uri(self, dirpath):
155 ''' Convert directory path to uri '''
155 ''' Convert directory path to uri '''
156 relpath = dirpath.replace(self.root_path, self.package_name)
156 relpath = dirpath.replace(self.root_path, self.package_name)
157 if relpath.startswith(os.path.sep):
157 if relpath.startswith(os.path.sep):
158 relpath = relpath[1:]
158 relpath = relpath[1:]
159 return relpath.replace(os.path.sep, '.')
159 return relpath.replace(os.path.sep, '.')
160
160
161 def _parse_module(self, uri):
161 def _parse_module(self, uri):
162 ''' Parse module defined in *uri* '''
162 ''' Parse module defined in *uri* '''
163 filename = self._uri2path(uri)
163 filename = self._uri2path(uri)
164 if filename is None:
164 if filename is None:
165 # nothing that we could handle here.
165 # nothing that we could handle here.
166 return ([],[])
166 return ([],[])
167 f = open(filename, 'rt')
167 f = open(filename, 'rt')
168 functions, classes = self._parse_lines(f)
168 functions, classes = self._parse_lines(f)
169 f.close()
169 f.close()
170 return functions, classes
170 return functions, classes
171
171
172 def _parse_lines(self, linesource):
172 def _parse_lines(self, linesource):
173 ''' Parse lines of text for functions and classes '''
173 ''' Parse lines of text for functions and classes '''
174 functions = []
174 functions = []
175 classes = []
175 classes = []
176 for line in linesource:
176 for line in linesource:
177 if line.startswith('def ') and line.count('('):
177 if line.startswith('def ') and line.count('('):
178 # exclude private stuff
178 # exclude private stuff
179 name = self._get_object_name(line)
179 name = self._get_object_name(line)
180 if not name.startswith('_'):
180 if not name.startswith('_'):
181 functions.append(name)
181 functions.append(name)
182 elif line.startswith('class '):
182 elif line.startswith('class '):
183 # exclude private stuff
183 # exclude private stuff
184 name = self._get_object_name(line)
184 name = self._get_object_name(line)
185 if not name.startswith('_'):
185 if not name.startswith('_'):
186 classes.append(name)
186 classes.append(name)
187 else:
187 else:
188 pass
188 pass
189 functions.sort()
189 functions.sort()
190 classes.sort()
190 classes.sort()
191 return functions, classes
191 return functions, classes
192
192
193 def generate_api_doc(self, uri):
193 def generate_api_doc(self, uri):
194 '''Make autodoc documentation template string for a module
194 '''Make autodoc documentation template string for a module
195
195
196 Parameters
196 Parameters
197 ----------
197 ----------
198 uri : string
198 uri : string
199 python location of module - e.g 'sphinx.builder'
199 python location of module - e.g 'sphinx.builder'
200
200
201 Returns
201 Returns
202 -------
202 -------
203 S : string
203 S : string
204 Contents of API doc
204 Contents of API doc
205 '''
205 '''
206 # get the names of all classes and functions
206 # get the names of all classes and functions
207 functions, classes = self._parse_module(uri)
207 functions, classes = self._parse_module(uri)
208 if not len(functions) and not len(classes):
208 if not len(functions) and not len(classes):
209 print 'WARNING: Empty -',uri # dbg
209 print 'WARNING: Empty -',uri # dbg
210 return ''
210 return ''
211
211
212 # Make a shorter version of the uri that omits the package name for
212 # Make a shorter version of the uri that omits the package name for
213 # titles
213 # titles
214 uri_short = re.sub(r'^%s\.' % self.package_name,'',uri)
214 uri_short = re.sub(r'^%s\.' % self.package_name,'',uri)
215
215
216 ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
216 ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
217
217
218 chap_title = uri_short
218 chap_title = uri_short
219 ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
219 ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
220 + '\n\n')
220 + '\n\n')
221
221
222 # Set the chapter title to read 'module' for all modules except for the
222 # Set the chapter title to read 'module' for all modules except for the
223 # main packages
223 # main packages
224 if '.' in uri:
224 if '.' in uri:
225 title = 'Module: :mod:`' + uri_short + '`'
225 title = 'Module: :mod:`' + uri_short + '`'
226 else:
226 else:
227 title = ':mod:`' + uri_short + '`'
227 title = ':mod:`' + uri_short + '`'
228 ad += title + '\n' + self.rst_section_levels[2] * len(title)
228 ad += title + '\n' + self.rst_section_levels[2] * len(title)
229
229
230 if len(classes):
230 if len(classes):
231 ad += '\nInheritance diagram for ``%s``:\n\n' % uri
231 ad += '\nInheritance diagram for ``%s``:\n\n' % uri
232 ad += '.. inheritance-diagram:: %s \n' % uri
232 ad += '.. inheritance-diagram:: %s \n' % uri
233 ad += ' :parts: 3\n'
233 ad += ' :parts: 3\n'
234
234
235 ad += '\n.. automodule:: ' + uri + '\n'
235 ad += '\n.. automodule:: ' + uri + '\n'
236 ad += '\n.. currentmodule:: ' + uri + '\n'
236 ad += '\n.. currentmodule:: ' + uri + '\n'
237 multi_class = len(classes) > 1
237 multi_class = len(classes) > 1
238 multi_fx = len(functions) > 1
238 multi_fx = len(functions) > 1
239 if multi_class:
239 if multi_class:
240 ad += '\n' + 'Classes' + '\n' + \
240 ad += '\n' + 'Classes' + '\n' + \
241 self.rst_section_levels[2] * 7 + '\n'
241 self.rst_section_levels[2] * 7 + '\n'
242 elif len(classes) and multi_fx:
242 elif len(classes) and multi_fx:
243 ad += '\n' + 'Class' + '\n' + \
243 ad += '\n' + 'Class' + '\n' + \
244 self.rst_section_levels[2] * 5 + '\n'
244 self.rst_section_levels[2] * 5 + '\n'
245 for c in classes:
245 for c in classes:
246 ad += '\n:class:`' + c + '`\n' \
246 ad += '\n:class:`' + c + '`\n' \
247 + self.rst_section_levels[multi_class + 2 ] * \
247 + self.rst_section_levels[multi_class + 2 ] * \
248 (len(c)+9) + '\n\n'
248 (len(c)+9) + '\n\n'
249 ad += '\n.. autoclass:: ' + c + '\n'
249 ad += '\n.. autoclass:: ' + c + '\n'
250 # must NOT exclude from index to keep cross-refs working
250 # must NOT exclude from index to keep cross-refs working
251 ad += ' :members:\n' \
251 ad += ' :members:\n' \
252 ' :undoc-members:\n' \
252 ' :undoc-members:\n' \
253 ' :show-inheritance:\n' \
253 ' :show-inheritance:\n' \
254 ' :inherited-members:\n' \
254 '\n' \
255 '\n' \
255 ' .. automethod:: __init__\n'
256 ' .. automethod:: __init__\n'
256 if multi_fx:
257 if multi_fx:
257 ad += '\n' + 'Functions' + '\n' + \
258 ad += '\n' + 'Functions' + '\n' + \
258 self.rst_section_levels[2] * 9 + '\n\n'
259 self.rst_section_levels[2] * 9 + '\n\n'
259 elif len(functions) and multi_class:
260 elif len(functions) and multi_class:
260 ad += '\n' + 'Function' + '\n' + \
261 ad += '\n' + 'Function' + '\n' + \
261 self.rst_section_levels[2] * 8 + '\n\n'
262 self.rst_section_levels[2] * 8 + '\n\n'
262 for f in functions:
263 for f in functions:
263 # must NOT exclude from index to keep cross-refs working
264 # must NOT exclude from index to keep cross-refs working
264 ad += '\n.. autofunction:: ' + uri + '.' + f + '\n\n'
265 ad += '\n.. autofunction:: ' + uri + '.' + f + '\n\n'
265 return ad
266 return ad
266
267
267 def _survives_exclude(self, matchstr, match_type):
268 def _survives_exclude(self, matchstr, match_type):
268 ''' Returns True if *matchstr* does not match patterns
269 ''' Returns True if *matchstr* does not match patterns
269
270
270 ``self.package_name`` removed from front of string if present
271 ``self.package_name`` removed from front of string if present
271
272
272 Examples
273 Examples
273 --------
274 --------
274 >>> dw = ApiDocWriter('sphinx')
275 >>> dw = ApiDocWriter('sphinx')
275 >>> dw._survives_exclude('sphinx.okpkg', 'package')
276 >>> dw._survives_exclude('sphinx.okpkg', 'package')
276 True
277 True
277 >>> dw.package_skip_patterns.append('^\\.badpkg$')
278 >>> dw.package_skip_patterns.append('^\\.badpkg$')
278 >>> dw._survives_exclude('sphinx.badpkg', 'package')
279 >>> dw._survives_exclude('sphinx.badpkg', 'package')
279 False
280 False
280 >>> dw._survives_exclude('sphinx.badpkg', 'module')
281 >>> dw._survives_exclude('sphinx.badpkg', 'module')
281 True
282 True
282 >>> dw._survives_exclude('sphinx.badmod', 'module')
283 >>> dw._survives_exclude('sphinx.badmod', 'module')
283 True
284 True
284 >>> dw.module_skip_patterns.append('^\\.badmod$')
285 >>> dw.module_skip_patterns.append('^\\.badmod$')
285 >>> dw._survives_exclude('sphinx.badmod', 'module')
286 >>> dw._survives_exclude('sphinx.badmod', 'module')
286 False
287 False
287 '''
288 '''
288 if match_type == 'module':
289 if match_type == 'module':
289 patterns = self.module_skip_patterns
290 patterns = self.module_skip_patterns
290 elif match_type == 'package':
291 elif match_type == 'package':
291 patterns = self.package_skip_patterns
292 patterns = self.package_skip_patterns
292 else:
293 else:
293 raise ValueError('Cannot interpret match type "%s"'
294 raise ValueError('Cannot interpret match type "%s"'
294 % match_type)
295 % match_type)
295 # Match to URI without package name
296 # Match to URI without package name
296 L = len(self.package_name)
297 L = len(self.package_name)
297 if matchstr[:L] == self.package_name:
298 if matchstr[:L] == self.package_name:
298 matchstr = matchstr[L:]
299 matchstr = matchstr[L:]
299 for pat in patterns:
300 for pat in patterns:
300 try:
301 try:
301 pat.search
302 pat.search
302 except AttributeError:
303 except AttributeError:
303 pat = re.compile(pat)
304 pat = re.compile(pat)
304 if pat.search(matchstr):
305 if pat.search(matchstr):
305 return False
306 return False
306 return True
307 return True
307
308
308 def discover_modules(self):
309 def discover_modules(self):
309 ''' Return module sequence discovered from ``self.package_name``
310 ''' Return module sequence discovered from ``self.package_name``
310
311
311
312
312 Parameters
313 Parameters
313 ----------
314 ----------
314 None
315 None
315
316
316 Returns
317 Returns
317 -------
318 -------
318 mods : sequence
319 mods : sequence
319 Sequence of module names within ``self.package_name``
320 Sequence of module names within ``self.package_name``
320
321
321 Examples
322 Examples
322 --------
323 --------
323 >>> dw = ApiDocWriter('sphinx')
324 >>> dw = ApiDocWriter('sphinx')
324 >>> mods = dw.discover_modules()
325 >>> mods = dw.discover_modules()
325 >>> 'sphinx.util' in mods
326 >>> 'sphinx.util' in mods
326 True
327 True
327 >>> dw.package_skip_patterns.append('\.util$')
328 >>> dw.package_skip_patterns.append('\.util$')
328 >>> 'sphinx.util' in dw.discover_modules()
329 >>> 'sphinx.util' in dw.discover_modules()
329 False
330 False
330 >>>
331 >>>
331 '''
332 '''
332 modules = [self.package_name]
333 modules = [self.package_name]
333 # raw directory parsing
334 # raw directory parsing
334 for dirpath, dirnames, filenames in os.walk(self.root_path):
335 for dirpath, dirnames, filenames in os.walk(self.root_path):
335 # Check directory names for packages
336 # Check directory names for packages
336 root_uri = self._path2uri(os.path.join(self.root_path,
337 root_uri = self._path2uri(os.path.join(self.root_path,
337 dirpath))
338 dirpath))
338 for dirname in dirnames[:]: # copy list - we modify inplace
339 for dirname in dirnames[:]: # copy list - we modify inplace
339 package_uri = '.'.join((root_uri, dirname))
340 package_uri = '.'.join((root_uri, dirname))
340 if (self._uri2path(package_uri) and
341 if (self._uri2path(package_uri) and
341 self._survives_exclude(package_uri, 'package')):
342 self._survives_exclude(package_uri, 'package')):
342 modules.append(package_uri)
343 modules.append(package_uri)
343 else:
344 else:
344 dirnames.remove(dirname)
345 dirnames.remove(dirname)
345 # Check filenames for modules
346 # Check filenames for modules
346 for filename in filenames:
347 for filename in filenames:
347 module_name = filename[:-3]
348 module_name = filename[:-3]
348 module_uri = '.'.join((root_uri, module_name))
349 module_uri = '.'.join((root_uri, module_name))
349 if (self._uri2path(module_uri) and
350 if (self._uri2path(module_uri) and
350 self._survives_exclude(module_uri, 'module')):
351 self._survives_exclude(module_uri, 'module')):
351 modules.append(module_uri)
352 modules.append(module_uri)
352 return sorted(modules)
353 return sorted(modules)
353
354
354 def write_modules_api(self, modules,outdir):
355 def write_modules_api(self, modules,outdir):
355 # write the list
356 # write the list
356 written_modules = []
357 written_modules = []
357 for m in modules:
358 for m in modules:
358 api_str = self.generate_api_doc(m)
359 api_str = self.generate_api_doc(m)
359 if not api_str:
360 if not api_str:
360 continue
361 continue
361 # write out to file
362 # write out to file
362 outfile = os.path.join(outdir,
363 outfile = os.path.join(outdir,
363 m + self.rst_extension)
364 m + self.rst_extension)
364 fileobj = open(outfile, 'wt')
365 fileobj = open(outfile, 'wt')
365 fileobj.write(api_str)
366 fileobj.write(api_str)
366 fileobj.close()
367 fileobj.close()
367 written_modules.append(m)
368 written_modules.append(m)
368 self.written_modules = written_modules
369 self.written_modules = written_modules
369
370
370 def write_api_docs(self, outdir):
371 def write_api_docs(self, outdir):
371 """Generate API reST files.
372 """Generate API reST files.
372
373
373 Parameters
374 Parameters
374 ----------
375 ----------
375 outdir : string
376 outdir : string
376 Directory name in which to store files
377 Directory name in which to store files
377 We create automatic filenames for each module
378 We create automatic filenames for each module
378
379
379 Returns
380 Returns
380 -------
381 -------
381 None
382 None
382
383
383 Notes
384 Notes
384 -----
385 -----
385 Sets self.written_modules to list of written modules
386 Sets self.written_modules to list of written modules
386 """
387 """
387 if not os.path.exists(outdir):
388 if not os.path.exists(outdir):
388 os.mkdir(outdir)
389 os.mkdir(outdir)
389 # compose list of modules
390 # compose list of modules
390 modules = self.discover_modules()
391 modules = self.discover_modules()
391 self.write_modules_api(modules,outdir)
392 self.write_modules_api(modules,outdir)
392
393
393 def write_index(self, outdir, froot='gen', relative_to=None):
394 def write_index(self, outdir, froot='gen', relative_to=None):
394 """Make a reST API index file from written files
395 """Make a reST API index file from written files
395
396
396 Parameters
397 Parameters
397 ----------
398 ----------
398 path : string
399 path : string
399 Filename to write index to
400 Filename to write index to
400 outdir : string
401 outdir : string
401 Directory to which to write generated index file
402 Directory to which to write generated index file
402 froot : string, optional
403 froot : string, optional
403 root (filename without extension) of filename to write to
404 root (filename without extension) of filename to write to
404 Defaults to 'gen'. We add ``self.rst_extension``.
405 Defaults to 'gen'. We add ``self.rst_extension``.
405 relative_to : string
406 relative_to : string
406 path to which written filenames are relative. This
407 path to which written filenames are relative. This
407 component of the written file path will be removed from
408 component of the written file path will be removed from
408 outdir, in the generated index. Default is None, meaning,
409 outdir, in the generated index. Default is None, meaning,
409 leave path as it is.
410 leave path as it is.
410 """
411 """
411 if self.written_modules is None:
412 if self.written_modules is None:
412 raise ValueError('No modules written')
413 raise ValueError('No modules written')
413 # Get full filename path
414 # Get full filename path
414 path = os.path.join(outdir, froot+self.rst_extension)
415 path = os.path.join(outdir, froot+self.rst_extension)
415 # Path written into index is relative to rootpath
416 # Path written into index is relative to rootpath
416 if relative_to is not None:
417 if relative_to is not None:
417 relpath = outdir.replace(relative_to + os.path.sep, '')
418 relpath = outdir.replace(relative_to + os.path.sep, '')
418 else:
419 else:
419 relpath = outdir
420 relpath = outdir
420 idx = open(path,'wt')
421 idx = open(path,'wt')
421 w = idx.write
422 w = idx.write
422 w('.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n')
423 w('.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n')
423 w('.. toctree::\n\n')
424 w('.. toctree::\n\n')
424 for f in self.written_modules:
425 for f in self.written_modules:
425 w(' %s\n' % os.path.join(relpath,f))
426 w(' %s\n' % os.path.join(relpath,f))
426 idx.close()
427 idx.close()
@@ -1,98 +1,114 b''
1 """reST directive for syntax-highlighting ipython interactive sessions.
1 """reST directive for syntax-highlighting ipython interactive sessions.
2
3 XXX - See what improvements can be made based on the new (as of Sept 2009)
4 'pycon' lexer for the python console. At the very least it will give better
5 highlighted tracebacks.
2 """
6 """
3
7
4 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
5 # Needed modules
9 # Needed modules
6
10
7 # Standard library
11 # Standard library
8 import re
12 import re
9
13
10 # Third party
14 # Third party
11 from pygments.lexer import Lexer, do_insertions
15 from pygments.lexer import Lexer, do_insertions
12 from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
16 from pygments.lexers.agile import (PythonConsoleLexer, PythonLexer,
13 PythonTracebackLexer)
17 PythonTracebackLexer)
14 from pygments.token import Comment, Generic
18 from pygments.token import Comment, Generic
15
19
16 from sphinx import highlighting
20 from sphinx import highlighting
17
21
18
19 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
20 # Global constants
23 # Global constants
21 line_re = re.compile('.*?\n')
24 line_re = re.compile('.*?\n')
22
25
23 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
24 # Code begins - classes and functions
27 # Code begins - classes and functions
25
28
26 class IPythonConsoleLexer(Lexer):
29 class IPythonConsoleLexer(Lexer):
27 """
30 """
28 For IPython console output or doctests, such as:
31 For IPython console output or doctests, such as:
29
32
30 .. sourcecode:: ipython
33 .. sourcecode:: ipython
31
34
32 In [1]: a = 'foo'
35 In [1]: a = 'foo'
33
36
34 In [2]: a
37 In [2]: a
35 Out[2]: 'foo'
38 Out[2]: 'foo'
36
39
37 In [3]: print a
40 In [3]: print a
38 foo
41 foo
39
42
40 In [4]: 1 / 0
43 In [4]: 1 / 0
41
44
42 Notes:
45 Notes:
43
46
44 - Tracebacks are not currently supported.
47 - Tracebacks are not currently supported.
45
48
46 - It assumes the default IPython prompts, not customized ones.
49 - It assumes the default IPython prompts, not customized ones.
47 """
50 """
48
51
49 name = 'IPython console session'
52 name = 'IPython console session'
50 aliases = ['ipython']
53 aliases = ['ipython']
51 mimetypes = ['text/x-ipython-console']
54 mimetypes = ['text/x-ipython-console']
52 input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)")
55 input_prompt = re.compile("(In \[[0-9]+\]: )|( \.\.\.+:)")
53 output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)")
56 output_prompt = re.compile("(Out\[[0-9]+\]: )|( \.\.\.+:)")
54 continue_prompt = re.compile(" \.\.\.+:")
57 continue_prompt = re.compile(" \.\.\.+:")
55 tb_start = re.compile("\-+")
58 tb_start = re.compile("\-+")
56
59
57 def get_tokens_unprocessed(self, text):
60 def get_tokens_unprocessed(self, text):
58 pylexer = PythonLexer(**self.options)
61 pylexer = PythonLexer(**self.options)
59 tblexer = PythonTracebackLexer(**self.options)
62 tblexer = PythonTracebackLexer(**self.options)
60
63
61 curcode = ''
64 curcode = ''
62 insertions = []
65 insertions = []
63 for match in line_re.finditer(text):
66 for match in line_re.finditer(text):
64 line = match.group()
67 line = match.group()
65 input_prompt = self.input_prompt.match(line)
68 input_prompt = self.input_prompt.match(line)
66 continue_prompt = self.continue_prompt.match(line.rstrip())
69 continue_prompt = self.continue_prompt.match(line.rstrip())
67 output_prompt = self.output_prompt.match(line)
70 output_prompt = self.output_prompt.match(line)
68 if line.startswith("#"):
71 if line.startswith("#"):
69 insertions.append((len(curcode),
72 insertions.append((len(curcode),
70 [(0, Comment, line)]))
73 [(0, Comment, line)]))
71 elif input_prompt is not None:
74 elif input_prompt is not None:
72 insertions.append((len(curcode),
75 insertions.append((len(curcode),
73 [(0, Generic.Prompt, input_prompt.group())]))
76 [(0, Generic.Prompt, input_prompt.group())]))
74 curcode += line[input_prompt.end():]
77 curcode += line[input_prompt.end():]
75 elif continue_prompt is not None:
78 elif continue_prompt is not None:
76 insertions.append((len(curcode),
79 insertions.append((len(curcode),
77 [(0, Generic.Prompt, continue_prompt.group())]))
80 [(0, Generic.Prompt, continue_prompt.group())]))
78 curcode += line[continue_prompt.end():]
81 curcode += line[continue_prompt.end():]
79 elif output_prompt is not None:
82 elif output_prompt is not None:
83 # Use the 'error' token for output. We should probably make
84 # our own token, but error is typicaly in a bright color like
85 # red, so it works fine for our output prompts.
80 insertions.append((len(curcode),
86 insertions.append((len(curcode),
81 [(0, Generic.Output, output_prompt.group())]))
87 [(0, Generic.Error, output_prompt.group())]))
82 curcode += line[output_prompt.end():]
88 curcode += line[output_prompt.end():]
83 else:
89 else:
84 if curcode:
90 if curcode:
85 for item in do_insertions(insertions,
91 for item in do_insertions(insertions,
86 pylexer.get_tokens_unprocessed(curcode)):
92 pylexer.get_tokens_unprocessed(curcode)):
87 yield item
93 yield item
88 curcode = ''
94 curcode = ''
89 insertions = []
95 insertions = []
90 yield match.start(), Generic.Output, line
96 yield match.start(), Generic.Output, line
91 if curcode:
97 if curcode:
92 for item in do_insertions(insertions,
98 for item in do_insertions(insertions,
93 pylexer.get_tokens_unprocessed(curcode)):
99 pylexer.get_tokens_unprocessed(curcode)):
94 yield item
100 yield item
95
101
102
103 def setup(app):
104 """Setup as a sphinx extension."""
105
106 # This is only a lexer, so adding it below to pygments appears sufficient.
107 # But if somebody knows that the right API usage should be to do that via
108 # sphinx, by all means fix it here. At least having this setup.py
109 # suppresses the sphinx warning we'd get without it.
110 pass
111
96 #-----------------------------------------------------------------------------
112 #-----------------------------------------------------------------------------
97 # Register the extension as a valid pygments lexer
113 # Register the extension as a valid pygments lexer
98 highlighting.lexers['ipython'] = IPythonConsoleLexer()
114 highlighting.lexers['ipython'] = IPythonConsoleLexer()
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (589 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now