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