Show More
@@ -0,0 +1,117 b'' | |||
|
1 | .. _editors: | |
|
2 | ||
|
3 | ==================== | |
|
4 | Editor configuration | |
|
5 | ==================== | |
|
6 | ||
|
7 | IPython can integrate with text editors in a number of different ways: | |
|
8 | ||
|
9 | * Editors (such as (X)Emacs [Emacs]_, vim [vim]_ and TextMate [TextMate]_) can | |
|
10 | send code to IPython for execution. | |
|
11 | ||
|
12 | * IPython's ``%edit`` magic command can open an editor of choice to edit | |
|
13 | a code block. | |
|
14 | ||
|
15 | The %edit command (and its alias %ed) will invoke the editor set in your | |
|
16 | environment as :envvar:`EDITOR`. If this variable is not set, it will default | |
|
17 | to vi under Linux/Unix and to notepad under Windows. You may want to set this | |
|
18 | variable properly and to a lightweight editor which doesn't take too long to | |
|
19 | start (that is, something other than a new instance of Emacs). This way you | |
|
20 | can edit multi-line code quickly and with the power of a real editor right | |
|
21 | inside IPython. | |
|
22 | ||
|
23 | You can also control the editor via the commmand-line option '-editor' or in | |
|
24 | your configuration file, by setting the :attr:`InteractiveShell.editor` | |
|
25 | configuration attribute. | |
|
26 | ||
|
27 | TextMate | |
|
28 | ======== | |
|
29 | ||
|
30 | Currently, TextMate support in IPython is broken. It used to work well, | |
|
31 | but the code has been moved to :mod:`IPython.quarantine` until it is updated. | |
|
32 | ||
|
33 | vim configuration | |
|
34 | ================= | |
|
35 | ||
|
36 | Currently, vim support in IPython is broken. Like the TextMate code, | |
|
37 | the vim support code has been moved to :mod:`IPython.quarantine` until it | |
|
38 | is updated. | |
|
39 | ||
|
40 | .. _emacs: | |
|
41 | ||
|
42 | (X)Emacs | |
|
43 | ======== | |
|
44 | ||
|
45 | Editor | |
|
46 | ====== | |
|
47 | ||
|
48 | If you are a dedicated Emacs user, and want to use Emacs when IPython's | |
|
49 | ``%edit`` magic command is called you should set up the Emacs server so that | |
|
50 | new requests are handled by the original process. This means that almost no | |
|
51 | time is spent in handling the request (assuming an Emacs process is already | |
|
52 | running). For this to work, you need to set your EDITOR environment variable | |
|
53 | to 'emacsclient'. The code below, supplied by Francois Pinard, can then be | |
|
54 | used in your :file:`.emacs` file to enable the server:: | |
|
55 | ||
|
56 | (defvar server-buffer-clients) | |
|
57 | (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) | |
|
58 | (server-start) | |
|
59 | (defun fp-kill-server-with-buffer-routine () | |
|
60 | (and server-buffer-clients (server-done))) | |
|
61 | (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine)) | |
|
62 | ||
|
63 | Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, | |
|
64 | currently (X)Emacs and IPython get along very well in other ways. | |
|
65 | ||
|
66 | .. note:: | |
|
67 | ||
|
68 | You will need to use a recent enough version of :file:`python-mode.el`, | |
|
69 | along with the file :file:`ipython.el`. You can check that the version you | |
|
70 | have of :file:`python-mode.el` is new enough by either looking at the | |
|
71 | revision number in the file itself, or asking for it in (X)Emacs via ``M-x | |
|
72 | py-version``. Versions 4.68 and newer contain the necessary fixes for | |
|
73 | proper IPython support. | |
|
74 | ||
|
75 | The file :file:`ipython.el` is included with the IPython distribution, in the | |
|
76 | directory :file:`docs/emacs`. Once you put these files in your Emacs path, all | |
|
77 | you need in your :file:`.emacs` file is:: | |
|
78 | ||
|
79 | (require 'ipython) | |
|
80 | ||
|
81 | This should give you full support for executing code snippets via | |
|
82 | IPython, opening IPython as your Python shell via ``C-c !``, etc. | |
|
83 | ||
|
84 | You can customize the arguments passed to the IPython instance at startup by | |
|
85 | setting the ``py-python-command-args`` variable. For example, to start always | |
|
86 | in ``pylab`` mode with hardcoded light-background colors, you can use:: | |
|
87 | ||
|
88 | (setq py-python-command-args '("-pylab" "-colors" "LightBG")) | |
|
89 | ||
|
90 | If you happen to get garbage instead of colored prompts as described in | |
|
91 | the previous section, you may need to set also in your :file:`.emacs` file:: | |
|
92 | ||
|
93 | (setq ansi-color-for-comint-mode t) | |
|
94 | ||
|
95 | Notes on emacs support: | |
|
96 | ||
|
97 | * There is one caveat you should be aware of: you must start the IPython shell | |
|
98 | before attempting to execute any code regions via ``C-c |``. Simply type | |
|
99 | ``C-c !`` to start IPython before passing any code regions to the | |
|
100 | interpreter, and you shouldn't experience any problems. This is due to a bug | |
|
101 | in Python itself, which has been fixed for Python 2.3, but exists as of | |
|
102 | Python 2.2.2 (reported as SF bug [ 737947 ]). | |
|
103 | ||
|
104 | * The (X)Emacs support is maintained by Alexander Schmolck, so all | |
|
105 | comments/requests should be directed to him through the IPython mailing | |
|
106 | lists. | |
|
107 | ||
|
108 | * This code is still somewhat experimental so it's a bit rough around the | |
|
109 | edges (although in practice, it works quite well). | |
|
110 | ||
|
111 | * Be aware that if you customized ``py-python-command`` previously, this value | |
|
112 | will override what :file:`ipython.el` does (because loading the customization | |
|
113 | variables comes later). | |
|
114 | ||
|
115 | .. [Emacs] Emacs. http://www.gnu.org/software/emacs/ | |
|
116 | .. [TextMate] TextMate: the missing editor. http://macromates.com/ | |
|
117 | .. [vim] vim. http://www.vim.org/ |
@@ -0,0 +1,134 b'' | |||
|
1 | .. _configuring_ipython: | |
|
2 | ||
|
3 | =========================================================== | |
|
4 | Configuring the :command:`ipython` command line application | |
|
5 | =========================================================== | |
|
6 | ||
|
7 | This section contains information about how to configure the | |
|
8 | :command:`ipython` command line application. See the :ref:`configuration | |
|
9 | overview <config_overview>` for a more general description of the | |
|
10 | configuration system and configuration file format. | |
|
11 | ||
|
12 | The default configuration file for the :command:`ipython` command line application | |
|
13 | is :file:`ipython_config.py`. By setting the attributes in this file, you | |
|
14 | can configure the application. A sample is provided in | |
|
15 | :mod:`IPython.config.default.ipython_config`. Simply copy this file to your | |
|
16 | IPython directory to start using it. | |
|
17 | ||
|
18 | Most configuration attributes that this file accepts are associated with | |
|
19 | classes that are subclasses of :class:`~IPython.core.component.Component`. | |
|
20 | ||
|
21 | A few configuration attributes are not associated with a particular | |
|
22 | :class:`~IPython.core.component.Component` subclass. These are application | |
|
23 | wide configuration attributes and are stored in the ``Global`` | |
|
24 | sub-configuration section. We begin with a description of these | |
|
25 | attributes. | |
|
26 | ||
|
27 | Global configuration | |
|
28 | ==================== | |
|
29 | ||
|
30 | Assuming that your configuration file has the following at the top:: | |
|
31 | ||
|
32 | c = get_config() | |
|
33 | ||
|
34 | the following attributes can be set in the ``Global`` section. | |
|
35 | ||
|
36 | :attr:`c.Global.display_banner` | |
|
37 | A boolean that determined if the banner is printer when :command:`ipython` | |
|
38 | is started. | |
|
39 | ||
|
40 | :attr:`c.Global.classic` | |
|
41 | A boolean that determines if IPython starts in "classic" mode. In this | |
|
42 | mode, the prompts and everything mimic that of the normal :command:`python` | |
|
43 | shell | |
|
44 | ||
|
45 | :attr:`c.Global.nosep` | |
|
46 | A boolean that determines if there should be no blank lines between | |
|
47 | prompts. | |
|
48 | ||
|
49 | :attr:`c.Global.log_level` | |
|
50 | An integer that sets the detail of the logging level during the startup | |
|
51 | of :command:`ipython`. The default is 30 and the possible values are | |
|
52 | (0, 10, 20, 30, 40, 50). Higher is quieter and lower is more verbose. | |
|
53 | ||
|
54 | :attr:`c.Global.extensions` | |
|
55 | A list of strings, each of which is an importable IPython extension. An | |
|
56 | IPython extension is a regular Python module or package that has a | |
|
57 | :func:`load_in_ipython(ip)` method. This method gets called when the | |
|
58 | extension is loaded with the currently running | |
|
59 | :class:`~IPython.core.iplib.InteractiveShell` as its only argument. You | |
|
60 | can put your extensions anywhere they can be imported but we add the | |
|
61 | :file:`extensions` subdirectory of the ipython directory to ``sys.path`` | |
|
62 | during extension loading, so you can put them there as well. Extensions | |
|
63 | are not executed in the user's interactive namespace and they must | |
|
64 | be pure Python code. Extensions are the recommended way of customizing | |
|
65 | :command:`ipython`. | |
|
66 | ||
|
67 | :attr:`c.Global.exec_lines` | |
|
68 | A list of strings, each of which is Python code that is run in the user's | |
|
69 | namespace after IPython start. These lines can contain full IPython syntax | |
|
70 | with magics, etc. | |
|
71 | ||
|
72 | :attr:`c.Global.exec_files` | |
|
73 | A list of strings, each of which is the full pathname of a ``.py`` or | |
|
74 | ``.ipy`` file that will be executed as IPython starts. These files are run | |
|
75 | in IPython in the user's namespace. Files with a ``.py`` extension need to | |
|
76 | be pure Python. Files with a ``.ipy`` extension can have custom IPython | |
|
77 | syntax (magics, etc.). These files need to be in the cwd, the ipythondir | |
|
78 | or be absolute paths. | |
|
79 | ||
|
80 | Classes that can be configured | |
|
81 | ============================== | |
|
82 | ||
|
83 | The following classes can also be configured in the configuration file for | |
|
84 | :command:`ipython`: | |
|
85 | ||
|
86 | * :class:`~IPython.core.iplib.InteractiveShell` | |
|
87 | ||
|
88 | * :class:`~IPython.core.prefilter.PrefilterManager` | |
|
89 | ||
|
90 | * :class:`~IPython.core.alias.AliasManager` | |
|
91 | ||
|
92 | To see which attributes of these classes are configurable, please see the | |
|
93 | source code for these classes, the class docstrings or the sample | |
|
94 | configuration file :mod:`IPython.config.default.ipython_config`. | |
|
95 | ||
|
96 | Example | |
|
97 | ======= | |
|
98 | ||
|
99 | For those who want to get a quick start, here is a sample | |
|
100 | :file:`ipython_config.py` that sets some of the common configuration | |
|
101 | attributes:: | |
|
102 | ||
|
103 | # sample ipython_config.py | |
|
104 | c = get_config() | |
|
105 | ||
|
106 | c.Global.display_banner = True | |
|
107 | c.Global.log_level = 20 | |
|
108 | c.Global.extensions = [ | |
|
109 | 'myextension' | |
|
110 | ] | |
|
111 | c.Global.exec_lines = [ | |
|
112 | 'import numpy', | |
|
113 | 'import scipy' | |
|
114 | ] | |
|
115 | c.Global.exec_files = [ | |
|
116 | 'mycode.py', | |
|
117 | 'fancy.ipy' | |
|
118 | ] | |
|
119 | c.InteractiveShell.autoindent = True | |
|
120 | c.InteractiveShell.colors = 'LightBG' | |
|
121 | c.InteractiveShell.confirm_exit = False | |
|
122 | c.InteractiveShell.deep_reload = True | |
|
123 | c.InteractiveShell.editor = 'nano' | |
|
124 | c.InteractiveShell.prompt_in1 = 'In [\#]: ' | |
|
125 | c.InteractiveShell.prompt_in2 = ' .\D.: ' | |
|
126 | c.InteractiveShell.prompt_out = 'Out[\#]: ' | |
|
127 | c.InteractiveShell.prompts_pad_left = True | |
|
128 | c.InteractiveShell.xmode = 'Context' | |
|
129 | ||
|
130 | c.PrefilterManager.multi_line_specials = True | |
|
131 | ||
|
132 | c.AliasManager.user_aliases = [ | |
|
133 | ('la', 'ls -al') | |
|
134 | ] No newline at end of file |
@@ -0,0 +1,331 b'' | |||
|
1 | .. _config_overview: | |
|
2 | ||
|
3 | ============================================ | |
|
4 | Overview of the IPython configuration system | |
|
5 | ============================================ | |
|
6 | ||
|
7 | This section describes the IPython configuration system. Starting with version | |
|
8 | 0.11, IPython has a completely new configuration system that is quite | |
|
9 | different from the older :file:`ipythonrc` or :file:`ipy_user_conf.py` | |
|
10 | approaches. The new configuration system was designed from scratch to address | |
|
11 | the particular configuration needs of IPython. While there are many | |
|
12 | other excellent configuration systems out there, we found that none of them | |
|
13 | met our requirements. | |
|
14 | ||
|
15 | .. warning:: | |
|
16 | ||
|
17 | If you are upgrading to version 0.11 of IPython, you will need to migrate | |
|
18 | your old :file:`ipythonrc` or :file:`ipy_user_conf.py` configuration files | |
|
19 | to the new system. Read on for information on how to do this. | |
|
20 | ||
|
21 | The discussion that follows is focused on teaching user's how to configure | |
|
22 | IPython to their liking. Developer's who want to know more about how they | |
|
23 | can enable their objects to take advantage of the configuration system | |
|
24 | should consult our :ref:`developer guide <developer_guide>` | |
|
25 | ||
|
26 | The main concepts | |
|
27 | ================= | |
|
28 | ||
|
29 | There are a number of abstractions that the IPython configuration system uses. | |
|
30 | Each of these abstractions is represented by a Python class. | |
|
31 | ||
|
32 | Configuration object: :class:`~IPython.config.loader.Config` | |
|
33 | A configuration object is a simple dictionary-like class that holds | |
|
34 | configuration attributes and sub-configuration objects. These classes | |
|
35 | support dotted attribute style access (``Foo.bar``) in addition to the | |
|
36 | regular dictionary style access (``Foo['bar']``). Configuration objects | |
|
37 | are smart. They know how to merge themselves with other configuration | |
|
38 | objects and they automatically create sub-configuration objects. | |
|
39 | ||
|
40 | Application: :class:`~IPython.core.application.Application` | |
|
41 | An application is a process that does a specific job. The most obvious | |
|
42 | application is the :command:`ipython` command line program. Each | |
|
43 | application reads a *single* configuration file and command line options | |
|
44 | and then produces a master configuration object for the application. This | |
|
45 | configuration object is then passed to the components that the application | |
|
46 | creates. Components implement the actual logic of the application and know | |
|
47 | how to configure themselves given the configuration object. | |
|
48 | ||
|
49 | Component: :class:`~IPython.core.component.Component` | |
|
50 | A component is a regular Python class that serves as a base class for all | |
|
51 | main classes in an application. The | |
|
52 | :class:`~IPython.core.component.Component` base class is lightweight and | |
|
53 | only does two main things. | |
|
54 | ||
|
55 | First, it keeps track of all instances of itself and provides an | |
|
56 | interfaces for querying those instances. This enables components to get | |
|
57 | references to other components, even though they are not "nearby" in the | |
|
58 | runtime object graph. | |
|
59 | ||
|
60 | Second, it declares what class attributes are configurable and specifies | |
|
61 | the default types and values of those attributes. This information is used | |
|
62 | to automatically configure instances given the applications configuration | |
|
63 | object. | |
|
64 | ||
|
65 | Developers create :class:`~IPython.core.component.Component` subclasses | |
|
66 | that implement all of the logic in the application. Each of these | |
|
67 | subclasses has its own configuration information that controls how | |
|
68 | instances are created. | |
|
69 | ||
|
70 | Having described these main concepts, we can now state the main idea in our | |
|
71 | configuration system: *"configuration" allows the default values of class | |
|
72 | attributes to be controlled on a class by class basis*. Thus all instances of | |
|
73 | a given class are configured in the same way. Furthermore, if two instances | |
|
74 | need to be configured differently, they need to be instances of two different | |
|
75 | classes. While this model may seem a bit restrictive, we have found that it | |
|
76 | expresses most things that need to be configured extremely well. | |
|
77 | ||
|
78 | Now, we show what our configuration objects and files look like. | |
|
79 | ||
|
80 | Configuration objects and files | |
|
81 | =============================== | |
|
82 | ||
|
83 | A configuration file is simply a pure Python file that sets the attributes | |
|
84 | of a global, pre-created configuration object. This configuration object is a | |
|
85 | :class:`~IPython.config.loader.Config` instance. While in a configuration | |
|
86 | file, to get a reference to this object, simply call the :func:`get_config` | |
|
87 | function. We inject this function into the global namespace that the | |
|
88 | configuration file is executed in. | |
|
89 | ||
|
90 | Here is an example of a super simple configuration file that does nothing:: | |
|
91 | ||
|
92 | c = get_config() | |
|
93 | ||
|
94 | Once you get a reference to the configuration object, you simply set | |
|
95 | attributes on it. All you have to know is: | |
|
96 | ||
|
97 | * The name of each attribute. | |
|
98 | * The type of each attribute. | |
|
99 | ||
|
100 | The answers to these two questions are provided by the various | |
|
101 | :class:`~IPython.core.component.Component` subclasses that an application | |
|
102 | uses. Let's look at how this would work for a simple component subclass:: | |
|
103 | ||
|
104 | # Sample component that can be configured. | |
|
105 | from IPython.core.component import Component | |
|
106 | from IPython.utils.traitlets import Int, Float, Str, Bool | |
|
107 | ||
|
108 | class MyComponent(Component): | |
|
109 | name = Str('defaultname', config=True) | |
|
110 | ranking = Int(0, config=True) | |
|
111 | value = Float(99.0) | |
|
112 | # The rest of the class implementation would go here.. | |
|
113 | ||
|
114 | In this example, we see that :class:`MyComponent` has three attributes, two | |
|
115 | of whom (``name``, ``ranking``) can be configured. All of the attributes | |
|
116 | are given types and default values. If a :class:`MyComponent` is instantiated, | |
|
117 | but not configured, these default values will be used. But let's see how | |
|
118 | to configure this class in a configuration file:: | |
|
119 | ||
|
120 | # Sample config file | |
|
121 | c = get_config() | |
|
122 | ||
|
123 | c.MyComponent.name = 'coolname' | |
|
124 | c.MyComponent.ranking = 10 | |
|
125 | ||
|
126 | After this configuration file is loaded, the values set in it will override | |
|
127 | the class defaults anytime a :class:`MyComponent` is created. Furthermore, | |
|
128 | these attributes will be type checked and validated anytime they are set. | |
|
129 | This type checking is handled by the :mod:`IPython.utils.traitlets` module, | |
|
130 | which provides the :class:`Str`, :class:`Int` and :class:`Float` types. In | |
|
131 | addition to these traitlets, the :mod:`IPython.utils.traitlets` provides | |
|
132 | traitlets for a number of other types. | |
|
133 | ||
|
134 | .. note:: | |
|
135 | ||
|
136 | Underneath the hood, the :class:`Component` base class is a subclass of | |
|
137 | :class:`IPython.utils.traitlets.HasTraitlets`. The | |
|
138 | :mod:`IPython.utils.traitlets` module is a lightweight version of | |
|
139 | :mod:`enthought.traits`. Our implementation is a pure Python subset | |
|
140 | (mostly API compatible) of :mod:`enthought.traits` that does not have any | |
|
141 | of the automatic GUI generation capabilities. Our plan is to achieve 100% | |
|
142 | API compatibility to enable the actual :mod:`enthought.traits` to | |
|
143 | eventually be used instead. Currently, we cannot use | |
|
144 | :mod:`enthought.traits` as we are committed to the core of IPython being | |
|
145 | pure Python. | |
|
146 | ||
|
147 | It should be very clear at this point what the naming convention is for | |
|
148 | configuration attributes:: | |
|
149 | ||
|
150 | c.ClassName.attribute_name = attribute_value | |
|
151 | ||
|
152 | Here, ``ClassName`` is the name of the class whose configuration attribute you | |
|
153 | want to set, ``attribute_name`` is the name of the attribute you want to set | |
|
154 | and ``attribute_value`` the the value you want it to have. The ``ClassName`` | |
|
155 | attribute of ``c`` is not the actual class, but instead is another | |
|
156 | :class:`~IPython.config.loader.Config` instance. | |
|
157 | ||
|
158 | .. note:: | |
|
159 | ||
|
160 | The careful reader may wonder how the ``ClassName`` (``MyComponent`` in | |
|
161 | the above example) attribute of the configuration object ``c`` gets | |
|
162 | created. These attributes are created on the fly by the | |
|
163 | :class:`~IPython.config.loader.Config` instance, using a simple naming | |
|
164 | convention. Any attribute of a :class:`~IPython.config.loader.Config` | |
|
165 | instance whose name begins with an uppercase character is assumed to be a | |
|
166 | sub-configuration and a new empty :class:`~IPython.config.loader.Config` | |
|
167 | instance is dynamically created for that attribute. This allows deeply | |
|
168 | hierarchical information created easily (``c.Foo.Bar.value``) on the | |
|
169 | fly. | |
|
170 | ||
|
171 | Configuration files inheritance | |
|
172 | =============================== | |
|
173 | ||
|
174 | Let's say you want to have different configuration files for various purposes. | |
|
175 | Our configuration system makes it easy for one configuration file to inherit | |
|
176 | the information in another configuration file. The :func:`load_subconfig` | |
|
177 | command can be used in a configuration file for this purpose. Here is a simple | |
|
178 | example that loads all of the values from the file :file:`base_config.py`:: | |
|
179 | ||
|
180 | # base_config.py | |
|
181 | c = get_config() | |
|
182 | c.MyComponent.name = 'coolname' | |
|
183 | c.MyComponent.ranking = 100 | |
|
184 | ||
|
185 | into the configuration file :file:`main_config.py`:: | |
|
186 | ||
|
187 | # main_config.py | |
|
188 | c = get_config() | |
|
189 | ||
|
190 | # Load everything from base_config.py | |
|
191 | load_subconfig('base_config.py') | |
|
192 | ||
|
193 | # Now override one of the values | |
|
194 | c.MyComponent.name = 'bettername' | |
|
195 | ||
|
196 | In a situation like this the :func:`load_subconfig` makes sure that the | |
|
197 | search path for sub-configuration files is inherited from that of the parent. | |
|
198 | Thus, you can typically put the two in the same directory and everything will | |
|
199 | just work. | |
|
200 | ||
|
201 | Class based configuration inheritance | |
|
202 | ===================================== | |
|
203 | ||
|
204 | There is another aspect of configuration where inheritance comes into play. | |
|
205 | Sometimes, your classes will have an inheritance hierarchy that you want | |
|
206 | to be reflected in the configuration system. Here is a simple example:: | |
|
207 | ||
|
208 | from IPython.core.component import Component | |
|
209 | from IPython.utils.traitlets import Int, Float, Str, Bool | |
|
210 | ||
|
211 | class Foo(Component): | |
|
212 | name = Str('fooname', config=True) | |
|
213 | value = Float(100.0, config=True) | |
|
214 | ||
|
215 | class Bar(Foo): | |
|
216 | name = Str('barname', config=True) | |
|
217 | othervalue = Int(0, config=True) | |
|
218 | ||
|
219 | Now, we can create a configuration file to configure instances of :class:`Foo` | |
|
220 | and :class:`Bar`:: | |
|
221 | ||
|
222 | # config file | |
|
223 | c = get_config() | |
|
224 | ||
|
225 | c.Foo.name = 'bestname' | |
|
226 | c.Bar.othervalue = 10 | |
|
227 | ||
|
228 | This class hierarchy and configuration file accomplishes the following: | |
|
229 | ||
|
230 | * The default value for :attr:`Foo.name` and :attr:`Bar.name` will be | |
|
231 | 'bestname'. Because :class:`Bar` is a :class:`Foo` subclass it also | |
|
232 | picks up the configuration information for :class:`Foo`. | |
|
233 | * The default value for :attr:`Foo.value` and :attr:`Bar.value` will be | |
|
234 | ``100.0``, which is the value specified as the class default. | |
|
235 | * The default value for :attr:`Bar.othervalue` will be 10 as set in the | |
|
236 | configuration file. Because :class:`Foo` is the parent of :class:`Bar` | |
|
237 | it doesn't know anything about the :attr:`othervalue` attribute. | |
|
238 | ||
|
239 | Configuration file location | |
|
240 | =========================== | |
|
241 | ||
|
242 | So where should you put your configuration files? By default, all IPython | |
|
243 | applications look in the so called "IPython directory". The location of | |
|
244 | this directory is determined by the following algorithm: | |
|
245 | ||
|
246 | * If the ``-ipythondir`` command line flag is given, its value is used. | |
|
247 | ||
|
248 | * If not, the value returned by :func:`IPython.utils.genutils.get_ipython_dir` | |
|
249 | is used. This function will first look at the :envvar:`IPYTHONDIR` | |
|
250 | environment variable and then default to the directory | |
|
251 | :file:`$HOME/.ipythondir`. | |
|
252 | ||
|
253 | For most users, the default value will simply be something like | |
|
254 | :file:`$HOME/.ipythondir`. | |
|
255 | ||
|
256 | Once the location of the IPython directory has been determined, you need to | |
|
257 | know what filename to use for the configuration file. The basic idea is that | |
|
258 | each application has its own default configuration filename. The default named | |
|
259 | used by the :command:`ipython` command line program is | |
|
260 | :file:`ipython_config.py`. This value can be overriden by the ``-config_file`` | |
|
261 | command line flag. A sample :file:`ipython_config.py` file can be found | |
|
262 | in :mod:`IPython.config.default.ipython_config.py`. Simple copy it to your | |
|
263 | IPython directory to begin using it. | |
|
264 | ||
|
265 | .. _Profiles: | |
|
266 | ||
|
267 | Profiles | |
|
268 | ======== | |
|
269 | ||
|
270 | A profile is simply a configuration file that follows a simple naming | |
|
271 | convention and can be loaded using a simplified syntax. The idea is | |
|
272 | that users often want to maintain a set of configuration files for different | |
|
273 | purposes: one for doing numerical computing with NumPy and SciPy and | |
|
274 | another for doing symbolic computing with SymPy. Profiles make it easy | |
|
275 | to keep a separate configuration file for each of these purposes. | |
|
276 | ||
|
277 | Let's start by showing how a profile is used: | |
|
278 | ||
|
279 | .. code-block:: bash | |
|
280 | ||
|
281 | $ ipython -p sympy | |
|
282 | ||
|
283 | This tells the :command:`ipython` command line program to get its | |
|
284 | configuration from the "sympy" profile. The search path for profiles is the | |
|
285 | same as that of regular configuration files. The only difference is that | |
|
286 | profiles are named in a special way. In the case above, the "sympy" profile | |
|
287 | would need to have the name :file:`ipython_config_sympy.py`. | |
|
288 | ||
|
289 | The general pattern is this: simply add ``_profilename`` to the end of the | |
|
290 | normal configuration file name. Then load the profile by adding ``-p | |
|
291 | profilename`` to your command line options. | |
|
292 | ||
|
293 | IPython ships with some sample profiles in :mod:`IPython.config.profile`. | |
|
294 | Simply copy these to your IPython directory to begin using them. | |
|
295 | ||
|
296 | Design requirements | |
|
297 | =================== | |
|
298 | ||
|
299 | Here are the main requirements we wanted our configuration system to have: | |
|
300 | ||
|
301 | * Support for hierarchical configuration information. | |
|
302 | ||
|
303 | * Full integration with command line option parsers. Often, you want to read | |
|
304 | a configuration file, but then override some of the values with command line | |
|
305 | options. Our configuration system automates this process and allows each | |
|
306 | command line option to be linked to a particular attribute in the | |
|
307 | configuration hierarchy that it will override. | |
|
308 | ||
|
309 | * Configuration files that are themselves valid Python code. This accomplishes | |
|
310 | many things. First, it becomes possible to put logic in your configuration | |
|
311 | files that sets attributes based on your operating system, network setup, | |
|
312 | Python version, etc. Second, Python has a super simple syntax for accessing | |
|
313 | hierarchical data structures, namely regular attribute access | |
|
314 | (``Foo.Bar.Bam.name``). Third, using Python makes it easy for users to | |
|
315 | import configuration attributes from one configuration file to another. | |
|
316 | Forth, even though Python is dynamically typed, it does have types that can | |
|
317 | be checked at runtime. Thus, a ``1`` in a config file is the integer '1', | |
|
318 | while a ``'1'`` is a string. | |
|
319 | ||
|
320 | * A fully automated method for getting the configuration information to the | |
|
321 | classes that need it at runtime. Writing code that walks a configuration | |
|
322 | hierarchy to extract a particular attribute is painful. When you have | |
|
323 | complex configuration information with hundreds of attributes, this makes | |
|
324 | you want to cry. | |
|
325 | ||
|
326 | * Type checking and validation that doesn't require the entire configuration | |
|
327 | hierarchy to be specified statically before runtime. Python is a very | |
|
328 | dynamic language and you don't always know everything that needs to be | |
|
329 | configured when a program starts. | |
|
330 | ||
|
331 |
@@ -1,148 +1,148 b'' | |||
|
1 | 1 | # Get the config being loaded so we can set attributes on it |
|
2 | 2 | c = get_config() |
|
3 | 3 | |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Global options |
|
6 | 6 | #----------------------------------------------------------------------------- |
|
7 | 7 | |
|
8 | 8 | # c.Global.display_banner = True |
|
9 | 9 | |
|
10 | 10 | # c.Global.classic = False |
|
11 | 11 | |
|
12 | 12 | # c.Global.nosep = True |
|
13 | 13 | |
|
14 | 14 | # Set this to determine the detail of what is logged at startup. |
|
15 | 15 | # The default is 30 and possible values are 0,10,20,30,40,50. |
|
16 | 16 | c.Global.log_level = 20 |
|
17 | 17 | |
|
18 | 18 | # This should be a list of importable Python modules that have an |
|
19 | 19 | # load_in_ipython(ip) method. This method gets called when the extension |
|
20 | 20 | # is loaded. You can put your extensions anywhere they can be imported |
|
21 | 21 | # but we add the extensions subdir of the ipython directory to sys.path |
|
22 | 22 | # during extension loading, so you can put them there as well. |
|
23 | 23 | # c.Global.extensions = [ |
|
24 | 24 | # 'myextension' |
|
25 | 25 | # ] |
|
26 | 26 | |
|
27 | 27 | # These lines are run in IPython in the user's namespace after extensions |
|
28 | 28 | # are loaded. They can contain full IPython syntax with magics etc. |
|
29 | 29 | # c.Global.exec_lines = [ |
|
30 | 30 | # 'import numpy', |
|
31 | 31 | # 'a = 10; b = 20', |
|
32 | 32 | # '1/0' |
|
33 | 33 | # ] |
|
34 | 34 | |
|
35 | 35 | # These files are run in IPython in the user's namespace. Files with a .py |
|
36 | 36 | # extension need to be pure Python. Files with a .ipy extension can have |
|
37 | 37 | # custom IPython syntax (like magics, etc.). |
|
38 | 38 | # These files need to be in the cwd, the ipythondir or be absolute paths. |
|
39 | 39 | # c.Global.exec_files = [ |
|
40 | 40 | # 'mycode.py', |
|
41 | 41 | # 'fancy.ipy' |
|
42 | 42 | # ] |
|
43 | 43 | |
|
44 | 44 | #----------------------------------------------------------------------------- |
|
45 | 45 | # InteractiveShell options |
|
46 | 46 | #----------------------------------------------------------------------------- |
|
47 | 47 | |
|
48 | 48 | # c.InteractiveShell.autocall = 1 |
|
49 | 49 | |
|
50 | 50 | # c.InteractiveShell.autoedit_syntax = False |
|
51 | 51 | |
|
52 | 52 | # c.InteractiveShell.autoindent = True |
|
53 | 53 | |
|
54 | 54 | # c.InteractiveShell.automagic = False |
|
55 | 55 | |
|
56 | 56 | # c.InteractiveShell.banner1 = 'This if for overriding the default IPython banner' |
|
57 | 57 | |
|
58 | 58 | # c.InteractiveShell.banner2 = "This is for extra banner text" |
|
59 | 59 | |
|
60 | 60 | # c.InteractiveShell.cache_size = 1000 |
|
61 | 61 | |
|
62 | 62 | # c.InteractiveShell.colors = 'LightBG' |
|
63 | 63 | |
|
64 | 64 | # c.InteractiveShell.color_info = True |
|
65 | 65 | |
|
66 | 66 | # c.InteractiveShell.confirm_exit = True |
|
67 | 67 | |
|
68 | 68 | # c.InteractiveShell.deep_reload = False |
|
69 | 69 | |
|
70 | 70 | # c.InteractiveShell.editor = 'nano' |
|
71 | 71 | |
|
72 | 72 | # c.InteractiveShell.logstart = True |
|
73 | 73 | |
|
74 | 74 | # c.InteractiveShell.logfile = 'ipython_log.py' |
|
75 | 75 | |
|
76 | 76 | # c.InteractiveShell.logappend = 'mylog.py' |
|
77 | 77 | |
|
78 | 78 | # c.InteractiveShell.object_info_string_level = 0 |
|
79 | 79 | |
|
80 | 80 | # c.InteractiveShell.pager = 'less' |
|
81 | 81 | |
|
82 | 82 | # c.InteractiveShell.pdb = False |
|
83 | 83 | |
|
84 | 84 | # c.InteractiveShell.pprint = True |
|
85 | 85 | |
|
86 | 86 | # c.InteractiveShell.prompt_in1 = 'In [\#]: ' |
|
87 | 87 | # c.InteractiveShell.prompt_in2 = ' .\D.: ' |
|
88 | 88 | # c.InteractiveShell.prompt_out = 'Out[\#]: ' |
|
89 | 89 | # c.InteractiveShell.prompts_pad_left = True |
|
90 | 90 | |
|
91 | 91 | # c.InteractiveShell.quiet = False |
|
92 | 92 | |
|
93 | 93 | # Readline |
|
94 | 94 | # c.InteractiveShell.readline_use = True |
|
95 | 95 | |
|
96 | 96 | # c.InteractiveShell.readline_parse_and_bind = [ |
|
97 | 97 | # 'tab: complete', |
|
98 | 98 | # '"\C-l": possible-completions', |
|
99 | 99 | # 'set show-all-if-ambiguous on', |
|
100 | 100 | # '"\C-o": tab-insert', |
|
101 | 101 | # '"\M-i": " "', |
|
102 | 102 | # '"\M-o": "\d\d\d\d"', |
|
103 | 103 | # '"\M-I": "\d\d\d\d"', |
|
104 | 104 | # '"\C-r": reverse-search-history', |
|
105 | 105 | # '"\C-s": forward-search-history', |
|
106 | 106 | # '"\C-p": history-search-backward', |
|
107 | 107 | # '"\C-n": history-search-forward', |
|
108 | 108 | # '"\e[A": history-search-backward', |
|
109 | 109 | # '"\e[B": history-search-forward', |
|
110 | 110 | # '"\C-k": kill-line', |
|
111 | 111 | # '"\C-u": unix-line-discard', |
|
112 | 112 | # ] |
|
113 | 113 | # c.InteractiveShell.readline_remove_delims = '-/~' |
|
114 | 114 | # c.InteractiveShell.readline_merge_completions = True |
|
115 | 115 | # c.InteractiveShell.readline_omit_names = 0 |
|
116 | 116 | |
|
117 | 117 | # c.InteractiveShell.screen_length = 0 |
|
118 | 118 | |
|
119 | 119 | # c.InteractiveShell.separate_in = '\n' |
|
120 | 120 | # c.InteractiveShell.separate_out = '' |
|
121 | 121 | # c.InteractiveShell.separate_out2 = '' |
|
122 | 122 | |
|
123 | 123 | # c.InteractiveShell.system_header = "IPython system call: " |
|
124 | 124 | |
|
125 | 125 | # c.InteractiveShell.system_verbose = True |
|
126 | 126 | |
|
127 | 127 | # c.InteractiveShell.term_title = False |
|
128 | 128 | |
|
129 | 129 | # c.InteractiveShell.wildcards_case_sensitive = True |
|
130 | 130 | |
|
131 | 131 | # c.InteractiveShell.xmode = 'Context' |
|
132 | 132 | |
|
133 | 133 | #----------------------------------------------------------------------------- |
|
134 | 134 | # PrefilterManager options |
|
135 | 135 | #----------------------------------------------------------------------------- |
|
136 | 136 | |
|
137 | 137 | # c.PrefilterManager.multi_line_specials = True |
|
138 | 138 | |
|
139 | 139 | #----------------------------------------------------------------------------- |
|
140 | 140 | # AliasManager options |
|
141 | 141 | #----------------------------------------------------------------------------- |
|
142 | 142 | |
|
143 |
# Do this to |
|
|
143 | # Do this to disable all defaults | |
|
144 | 144 | # c.AliasManager.default_aliases = [] |
|
145 | 145 | |
|
146 | 146 | # c.AliasManager.user_aliases = [ |
|
147 | 147 | # ('foo', 'echo Hi') |
|
148 | 148 | # ] No newline at end of file |
@@ -1,325 +1,325 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """ |
|
4 | 4 | A lightweight component system for IPython. |
|
5 | 5 | |
|
6 | 6 | Authors: |
|
7 | 7 | |
|
8 | 8 | * Brian Granger |
|
9 | 9 | * Fernando Perez |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | # Copyright (C) 2008-2009 The IPython Development Team |
|
14 | 14 | # |
|
15 | 15 | # Distributed under the terms of the BSD License. The full license is in |
|
16 | 16 | # the file COPYING, distributed as part of this software. |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | # Imports |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | |
|
23 | 23 | from copy import deepcopy |
|
24 | 24 | import datetime |
|
25 | 25 | from weakref import WeakValueDictionary |
|
26 | 26 | |
|
27 | 27 | from IPython.utils.importstring import import_item |
|
28 | 28 | from IPython.config.loader import Config |
|
29 | 29 | from IPython.utils.traitlets import ( |
|
30 | 30 | HasTraitlets, TraitletError, MetaHasTraitlets, Instance, This |
|
31 | 31 | ) |
|
32 | 32 | |
|
33 | 33 | |
|
34 | 34 | #----------------------------------------------------------------------------- |
|
35 | 35 | # Helper classes for Components |
|
36 | 36 | #----------------------------------------------------------------------------- |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class ComponentError(Exception): |
|
40 | 40 | pass |
|
41 | 41 | |
|
42 | 42 | class MetaComponentTracker(type): |
|
43 | 43 | """A metaclass that tracks instances of Components and its subclasses.""" |
|
44 | 44 | |
|
45 | 45 | def __init__(cls, name, bases, d): |
|
46 | 46 | super(MetaComponentTracker, cls).__init__(name, bases, d) |
|
47 | 47 | cls.__instance_refs = WeakValueDictionary() |
|
48 | 48 | cls.__numcreated = 0 |
|
49 | 49 | |
|
50 | 50 | def __call__(cls, *args, **kw): |
|
51 | 51 | """Called when a class is called (instantiated)!!! |
|
52 | 52 | |
|
53 | 53 | When a Component or subclass is instantiated, this is called and |
|
54 | 54 | the instance is saved in a WeakValueDictionary for tracking. |
|
55 | 55 | """ |
|
56 | 56 | instance = cls.__new__(cls, *args, **kw) |
|
57 | 57 | |
|
58 | 58 | # Register the instance before __init__ is called so get_instances |
|
59 | 59 | # works inside __init__ methods! |
|
60 | 60 | indices = cls.register_instance(instance) |
|
61 | 61 | |
|
62 | 62 | # This is in a try/except because of the __init__ method fails, the |
|
63 | 63 | # instance is discarded and shouldn't be tracked. |
|
64 | 64 | try: |
|
65 | 65 | if isinstance(instance, cls): |
|
66 | 66 | cls.__init__(instance, *args, **kw) |
|
67 | 67 | except: |
|
68 | 68 | # Unregister the instance because __init__ failed! |
|
69 | 69 | cls.unregister_instances(indices) |
|
70 | 70 | raise |
|
71 | 71 | else: |
|
72 | 72 | return instance |
|
73 | 73 | |
|
74 | 74 | def register_instance(cls, instance): |
|
75 | 75 | """Register instance with cls and its subclasses.""" |
|
76 | 76 | # indices is a list of the keys used to register the instance |
|
77 | 77 | # with. This list is needed if the instance needs to be unregistered. |
|
78 | 78 | indices = [] |
|
79 | 79 | for c in cls.__mro__: |
|
80 | 80 | if issubclass(cls, c) and issubclass(c, Component): |
|
81 | 81 | c.__numcreated += 1 |
|
82 | 82 | indices.append(c.__numcreated) |
|
83 | 83 | c.__instance_refs[c.__numcreated] = instance |
|
84 | 84 | else: |
|
85 | 85 | break |
|
86 | 86 | return indices |
|
87 | 87 | |
|
88 | 88 | def unregister_instances(cls, indices): |
|
89 | 89 | """Unregister instance with cls and its subclasses.""" |
|
90 | 90 | for c, index in zip(cls.__mro__, indices): |
|
91 | 91 | try: |
|
92 | 92 | del c.__instance_refs[index] |
|
93 | 93 | except KeyError: |
|
94 | 94 | pass |
|
95 | 95 | |
|
96 | 96 | def clear_instances(cls): |
|
97 | 97 | """Clear all instances tracked by cls.""" |
|
98 | 98 | cls.__instance_refs.clear() |
|
99 | 99 | cls.__numcreated = 0 |
|
100 | 100 | |
|
101 | 101 | def get_instances(cls, name=None, root=None, klass=None): |
|
102 | 102 | """Get all instances of cls and its subclasses. |
|
103 | 103 | |
|
104 | 104 | Parameters |
|
105 | 105 | ---------- |
|
106 | 106 | name : str |
|
107 | 107 | Limit to components with this name. |
|
108 | 108 | root : Component or subclass |
|
109 | 109 | Limit to components having this root. |
|
110 | 110 | klass : class or str |
|
111 | 111 | Limits to instances of the class or its subclasses. If a str |
|
112 | 112 | is given ut must be in the form 'foo.bar.MyClass'. The str |
|
113 | 113 | form of this argument is useful for forward declarations. |
|
114 | 114 | """ |
|
115 | 115 | if klass is not None: |
|
116 | 116 | if isinstance(klass, basestring): |
|
117 | 117 | klass = import_item(klass) |
|
118 | 118 | # Limit search to instances of klass for performance |
|
119 | 119 | if issubclass(klass, Component): |
|
120 | 120 | return klass.get_instances(name=name, root=root) |
|
121 | 121 | instances = cls.__instance_refs.values() |
|
122 | 122 | if name is not None: |
|
123 | 123 | instances = [i for i in instances if i.name == name] |
|
124 | 124 | if klass is not None: |
|
125 | 125 | instances = [i for i in instances if isinstance(i, klass)] |
|
126 | 126 | if root is not None: |
|
127 | 127 | instances = [i for i in instances if i.root == root] |
|
128 | 128 | return instances |
|
129 | 129 | |
|
130 | 130 | def get_instances_by_condition(cls, call, name=None, root=None, |
|
131 | 131 | klass=None): |
|
132 | 132 | """Get all instances of cls, i such that call(i)==True. |
|
133 | 133 | |
|
134 | 134 | This also takes the ``name`` and ``root`` and ``classname`` |
|
135 | 135 | arguments of :meth:`get_instance` |
|
136 | 136 | """ |
|
137 | 137 | return [i for i in cls.get_instances(name, root, klass) if call(i)] |
|
138 | 138 | |
|
139 | 139 | |
|
140 | 140 | def masquerade_as(instance, cls): |
|
141 | 141 | """Let instance masquerade as an instance of cls. |
|
142 | 142 | |
|
143 | 143 | Sometimes, such as in testing code, it is useful to let a class |
|
144 | 144 | masquerade as another. Python, being duck typed, allows this by |
|
145 | 145 | default. But, instances of components are tracked by their class type. |
|
146 | 146 | |
|
147 |
After calling this, cls.get_instances() will return ``instance``. |
|
|
148 | does not, however, cause isinstance(instance, cls) to return ``True``. | |
|
147 | After calling this, ``cls.get_instances()`` will return ``instance``. This | |
|
148 | does not, however, cause ``isinstance(instance, cls)`` to return ``True``. | |
|
149 | 149 | |
|
150 | 150 | Parameters |
|
151 | 151 | ---------- |
|
152 | 152 | instance : an instance of a Component or Component subclass |
|
153 | 153 | The instance that will pretend to be a cls. |
|
154 | 154 | cls : subclass of Component |
|
155 | 155 | The Component subclass that instance will pretend to be. |
|
156 | 156 | """ |
|
157 | 157 | cls.register_instance(instance) |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | class ComponentNameGenerator(object): |
|
161 | 161 | """A Singleton to generate unique component names.""" |
|
162 | 162 | |
|
163 | 163 | def __init__(self, prefix): |
|
164 | 164 | self.prefix = prefix |
|
165 | 165 | self.i = 0 |
|
166 | 166 | |
|
167 | 167 | def __call__(self): |
|
168 | 168 | count = self.i |
|
169 | 169 | self.i += 1 |
|
170 | 170 | return "%s%s" % (self.prefix, count) |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | ComponentNameGenerator = ComponentNameGenerator('ipython.component') |
|
174 | 174 | |
|
175 | 175 | |
|
176 | 176 | class MetaComponent(MetaHasTraitlets, MetaComponentTracker): |
|
177 | 177 | pass |
|
178 | 178 | |
|
179 | 179 | |
|
180 | 180 | #----------------------------------------------------------------------------- |
|
181 | 181 | # Component implementation |
|
182 | 182 | #----------------------------------------------------------------------------- |
|
183 | 183 | |
|
184 | 184 | |
|
185 | 185 | class Component(HasTraitlets): |
|
186 | 186 | |
|
187 | 187 | __metaclass__ = MetaComponent |
|
188 | 188 | |
|
189 | 189 | # Traitlets are fun! |
|
190 | 190 | config = Instance(Config,(),{}) |
|
191 | 191 | parent = This() |
|
192 | 192 | root = This() |
|
193 | 193 | created = None |
|
194 | 194 | |
|
195 | 195 | def __init__(self, parent, name=None, config=None): |
|
196 | 196 | """Create a component given a parent and possibly and name and config. |
|
197 | 197 | |
|
198 | 198 | Parameters |
|
199 | 199 | ---------- |
|
200 | 200 | parent : Component subclass |
|
201 | 201 | The parent in the component graph. The parent is used |
|
202 | 202 | to get the root of the component graph. |
|
203 | 203 | name : str |
|
204 | 204 | The unique name of the component. If empty, then a unique |
|
205 | 205 | one will be autogenerated. |
|
206 | 206 | config : Config |
|
207 | 207 | If this is empty, self.config = parent.config, otherwise |
|
208 | 208 | self.config = config and root.config is ignored. This argument |
|
209 | 209 | should only be used to *override* the automatic inheritance of |
|
210 | 210 | parent.config. If a caller wants to modify parent.config |
|
211 | 211 | (not override), the caller should make a copy and change |
|
212 | 212 | attributes and then pass the copy to this argument. |
|
213 | 213 | |
|
214 | 214 | Notes |
|
215 | 215 | ----- |
|
216 | 216 | Subclasses of Component must call the :meth:`__init__` method of |
|
217 | 217 | :class:`Component` *before* doing anything else and using |
|
218 | 218 | :func:`super`:: |
|
219 | 219 | |
|
220 | 220 | class MyComponent(Component): |
|
221 | 221 | def __init__(self, parent, name=None, config=None): |
|
222 | 222 | super(MyComponent, self).__init__(parent, name, config) |
|
223 | 223 | # Then any other code you need to finish initialization. |
|
224 | 224 | |
|
225 | 225 | This ensures that the :attr:`parent`, :attr:`name` and :attr:`config` |
|
226 | 226 | attributes are handled properly. |
|
227 | 227 | """ |
|
228 | 228 | super(Component, self).__init__() |
|
229 | 229 | self._children = [] |
|
230 | 230 | if name is None: |
|
231 | 231 | self.name = ComponentNameGenerator() |
|
232 | 232 | else: |
|
233 | 233 | self.name = name |
|
234 | 234 | self.root = self # This is the default, it is set when parent is set |
|
235 | 235 | self.parent = parent |
|
236 | 236 | if config is not None: |
|
237 | 237 | self.config = config |
|
238 | 238 | # We used to deepcopy, but for now we are trying to just save |
|
239 | 239 | # by reference. This *could* have side effects as all components |
|
240 | 240 | # will share config. |
|
241 | 241 | # self.config = deepcopy(config) |
|
242 | 242 | else: |
|
243 | 243 | if self.parent is not None: |
|
244 | 244 | self.config = self.parent.config |
|
245 | 245 | # We used to deepcopy, but for now we are trying to just save |
|
246 | 246 | # by reference. This *could* have side effects as all components |
|
247 | 247 | # will share config. |
|
248 | 248 | # self.config = deepcopy(self.parent.config) |
|
249 | 249 | |
|
250 | 250 | self.created = datetime.datetime.now() |
|
251 | 251 | |
|
252 | 252 | #------------------------------------------------------------------------- |
|
253 | 253 | # Static traitlet notifiations |
|
254 | 254 | #------------------------------------------------------------------------- |
|
255 | 255 | |
|
256 | 256 | def _parent_changed(self, name, old, new): |
|
257 | 257 | if old is not None: |
|
258 | 258 | old._remove_child(self) |
|
259 | 259 | if new is not None: |
|
260 | 260 | new._add_child(self) |
|
261 | 261 | |
|
262 | 262 | if new is None: |
|
263 | 263 | self.root = self |
|
264 | 264 | else: |
|
265 | 265 | self.root = new.root |
|
266 | 266 | |
|
267 | 267 | def _root_changed(self, name, old, new): |
|
268 | 268 | if self.parent is None: |
|
269 | 269 | if not (new is self): |
|
270 | 270 | raise ComponentError("Root not self, but parent is None.") |
|
271 | 271 | else: |
|
272 | 272 | if not self.parent.root is new: |
|
273 | 273 | raise ComponentError("Error in setting the root attribute: " |
|
274 | 274 | "root != parent.root") |
|
275 | 275 | |
|
276 | 276 | def _config_changed(self, name, old, new): |
|
277 | 277 | """Update all the class traits having ``config=True`` as metadata. |
|
278 | 278 | |
|
279 | 279 | For any class traitlet with a ``config`` metadata attribute that is |
|
280 | 280 | ``True``, we update the traitlet with the value of the corresponding |
|
281 | 281 | config entry. |
|
282 | 282 | """ |
|
283 | 283 | # Get all traitlets with a config metadata entry that is True |
|
284 | 284 | traitlets = self.traitlets(config=True) |
|
285 | 285 | |
|
286 | 286 | # We auto-load config section for this class as well as any parent |
|
287 | 287 | # classes that are Component subclasses. This starts with Component |
|
288 | 288 | # and works down the mro loading the config for each section. |
|
289 | 289 | section_names = [cls.__name__ for cls in \ |
|
290 | 290 | reversed(self.__class__.__mro__) if |
|
291 | 291 | issubclass(cls, Component) and issubclass(self.__class__, cls)] |
|
292 | 292 | |
|
293 | 293 | for sname in section_names: |
|
294 | 294 | # Don't do a blind getattr as that would cause the config to |
|
295 | 295 | # dynamically create the section with name self.__class__.__name__. |
|
296 | 296 | if new._has_section(sname): |
|
297 | 297 | my_config = new[sname] |
|
298 | 298 | for k, v in traitlets.items(): |
|
299 | 299 | try: |
|
300 | 300 | config_value = my_config[k] |
|
301 | 301 | except KeyError: |
|
302 | 302 | pass |
|
303 | 303 | else: |
|
304 | 304 | # print "Setting %s.%s from %s.%s=%r" % \ |
|
305 | 305 | # (self.__class__.__name__,k,sname,k,config_value) |
|
306 | 306 | setattr(self, k, config_value) |
|
307 | 307 | |
|
308 | 308 | @property |
|
309 | 309 | def children(self): |
|
310 | 310 | """A list of all my child components.""" |
|
311 | 311 | return self._children |
|
312 | 312 | |
|
313 | 313 | def _remove_child(self, child): |
|
314 | 314 | """A private method for removing children components.""" |
|
315 | 315 | if child in self._children: |
|
316 | 316 | index = self._children.index(child) |
|
317 | 317 | del self._children[index] |
|
318 | 318 | |
|
319 | 319 | def _add_child(self, child): |
|
320 | 320 | """A private method for adding children components.""" |
|
321 | 321 | if child not in self._children: |
|
322 | 322 | self._children.append(child) |
|
323 | 323 | |
|
324 | 324 | def __repr__(self): |
|
325 | 325 | return "<%s('%s')>" % (self.__class__.__name__, self.name) |
@@ -1,995 +1,995 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """ |
|
4 | 4 | Prefiltering components. |
|
5 | 5 | |
|
6 | 6 | Prefilters transform user input before it is exec'd by Python. These |
|
7 | 7 | transforms are used to implement additional syntax such as !ls and %magic. |
|
8 | 8 | |
|
9 | 9 | Authors: |
|
10 | 10 | |
|
11 | 11 | * Brian Granger |
|
12 | 12 | * Fernando Perez |
|
13 | 13 | * Dan Milstein |
|
14 | 14 | * Ville Vainio |
|
15 | 15 | """ |
|
16 | 16 | |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | # Copyright (C) 2008-2009 The IPython Development Team |
|
19 | 19 | # |
|
20 | 20 | # Distributed under the terms of the BSD License. The full license is in |
|
21 | 21 | # the file COPYING, distributed as part of this software. |
|
22 | 22 | #----------------------------------------------------------------------------- |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Imports |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | import __builtin__ |
|
29 | 29 | import codeop |
|
30 | 30 | import keyword |
|
31 | 31 | import os |
|
32 | 32 | import re |
|
33 | 33 | import sys |
|
34 | 34 | |
|
35 | 35 | from IPython.core.alias import AliasManager |
|
36 | 36 | from IPython.core.autocall import IPyAutocall |
|
37 | 37 | from IPython.core.component import Component |
|
38 | 38 | from IPython.core.splitinput import split_user_input |
|
39 | 39 | from IPython.core.page import page |
|
40 | 40 | |
|
41 | 41 | from IPython.utils.traitlets import List, Int, Any, Str, CBool, Bool |
|
42 | 42 | from IPython.utils.genutils import make_quoted_expr |
|
43 | 43 | from IPython.utils.autoattr import auto_attr |
|
44 | 44 | |
|
45 | 45 | #----------------------------------------------------------------------------- |
|
46 | 46 | # Global utilities, errors and constants |
|
47 | 47 | #----------------------------------------------------------------------------- |
|
48 | 48 | |
|
49 | 49 | # Warning, these cannot be changed unless various regular expressions |
|
50 | 50 | # are updated in a number of places. Not great, but at least we told you. |
|
51 | 51 | ESC_SHELL = '!' |
|
52 | 52 | ESC_SH_CAP = '!!' |
|
53 | 53 | ESC_HELP = '?' |
|
54 | 54 | ESC_MAGIC = '%' |
|
55 | 55 | ESC_QUOTE = ',' |
|
56 | 56 | ESC_QUOTE2 = ';' |
|
57 | 57 | ESC_PAREN = '/' |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | class PrefilterError(Exception): |
|
61 | 61 | pass |
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | # RegExp to identify potential function names |
|
65 | 65 | re_fun_name = re.compile(r'[a-zA-Z_]([a-zA-Z0-9_.]*) *$') |
|
66 | 66 | |
|
67 | 67 | # RegExp to exclude strings with this start from autocalling. In |
|
68 | 68 | # particular, all binary operators should be excluded, so that if foo is |
|
69 | 69 | # callable, foo OP bar doesn't become foo(OP bar), which is invalid. The |
|
70 | 70 | # characters '!=()' don't need to be checked for, as the checkPythonChars |
|
71 | 71 | # routine explicitely does so, to catch direct calls and rebindings of |
|
72 | 72 | # existing names. |
|
73 | 73 | |
|
74 | 74 | # Warning: the '-' HAS TO BE AT THE END of the first group, otherwise |
|
75 | 75 | # it affects the rest of the group in square brackets. |
|
76 | 76 | re_exclude_auto = re.compile(r'^[,&^\|\*/\+-]' |
|
77 | 77 | r'|^is |^not |^in |^and |^or ') |
|
78 | 78 | |
|
79 | 79 | # try to catch also methods for stuff in lists/tuples/dicts: off |
|
80 | 80 | # (experimental). For this to work, the line_split regexp would need |
|
81 | 81 | # to be modified so it wouldn't break things at '['. That line is |
|
82 | 82 | # nasty enough that I shouldn't change it until I can test it _well_. |
|
83 | 83 | #self.re_fun_name = re.compile (r'[a-zA-Z_]([a-zA-Z0-9_.\[\]]*) ?$') |
|
84 | 84 | |
|
85 | 85 | |
|
86 | 86 | # Handler Check Utilities |
|
87 | 87 | def is_shadowed(identifier, ip): |
|
88 | 88 | """Is the given identifier defined in one of the namespaces which shadow |
|
89 | 89 | the alias and magic namespaces? Note that an identifier is different |
|
90 | 90 | than ifun, because it can not contain a '.' character.""" |
|
91 | 91 | # This is much safer than calling ofind, which can change state |
|
92 | 92 | return (identifier in ip.user_ns \ |
|
93 | 93 | or identifier in ip.internal_ns \ |
|
94 | 94 | or identifier in ip.ns_table['builtin']) |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | #----------------------------------------------------------------------------- |
|
98 | 98 | # The LineInfo class used throughout |
|
99 | 99 | #----------------------------------------------------------------------------- |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | class LineInfo(object): |
|
103 | 103 | """A single line of input and associated info. |
|
104 | 104 | |
|
105 | 105 | Includes the following as properties: |
|
106 | 106 | |
|
107 | 107 | line |
|
108 | 108 | The original, raw line |
|
109 | 109 | |
|
110 | 110 | continue_prompt |
|
111 | 111 | Is this line a continuation in a sequence of multiline input? |
|
112 | 112 | |
|
113 | 113 | pre |
|
114 | 114 | The initial esc character or whitespace. |
|
115 | 115 | |
|
116 | 116 | pre_char |
|
117 | 117 | The escape character(s) in pre or the empty string if there isn't one. |
|
118 | 118 | Note that '!!' is a possible value for pre_char. Otherwise it will |
|
119 | 119 | always be a single character. |
|
120 | 120 | |
|
121 | 121 | pre_whitespace |
|
122 | 122 | The leading whitespace from pre if it exists. If there is a pre_char, |
|
123 | 123 | this is just ''. |
|
124 | 124 | |
|
125 | 125 | ifun |
|
126 | 126 | The 'function part', which is basically the maximal initial sequence |
|
127 | 127 | of valid python identifiers and the '.' character. This is what is |
|
128 | 128 | checked for alias and magic transformations, used for auto-calling, |
|
129 | 129 | etc. |
|
130 | 130 | |
|
131 | 131 | the_rest |
|
132 | 132 | Everything else on the line. |
|
133 | 133 | """ |
|
134 | 134 | def __init__(self, line, continue_prompt): |
|
135 | 135 | self.line = line |
|
136 | 136 | self.continue_prompt = continue_prompt |
|
137 | 137 | self.pre, self.ifun, self.the_rest = split_user_input(line) |
|
138 | 138 | |
|
139 | 139 | self.pre_char = self.pre.strip() |
|
140 | 140 | if self.pre_char: |
|
141 | 141 | self.pre_whitespace = '' # No whitespace allowd before esc chars |
|
142 | 142 | else: |
|
143 | 143 | self.pre_whitespace = self.pre |
|
144 | 144 | |
|
145 | 145 | self._oinfo = None |
|
146 | 146 | |
|
147 | 147 | def ofind(self, ip): |
|
148 | 148 | """Do a full, attribute-walking lookup of the ifun in the various |
|
149 | 149 | namespaces for the given IPython InteractiveShell instance. |
|
150 | 150 | |
|
151 | 151 | Return a dict with keys: found,obj,ospace,ismagic |
|
152 | 152 | |
|
153 | 153 | Note: can cause state changes because of calling getattr, but should |
|
154 | 154 | only be run if autocall is on and if the line hasn't matched any |
|
155 | 155 | other, less dangerous handlers. |
|
156 | 156 | |
|
157 | 157 | Does cache the results of the call, so can be called multiple times |
|
158 | 158 | without worrying about *further* damaging state. |
|
159 | 159 | """ |
|
160 | 160 | if not self._oinfo: |
|
161 | 161 | self._oinfo = ip._ofind(self.ifun) |
|
162 | 162 | return self._oinfo |
|
163 | 163 | |
|
164 | 164 | def __str__(self): |
|
165 | 165 | return "Lineinfo [%s|%s|%s]" %(self.pre,self.ifun,self.the_rest) |
|
166 | 166 | |
|
167 | 167 | |
|
168 | 168 | #----------------------------------------------------------------------------- |
|
169 | 169 | # Main Prefilter manager |
|
170 | 170 | #----------------------------------------------------------------------------- |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | class PrefilterManager(Component): |
|
174 | 174 | """Main prefilter component. |
|
175 | 175 | |
|
176 | 176 | The IPython prefilter is run on all user input before it is run. The |
|
177 | 177 | prefilter consumes lines of input and produces transformed lines of |
|
178 | 178 | input. |
|
179 | 179 | |
|
180 | 180 | The iplementation consists of two phases: |
|
181 | 181 | |
|
182 | 182 | 1. Transformers |
|
183 | 183 | 2. Checkers and handlers |
|
184 | 184 | |
|
185 | 185 | Over time, we plan on deprecating the checkers and handlers and doing |
|
186 | 186 | everything in the transformers. |
|
187 | 187 | |
|
188 | 188 | The transformers are instances of :class:`PrefilterTransformer` and have |
|
189 | 189 | a single method :meth:`transform` that takes a line and returns a |
|
190 | 190 | transformed line. The transformation can be accomplished using any |
|
191 | 191 | tool, but our current ones use regular expressions for speed. We also |
|
192 | 192 | ship :mod:`pyparsing` in :mod:`IPython.external` for use in transformers. |
|
193 | 193 | |
|
194 | 194 | After all the transformers have been run, the line is fed to the checkers, |
|
195 | 195 | which are instances of :class:`PrefilterChecker`. The line is passed to |
|
196 | 196 | the :meth:`check` method, which either returns `None` or a |
|
197 | 197 | :class:`PrefilterHandler` instance. If `None` is returned, the other |
|
198 | 198 | checkers are tried. If an :class:`PrefilterHandler` instance is returned, |
|
199 | 199 | the line is passed to the :meth:`handle` method of the returned |
|
200 | 200 | handler and no further checkers are tried. |
|
201 | 201 | |
|
202 | 202 | Both transformers and checkers have a `priority` attribute, that determines |
|
203 | 203 | the order in which they are called. Smaller priorities are tried first. |
|
204 | 204 | |
|
205 | 205 | Both transformers and checkers also have `enabled` attribute, which is |
|
206 | 206 | a boolean that determines if the instance is used. |
|
207 | 207 | |
|
208 | 208 | Users or developers can change the priority or enabled attribute of |
|
209 | 209 | transformers or checkers, but they must call the :meth:`sort_checkers` |
|
210 | or :meth`sort_transformers` method after changing the priority. | |
|
210 | or :meth:`sort_transformers` method after changing the priority. | |
|
211 | 211 | """ |
|
212 | 212 | |
|
213 | 213 | multi_line_specials = CBool(True, config=True) |
|
214 | 214 | |
|
215 | 215 | def __init__(self, parent, config=None): |
|
216 | 216 | super(PrefilterManager, self).__init__(parent, config=config) |
|
217 | 217 | self.init_transformers() |
|
218 | 218 | self.init_handlers() |
|
219 | 219 | self.init_checkers() |
|
220 | 220 | |
|
221 | 221 | @auto_attr |
|
222 | 222 | def shell(self): |
|
223 | 223 | return Component.get_instances( |
|
224 | 224 | root=self.root, |
|
225 | 225 | klass='IPython.core.iplib.InteractiveShell')[0] |
|
226 | 226 | |
|
227 | 227 | #------------------------------------------------------------------------- |
|
228 | 228 | # API for managing transformers |
|
229 | 229 | #------------------------------------------------------------------------- |
|
230 | 230 | |
|
231 | 231 | def init_transformers(self): |
|
232 | 232 | """Create the default transformers.""" |
|
233 | 233 | self._transformers = [] |
|
234 | 234 | for transformer_cls in _default_transformers: |
|
235 | 235 | transformer_cls(self, config=self.config) |
|
236 | 236 | |
|
237 | 237 | def sort_transformers(self): |
|
238 | 238 | """Sort the transformers by priority. |
|
239 | 239 | |
|
240 | 240 | This must be called after the priority of a transformer is changed. |
|
241 | 241 | The :meth:`register_transformer` method calls this automatically. |
|
242 | 242 | """ |
|
243 | 243 | self._transformers.sort(cmp=lambda x,y: x.priority-y.priority) |
|
244 | 244 | |
|
245 | 245 | @property |
|
246 | 246 | def transformers(self): |
|
247 | 247 | """Return a list of checkers, sorted by priority.""" |
|
248 | 248 | return self._transformers |
|
249 | 249 | |
|
250 | 250 | def register_transformer(self, transformer): |
|
251 | 251 | """Register a transformer instance.""" |
|
252 | 252 | if transformer not in self._transformers: |
|
253 | 253 | self._transformers.append(transformer) |
|
254 | 254 | self.sort_transformers() |
|
255 | 255 | |
|
256 | 256 | def unregister_transformer(self, transformer): |
|
257 | 257 | """Unregister a transformer instance.""" |
|
258 | 258 | if transformer in self._transformers: |
|
259 | 259 | self._transformers.remove(transformer) |
|
260 | 260 | |
|
261 | 261 | #------------------------------------------------------------------------- |
|
262 | 262 | # API for managing checkers |
|
263 | 263 | #------------------------------------------------------------------------- |
|
264 | 264 | |
|
265 | 265 | def init_checkers(self): |
|
266 | 266 | """Create the default checkers.""" |
|
267 | 267 | self._checkers = [] |
|
268 | 268 | for checker in _default_checkers: |
|
269 | 269 | checker(self, config=self.config) |
|
270 | 270 | |
|
271 | 271 | def sort_checkers(self): |
|
272 | 272 | """Sort the checkers by priority. |
|
273 | 273 | |
|
274 | 274 | This must be called after the priority of a checker is changed. |
|
275 | 275 | The :meth:`register_checker` method calls this automatically. |
|
276 | 276 | """ |
|
277 | 277 | self._checkers.sort(cmp=lambda x,y: x.priority-y.priority) |
|
278 | 278 | |
|
279 | 279 | @property |
|
280 | 280 | def checkers(self): |
|
281 | 281 | """Return a list of checkers, sorted by priority.""" |
|
282 | 282 | return self._checkers |
|
283 | 283 | |
|
284 | 284 | def register_checker(self, checker): |
|
285 | 285 | """Register a checker instance.""" |
|
286 | 286 | if checker not in self._checkers: |
|
287 | 287 | self._checkers.append(checker) |
|
288 | 288 | self.sort_checkers() |
|
289 | 289 | |
|
290 | 290 | def unregister_checker(self, checker): |
|
291 | 291 | """Unregister a checker instance.""" |
|
292 | 292 | if checker in self._checkers: |
|
293 | 293 | self._checkers.remove(checker) |
|
294 | 294 | |
|
295 | 295 | #------------------------------------------------------------------------- |
|
296 | 296 | # API for managing checkers |
|
297 | 297 | #------------------------------------------------------------------------- |
|
298 | 298 | |
|
299 | 299 | def init_handlers(self): |
|
300 | 300 | """Create the default handlers.""" |
|
301 | 301 | self._handlers = {} |
|
302 | 302 | self._esc_handlers = {} |
|
303 | 303 | for handler in _default_handlers: |
|
304 | 304 | handler(self, config=self.config) |
|
305 | 305 | |
|
306 | 306 | @property |
|
307 | 307 | def handlers(self): |
|
308 | 308 | """Return a dict of all the handlers.""" |
|
309 | 309 | return self._handlers |
|
310 | 310 | |
|
311 | 311 | def register_handler(self, name, handler, esc_strings): |
|
312 | 312 | """Register a handler instance by name with esc_strings.""" |
|
313 | 313 | self._handlers[name] = handler |
|
314 | 314 | for esc_str in esc_strings: |
|
315 | 315 | self._esc_handlers[esc_str] = handler |
|
316 | 316 | |
|
317 | 317 | def unregister_handler(self, name, handler, esc_strings): |
|
318 | 318 | """Unregister a handler instance by name with esc_strings.""" |
|
319 | 319 | try: |
|
320 | 320 | del self._handlers[name] |
|
321 | 321 | except KeyError: |
|
322 | 322 | pass |
|
323 | 323 | for esc_str in esc_strings: |
|
324 | 324 | h = self._esc_handlers.get(esc_str) |
|
325 | 325 | if h is handler: |
|
326 | 326 | del self._esc_handlers[esc_str] |
|
327 | 327 | |
|
328 | 328 | def get_handler_by_name(self, name): |
|
329 | 329 | """Get a handler by its name.""" |
|
330 | 330 | return self._handlers.get(name) |
|
331 | 331 | |
|
332 | 332 | def get_handler_by_esc(self, esc_str): |
|
333 | 333 | """Get a handler by its escape string.""" |
|
334 | 334 | return self._esc_handlers.get(esc_str) |
|
335 | 335 | |
|
336 | 336 | #------------------------------------------------------------------------- |
|
337 | 337 | # Main prefiltering API |
|
338 | 338 | #------------------------------------------------------------------------- |
|
339 | 339 | |
|
340 | 340 | def prefilter_line_info(self, line_info): |
|
341 | 341 | """Prefilter a line that has been converted to a LineInfo object. |
|
342 | 342 | |
|
343 | 343 | This implements the checker/handler part of the prefilter pipe. |
|
344 | 344 | """ |
|
345 | 345 | # print "prefilter_line_info: ", line_info |
|
346 | 346 | handler = self.find_handler(line_info) |
|
347 | 347 | return handler.handle(line_info) |
|
348 | 348 | |
|
349 | 349 | def find_handler(self, line_info): |
|
350 | 350 | """Find a handler for the line_info by trying checkers.""" |
|
351 | 351 | for checker in self.checkers: |
|
352 | 352 | if checker.enabled: |
|
353 | 353 | handler = checker.check(line_info) |
|
354 | 354 | if handler: |
|
355 | 355 | return handler |
|
356 | 356 | return self.get_handler_by_name('normal') |
|
357 | 357 | |
|
358 | 358 | def transform_line(self, line, continue_prompt): |
|
359 | 359 | """Calls the enabled transformers in order of increasing priority.""" |
|
360 | 360 | for transformer in self.transformers: |
|
361 | 361 | if transformer.enabled: |
|
362 | 362 | line = transformer.transform(line, continue_prompt) |
|
363 | 363 | return line |
|
364 | 364 | |
|
365 | 365 | def prefilter_line(self, line, continue_prompt): |
|
366 | 366 | """Prefilter a single input line as text. |
|
367 | 367 | |
|
368 | 368 | This method prefilters a single line of text by calling the |
|
369 | 369 | transformers and then the checkers/handlers. |
|
370 | 370 | """ |
|
371 | 371 | |
|
372 | 372 | # print "prefilter_line: ", line, continue_prompt |
|
373 | 373 | # All handlers *must* return a value, even if it's blank (''). |
|
374 | 374 | |
|
375 | 375 | # Lines are NOT logged here. Handlers should process the line as |
|
376 | 376 | # needed, update the cache AND log it (so that the input cache array |
|
377 | 377 | # stays synced). |
|
378 | 378 | |
|
379 | 379 | # save the line away in case we crash, so the post-mortem handler can |
|
380 | 380 | # record it |
|
381 | 381 | self.shell._last_input_line = line |
|
382 | 382 | |
|
383 | 383 | if not line: |
|
384 | 384 | # Return immediately on purely empty lines, so that if the user |
|
385 | 385 | # previously typed some whitespace that started a continuation |
|
386 | 386 | # prompt, he can break out of that loop with just an empty line. |
|
387 | 387 | # This is how the default python prompt works. |
|
388 | 388 | |
|
389 | 389 | # Only return if the accumulated input buffer was just whitespace! |
|
390 | 390 | if ''.join(self.shell.buffer).isspace(): |
|
391 | 391 | self.shell.buffer[:] = [] |
|
392 | 392 | return '' |
|
393 | 393 | |
|
394 | 394 | # At this point, we invoke our transformers. |
|
395 | 395 | if not continue_prompt or (continue_prompt and self.multi_line_specials): |
|
396 | 396 | line = self.transform_line(line, continue_prompt) |
|
397 | 397 | |
|
398 | 398 | # Now we compute line_info for the checkers and handlers |
|
399 | 399 | line_info = LineInfo(line, continue_prompt) |
|
400 | 400 | |
|
401 | 401 | # the input history needs to track even empty lines |
|
402 | 402 | stripped = line.strip() |
|
403 | 403 | |
|
404 | 404 | normal_handler = self.get_handler_by_name('normal') |
|
405 | 405 | if not stripped: |
|
406 | 406 | if not continue_prompt: |
|
407 | 407 | self.shell.outputcache.prompt_count -= 1 |
|
408 | 408 | |
|
409 | 409 | return normal_handler.handle(line_info) |
|
410 | 410 | |
|
411 | 411 | # special handlers are only allowed for single line statements |
|
412 | 412 | if continue_prompt and not self.multi_line_specials: |
|
413 | 413 | return normal_handler.handle(line_info) |
|
414 | 414 | |
|
415 | 415 | prefiltered = self.prefilter_line_info(line_info) |
|
416 | 416 | # print "prefiltered line: %r" % prefiltered |
|
417 | 417 | return prefiltered |
|
418 | 418 | |
|
419 | 419 | def prefilter_lines(self, lines, continue_prompt): |
|
420 | 420 | """Prefilter multiple input lines of text. |
|
421 | 421 | |
|
422 | 422 | This is the main entry point for prefiltering multiple lines of |
|
423 | 423 | input. This simply calls :meth:`prefilter_line` for each line of |
|
424 | 424 | input. |
|
425 | 425 | |
|
426 | 426 | This covers cases where there are multiple lines in the user entry, |
|
427 | 427 | which is the case when the user goes back to a multiline history |
|
428 | 428 | entry and presses enter. |
|
429 | 429 | """ |
|
430 | 430 | out = [] |
|
431 | 431 | for line in lines.rstrip('\n').split('\n'): |
|
432 | 432 | out.append(self.prefilter_line(line, continue_prompt)) |
|
433 | 433 | return '\n'.join(out) |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | #----------------------------------------------------------------------------- |
|
437 | 437 | # Prefilter transformers |
|
438 | 438 | #----------------------------------------------------------------------------- |
|
439 | 439 | |
|
440 | 440 | |
|
441 | 441 | class PrefilterTransformer(Component): |
|
442 | 442 | """Transform a line of user input.""" |
|
443 | 443 | |
|
444 | 444 | priority = Int(100, config=True) |
|
445 | 445 | shell = Any |
|
446 | 446 | prefilter_manager = Any |
|
447 | 447 | enabled = Bool(True, config=True) |
|
448 | 448 | |
|
449 | 449 | def __init__(self, parent, config=None): |
|
450 | 450 | super(PrefilterTransformer, self).__init__(parent, config=config) |
|
451 | 451 | self.prefilter_manager.register_transformer(self) |
|
452 | 452 | |
|
453 | 453 | @auto_attr |
|
454 | 454 | def shell(self): |
|
455 | 455 | return Component.get_instances( |
|
456 | 456 | root=self.root, |
|
457 | 457 | klass='IPython.core.iplib.InteractiveShell')[0] |
|
458 | 458 | |
|
459 | 459 | @auto_attr |
|
460 | 460 | def prefilter_manager(self): |
|
461 | 461 | return PrefilterManager.get_instances(root=self.root)[0] |
|
462 | 462 | |
|
463 | 463 | def transform(self, line, continue_prompt): |
|
464 | 464 | """Transform a line, returning the new one.""" |
|
465 | 465 | return None |
|
466 | 466 | |
|
467 | 467 | def __repr__(self): |
|
468 | 468 | return "<%s(priority=%r, enabled=%r)>" % ( |
|
469 | 469 | self.__class__.__name__, self.priority, self.enabled) |
|
470 | 470 | |
|
471 | 471 | |
|
472 | 472 | _assign_system_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))' |
|
473 | 473 | r'\s*=\s*!(?P<cmd>.*)') |
|
474 | 474 | |
|
475 | 475 | |
|
476 | 476 | class AssignSystemTransformer(PrefilterTransformer): |
|
477 | 477 | """Handle the `files = !ls` syntax.""" |
|
478 | 478 | |
|
479 | 479 | priority = Int(100, config=True) |
|
480 | 480 | |
|
481 | 481 | def transform(self, line, continue_prompt): |
|
482 | 482 | m = _assign_system_re.match(line) |
|
483 | 483 | if m is not None: |
|
484 | 484 | cmd = m.group('cmd') |
|
485 | 485 | lhs = m.group('lhs') |
|
486 | 486 | expr = make_quoted_expr("sc -l =%s" % cmd) |
|
487 | 487 | new_line = '%s = get_ipython().magic(%s)' % (lhs, expr) |
|
488 | 488 | return new_line |
|
489 | 489 | return line |
|
490 | 490 | |
|
491 | 491 | |
|
492 | 492 | _assign_magic_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))' |
|
493 | 493 | r'\s*=\s*%(?P<cmd>.*)') |
|
494 | 494 | |
|
495 | 495 | class AssignMagicTransformer(PrefilterTransformer): |
|
496 | 496 | """Handle the `a = %who` syntax.""" |
|
497 | 497 | |
|
498 | 498 | priority = Int(200, config=True) |
|
499 | 499 | |
|
500 | 500 | def transform(self, line, continue_prompt): |
|
501 | 501 | m = _assign_magic_re.match(line) |
|
502 | 502 | if m is not None: |
|
503 | 503 | cmd = m.group('cmd') |
|
504 | 504 | lhs = m.group('lhs') |
|
505 | 505 | expr = make_quoted_expr(cmd) |
|
506 | 506 | new_line = '%s = get_ipython().magic(%s)' % (lhs, expr) |
|
507 | 507 | return new_line |
|
508 | 508 | return line |
|
509 | 509 | |
|
510 | 510 | |
|
511 | 511 | #----------------------------------------------------------------------------- |
|
512 | 512 | # Prefilter checkers |
|
513 | 513 | #----------------------------------------------------------------------------- |
|
514 | 514 | |
|
515 | 515 | |
|
516 | 516 | class PrefilterChecker(Component): |
|
517 | 517 | """Inspect an input line and return a handler for that line.""" |
|
518 | 518 | |
|
519 | 519 | priority = Int(100, config=True) |
|
520 | 520 | shell = Any |
|
521 | 521 | prefilter_manager = Any |
|
522 | 522 | enabled = Bool(True, config=True) |
|
523 | 523 | |
|
524 | 524 | def __init__(self, parent, config=None): |
|
525 | 525 | super(PrefilterChecker, self).__init__(parent, config=config) |
|
526 | 526 | self.prefilter_manager.register_checker(self) |
|
527 | 527 | |
|
528 | 528 | @auto_attr |
|
529 | 529 | def shell(self): |
|
530 | 530 | return Component.get_instances( |
|
531 | 531 | root=self.root, |
|
532 | 532 | klass='IPython.core.iplib.InteractiveShell')[0] |
|
533 | 533 | |
|
534 | 534 | @auto_attr |
|
535 | 535 | def prefilter_manager(self): |
|
536 | 536 | return PrefilterManager.get_instances(root=self.root)[0] |
|
537 | 537 | |
|
538 | 538 | def check(self, line_info): |
|
539 | 539 | """Inspect line_info and return a handler instance or None.""" |
|
540 | 540 | return None |
|
541 | 541 | |
|
542 | 542 | def __repr__(self): |
|
543 | 543 | return "<%s(priority=%r, enabled=%r)>" % ( |
|
544 | 544 | self.__class__.__name__, self.priority, self.enabled) |
|
545 | 545 | |
|
546 | 546 | |
|
547 | 547 | class EmacsChecker(PrefilterChecker): |
|
548 | 548 | |
|
549 | 549 | priority = Int(100, config=True) |
|
550 | 550 | enabled = Bool(False, config=True) |
|
551 | 551 | |
|
552 | 552 | def check(self, line_info): |
|
553 | 553 | "Emacs ipython-mode tags certain input lines." |
|
554 | 554 | if line_info.line.endswith('# PYTHON-MODE'): |
|
555 | 555 | return self.prefilter_manager.get_handler_by_name('emacs') |
|
556 | 556 | else: |
|
557 | 557 | return None |
|
558 | 558 | |
|
559 | 559 | |
|
560 | 560 | class ShellEscapeChecker(PrefilterChecker): |
|
561 | 561 | |
|
562 | 562 | priority = Int(200, config=True) |
|
563 | 563 | |
|
564 | 564 | def check(self, line_info): |
|
565 | 565 | if line_info.line.lstrip().startswith(ESC_SHELL): |
|
566 | 566 | return self.prefilter_manager.get_handler_by_name('shell') |
|
567 | 567 | |
|
568 | 568 | |
|
569 | 569 | class IPyAutocallChecker(PrefilterChecker): |
|
570 | 570 | |
|
571 | 571 | priority = Int(300, config=True) |
|
572 | 572 | |
|
573 | 573 | def check(self, line_info): |
|
574 | 574 | "Instances of IPyAutocall in user_ns get autocalled immediately" |
|
575 | 575 | obj = self.shell.user_ns.get(line_info.ifun, None) |
|
576 | 576 | if isinstance(obj, IPyAutocall): |
|
577 | 577 | obj.set_ip(self.shell) |
|
578 | 578 | return self.prefilter_manager.get_handler_by_name('auto') |
|
579 | 579 | else: |
|
580 | 580 | return None |
|
581 | 581 | |
|
582 | 582 | |
|
583 | 583 | class MultiLineMagicChecker(PrefilterChecker): |
|
584 | 584 | |
|
585 | 585 | priority = Int(400, config=True) |
|
586 | 586 | |
|
587 | 587 | def check(self, line_info): |
|
588 | 588 | "Allow ! and !! in multi-line statements if multi_line_specials is on" |
|
589 | 589 | # Note that this one of the only places we check the first character of |
|
590 | 590 | # ifun and *not* the pre_char. Also note that the below test matches |
|
591 | 591 | # both ! and !!. |
|
592 | 592 | if line_info.continue_prompt \ |
|
593 | 593 | and self.prefilter_manager.multi_line_specials: |
|
594 | 594 | if line_info.ifun.startswith(ESC_MAGIC): |
|
595 | 595 | return self.prefilter_manager.get_handler_by_name('magic') |
|
596 | 596 | else: |
|
597 | 597 | return None |
|
598 | 598 | |
|
599 | 599 | |
|
600 | 600 | class EscCharsChecker(PrefilterChecker): |
|
601 | 601 | |
|
602 | 602 | priority = Int(500, config=True) |
|
603 | 603 | |
|
604 | 604 | def check(self, line_info): |
|
605 | 605 | """Check for escape character and return either a handler to handle it, |
|
606 | 606 | or None if there is no escape char.""" |
|
607 | 607 | if line_info.line[-1] == ESC_HELP \ |
|
608 | 608 | and line_info.pre_char != ESC_SHELL \ |
|
609 | 609 | and line_info.pre_char != ESC_SH_CAP: |
|
610 | 610 | # the ? can be at the end, but *not* for either kind of shell escape, |
|
611 | 611 | # because a ? can be a vaild final char in a shell cmd |
|
612 | 612 | return self.prefilter_manager.get_handler_by_name('help') |
|
613 | 613 | else: |
|
614 | 614 | # This returns None like it should if no handler exists |
|
615 | 615 | return self.prefilter_manager.get_handler_by_esc(line_info.pre_char) |
|
616 | 616 | |
|
617 | 617 | |
|
618 | 618 | class AssignmentChecker(PrefilterChecker): |
|
619 | 619 | |
|
620 | 620 | priority = Int(600, config=True) |
|
621 | 621 | |
|
622 | 622 | def check(self, line_info): |
|
623 | 623 | """Check to see if user is assigning to a var for the first time, in |
|
624 | 624 | which case we want to avoid any sort of automagic / autocall games. |
|
625 | 625 | |
|
626 | 626 | This allows users to assign to either alias or magic names true python |
|
627 | 627 | variables (the magic/alias systems always take second seat to true |
|
628 | 628 | python code). E.g. ls='hi', or ls,that=1,2""" |
|
629 | 629 | if line_info.the_rest: |
|
630 | 630 | if line_info.the_rest[0] in '=,': |
|
631 | 631 | return self.prefilter_manager.get_handler_by_name('normal') |
|
632 | 632 | else: |
|
633 | 633 | return None |
|
634 | 634 | |
|
635 | 635 | |
|
636 | 636 | class AutoMagicChecker(PrefilterChecker): |
|
637 | 637 | |
|
638 | 638 | priority = Int(700, config=True) |
|
639 | 639 | |
|
640 | 640 | def check(self, line_info): |
|
641 | 641 | """If the ifun is magic, and automagic is on, run it. Note: normal, |
|
642 | 642 | non-auto magic would already have been triggered via '%' in |
|
643 | 643 | check_esc_chars. This just checks for automagic. Also, before |
|
644 | 644 | triggering the magic handler, make sure that there is nothing in the |
|
645 | 645 | user namespace which could shadow it.""" |
|
646 | 646 | if not self.shell.automagic or not hasattr(self.shell,'magic_'+line_info.ifun): |
|
647 | 647 | return None |
|
648 | 648 | |
|
649 | 649 | # We have a likely magic method. Make sure we should actually call it. |
|
650 | 650 | if line_info.continue_prompt and not self.shell.multi_line_specials: |
|
651 | 651 | return None |
|
652 | 652 | |
|
653 | 653 | head = line_info.ifun.split('.',1)[0] |
|
654 | 654 | if is_shadowed(head, self.shell): |
|
655 | 655 | return None |
|
656 | 656 | |
|
657 | 657 | return self.prefilter_manager.get_handler_by_name('magic') |
|
658 | 658 | |
|
659 | 659 | |
|
660 | 660 | class AliasChecker(PrefilterChecker): |
|
661 | 661 | |
|
662 | 662 | priority = Int(800, config=True) |
|
663 | 663 | |
|
664 | 664 | @auto_attr |
|
665 | 665 | def alias_manager(self): |
|
666 | 666 | return AliasManager.get_instances(root=self.root)[0] |
|
667 | 667 | |
|
668 | 668 | def check(self, line_info): |
|
669 | 669 | "Check if the initital identifier on the line is an alias." |
|
670 | 670 | # Note: aliases can not contain '.' |
|
671 | 671 | head = line_info.ifun.split('.',1)[0] |
|
672 | 672 | if line_info.ifun not in self.alias_manager \ |
|
673 | 673 | or head not in self.alias_manager \ |
|
674 | 674 | or is_shadowed(head, self.shell): |
|
675 | 675 | return None |
|
676 | 676 | |
|
677 | 677 | return self.prefilter_manager.get_handler_by_name('alias') |
|
678 | 678 | |
|
679 | 679 | |
|
680 | 680 | class PythonOpsChecker(PrefilterChecker): |
|
681 | 681 | |
|
682 | 682 | priority = Int(900, config=True) |
|
683 | 683 | |
|
684 | 684 | def check(self, line_info): |
|
685 | 685 | """If the 'rest' of the line begins with a function call or pretty much |
|
686 | 686 | any python operator, we should simply execute the line (regardless of |
|
687 | 687 | whether or not there's a possible autocall expansion). This avoids |
|
688 | 688 | spurious (and very confusing) geattr() accesses.""" |
|
689 | 689 | if line_info.the_rest and line_info.the_rest[0] in '!=()<>,+*/%^&|': |
|
690 | 690 | return self.prefilter_manager.get_handler_by_name('normal') |
|
691 | 691 | else: |
|
692 | 692 | return None |
|
693 | 693 | |
|
694 | 694 | |
|
695 | 695 | class AutocallChecker(PrefilterChecker): |
|
696 | 696 | |
|
697 | 697 | priority = Int(1000, config=True) |
|
698 | 698 | |
|
699 | 699 | def check(self, line_info): |
|
700 | 700 | "Check if the initial word/function is callable and autocall is on." |
|
701 | 701 | if not self.shell.autocall: |
|
702 | 702 | return None |
|
703 | 703 | |
|
704 | 704 | oinfo = line_info.ofind(self.shell) # This can mutate state via getattr |
|
705 | 705 | if not oinfo['found']: |
|
706 | 706 | return None |
|
707 | 707 | |
|
708 | 708 | if callable(oinfo['obj']) \ |
|
709 | 709 | and (not re_exclude_auto.match(line_info.the_rest)) \ |
|
710 | 710 | and re_fun_name.match(line_info.ifun): |
|
711 | 711 | return self.prefilter_manager.get_handler_by_name('auto') |
|
712 | 712 | else: |
|
713 | 713 | return None |
|
714 | 714 | |
|
715 | 715 | |
|
716 | 716 | #----------------------------------------------------------------------------- |
|
717 | 717 | # Prefilter handlers |
|
718 | 718 | #----------------------------------------------------------------------------- |
|
719 | 719 | |
|
720 | 720 | |
|
721 | 721 | class PrefilterHandler(Component): |
|
722 | 722 | |
|
723 | 723 | handler_name = Str('normal') |
|
724 | 724 | esc_strings = List([]) |
|
725 | 725 | shell = Any |
|
726 | 726 | prefilter_manager = Any |
|
727 | 727 | |
|
728 | 728 | def __init__(self, parent, config=None): |
|
729 | 729 | super(PrefilterHandler, self).__init__(parent, config=config) |
|
730 | 730 | self.prefilter_manager.register_handler( |
|
731 | 731 | self.handler_name, |
|
732 | 732 | self, |
|
733 | 733 | self.esc_strings |
|
734 | 734 | ) |
|
735 | 735 | |
|
736 | 736 | @auto_attr |
|
737 | 737 | def shell(self): |
|
738 | 738 | return Component.get_instances( |
|
739 | 739 | root=self.root, |
|
740 | 740 | klass='IPython.core.iplib.InteractiveShell')[0] |
|
741 | 741 | |
|
742 | 742 | @auto_attr |
|
743 | 743 | def prefilter_manager(self): |
|
744 | 744 | return PrefilterManager.get_instances(root=self.root)[0] |
|
745 | 745 | |
|
746 | 746 | def handle(self, line_info): |
|
747 | 747 | # print "normal: ", line_info |
|
748 | 748 | """Handle normal input lines. Use as a template for handlers.""" |
|
749 | 749 | |
|
750 | 750 | # With autoindent on, we need some way to exit the input loop, and I |
|
751 | 751 | # don't want to force the user to have to backspace all the way to |
|
752 | 752 | # clear the line. The rule will be in this case, that either two |
|
753 | 753 | # lines of pure whitespace in a row, or a line of pure whitespace but |
|
754 | 754 | # of a size different to the indent level, will exit the input loop. |
|
755 | 755 | line = line_info.line |
|
756 | 756 | continue_prompt = line_info.continue_prompt |
|
757 | 757 | |
|
758 | 758 | if (continue_prompt and self.shell.autoindent and line.isspace() and |
|
759 | 759 | (0 < abs(len(line) - self.shell.indent_current_nsp) <= 2 or |
|
760 | 760 | (self.shell.buffer[-1]).isspace() )): |
|
761 | 761 | line = '' |
|
762 | 762 | |
|
763 | 763 | self.shell.log(line, line, continue_prompt) |
|
764 | 764 | return line |
|
765 | 765 | |
|
766 | 766 | def __str__(self): |
|
767 | 767 | return "<%s(name=%s)>" % (self.__class__.__name__, self.handler_name) |
|
768 | 768 | |
|
769 | 769 | |
|
770 | 770 | class AliasHandler(PrefilterHandler): |
|
771 | 771 | |
|
772 | 772 | handler_name = Str('alias') |
|
773 | 773 | |
|
774 | 774 | @auto_attr |
|
775 | 775 | def alias_manager(self): |
|
776 | 776 | return AliasManager.get_instances(root=self.root)[0] |
|
777 | 777 | |
|
778 | 778 | def handle(self, line_info): |
|
779 | 779 | """Handle alias input lines. """ |
|
780 | 780 | transformed = self.alias_manager.expand_aliases(line_info.ifun,line_info.the_rest) |
|
781 | 781 | # pre is needed, because it carries the leading whitespace. Otherwise |
|
782 | 782 | # aliases won't work in indented sections. |
|
783 | 783 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, |
|
784 | 784 | make_quoted_expr(transformed)) |
|
785 | 785 | |
|
786 | 786 | self.shell.log(line_info.line, line_out, line_info.continue_prompt) |
|
787 | 787 | return line_out |
|
788 | 788 | |
|
789 | 789 | |
|
790 | 790 | class ShellEscapeHandler(PrefilterHandler): |
|
791 | 791 | |
|
792 | 792 | handler_name = Str('shell') |
|
793 | 793 | esc_strings = List([ESC_SHELL, ESC_SH_CAP]) |
|
794 | 794 | |
|
795 | 795 | def handle(self, line_info): |
|
796 | 796 | """Execute the line in a shell, empty return value""" |
|
797 | 797 | magic_handler = self.prefilter_manager.get_handler_by_name('magic') |
|
798 | 798 | |
|
799 | 799 | line = line_info.line |
|
800 | 800 | if line.lstrip().startswith(ESC_SH_CAP): |
|
801 | 801 | # rewrite LineInfo's line, ifun and the_rest to properly hold the |
|
802 | 802 | # call to %sx and the actual command to be executed, so |
|
803 | 803 | # handle_magic can work correctly. Note that this works even if |
|
804 | 804 | # the line is indented, so it handles multi_line_specials |
|
805 | 805 | # properly. |
|
806 | 806 | new_rest = line.lstrip()[2:] |
|
807 | 807 | line_info.line = '%ssx %s' % (ESC_MAGIC, new_rest) |
|
808 | 808 | line_info.ifun = 'sx' |
|
809 | 809 | line_info.the_rest = new_rest |
|
810 | 810 | return magic_handler.handle(line_info) |
|
811 | 811 | else: |
|
812 | 812 | cmd = line.lstrip().lstrip(ESC_SHELL) |
|
813 | 813 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, |
|
814 | 814 | make_quoted_expr(cmd)) |
|
815 | 815 | # update cache/log and return |
|
816 | 816 | self.shell.log(line, line_out, line_info.continue_prompt) |
|
817 | 817 | return line_out |
|
818 | 818 | |
|
819 | 819 | |
|
820 | 820 | class MagicHandler(PrefilterHandler): |
|
821 | 821 | |
|
822 | 822 | handler_name = Str('magic') |
|
823 | 823 | esc_strings = List([ESC_MAGIC]) |
|
824 | 824 | |
|
825 | 825 | def handle(self, line_info): |
|
826 | 826 | """Execute magic functions.""" |
|
827 | 827 | ifun = line_info.ifun |
|
828 | 828 | the_rest = line_info.the_rest |
|
829 | 829 | cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace, |
|
830 | 830 | make_quoted_expr(ifun + " " + the_rest)) |
|
831 | 831 | self.shell.log(line_info.line, cmd, line_info.continue_prompt) |
|
832 | 832 | return cmd |
|
833 | 833 | |
|
834 | 834 | |
|
835 | 835 | class AutoHandler(PrefilterHandler): |
|
836 | 836 | |
|
837 | 837 | handler_name = Str('auto') |
|
838 | 838 | esc_strings = List([ESC_PAREN, ESC_QUOTE, ESC_QUOTE2]) |
|
839 | 839 | |
|
840 | 840 | def handle(self, line_info): |
|
841 | 841 | """Hande lines which can be auto-executed, quoting if requested.""" |
|
842 | 842 | line = line_info.line |
|
843 | 843 | ifun = line_info.ifun |
|
844 | 844 | the_rest = line_info.the_rest |
|
845 | 845 | pre = line_info.pre |
|
846 | 846 | continue_prompt = line_info.continue_prompt |
|
847 | 847 | obj = line_info.ofind(self)['obj'] |
|
848 | 848 | |
|
849 | 849 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun,the_rest) # dbg |
|
850 | 850 | |
|
851 | 851 | # This should only be active for single-line input! |
|
852 | 852 | if continue_prompt: |
|
853 | 853 | self.log(line,line,continue_prompt) |
|
854 | 854 | return line |
|
855 | 855 | |
|
856 | 856 | force_auto = isinstance(obj, IPyAutocall) |
|
857 | 857 | auto_rewrite = True |
|
858 | 858 | |
|
859 | 859 | if pre == ESC_QUOTE: |
|
860 | 860 | # Auto-quote splitting on whitespace |
|
861 | 861 | newcmd = '%s("%s")' % (ifun,'", "'.join(the_rest.split()) ) |
|
862 | 862 | elif pre == ESC_QUOTE2: |
|
863 | 863 | # Auto-quote whole string |
|
864 | 864 | newcmd = '%s("%s")' % (ifun,the_rest) |
|
865 | 865 | elif pre == ESC_PAREN: |
|
866 | 866 | newcmd = '%s(%s)' % (ifun,",".join(the_rest.split())) |
|
867 | 867 | else: |
|
868 | 868 | # Auto-paren. |
|
869 | 869 | # We only apply it to argument-less calls if the autocall |
|
870 | 870 | # parameter is set to 2. We only need to check that autocall is < |
|
871 | 871 | # 2, since this function isn't called unless it's at least 1. |
|
872 | 872 | if not the_rest and (self.shell.autocall < 2) and not force_auto: |
|
873 | 873 | newcmd = '%s %s' % (ifun,the_rest) |
|
874 | 874 | auto_rewrite = False |
|
875 | 875 | else: |
|
876 | 876 | if not force_auto and the_rest.startswith('['): |
|
877 | 877 | if hasattr(obj,'__getitem__'): |
|
878 | 878 | # Don't autocall in this case: item access for an object |
|
879 | 879 | # which is BOTH callable and implements __getitem__. |
|
880 | 880 | newcmd = '%s %s' % (ifun,the_rest) |
|
881 | 881 | auto_rewrite = False |
|
882 | 882 | else: |
|
883 | 883 | # if the object doesn't support [] access, go ahead and |
|
884 | 884 | # autocall |
|
885 | 885 | newcmd = '%s(%s)' % (ifun.rstrip(),the_rest) |
|
886 | 886 | elif the_rest.endswith(';'): |
|
887 | 887 | newcmd = '%s(%s);' % (ifun.rstrip(),the_rest[:-1]) |
|
888 | 888 | else: |
|
889 | 889 | newcmd = '%s(%s)' % (ifun.rstrip(), the_rest) |
|
890 | 890 | |
|
891 | 891 | if auto_rewrite: |
|
892 | 892 | rw = self.shell.outputcache.prompt1.auto_rewrite() + newcmd |
|
893 | 893 | |
|
894 | 894 | try: |
|
895 | 895 | # plain ascii works better w/ pyreadline, on some machines, so |
|
896 | 896 | # we use it and only print uncolored rewrite if we have unicode |
|
897 | 897 | rw = str(rw) |
|
898 | 898 | print >>Term.cout, rw |
|
899 | 899 | except UnicodeEncodeError: |
|
900 | 900 | print "-------------->" + newcmd |
|
901 | 901 | |
|
902 | 902 | # log what is now valid Python, not the actual user input (without the |
|
903 | 903 | # final newline) |
|
904 | 904 | self.shell.log(line,newcmd,continue_prompt) |
|
905 | 905 | return newcmd |
|
906 | 906 | |
|
907 | 907 | |
|
908 | 908 | class HelpHandler(PrefilterHandler): |
|
909 | 909 | |
|
910 | 910 | handler_name = Str('help') |
|
911 | 911 | esc_strings = List([ESC_HELP]) |
|
912 | 912 | |
|
913 | 913 | def handle(self, line_info): |
|
914 | 914 | """Try to get some help for the object. |
|
915 | 915 | |
|
916 | 916 | obj? or ?obj -> basic information. |
|
917 | 917 | obj?? or ??obj -> more details. |
|
918 | 918 | """ |
|
919 | 919 | normal_handler = self.prefilter_manager.get_handler_by_name('normal') |
|
920 | 920 | line = line_info.line |
|
921 | 921 | # We need to make sure that we don't process lines which would be |
|
922 | 922 | # otherwise valid python, such as "x=1 # what?" |
|
923 | 923 | try: |
|
924 | 924 | codeop.compile_command(line) |
|
925 | 925 | except SyntaxError: |
|
926 | 926 | # We should only handle as help stuff which is NOT valid syntax |
|
927 | 927 | if line[0]==ESC_HELP: |
|
928 | 928 | line = line[1:] |
|
929 | 929 | elif line[-1]==ESC_HELP: |
|
930 | 930 | line = line[:-1] |
|
931 | 931 | self.shell.log(line, '#?'+line, line_info.continue_prompt) |
|
932 | 932 | if line: |
|
933 | 933 | #print 'line:<%r>' % line # dbg |
|
934 | 934 | self.shell.magic_pinfo(line) |
|
935 | 935 | else: |
|
936 | 936 | page(self.shell.usage, screen_lines=self.shell.usable_screen_length) |
|
937 | 937 | return '' # Empty string is needed here! |
|
938 | 938 | except: |
|
939 | 939 | raise |
|
940 | 940 | # Pass any other exceptions through to the normal handler |
|
941 | 941 | return normal_handler.handle(line_info) |
|
942 | 942 | else: |
|
943 | 943 | raise |
|
944 | 944 | # If the code compiles ok, we should handle it normally |
|
945 | 945 | return normal_handler.handle(line_info) |
|
946 | 946 | |
|
947 | 947 | |
|
948 | 948 | class EmacsHandler(PrefilterHandler): |
|
949 | 949 | |
|
950 | 950 | handler_name = Str('emacs') |
|
951 | 951 | esc_strings = List([]) |
|
952 | 952 | |
|
953 | 953 | def handle(self, line_info): |
|
954 | 954 | """Handle input lines marked by python-mode.""" |
|
955 | 955 | |
|
956 | 956 | # Currently, nothing is done. Later more functionality can be added |
|
957 | 957 | # here if needed. |
|
958 | 958 | |
|
959 | 959 | # The input cache shouldn't be updated |
|
960 | 960 | return line_info.line |
|
961 | 961 | |
|
962 | 962 | |
|
963 | 963 | #----------------------------------------------------------------------------- |
|
964 | 964 | # Defaults |
|
965 | 965 | #----------------------------------------------------------------------------- |
|
966 | 966 | |
|
967 | 967 | |
|
968 | 968 | _default_transformers = [ |
|
969 | 969 | AssignSystemTransformer, |
|
970 | 970 | AssignMagicTransformer |
|
971 | 971 | ] |
|
972 | 972 | |
|
973 | 973 | _default_checkers = [ |
|
974 | 974 | EmacsChecker, |
|
975 | 975 | ShellEscapeChecker, |
|
976 | 976 | IPyAutocallChecker, |
|
977 | 977 | MultiLineMagicChecker, |
|
978 | 978 | EscCharsChecker, |
|
979 | 979 | AssignmentChecker, |
|
980 | 980 | AutoMagicChecker, |
|
981 | 981 | AliasChecker, |
|
982 | 982 | PythonOpsChecker, |
|
983 | 983 | AutocallChecker |
|
984 | 984 | ] |
|
985 | 985 | |
|
986 | 986 | _default_handlers = [ |
|
987 | 987 | PrefilterHandler, |
|
988 | 988 | AliasHandler, |
|
989 | 989 | ShellEscapeHandler, |
|
990 | 990 | MagicHandler, |
|
991 | 991 | AutoHandler, |
|
992 | 992 | HelpHandler, |
|
993 | 993 | EmacsHandler |
|
994 | 994 | ] |
|
995 | 995 |
|
1 | NO CONTENT: modified file |
@@ -1,23 +1,23 b'' | |||
|
1 | 1 | {% extends "!layout.html" %} |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | {% block rootrellink %} |
|
5 | 5 | <li><a href="{{ pathto('index') }}">home</a>| </li> |
|
6 | 6 | <li><a href="{{ pathto('search') }}">search</a>| </li> |
|
7 |
<li><a href="{{ pathto(' |
|
|
7 | <li><a href="{{ pathto('index') }}">documentation </a> »</li> | |
|
8 | 8 | {% endblock %} |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | {% block relbar1 %} |
|
12 | 12 | |
|
13 | 13 | <div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px"> |
|
14 | 14 | <a href="{{ pathto('index') }}"><img src="{{ |
|
15 | 15 | pathto("_static/logo.png", 1) }}" border="0" alt="IPython Documentation"/></a> |
|
16 | 16 | </div> |
|
17 | 17 | {{ super() }} |
|
18 | 18 | {% endblock %} |
|
19 | 19 | |
|
20 | 20 | {# put the sidebar before the body #} |
|
21 | 21 | {% block sidebar1 %}{{ sidebar() }}{% endblock %} |
|
22 | 22 | {% block sidebar2 %}{% endblock %} |
|
23 | 23 |
@@ -1,11 +1,11 b'' | |||
|
1 | 1 | =============================== |
|
2 | 2 | Configuration and customization |
|
3 | 3 | =============================== |
|
4 | 4 | |
|
5 | 5 | .. toctree:: |
|
6 | 6 | :maxdepth: 2 |
|
7 | 7 | |
|
8 | initial_config.txt | |
|
9 | customization.txt | |
|
10 | new_config.txt | |
|
11 | ||
|
8 | overview.txt | |
|
9 | ipython.txt | |
|
10 | editors.txt | |
|
11 | old.txt |
@@ -1,250 +1,230 b'' | |||
|
1 | 1 | .. _initial config: |
|
2 | 2 | |
|
3 | ========================================= | |
|
4 | Initial configuration of your environment | |
|
5 | ========================================= | |
|
3 | ============================================================= | |
|
4 | Outdated configuration information that might still be useful | |
|
5 | ============================================================= | |
|
6 | ||
|
7 | .. warning:: | |
|
8 | ||
|
9 | All of the information in this file is outdated. Until the new | |
|
10 | configuration system is better documented, this material is being kept. | |
|
6 | 11 | |
|
7 | 12 | This section will help you set various things in your environment for |
|
8 | 13 | your IPython sessions to be as efficient as possible. All of IPython's |
|
9 | 14 | configuration information, along with several example files, is stored |
|
10 | 15 | in a directory named by default $HOME/.ipython. You can change this by |
|
11 | 16 | defining the environment variable IPYTHONDIR, or at runtime with the |
|
12 | 17 | command line option -ipythondir. |
|
13 | 18 | |
|
14 | 19 | If all goes well, the first time you run IPython it should automatically create |
|
15 | 20 | a user copy of the config directory for you, based on its builtin defaults. You |
|
16 | 21 | can look at the files it creates to learn more about configuring the |
|
17 | 22 | system. The main file you will modify to configure IPython's behavior is called |
|
18 | 23 | ipythonrc (with a .ini extension under Windows), included for reference |
|
19 | 24 | :ref:`here <ipythonrc>`. This file is very commented and has many variables you |
|
20 | 25 | can change to suit your taste, you can find more details :ref:`here |
|
21 | 26 | <customization>`. Here we discuss the basic things you will want to make sure |
|
22 | 27 | things are working properly from the beginning. |
|
23 | 28 | |
|
24 | ||
|
25 | .. _accessing_help: | |
|
26 | ||
|
27 | Access to the Python help system | |
|
28 | ================================ | |
|
29 | ||
|
30 | This is true for Python in general (not just for IPython): you should have an | |
|
31 | environment variable called PYTHONDOCS pointing to the directory where your | |
|
32 | HTML Python documentation lives. In my system it's | |
|
33 | :file:`/usr/share/doc/python-doc/html`, check your local details or ask your | |
|
34 | systems administrator. | |
|
35 | ||
|
36 | This is the directory which holds the HTML version of the Python | |
|
37 | manuals. Unfortunately it seems that different Linux distributions | |
|
38 | package these files differently, so you may have to look around a bit. | |
|
39 | Below I show the contents of this directory on my system for reference:: | |
|
40 | ||
|
41 | [html]> ls | |
|
42 | about.html dist/ icons/ lib/ python2.5.devhelp.gz whatsnew/ | |
|
43 | acks.html doc/ index.html mac/ ref/ | |
|
44 | api/ ext/ inst/ modindex.html tut/ | |
|
45 | ||
|
46 | You should really make sure this variable is correctly set so that | |
|
47 | Python's pydoc-based help system works. It is a powerful and convenient | |
|
48 | system with full access to the Python manuals and all modules accessible | |
|
49 | to you. | |
|
50 | ||
|
51 | Under Windows it seems that pydoc finds the documentation automatically, | |
|
52 | so no extra setup appears necessary. | |
|
53 | ||
|
54 | ||
|
55 | Editor | |
|
56 | ====== | |
|
57 | ||
|
58 | The %edit command (and its alias %ed) will invoke the editor set in your | |
|
59 | environment as EDITOR. If this variable is not set, it will default to | |
|
60 | vi under Linux/Unix and to notepad under Windows. You may want to set | |
|
61 | this variable properly and to a lightweight editor which doesn't take | |
|
62 | too long to start (that is, something other than a new instance of | |
|
63 | Emacs). This way you can edit multi-line code quickly and with the power | |
|
64 | of a real editor right inside IPython. | |
|
65 | ||
|
66 | If you are a dedicated Emacs user, you should set up the Emacs server so | |
|
67 | that new requests are handled by the original process. This means that | |
|
68 | almost no time is spent in handling the request (assuming an Emacs | |
|
69 | process is already running). For this to work, you need to set your | |
|
70 | EDITOR environment variable to 'emacsclient'. The code below, supplied | |
|
71 | by Francois Pinard, can then be used in your .emacs file to enable the | |
|
72 | server:: | |
|
73 | ||
|
74 | (defvar server-buffer-clients) | |
|
75 | (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) | |
|
76 | (server-start) | |
|
77 | (defun fp-kill-server-with-buffer-routine () | |
|
78 | (and server-buffer-clients (server-done))) | |
|
79 | (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine)) | |
|
80 | ||
|
81 | You can also set the value of this editor via the commmand-line option | |
|
82 | '-editor' or in your ipythonrc file. This is useful if you wish to use | |
|
83 | specifically for IPython an editor different from your typical default | |
|
84 | (and for Windows users who tend to use fewer environment variables). | |
|
85 | ||
|
86 | ||
|
87 | 29 | Color |
|
88 | 30 | ===== |
|
89 | 31 | |
|
90 | 32 | The default IPython configuration has most bells and whistles turned on |
|
91 | 33 | (they're pretty safe). But there's one that may cause problems on some |
|
92 | 34 | systems: the use of color on screen for displaying information. This is |
|
93 | 35 | very useful, since IPython can show prompts and exception tracebacks |
|
94 | 36 | with various colors, display syntax-highlighted source code, and in |
|
95 | 37 | general make it easier to visually parse information. |
|
96 | 38 | |
|
97 | 39 | The following terminals seem to handle the color sequences fine: |
|
98 | 40 | |
|
99 | 41 | * Linux main text console, KDE Konsole, Gnome Terminal, E-term, |
|
100 | 42 | rxvt, xterm. |
|
101 | 43 | * CDE terminal (tested under Solaris). This one boldfaces light colors. |
|
102 | 44 | * (X)Emacs buffers. See the emacs_ section for more details on |
|
103 | 45 | using IPython with (X)Emacs. |
|
104 | 46 | * A Windows (XP/2k) command prompt with pyreadline_. |
|
105 | 47 | * A Windows (XP/2k) CygWin shell. Although some users have reported |
|
106 | 48 | problems; it is not clear whether there is an issue for everyone |
|
107 | 49 | or only under specific configurations. If you have full color |
|
108 | 50 | support under cygwin, please post to the IPython mailing list so |
|
109 | 51 | this issue can be resolved for all users. |
|
110 | 52 | |
|
111 | 53 | .. _pyreadline: https://code.launchpad.net/pyreadline |
|
112 | 54 | |
|
113 | 55 | These have shown problems: |
|
114 | 56 | |
|
115 | 57 | * Windows command prompt in WinXP/2k logged into a Linux machine via |
|
116 | 58 | telnet or ssh. |
|
117 | 59 | * Windows native command prompt in WinXP/2k, without Gary Bishop's |
|
118 | 60 | extensions. Once Gary's readline library is installed, the normal |
|
119 | 61 | WinXP/2k command prompt works perfectly. |
|
120 | 62 | |
|
121 | 63 | Currently the following color schemes are available: |
|
122 | 64 | |
|
123 | 65 | * NoColor: uses no color escapes at all (all escapes are empty '' '' |
|
124 | 66 | strings). This 'scheme' is thus fully safe to use in any terminal. |
|
125 | 67 | * Linux: works well in Linux console type environments: dark |
|
126 | 68 | background with light fonts. It uses bright colors for |
|
127 | 69 | information, so it is difficult to read if you have a light |
|
128 | 70 | colored background. |
|
129 | 71 | * LightBG: the basic colors are similar to those in the Linux scheme |
|
130 | 72 | but darker. It is easy to read in terminals with light backgrounds. |
|
131 | 73 | |
|
132 | 74 | IPython uses colors for two main groups of things: prompts and |
|
133 | 75 | tracebacks which are directly printed to the terminal, and the object |
|
134 | 76 | introspection system which passes large sets of data through a pager. |
|
135 | 77 | |
|
136 | ||
|
137 | 78 | Input/Output prompts and exception tracebacks |
|
138 | 79 | ============================================= |
|
139 | 80 | |
|
140 | 81 | You can test whether the colored prompts and tracebacks work on your |
|
141 | 82 | system interactively by typing '%colors Linux' at the prompt (use |
|
142 | 83 | '%colors LightBG' if your terminal has a light background). If the input |
|
143 | 84 | prompt shows garbage like:: |
|
144 | 85 | |
|
145 | 86 | [0;32mIn [[1;32m1[0;32m]: [0;00m |
|
146 | 87 | |
|
147 | 88 | instead of (in color) something like:: |
|
148 | 89 | |
|
149 | 90 | In [1]: |
|
150 | 91 | |
|
151 | 92 | this means that your terminal doesn't properly handle color escape |
|
152 | 93 | sequences. You can go to a 'no color' mode by typing '%colors NoColor'. |
|
153 | 94 | |
|
154 | 95 | You can try using a different terminal emulator program (Emacs users, |
|
155 | 96 | see below). To permanently set your color preferences, edit the file |
|
156 | 97 | $HOME/.ipython/ipythonrc and set the colors option to the desired value. |
|
157 | 98 | |
|
158 | 99 | |
|
159 | 100 | Object details (types, docstrings, source code, etc.) |
|
160 | 101 | ===================================================== |
|
161 | 102 | |
|
162 | 103 | IPython has a set of special functions for studying the objects you are working |
|
163 | 104 | with, discussed in detail :ref:`here <dynamic_object_info>`. But this system |
|
164 | 105 | relies on passing information which is longer than your screen through a data |
|
165 | 106 | pager, such as the common Unix less and more programs. In order to be able to |
|
166 | 107 | see this information in color, your pager needs to be properly configured. I |
|
167 | 108 | strongly recommend using less instead of more, as it seems that more simply can |
|
168 | 109 | not understand colored text correctly. |
|
169 | 110 | |
|
170 | 111 | In order to configure less as your default pager, do the following: |
|
171 | 112 | |
|
172 | 113 | 1. Set the environment PAGER variable to less. |
|
173 | 114 | 2. Set the environment LESS variable to -r (plus any other options |
|
174 | 115 | you always want to pass to less by default). This tells less to |
|
175 | 116 | properly interpret control sequences, which is how color |
|
176 | 117 | information is given to your terminal. |
|
177 | 118 | |
|
178 | 119 | For the bash shell, add to your ~/.bashrc file the lines:: |
|
179 | 120 | |
|
180 | 121 | export PAGER=less |
|
181 | 122 | export LESS=-r |
|
182 | 123 | |
|
183 | 124 | For the csh or tcsh shells, add to your ~/.cshrc file the lines:: |
|
184 | 125 | |
|
185 | 126 | setenv PAGER less |
|
186 | 127 | setenv LESS -r |
|
187 | 128 | |
|
188 | 129 | There is similar syntax for other Unix shells, look at your system |
|
189 | 130 | documentation for details. |
|
190 | 131 | |
|
191 | 132 | If you are on a system which lacks proper data pagers (such as Windows), |
|
192 | 133 | IPython will use a very limited builtin pager. |
|
193 | 134 | |
|
194 |
.. _ |
|
|
195 | ||
|
196 | (X)Emacs configuration | |
|
197 | ====================== | |
|
198 | ||
|
199 | Thanks to the work of Alexander Schmolck and Prabhu Ramachandran, | |
|
200 | currently (X)Emacs and IPython get along very well. | |
|
201 | ||
|
202 | Important note: You will need to use a recent enough version of | |
|
203 | python-mode.el, along with the file ipython.el. You can check that the | |
|
204 | version you have of python-mode.el is new enough by either looking at | |
|
205 | the revision number in the file itself, or asking for it in (X)Emacs via | |
|
206 | M-x py-version. Versions 4.68 and newer contain the necessary fixes for | |
|
207 | proper IPython support. | |
|
208 | ||
|
209 | The file ipython.el is included with the IPython distribution, in the | |
|
210 | documentation directory (where this manual resides in PDF and HTML | |
|
211 | formats). | |
|
212 | ||
|
213 | Once you put these files in your Emacs path, all you need in your .emacs | |
|
214 | file is:: | |
|
215 | ||
|
216 | (require 'ipython) | |
|
217 | ||
|
218 | This should give you full support for executing code snippets via | |
|
219 | IPython, opening IPython as your Python shell via ``C-c !``, etc. | |
|
220 | ||
|
221 | You can customize the arguments passed to the IPython instance at startup by | |
|
222 | setting the ``py-python-command-args`` variable. For example, to start always | |
|
223 | in ``pylab`` mode with hardcoded light-background colors, you can use:: | |
|
224 | ||
|
225 | (setq py-python-command-args '("-pylab" "-colors" "LightBG")) | |
|
226 | ||
|
227 | If you happen to get garbage instead of colored prompts as described in | |
|
228 | the previous section, you may need to set also in your .emacs file:: | |
|
229 | ||
|
230 | (setq ansi-color-for-comint-mode t) | |
|
231 | ||
|
232 | Notes: | |
|
135 | .. _Prompts: | |
|
136 | ||
|
137 | Fine-tuning your prompt | |
|
138 | ======================= | |
|
139 | ||
|
140 | IPython's prompts can be customized using a syntax similar to that of | |
|
141 | the bash shell. Many of bash's escapes are supported, as well as a few | |
|
142 | additional ones. We list them below:: | |
|
143 | ||
|
144 | \# | |
|
145 | the prompt/history count number. This escape is automatically | |
|
146 | wrapped in the coloring codes for the currently active color scheme. | |
|
147 | \N | |
|
148 | the 'naked' prompt/history count number: this is just the number | |
|
149 | itself, without any coloring applied to it. This lets you produce | |
|
150 | numbered prompts with your own colors. | |
|
151 | \D | |
|
152 | the prompt/history count, with the actual digits replaced by dots. | |
|
153 | Used mainly in continuation prompts (prompt_in2) | |
|
154 | \w | |
|
155 | the current working directory | |
|
156 | \W | |
|
157 | the basename of current working directory | |
|
158 | \Xn | |
|
159 | where $n=0\ldots5.$ The current working directory, with $HOME | |
|
160 | replaced by ~, and filtered out to contain only $n$ path elements | |
|
161 | \Yn | |
|
162 | Similar to \Xn, but with the $n+1$ element included if it is ~ (this | |
|
163 | is similar to the behavior of the %cn escapes in tcsh) | |
|
164 | \u | |
|
165 | the username of the current user | |
|
166 | \$ | |
|
167 | if the effective UID is 0, a #, otherwise a $ | |
|
168 | \h | |
|
169 | the hostname up to the first '.' | |
|
170 | \H | |
|
171 | the hostname | |
|
172 | \n | |
|
173 | a newline | |
|
174 | \r | |
|
175 | a carriage return | |
|
176 | \v | |
|
177 | IPython version string | |
|
178 | ||
|
179 | In addition to these, ANSI color escapes can be insterted into the | |
|
180 | prompts, as \C_ColorName. The list of valid color names is: Black, Blue, | |
|
181 | Brown, Cyan, DarkGray, Green, LightBlue, LightCyan, LightGray, | |
|
182 | LightGreen, LightPurple, LightRed, NoColor, Normal, Purple, Red, White, | |
|
183 | Yellow. | |
|
184 | ||
|
185 | Finally, IPython supports the evaluation of arbitrary expressions in | |
|
186 | your prompt string. The prompt strings are evaluated through the syntax | |
|
187 | of PEP 215, but basically you can use $x.y to expand the value of x.y, | |
|
188 | and for more complicated expressions you can use braces: ${foo()+x} will | |
|
189 | call function foo and add to it the value of x, before putting the | |
|
190 | result into your prompt. For example, using | |
|
191 | prompt_in1 '${commands.getoutput("uptime")}\nIn [\#]: ' | |
|
192 | will print the result of the uptime command on each prompt (assuming the | |
|
193 | commands module has been imported in your ipythonrc file). | |
|
194 | ||
|
195 | ||
|
196 | Prompt examples | |
|
197 | ||
|
198 | The following options in an ipythonrc file will give you IPython's | |
|
199 | default prompts:: | |
|
200 | ||
|
201 | prompt_in1 'In [\#]:' | |
|
202 | prompt_in2 ' .\D.:' | |
|
203 | prompt_out 'Out[\#]:' | |
|
204 | ||
|
205 | which look like this:: | |
|
206 | ||
|
207 | In [1]: 1+2 | |
|
208 | Out[1]: 3 | |
|
209 | ||
|
210 | In [2]: for i in (1,2,3): | |
|
211 | ...: print i, | |
|
212 | ...: | |
|
213 | 1 2 3 | |
|
214 | ||
|
215 | These will give you a very colorful prompt with path information:: | |
|
216 | ||
|
217 | #prompt_in1 '\C_Red\u\C_Blue[\C_Cyan\Y1\C_Blue]\C_LightGreen\#>' | |
|
218 | prompt_in2 ' ..\D>' | |
|
219 | prompt_out '<\#>' | |
|
220 | ||
|
221 | which look like this:: | |
|
222 | ||
|
223 | fperez[~/ipython]1> 1+2 | |
|
224 | <1> 3 | |
|
225 | fperez[~/ipython]2> for i in (1,2,3): | |
|
226 | ...> print i, | |
|
227 | ...> | |
|
228 | 1 2 3 | |
|
233 | 229 | |
|
234 | * There is one caveat you should be aware of: you must start the | |
|
235 | IPython shell before attempting to execute any code regions via | |
|
236 | ``C-c |``. Simply type C-c ! to start IPython before passing any code | |
|
237 | regions to the interpreter, and you shouldn't experience any | |
|
238 | problems. | |
|
239 | This is due to a bug in Python itself, which has been fixed for | |
|
240 | Python 2.3, but exists as of Python 2.2.2 (reported as SF bug [ | |
|
241 | 737947 ]). | |
|
242 | * The (X)Emacs support is maintained by Alexander Schmolck, so all | |
|
243 | comments/requests should be directed to him through the IPython | |
|
244 | mailing lists. | |
|
245 | * This code is still somewhat experimental so it's a bit rough | |
|
246 | around the edges (although in practice, it works quite well). | |
|
247 | * Be aware that if you customize py-python-command previously, this | |
|
248 | value will override what ipython.el does (because loading the | |
|
249 | customization variables comes later). | |
|
250 | 230 |
@@ -1,156 +1,78 b'' | |||
|
1 |
============ |
|
|
1 | ============ | |
|
2 | 2 |
|
|
3 |
============ |
|
|
3 | ============ | |
|
4 | 4 | |
|
5 | ||
|
6 | Coding conventions | |
|
7 | ================== | |
|
5 | General coding conventions | |
|
6 | ========================== | |
|
8 | 7 | |
|
9 | 8 | In general, we'll try to follow the standard Python style conventions as |
|
10 |
described in Python's |
|
|
9 | described in Python's PEP 8 [PEP8]_, the official Python Style Guide. | |
|
11 | 10 | |
|
12 | .. _PEP 8: http://www.python.org/peps/pep-0008.html | |
|
11 | Other general comments: | |
|
13 | 12 | |
|
14 | Other comments: | |
|
15 | ||
|
16 | - In a large file, top level classes and functions should be separated by 2-3 | |
|
13 | * In a large file, top level classes and functions should be separated by 2 | |
|
17 | 14 | lines to make it easier to separate them visually. |
|
18 | 15 | |
|
19 |
|
|
|
16 | * Use 4 spaces for indentation, **never** use hard tabs. | |
|
20 | 17 | |
|
21 |
|
|
|
18 | * Keep the ordering of methods the same in classes that have the same methods. | |
|
22 | 19 | This is particularly true for classes that implement similar interfaces and |
|
23 | 20 | for interfaces that are similar. |
|
24 | 21 | |
|
25 | 22 | Naming conventions |
|
26 | ------------------ | |
|
23 | ================== | |
|
27 | 24 | |
|
28 |
In terms of naming conventions, we'll follow the guidelines of PEP 8. |
|
|
29 |
the existing code doesn't honor this perfectly, but for all new |
|
|
30 | (and much existing code is being refactored), we'll use: | |
|
25 | In terms of naming conventions, we'll follow the guidelines of PEP 8 [PEP8]_. | |
|
26 | Some of the existing code doesn't honor this perfectly, but for all new | |
|
27 | IPython code (and much existing code is being refactored), we'll use: | |
|
31 | 28 | |
|
32 |
|
|
|
29 | * All ``lowercase`` module names. | |
|
33 | 30 | |
|
34 |
|
|
|
31 | * ``CamelCase`` for class names. | |
|
35 | 32 | |
|
36 |
|
|
|
33 | * ``lowercase_with_underscores`` for methods, functions, variables and | |
|
37 | 34 | attributes. |
|
38 | 35 | |
|
39 | 36 | This may be confusing as some of the existing codebase uses a different |
|
40 | 37 | convention (``lowerCamelCase`` for methods and attributes). Slowly, we will |
|
41 | 38 | move IPython over to the new convention, providing shadow names for backward |
|
42 | 39 | compatibility in public interfaces. |
|
43 | 40 | |
|
44 | 41 | There are, however, some important exceptions to these rules. In some cases, |
|
45 | 42 | IPython code will interface with packages (Twisted, Wx, Qt) that use other |
|
46 | 43 | conventions. At some level this makes it impossible to adhere to our own |
|
47 | 44 | standards at all times. In particular, when subclassing classes that use other |
|
48 | 45 | naming conventions, you must follow their naming conventions. To deal with |
|
49 | 46 | cases like this, we propose the following policy: |
|
50 | 47 | |
|
51 | - If you are subclassing a class that uses different conventions, use its | |
|
52 | naming conventions throughout your subclass. Thus, if you are creating a | |
|
53 | Twisted Protocol class, used Twisted's | |
|
54 | ``namingSchemeForMethodsAndAttributes.`` | |
|
55 | ||
|
56 | - All IPython's official interfaces should use our conventions. In some cases | |
|
57 | this will mean that you need to provide shadow names (first implement | |
|
58 | ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all | |
|
59 | costs, but it will probably be necessary at times. But, please use this | |
|
60 | sparingly! | |
|
61 | ||
|
62 | Implementation-specific *private* methods will use | |
|
63 | ``_single_underscore_prefix``. Names with a leading double underscore will | |
|
64 | *only* be used in special cases, as they makes subclassing difficult (such | |
|
65 | names are not easily seen by child classes). | |
|
66 | ||
|
67 | Occasionally some run-in lowercase names are used, but mostly for very short | |
|
68 | names or where we are implementing methods very similar to existing ones in a | |
|
69 | base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had | |
|
70 | established precedent). | |
|
71 | ||
|
72 | The old IPython codebase has a big mix of classes and modules prefixed with an | |
|
73 | explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned | |
|
74 | upon, as namespaces offer cleaner prefixing. The only case where this approach | |
|
75 | is justified is for classes which are expected to be imported into external | |
|
76 | namespaces and a very generic name (like Shell) is too likely to clash with | |
|
77 | something else. We'll need to revisit this issue as we clean up and refactor | |
|
78 | the code, but in general we should remove as many unnecessary ``IP``/``ip`` | |
|
79 | prefixes as possible. However, if a prefix seems absolutely necessary the more | |
|
80 | specific ``IPY`` or ``ipy`` are preferred. | |
|
81 | ||
|
82 | Older material | |
|
83 | ============== | |
|
84 | ||
|
85 | General | |
|
86 | ------- | |
|
87 | ||
|
88 | In general, we'll try to follow the standard Python style conventions as | |
|
89 | described here: | |
|
90 | ||
|
91 | * `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_ | |
|
92 | ||
|
93 | ||
|
94 | Other comments: | |
|
95 | ||
|
96 | * In a large file, top level classes and functions should be | |
|
97 | separated by 2-3 lines to make it easier to separate them visually. | |
|
98 | * Use 4 spaces for indentation. | |
|
99 | * Keep the ordering of methods the same in classes that have the same | |
|
100 | methods. This is particularly true for classes that implement an interface. | |
|
101 | ||
|
102 | Naming conventions | |
|
103 | ------------------ | |
|
104 | ||
|
105 | In terms of naming conventions, we'll follow the guidelines from the `Style | |
|
106 | Guide for Python Code`_. | |
|
107 | ||
|
108 | For all new IPython code (and much existing code is being refactored), we'll | |
|
109 | use: | |
|
110 | ||
|
111 | * All ``lowercase`` module names. | |
|
112 | ||
|
113 | * ``CamelCase`` for class names. | |
|
114 | ||
|
115 | * ``lowercase_with_underscores`` for methods, functions, variables and | |
|
116 | attributes. | |
|
117 | ||
|
118 | There are, however, some important exceptions to these rules. In some cases, | |
|
119 | IPython code will interface with packages (Twisted, Wx, Qt) that use other | |
|
120 | conventions. At some level this makes it impossible to adhere to our own | |
|
121 | standards at all times. In particular, when subclassing classes that use other | |
|
122 | naming conventions, you must follow their naming conventions. To deal with | |
|
123 | cases like this, we propose the following policy: | |
|
124 | ||
|
125 | 48 | * If you are subclassing a class that uses different conventions, use its |
|
126 | 49 | naming conventions throughout your subclass. Thus, if you are creating a |
|
127 | 50 | Twisted Protocol class, used Twisted's |
|
128 | 51 | ``namingSchemeForMethodsAndAttributes.`` |
|
129 | 52 | |
|
130 | 53 | * All IPython's official interfaces should use our conventions. In some cases |
|
131 | 54 | this will mean that you need to provide shadow names (first implement |
|
132 | 55 | ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all |
|
133 | 56 | costs, but it will probably be necessary at times. But, please use this |
|
134 | 57 | sparingly! |
|
135 | 58 | |
|
136 | 59 | Implementation-specific *private* methods will use |
|
137 | 60 | ``_single_underscore_prefix``. Names with a leading double underscore will |
|
138 | 61 | *only* be used in special cases, as they makes subclassing difficult (such |
|
139 | 62 | names are not easily seen by child classes). |
|
140 | 63 | |
|
141 | 64 | Occasionally some run-in lowercase names are used, but mostly for very short |
|
142 | 65 | names or where we are implementing methods very similar to existing ones in a |
|
143 | 66 | base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had |
|
144 | 67 | established precedent). |
|
145 | 68 | |
|
146 | 69 | The old IPython codebase has a big mix of classes and modules prefixed with an |
|
147 | 70 | explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned |
|
148 | 71 | upon, as namespaces offer cleaner prefixing. The only case where this approach |
|
149 | 72 | is justified is for classes which are expected to be imported into external |
|
150 | 73 | namespaces and a very generic name (like Shell) is too likely to clash with |
|
151 | something else. We'll need to revisit this issue as we clean up and refactor | |
|
152 | the code, but in general we should remove as many unnecessary ``IP``/``ip`` | |
|
153 | prefixes as possible. However, if a prefix seems absolutely necessary the more | |
|
74 | something else. However, if a prefix seems absolutely necessary the more | |
|
154 | 75 | specific ``IPY`` or ``ipy`` are preferred. |
|
155 | 76 | |
|
77 | .. [PEP8] Python Enhancement Proposal 8. http://www.python.org/peps/pep-0008.html | |
|
156 | 78 |
@@ -1,191 +1,209 b'' | |||
|
1 | .. _contributing: | |
|
2 | ||
|
3 | ============================ | |
|
1 | 4 | How to contribute to IPython |
|
2 | 5 | ============================ |
|
3 | 6 | |
|
7 | Overview | |
|
8 | ======== | |
|
9 | ||
|
4 | 10 | IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_. |
|
5 | 11 | This makes it easy for people to contribute to the development of IPython. |
|
6 | 12 | There are several ways in which you can join in. |
|
7 | 13 | |
|
8 |
If you have a small change that you want to |
|
|
9 |
|
|
|
10 |
differences: |
|
|
14 | If you have a small change that you want to contribute, you can edit your | |
|
15 | Bazaar checkout of IPython (see below) in-place, and ask Bazaar for the | |
|
16 | differences: | |
|
17 | ||
|
18 | .. code-block:: bash | |
|
11 | 19 | |
|
12 | 20 | $ cd /path/to/your/copy/of/ipython |
|
13 | 21 | $ bzr diff > my_fixes.diff |
|
14 | 22 | |
|
15 | 23 | This produces a patch file with your fixes, which we can apply to the source |
|
16 | 24 |
tree. |
|
17 | 25 | <https://bugs.launchpad.net/ipython>`_, indicating what it does. |
|
18 | 26 | |
|
19 | 27 | This model of creating small, self-contained patches works very well and there |
|
20 | 28 |
are open source projects that do their entire development this way. |
|
21 | 29 | in IPython we have found that for tracking larger changes, making use of |
|
22 |
|
|
|
30 | Bazaar's full capabilities in conjunction with Launchpad's code hosting | |
|
23 | 31 | services makes for a much better experience. |
|
24 | 32 | |
|
25 | 33 | Making your own branch of IPython allows you to refine your changes over time, |
|
26 | 34 | track the development of the main team, and propose your own full version of |
|
27 | 35 |
the code for others to use and review, with a minimum amount of fuss. |
|
28 | 36 | parts of this document will explain how to do this. |
|
29 | 37 | |
|
30 | 38 | Install Bazaar and create a Launchpad account |
|
31 | 39 | --------------------------------------------- |
|
32 | 40 | |
|
33 | 41 | First make sure you have installed Bazaar (see their `website |
|
34 | 42 | <http://bazaar-vcs.org/>`_). To see that Bazaar is installed and knows about |
|
35 |
you, try the following: |
|
|
43 | you, try the following: | |
|
44 | ||
|
45 | .. code-block:: bash | |
|
36 | 46 | |
|
37 | 47 | $ bzr whoami |
|
38 | 48 | Joe Coder <jcoder@gmail.com> |
|
39 | 49 | |
|
40 | 50 | This should display your name and email. Next, you will want to create an |
|
41 | 51 | account on the `Launchpad website <http://www.launchpad.net>`_ and setup your |
|
42 | 52 | ssh keys. For more information of setting up your ssh keys, see `this link |
|
43 | 53 | <https://help.launchpad.net/YourAccount/CreatingAnSSHKeyPair>`_. |
|
44 | 54 | |
|
45 | 55 | Get the main IPython branch from Launchpad |
|
46 | 56 | ------------------------------------------ |
|
47 | 57 | |
|
48 | 58 | Now, you can get a copy of the main IPython development branch (we call this |
|
49 |
the "trunk"): |
|
|
59 | the "trunk"): | |
|
60 | ||
|
61 | .. code-block:: bash | |
|
50 | 62 | |
|
51 | 63 | $ bzr branch lp:ipython |
|
52 | 64 | |
|
53 | 65 | Create a working branch |
|
54 | 66 | ----------------------- |
|
55 | 67 | |
|
56 | 68 | When working on IPython, you won't actually make edits directly to the |
|
57 | 69 | :file:`lp:ipython` branch. Instead, you will create a separate branch for your |
|
58 | 70 | changes. For now, let's assume you want to do your work in a branch named |
|
59 |
"ipython-mybranch". Create this branch by doing: |
|
|
71 | "ipython-mybranch". Create this branch by doing: | |
|
72 | ||
|
73 | .. code-block:: bash | |
|
60 | 74 | |
|
61 | 75 | $ bzr branch ipython ipython-mybranch |
|
62 | 76 | |
|
63 | 77 | When you actually create a branch, you will want to give it a name that |
|
64 | 78 | reflects the nature of the work that you will be doing in it, like |
|
65 | 79 | "install-docs-update". |
|
66 | 80 | |
|
67 | 81 | Make edits in your working branch |
|
68 | 82 | --------------------------------- |
|
69 | 83 | |
|
70 | 84 | Now you are ready to actually make edits in your :file:`ipython-mybranch` |
|
71 | 85 | branch. Before doing this, it is helpful to install this branch so you can |
|
72 | 86 | test your changes as you work. This is easiest if you have setuptools |
|
73 |
installed. Then, just do: |
|
|
87 | installed. Then, just do: | |
|
88 | ||
|
89 | .. code-block:: bash | |
|
74 | 90 | |
|
75 | 91 | $ cd ipython-mybranch |
|
76 | 92 | $ python setupegg.py develop |
|
77 | 93 | |
|
78 | 94 | Now, make some changes. After a while, you will want to commit your changes. |
|
79 | 95 | This let's Bazaar know that you like the changes you have made and gives you |
|
80 | 96 | an opportunity to keep a nice record of what you have done. This looks like |
|
81 |
this: |
|
|
97 | this: | |
|
98 | ||
|
99 | .. code-block:: bash | |
|
82 | 100 | |
|
83 | 101 | $ ...do work in ipython-mybranch... |
|
84 | 102 | $ bzr commit -m "the commit message goes here" |
|
85 | 103 | |
|
86 | 104 | Please note that since we now don't use an old-style linear ChangeLog (that |
|
87 | 105 | tends to cause problems with distributed version control systems), you should |
|
88 | 106 | ensure that your log messages are reasonably detailed. Use a docstring-like |
|
89 | 107 | approach in the commit messages (including the second line being left |
|
90 | 108 | *blank*):: |
|
91 | 109 | |
|
92 | 110 | Single line summary of changes being committed. |
|
93 | 111 | |
|
94 | 112 | * more details when warranted ... |
|
95 | 113 | * including crediting outside contributors if they sent the |
|
96 | 114 | code/bug/idea! |
|
97 | 115 | |
|
98 | 116 | As you work, you will repeat this edit/commit cycle many times. If you work on |
|
99 | 117 | your branch for a long time, you will also want to get the latest changes from |
|
100 | 118 | the :file:`lp:ipython` branch. This can be done with the following sequence of |
|
101 |
commands: |
|
|
119 | commands: | |
|
120 | ||
|
121 | .. code-block:: bash | |
|
102 | 122 | |
|
103 | 123 | $ ls |
|
104 | 124 | ipython |
|
105 | 125 | ipython-mybranch |
|
106 | 126 | |
|
107 | 127 | $ cd ipython |
|
108 | 128 | $ bzr pull |
|
109 | 129 | $ cd ../ipython-mybranch |
|
110 | 130 | $ bzr merge ../ipython |
|
111 | 131 | $ bzr commit -m "Merging changes from trunk" |
|
112 | 132 | |
|
113 | Along the way, you should also run the IPython test suite. You can do this | |
|
114 | using the :command:`iptest` command (which is basically a customized version of | |
|
115 | :command:`nosetests`):: | |
|
116 | ||
|
117 | $ cd | |
|
118 | $ iptest | |
|
119 | ||
|
120 | The :command:`iptest` command will also pick up and run any tests you have | |
|
121 | written. See :ref:`testing documentation <devel_testing>` for further details | |
|
122 | on the testing system. | |
|
123 | ||
|
124 | ||
|
125 | 133 | Post your branch and request a code review |
|
126 | 134 | ------------------------------------------ |
|
127 | 135 | |
|
128 | 136 | Once you are done with your edits, you should post your branch on Launchpad so |
|
129 | 137 | that other IPython developers can review the changes and help you merge your |
|
130 | 138 | changes into the main development branch. To post your branch on Launchpad, |
|
131 |
do: |
|
|
139 | do: | |
|
140 | ||
|
141 | .. code-block:: bash | |
|
132 | 142 | |
|
133 | 143 | $ cd ipython-mybranch |
|
134 | 144 | $ bzr push lp:~yourusername/ipython/ipython-mybranch |
|
135 | 145 | |
|
136 |
Then, go to the `IPython Launchpad site <www.launchpad.net/ipython>`_, |
|
|
137 |
should see your branch under the "Code" tab. If you click on your |
|
|
138 |
can provide a short description of the branch as well as mark its |
|
|
139 |
importantly, you should click the link that reads "Propose for |
|
|
140 | another branch". What does this do? | |
|
146 | Then, go to the `IPython Launchpad site <http://www.launchpad.net/ipython>`_, | |
|
147 | and you should see your branch under the "Code" tab. If you click on your | |
|
148 | branch, you can provide a short description of the branch as well as mark its | |
|
149 | status. Most importantly, you should click the link that reads "Propose for | |
|
150 | merging into another branch". What does this do? | |
|
141 | 151 | |
|
142 | 152 | This let's the other IPython developers know that your branch is ready to be |
|
143 | 153 | reviewed and merged into the main development branch. During this review |
|
144 | 154 | process, other developers will give you feedback and help you get your code |
|
145 | 155 | ready to be merged. What types of things will we be looking for: |
|
146 | 156 | |
|
147 | * All code is documented. | |
|
148 | * All code has tests. | |
|
157 | * All code is documented. How to document your code is described in | |
|
158 | :ref:`this section <documenting-ipython>`. | |
|
159 | * All code has tests. How to write and run tests is described in | |
|
160 | :ref:`this section <testing>`. | |
|
149 | 161 | * The entire IPython test suite passes. |
|
150 | 162 | |
|
163 | You should also provide us with a list of changes that your branch contains. | |
|
164 | See the :ref:`What's new <whatsnew_index>` section of our documentation | |
|
165 | (:file:`docs/source/whatsnew`) for details on the format and content of this. | |
|
166 | ||
|
151 | 167 | Once your changes have been reviewed and approved, someone will merge them |
|
152 | 168 | into the main development branch. |
|
153 | 169 | |
|
154 | 170 | |
|
155 | Some notes for core developers when merging third-party contributions | |
|
156 | ===================================================================== | |
|
171 | Merging a branch into trunk | |
|
172 | =========================== | |
|
157 | 173 | |
|
158 | 174 | Core developers, who ultimately merge any approved branch (from themselves, |
|
159 | 175 | another developer, or any third-party contribution) will typically use |
|
160 | 176 | :command:`bzr merge` to merge the branch into the trunk and push it to the |
|
161 |
main Launc |
|
|
162 |
this |
|
|
177 | main Launchpad site. There are a number of things to keep in mind when doing | |
|
178 | this, so that the project history is easy to understand in the long | |
|
163 | 179 | run, and that generating release notes is as painless and accurate as |
|
164 | 180 | possible. |
|
165 | 181 | |
|
166 |
|
|
|
167 |
big feature branch), please remember to always edit the |
|
|
168 | file accordingly. This file has one main section for each release, and if | |
|
169 | you edit it as you go, noting what new features, bug fixes or API changes | |
|
170 | you have made, the release notes will be almost finished when they are | |
|
171 | needed later. This is much easier if done when you merge the work, rather | |
|
172 | than weeks or months later by re-reading a massive Bazaar log. | |
|
173 | ||
|
174 | - When big merges are done, the practice of putting a summary commit message | |
|
175 | in the merge is *extremely* useful. It makes this kind of job much nicer, | |
|
176 | because that summary log message can be almost copy/pasted without changes, | |
|
177 | if it was well written, rather than dissecting the next-level messages from | |
|
178 | the individual commits. | |
|
179 | ||
|
180 | - It's important that we remember to always credit who gave us something if | |
|
182 | * When you merge any non-trivial functionality (from one small bug fix to a | |
|
183 | big feature branch), please remember to always edit the appropriate file in | |
|
184 | the :ref:`What's new <whatsnew_index>` section of our documentation. | |
|
185 | Ideally, the author of the branch should provide this content when they | |
|
186 | submit the branch for review. But if they don't it is the responsibility of | |
|
187 | the developer doing the merge to add this information. | |
|
188 | ||
|
189 | * When merges are done, the practice of putting a summary commit message in | |
|
190 | the merge is *extremely* useful. It is probably easiest if you simply use | |
|
191 | the same list of changes that were added to the :ref:`What's new | |
|
192 | <whatsnew_index>` section of the documentation. | |
|
193 | ||
|
194 | * It's important that we remember to always credit who gave us something if | |
|
181 | 195 | it's not the committer. In general, we have been fairly good on this front, |
|
182 | 196 | this is just a reminder to keep things up. As a note, if you are ever |
|
183 | 197 | committing something that is completely (or almost so) a third-party |
|
184 | 198 | contribution, do the commit as:: |
|
185 | 199 | |
|
186 | 200 | $ bzr commit --author="Someone Else" |
|
187 | 201 | |
|
188 | 202 | This way it will show that name separately in the log, which makes it even |
|
189 | 203 | easier to spot. Obviously we often rework third party contributions |
|
190 | 204 | extensively, but this is still good to keep in mind for cases when we don't |
|
191 | 205 | touch the code too much. |
|
206 | ||
|
207 | ||
|
208 | .. [Bazaar] Bazaar. http://bazaar-vcs.org/ | |
|
209 | .. [Launchpad] Launchpad. http://www.launchpad.net/ipython |
@@ -1,141 +1,104 b'' | |||
|
1 | 1 | .. _documenting-ipython: |
|
2 | 2 | |
|
3 | 3 | ===================== |
|
4 | 4 | Documenting IPython |
|
5 | 5 | ===================== |
|
6 | 6 | |
|
7 | 7 | Standalone documentation |
|
8 | 8 | ======================== |
|
9 | 9 | |
|
10 | 10 | All standalone documentation should be written in plain text (``.txt``) files |
|
11 |
using |
|
|
12 |
should be placed in the |
|
|
13 |
tree. Or, when appropriate, a suitably named subdirectory |
|
|
14 |
documentation in this location will serve as the main |
|
|
15 | documentation and all existing documentation should be converted to this | |
|
16 | format. | |
|
17 | ||
|
18 | The actual HTML and PDF docs are built using the Sphinx_ documentation | |
|
19 | generation tool. Sphinx has been adopted as the default documentation tool for | |
|
20 | Python itself as of version 2.6, as well as by a number of projects that | |
|
21 | IPython is related with, such as numpy, scipy, matplotlib, sage and nipy. | |
|
11 | using reStructuredText [reStructuredText]_ for markup and formatting. All such | |
|
12 | documentation should be placed in the directory :file:`docs/source` of the | |
|
13 | IPython source tree. Or, when appropriate, a suitably named subdirectory | |
|
14 | should be used. The documentation in this location will serve as the main | |
|
15 | source for IPython documentation. | |
|
22 | 16 | |
|
23 | .. _reStructuredText: http://docutils.sourceforge.net/rst.html | |
|
24 | .. _Sphinx: http://sphinx.pocoo.org/ | |
|
17 | The actual HTML and PDF docs are built using the Sphinx [Sphinx]_ | |
|
18 | documentation generation tool. Once you have Sphinx installed, you can build | |
|
19 | the html docs yourself by doing: | |
|
25 | 20 | |
|
21 | .. code-block:: bash | |
|
26 | 22 | |
|
27 | The rest of this document is mostly taken from the `matploblib | |
|
28 | documentation`__; we are using a number of Sphinx tools and extensions written | |
|
29 | by the matplotlib team and will mostly follow their conventions, which are | |
|
30 | nicely spelled out in their guide. What follows is thus a lightly adapted | |
|
31 | version of the matplotlib documentation guide, taken with permission from the | |
|
32 | MPL team. | |
|
23 | $ cd ipython-mybranch/docs | |
|
24 | $ make html | |
|
33 | 25 | |
|
34 | .. __: http://matplotlib.sourceforge.net/devel/documenting_mpl.html | |
|
26 | Our usage of Sphinx follows that of matplotlib [Matplotlib]_ closely. We are | |
|
27 | using a number of Sphinx tools and extensions written by the matplotlib team | |
|
28 | and will mostly follow their conventions, which are nicely spelled out in | |
|
29 | their documentation guide [MatplotlibDocGuide]_. What follows is thus a | |
|
30 | abridged version of the matplotlib documentation guide, taken with permission | |
|
31 | from the matplotlib team. | |
|
35 | 32 | |
|
33 | If you are reading this in a web browser, you can click on the "Show Source" | |
|
34 | link to see the original reStricturedText for the following examples. | |
|
36 | 35 | |
|
37 | 36 | A bit of Python code:: |
|
38 | 37 | |
|
39 | 38 | for i in range(10): |
|
40 | 39 | print i, |
|
41 | 40 | print "A big number:",2**34 |
|
42 | 41 | |
|
43 | 42 | An interactive Python session:: |
|
44 | 43 | |
|
45 | 44 | >>> from IPython import genutils |
|
46 | 45 | >>> genutils.get_ipython_dir() |
|
47 | 46 | '/home/fperez/.ipython' |
|
48 | 47 | |
|
49 | ||
|
50 | 48 | An IPython session: |
|
51 | 49 | |
|
52 | 50 | .. code-block:: ipython |
|
53 | 51 | |
|
54 | 52 | In [7]: import IPython |
|
55 | 53 | |
|
56 | 54 | In [8]: print "This IPython is version:",IPython.__version__ |
|
57 | 55 | This IPython is version: 0.9.1 |
|
58 | 56 | |
|
59 | 57 | In [9]: 2+4 |
|
60 | 58 | Out[9]: 6 |
|
61 | 59 | |
|
62 | 60 | |
|
63 | 61 | A bit of shell code: |
|
64 | 62 | |
|
65 | 63 | .. code-block:: bash |
|
66 | 64 | |
|
67 | 65 | cd /tmp |
|
68 | 66 | echo "My home directory is: $HOME" |
|
69 | 67 | ls |
|
70 | 68 | |
|
71 | ||
|
72 | 69 | Docstring format |
|
73 | 70 | ================ |
|
74 | 71 | |
|
75 | 72 | Good docstrings are very important. Unfortunately, Python itself only provides |
|
76 |
a rather loose standard for docstrings |
|
|
73 | a rather loose standard for docstrings [PEP257]_, and there is no universally | |
|
77 | 74 | accepted convention for all the different parts of a complete docstring. |
|
78 | 75 | However, the NumPy project has established a very reasonable standard, and has |
|
79 | 76 | developed some tools to support the smooth inclusion of such docstrings in |
|
80 | 77 | Sphinx-generated manuals. Rather than inventing yet another pseudo-standard, |
|
81 | 78 | IPython will be henceforth documented using the NumPy conventions; we carry |
|
82 | 79 | copies of some of the NumPy support tools to remain self-contained, but share |
|
83 | 80 | back upstream with NumPy any improvements or fixes we may make to the tools. |
|
84 | 81 | |
|
85 |
The |
|
|
86 |
standard, and for a quick overview, the NumPy |
|
|
87 | read. | |
|
82 | The NumPy documentation guidelines [NumPyDocGuide]_ contain detailed | |
|
83 | information on this standard, and for a quick overview, the NumPy example | |
|
84 | docstring [NumPyExampleDocstring]_ is a useful read. | |
|
88 | 85 | |
|
89 |
|
|
|
90 |
conventions. We will update them as we go, but all new code should be |
|
|
86 | In the past IPython used epydoc so currently many docstrings still use epydoc | |
|
87 | conventions. We will update them as we go, but all new code should be | |
|
91 | 88 | documented using the NumPy standard. |
|
92 | 89 | |
|
93 | .. _PEP 257: http://www.python.org/peps/pep-0257.html | |
|
94 | .. _NumPy documentation guidelines: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines | |
|
95 | ||
|
96 | .. _example docstring: http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt | |
|
97 | ||
|
98 | Additional PEPs of interest regarding documentation of code. While both of | |
|
99 | these were rejected, the ideas therein form much of the basis of docutils (the | |
|
100 | machinery to process reStructuredText): | |
|
101 | ||
|
102 | - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_ | |
|
103 | - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_ | |
|
104 | ||
|
105 | Older material | |
|
106 | ============== | |
|
107 | ||
|
108 | Documentation | |
|
109 | ============= | |
|
110 | ||
|
111 | Standalone documentation | |
|
112 | ------------------------ | |
|
90 | Here are two additional PEPs of interest regarding documentation of code. | |
|
91 | While both of these were rejected, the ideas therein form much of the basis of | |
|
92 | docutils (the machinery to process reStructuredText): | |
|
113 | 93 | |
|
114 | All standalone documentation should be written in plain text (``.txt``) files | |
|
115 | using reStructuredText [reStructuredText]_ for markup and formatting. All such | |
|
116 | documentation should be placed in directory :file:`docs/source` of the IPython | |
|
117 | source tree. The documentation in this location will serve as the main source | |
|
118 | for IPython documentation and all existing documentation should be converted | |
|
119 | to this format. | |
|
120 | ||
|
121 | To build the final documentation, we use Sphinx [Sphinx]_. Once you have | |
|
122 | Sphinx installed, you can build the html docs yourself by doing:: | |
|
123 | ||
|
124 | $ cd ipython-mybranch/docs | |
|
125 | $ make html | |
|
126 | ||
|
127 | Docstring format | |
|
128 | ---------------- | |
|
129 | ||
|
130 | Good docstrings are very important. All new code should have docstrings that | |
|
131 | are formatted using reStructuredText for markup and formatting, since it is | |
|
132 | understood by a wide variety of tools. Details about using reStructuredText | |
|
133 | for docstrings can be found `here | |
|
134 | <http://epydoc.sourceforge.net/manual-othermarkup.html>`_. | |
|
135 | ||
|
136 | Additional PEPs of interest regarding documentation of code: | |
|
137 | ||
|
138 | * `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_ | |
|
139 | 94 | * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_ |
|
140 | 95 | * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_ |
|
141 | 96 | |
|
97 | ||
|
98 | .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html | |
|
99 | .. [Sphinx] Sphinx. http://sphinx.pocoo.org/ | |
|
100 | .. [MatplotlibDocGuide] http://matplotlib.sourceforge.net/devel/documenting_mpl.html | |
|
101 | .. [PEP257] PEP 257. http://www.python.org/peps/pep-0257.html | |
|
102 | .. [NumPyDocGuide] NumPy documentation guide. http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines | |
|
103 | .. [NumPyExampleDocstring] NumPy example docstring. http://projects.scipy.org/numpy/browser/trunk/doc/EXAMPLE_DOCSTRING.txt | |
|
104 |
@@ -1,25 +1,18 b'' | |||
|
1 | 1 | .. _developer_guide: |
|
2 | 2 | |
|
3 | 3 | ========================= |
|
4 | 4 | IPython developer's guide |
|
5 | 5 | ========================= |
|
6 | 6 | |
|
7 | 7 | .. toctree:: |
|
8 |
:maxdepth: |
|
|
8 | :maxdepth: 1 | |
|
9 | 9 | |
|
10 | 10 | contributing.txt |
|
11 | 11 | coding_guide.txt |
|
12 | 12 | doc_guide.txt |
|
13 | 13 | testing.txt |
|
14 | 14 | release.txt |
|
15 | 15 | roadmap.txt |
|
16 | ||
|
17 | notification_blueprint.txt | |
|
18 | 16 | reorg.txt |
|
17 | notification_blueprint.txt | |
|
19 | 18 | |
|
20 | ||
|
21 | .. [Bazaar] Bazaar. http://bazaar-vcs.org/ | |
|
22 | .. [Launchpad] Launchpad. http://www.launchpad.net/ipython | |
|
23 | .. [reStructuredText] reStructuredText. http://docutils.sourceforge.net/rst.html | |
|
24 | .. [Sphinx] Sphinx. http://sphinx.pocoo.org/ | |
|
25 | .. [Nose] Nose: a discovery based unittest extension. http://code.google.com/p/python-nose/ No newline at end of file |
@@ -1,25 +1,32 b'' | |||
|
1 | Release checklist | |
|
1 | .. _releasing_ipython: | |
|
2 | ||
|
3 | ================= | |
|
4 | Releasing IPython | |
|
2 | 5 | ================= |
|
3 | 6 | |
|
7 | This section contains notes about the process that is used to release IPython. | |
|
8 | Our release process is currently not very formal and could be improved. | |
|
9 | ||
|
4 | 10 | Most of the release process is automated by the :file:`release` script in the |
|
5 | 11 | :file:`tools` directory. This is just a handy reminder for the release manager. |
|
6 | 12 | |
|
7 | 13 | #. First, run :file:`build_release`, which does all the file checking and |
|
8 | 14 | building that the real release script will do. This will let you do test |
|
9 | 15 | installations, check that the build procedure runs OK, etc. You may want to |
|
10 | 16 | disable a few things like multi-version RPM building while testing, because |
|
11 | 17 | otherwise the build takes really long. |
|
12 | 18 | |
|
13 | 19 | #. Run the release script, which makes the tar.gz, eggs and Win32 .exe |
|
14 | 20 | installer. It posts them to the site and registers the release with PyPI. |
|
15 | 21 | |
|
16 |
#. Updat |
|
|
17 |
|
|
|
18 |
|
|
|
22 | #. Update the website with announcements and links to the updated changes.txt | |
|
23 | in html form. Remember to put a short note both on the news page of the | |
|
24 | site and on Launcphad. | |
|
19 | 25 | |
|
20 | 26 | #. Drafting a short release announcement with i) highlights and ii) a link to |
|
21 | the html changes.txt. | |
|
27 | the html version of the :ref:`Whats new <whatsnew_index>` section of the | |
|
28 | documentation. | |
|
22 | 29 | |
|
23 | 30 | #. Make sure that the released version of the docs is live on the site. |
|
24 | 31 | |
|
25 | 32 | #. Celebrate! No newline at end of file |
@@ -1,85 +1,64 b'' | |||
|
1 | ============================= | |
|
2 | IPython module reorganization | |
|
3 | ============================= | |
|
1 | .. _module_reorg: | |
|
4 | 2 | |
|
5 | Currently, IPython has many top-level modules that serve many different | |
|
6 | purposes. The lack of organization make it very difficult for developers to | |
|
7 | work on IPython and understand its design. This document contains notes about | |
|
8 | how we will reorganize the modules into sub-packages. | |
|
3 | =========================== | |
|
4 | IPython module organization | |
|
5 | =========================== | |
|
9 | 6 | |
|
10 | .. warning:: | |
|
7 | As of the 0.11 release of IPython, the top-level packages and modules have | |
|
8 | been completely reorganized. This section describes the purpose of the | |
|
9 | top-level IPython subpackages. | |
|
11 | 10 | |
|
12 | This effort will possibly break third party packages that use IPython as | |
|
13 | a library or hack on the IPython internals. | |
|
11 | Subpackage descriptions | |
|
12 | ======================= | |
|
14 | 13 | |
|
15 | .. warning:: | |
|
14 | * :mod:`IPython.config`. This package contains the configuration system of | |
|
15 | IPython, as well as default configuration files for the different IPython | |
|
16 | applications. | |
|
16 | 17 | |
|
17 | This effort will result in the removal from IPython of certain modules | |
|
18 | that are not used anymore, don't currently work, are unmaintained, etc. | |
|
19 | ||
|
20 | ||
|
21 | Current subpackges | |
|
22 | ================== | |
|
23 | ||
|
24 | IPython currently has the following sub-packages: | |
|
25 | ||
|
26 | * :mod:`IPython.config` | |
|
27 | ||
|
28 | * :mod:`IPython.Extensions` | |
|
29 | ||
|
30 | * :mod:`IPython.external` | |
|
31 | ||
|
32 | * :mod:`IPython.frontend` | |
|
33 | ||
|
34 | * :mod:`IPython.gui` | |
|
35 | ||
|
36 | * :mod:`IPython.kernel` | |
|
18 | * :mod:`IPython.core`. This sub-package contains the core of the IPython | |
|
19 | interpreter, but none of its extended capabilities. | |
|
37 | 20 | |
|
38 | * :mod:`IPython.testing` | |
|
21 | * :mod:`IPython.deathrow`. This is for code that is outdated, untested, | |
|
22 | rotting, or that belongs in a separate third party project. Eventually all | |
|
23 | this code will either i) be revived by someone willing to maintain it with | |
|
24 | tests and docs and re-included into IPython or 2) be removed from IPython | |
|
25 | proper, but put into a separate third-party Python package. No new code will | |
|
26 | be allowed here. | |
|
39 | 27 | |
|
40 | * :mod:`IPython.tests` | |
|
28 | * :mod:`IPython.extensions`. This package contains fully supported IPython | |
|
29 | extensions. These extensions adhere to the official IPython extension API | |
|
30 | and can be enabled by adding them to a field in the configuration file. | |
|
41 | 31 | |
|
42 | * :mod:`IPython.tools` | |
|
32 | * :mod:`IPython.external`. This package contains third party packages and | |
|
33 | modules that IPython ships internally to reduce the number of dependencies. | |
|
34 | Usually, these are short, single file modules. | |
|
43 | 35 | |
|
44 | * :mod:`IPython.UserConfig` | |
|
36 | * :mod:`IPython.frontend`. This package contains the various IPython | |
|
37 | frontends. Currently, the code in this subpackage is very experimental and | |
|
38 | may be broken. | |
|
45 | 39 | |
|
46 | New Subpackages to be created | |
|
47 | ============================= | |
|
40 | * :mod:`IPython.gui`. Another semi-experimental wxPython based IPython GUI. | |
|
48 | 41 | |
|
49 | We propose to create the following new sub-packages: | |
|
50 | ||
|
51 | * :mod:`IPython.core`. This sub-package will contain the core of the IPython | |
|
52 | interpreter, but none of its extended capabilities. | |
|
42 | * :mod:`IPython.kernel`. This contains IPython's parallel computing system. | |
|
53 | 43 | |
|
54 | 44 | * :mod:`IPython.lib`. IPython has many extended capabilities that are not part |
|
55 | of the IPython core. These things will go here. | |
|
56 | ||
|
57 | * :mod:`IPython.utils`. This sub-package will contain anything that might | |
|
58 | eventually be found in the Python standard library, like things in | |
|
59 | :mod:`genutils`. Each sub-module in this sub-package should contain | |
|
60 | functions and classes that serve a single purpose. | |
|
61 | ||
|
62 | * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting | |
|
63 | and needs to be removed from IPython. Eventually all this code will either | |
|
64 | i) be revived by someone willing to maintain it with tests and docs and | |
|
65 | re-included into IPython or 2) be removed from IPython proper, but put into | |
|
66 | a separate top-level (not IPython) package that we keep around. No new code | |
|
67 | will be allowed here. | |
|
45 | of the IPython core. These things will go here and in. Modules in this | |
|
46 | package are similar to extensions, but don't adhere to the official | |
|
47 | IPython extension API. | |
|
68 | 48 | |
|
69 | 49 |
* :mod:`IPython.quarantine`. |
|
70 | 50 |
standards, but that we plan on keeping. |
|
71 | a module needs to have a maintainer, tests and documentation. | |
|
72 | ||
|
73 | Procedure | |
|
74 | ========= | |
|
51 | a module needs to have approval of the core IPython developers, tests and | |
|
52 | documentation. | |
|
75 | 53 | |
|
76 | 1. Move the file to its new location with its new name. | |
|
77 | 2. Rename all import statements to reflect the change. | |
|
78 | 3. Run PyFlakes on each changes module. | |
|
79 | 4. Add tests/test_imports.py to test it. | |
|
54 | * :mod:`IPython.scripts`. This package contains a variety of top-level | |
|
55 | command line scripts. Eventually, these should be moved to the | |
|
56 | :file:`scripts` subdirectory of the appropriate IPython subpackage. | |
|
80 | 57 | |
|
81 | Status | |
|
82 | ====== | |
|
58 | * :mod:`IPython.utils`. This sub-package will contain anything that might | |
|
59 | eventually be found in the Python standard library, like things in | |
|
60 | :mod:`genutils`. Each sub-module in this sub-package should contain | |
|
61 | functions and classes that serve a single purpose and that don't | |
|
62 | depend on things in the rest of IPython. | |
|
83 | 63 | |
|
84 | This branch was merged into trunk in early August of 2009. | |
|
85 | 64 |
@@ -1,114 +1,121 b'' | |||
|
1 | 1 | .. _roadmap: |
|
2 | 2 | |
|
3 | 3 | =================== |
|
4 | 4 | Development roadmap |
|
5 | 5 | =================== |
|
6 | 6 | |
|
7 | 7 | IPython is an ambitious project that is still under heavy development. |
|
8 | 8 | However, we want IPython to become useful to as many people as possible, as |
|
9 | 9 | quickly as possible. To help us accomplish this, we are laying out a roadmap |
|
10 | 10 | of where we are headed and what needs to happen to get there. Hopefully, this |
|
11 | 11 | will help the IPython developers figure out the best things to work on for |
|
12 | 12 | each upcoming release. |
|
13 | 13 | |
|
14 | 14 | Work targeted to particular releases |
|
15 | 15 | ==================================== |
|
16 | 16 | |
|
17 | 17 | Release 0.11 |
|
18 | 18 | ------------ |
|
19 | 19 | |
|
20 | 20 | * Full module and package reorganization (done). |
|
21 | 21 | |
|
22 | 22 | * Removal of the threaded shells and new implementation of GUI support |
|
23 | 23 | based on ``PyOSInputHook`` (done). |
|
24 | 24 | |
|
25 | 25 | * Refactor the configuration system (done). |
|
26 | 26 | |
|
27 | 27 | * Prepare to refactor IPython's core by creating a new component and |
|
28 | 28 | application system (done). |
|
29 | 29 | |
|
30 | 30 | * Start to refactor IPython's core by turning everything into components |
|
31 | 31 | (started). |
|
32 | 32 | |
|
33 | 33 | Release 0.12 |
|
34 | 34 | ------------ |
|
35 | 35 | |
|
36 | 36 | * Continue to refactor IPython's core by turning everything into components. |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | Major areas of work |
|
40 | 40 | =================== |
|
41 | 41 | |
|
42 | 42 | Refactoring the main IPython core |
|
43 | 43 | --------------------------------- |
|
44 | 44 | |
|
45 | 45 |
During the summer of 2009, we began refactoring IPython's core. |
|
46 | thrust in this work was make the IPython core into a set of loosely coupled | |
|
46 | thrust in this work was to make the IPython core into a set of loosely coupled | |
|
47 | 47 |
components. |
|
48 |
:class:`IPython.core.component.Component`. |
|
|
49 |
|
|
|
48 | :class:`IPython.core.component.Component`. This section outlines the status of | |
|
49 | this work. | |
|
50 | 50 | |
|
51 | 51 | Parts of the IPython core that have been turned into components: |
|
52 | 52 | |
|
53 | * The main :class:`InteractiveShell` class. | |
|
54 |
* The aliases (:mod:`IPython.core.alias |
|
|
53 | * The main :class:`~IPython.core.iplib.InteractiveShell` class. | |
|
54 | * The aliases (:mod:`IPython.core.alias`). | |
|
55 | 55 | * The display and builtin traps (:mod:`IPython.core.display_trap` and |
|
56 | 56 | :mod:`IPython.core.builtin_trap`). |
|
57 | 57 | * The prefilter machinery (:mod:`IPython.core.prefilter`). |
|
58 | 58 | |
|
59 | Parts of the IPythoncore that need to be turned into components: | |
|
59 | Parts of the IPythoncore that still need to be turned into components: | |
|
60 | 60 | |
|
61 | 61 | * Magics. |
|
62 | 62 | * Input and output history management. |
|
63 | 63 | * Prompts. |
|
64 |
* |
|
|
64 | * Tab completers. | |
|
65 | 65 | * Logging. |
|
66 | 66 | * Exception handling. |
|
67 | 67 | * Anything else. |
|
68 | 68 | |
|
69 | 69 | Process management for :mod:`IPython.kernel` |
|
70 | 70 | -------------------------------------------- |
|
71 | 71 | |
|
72 | A number of things need to be done to improve how processes are started | |
|
73 | up and managed for the parallel computing side of IPython: | |
|
74 | ||
|
75 | * All of the processes need to use the new configuration system, components | |
|
76 | and application. | |
|
77 | * We need to add support for other batch systems. | |
|
78 | ||
|
72 | 79 | Performance problems |
|
73 | 80 | -------------------- |
|
74 | 81 | |
|
75 | 82 | Currently, we have a number of performance issues in :mod:`IPython.kernel`: |
|
76 | 83 | |
|
77 | 84 | * The controller stores a large amount of state in Python dictionaries. Under |
|
78 | 85 | heavy usage, these dicts with get very large, causing memory usage problems. |
|
79 | 86 | We need to develop more scalable solutions to this problem. This will also |
|
80 | 87 | help the controller to be more fault tolerant. |
|
81 | 88 | |
|
82 | 89 | * We currently don't have a good way of handling large objects in the |
|
83 | 90 | controller. The biggest problem is that because we don't have any way of |
|
84 | 91 | streaming objects, we get lots of temporary copies in the low-level buffers. |
|
85 | 92 | We need to implement a better serialization approach and true streaming |
|
86 | 93 | support. |
|
87 | 94 | |
|
88 | 95 | * The controller currently unpickles and repickles objects. We need to use the |
|
89 | 96 | [push|pull]_serialized methods instead. |
|
90 | 97 | |
|
91 | 98 | * Currently the controller is a bottleneck. The best approach for this is to |
|
92 | 99 | separate the controller itself into multiple processes, one for the core |
|
93 | 100 | controller and one each for the controller interfaces. |
|
94 | 101 | |
|
95 | 102 | Porting to 3.0 |
|
96 | 103 | ============== |
|
97 | 104 | |
|
98 | 105 | There are no definite plans for porting of IPython to Python 3. The major |
|
99 | 106 | issue is the dependency on Twisted framework for the networking/threading |
|
100 | 107 | stuff. It is possible that it the traditional IPython interactive console |
|
101 | 108 | could be ported more easily since it has no such dependency. Here are a few |
|
102 | 109 | things that will need to be considered when doing such a port especially |
|
103 | 110 | if we want to have a codebase that works directly on both 2.x and 3.x. |
|
104 | 111 | |
|
105 | 112 | 1. The syntax for exceptions changed (PEP 3110). The old `except exc, var` |
|
106 | 113 | changed to `except exc as var`. At last count there was 78 occurrences of this |
|
107 | 114 | usage in the code base. This is a particularly problematic issue, because it's |
|
108 | 115 | not easy to implement it in a 2.5-compatible way. |
|
109 | 116 | |
|
110 | 117 | Because it is quite difficult to support simultaneously Python 2.5 and 3.x, we |
|
111 | 118 | will likely at some point put out a release that requires strictly 2.6 and |
|
112 | 119 | abandons 2.5 compatibility. This will then allow us to port the code to using |
|
113 | 120 | :func:`print` as a function, `except exc as var` syntax, etc. But as of |
|
114 | 121 | version 0.11 at least, we will retain Python 2.5 compatibility. |
@@ -1,194 +1,54 b'' | |||
|
1 | 1 | .. _testing: |
|
2 | 2 | |
|
3 | 3 | ========================= |
|
4 | 4 | Writing and running tests |
|
5 | 5 | ========================= |
|
6 | 6 | |
|
7 | 7 | Overview |
|
8 | 8 | ======== |
|
9 | 9 | |
|
10 | 10 | It is extremely important that all code contributed to IPython has tests. |
|
11 | 11 | Tests should be written as unittests, doctests or other entities that the |
|
12 | 12 | IPython test system can detect. See below for more details on this. |
|
13 | 13 | |
|
14 | 14 | Each subpackage in IPython should have its own :file:`tests` directory that |
|
15 | 15 | contains all of the tests for that subpackage. All of the files in the |
|
16 | 16 | :file:`tests` directory should have the word "tests" in them to enable |
|
17 | 17 | the testing framework to find them. |
|
18 | 18 | |
|
19 | 19 | If a subpackage has any dependencies beyond the Python standard library, the |
|
20 | 20 | tests for that subpackage should be skipped if the dependencies are not found. |
|
21 | 21 | This is very important so users don't get tests failing simply because they |
|
22 | 22 | don't have dependencies. We are still figuring out the best way for this |
|
23 | 23 | to be handled. |
|
24 | 24 | |
|
25 | 25 | Status |
|
26 | 26 | ====== |
|
27 | 27 | |
|
28 | 28 | Currently IPython's testing system is being reworked. In the meantime, |
|
29 | 29 | we recommend the following testing practices: |
|
30 | 30 | |
|
31 |
* To run regular tests, use the :cmd:`nosetests` command |
|
|
31 | * To run regular tests, use the :command:`nosetests` command that Nose [Nose]_ | |
|
32 | provides on a per file basis: | |
|
32 | 33 | |
|
33 | 34 | .. code-block:: bash |
|
34 | 35 | |
|
35 | 36 | nosetests -vvs IPython.core.tests.test_component |
|
36 | 37 | |
|
37 | * To run Twisted-using tests, use the :cmd:`trial` command on a per file | |
|
38 | * To run Twisted-using tests, use the :command:`trial` command on a per file | |
|
38 | 39 | basis: |
|
39 | 40 | |
|
40 | 41 | .. code-block:: bash |
|
41 | 42 | |
|
42 | 43 | trial IPython.kernel |
|
43 | 44 | |
|
44 | 45 | * For now, regular tests (of non-Twisted using code) should be written as |
|
45 | 46 | unit tests. They should be subclasses of :class:`unittest.TestCase`. |
|
46 | 47 | |
|
47 | 48 | * Tests of Twisted [Twisted]_ using code should be written by subclassing the |
|
48 | ``TestCase`` class that comes with ``twisted.trial.unittest``. | |
|
49 | ||
|
50 | .. _devel_testing: | |
|
51 | ||
|
52 | Older material | |
|
53 | ============== | |
|
54 | ||
|
55 | It is extremely important that all code contributed to IPython has tests. | |
|
56 | Tests should be written as unittests, doctests or as entities that the Nose | |
|
57 | [Nose]_ testing package will find. Regardless of how the tests are written, we | |
|
58 | will use Nose for discovering and running the tests. Nose will be required to | |
|
59 | run the IPython test suite, but will not be required to simply use IPython. | |
|
60 | ||
|
61 | Tests of Twisted using code need to follow two additional guidelines: | |
|
62 | ||
|
63 | 1. Twisted using tests should be written by subclassing the :class:`TestCase` | |
|
64 | class that comes with :mod:`twisted.trial.unittest`. | |
|
65 | ||
|
66 | 2. All :class:`Deferred` instances that are created in the test must be | |
|
49 | ``TestCase`` class that comes with ``twisted.trial.unittest``. Furthermore, | |
|
50 | all :class:`Deferred` instances that are created in the test must be | |
|
67 | 51 |
|
|
68 | 52 |
|
|
69 | 53 | |
|
70 | When these two things are done, Nose will be able to run the tests and the | |
|
71 | twisted reactor will be handled correctly. | |
|
72 | ||
|
73 | Each subpackage in IPython should have its own :file:`tests` directory that | |
|
74 | contains all of the tests for that subpackage. This allows each subpackage to | |
|
75 | be self-contained. A good convention to follow is to have a file named | |
|
76 | :file:`test_foo.py` for each module :file:`foo.py` in the package. This makes | |
|
77 | it easy to organize the tests, though like most conventions, it's OK to break | |
|
78 | it if logic and common sense dictate otherwise. | |
|
79 | ||
|
80 | If a subpackage has any dependencies beyond the Python standard library, the | |
|
81 | tests for that subpackage should be skipped if the dependencies are not | |
|
82 | found. This is very important so users don't get tests failing simply because | |
|
83 | they don't have dependencies. We ship a set of decorators in the | |
|
84 | :mod:`IPython.testing` package to tag tests that may be platform-specific or | |
|
85 | otherwise may have restrictions; if the existing ones don't fit your needs, add | |
|
86 | a new decorator in that location so other tests can reuse it. | |
|
87 | ||
|
88 | To run the IPython test suite, use the :command:`iptest` command that is | |
|
89 | installed with IPython (if you are using IPython in-place, without installing | |
|
90 | it, you can find this script in the :file:`scripts` directory):: | |
|
91 | ||
|
92 | $ iptest | |
|
93 | ||
|
94 | This command colects all IPython tests into separate groups, and then calls | |
|
95 | either Nose with the proper options and extensions, or Twisted's | |
|
96 | :command:`trial`. This ensures that tests that need the Twisted reactor | |
|
97 | management facilities execute separate of Nose. If any individual test group | |
|
98 | fails, :command:`iptest` will print what you need to type so you can rerun that | |
|
99 | particular test group alone for debugging. | |
|
100 | ||
|
101 | By default, :command:`iptest` runs the entire IPython test | |
|
102 | suite (skipping tests that may be platform-specific or which depend on tools | |
|
103 | you may not have). But you can also use it to run only one specific test file, | |
|
104 | or a specific test function. For example, this will run only the | |
|
105 | :file:`test_magic` file from the test suite:: | |
|
106 | ||
|
107 | $ iptest IPython.tests.test_magic | |
|
108 | ---------------------------------------------------------------------- | |
|
109 | Ran 10 tests in 0.348s | |
|
110 | ||
|
111 | OK (SKIP=3) | |
|
112 | Deleting object: second_pass | |
|
113 | ||
|
114 | while the ``path:function`` syntax allows you to select a specific function in | |
|
115 | that file to run:: | |
|
116 | ||
|
117 | $ iptest IPython.tests.test_magic:test_obj_del | |
|
118 | ---------------------------------------------------------------------- | |
|
119 | Ran 1 test in 0.204s | |
|
120 | ||
|
121 | OK | |
|
122 | ||
|
123 | Since :command:`iptest` is based on nosetests, you can pass it any regular | |
|
124 | nosetests option. For example, you can use ``--pdb`` or ``--pdb-failures`` to | |
|
125 | automatically activate the interactive Pdb debugger on errors or failures. See | |
|
126 | the nosetests documentation for further details. | |
|
127 | ||
|
128 | ||
|
129 | A few tips for writing tests | |
|
130 | ---------------------------- | |
|
131 | ||
|
132 | You can write tests either as normal test files, using all the conventions that | |
|
133 | Nose recognizes, or as doctests. Note that *all* IPython functions should have | |
|
134 | at least one example that serves as a doctest, whenever technically feasible. | |
|
135 | However, example doctests should only be in the main docstring if they are *a | |
|
136 | good example*, i.e. if they convey useful information about the function. If | |
|
137 | you simply would like to write a test as a doctest, put it in a separate test | |
|
138 | file and write a no-op function whose only purpose is its docstring. | |
|
139 | ||
|
140 | Note, however, that in a file named :file:`test_X`, functions whose only test | |
|
141 | is their docstring (as a doctest) and which have no test functionality of their | |
|
142 | own, should be called *doctest_foo* instead of *test_foo*, otherwise they get | |
|
143 | double-counted (the empty function call is counted as a test, which just | |
|
144 | inflates tests numbers artificially). This restriction does not apply to | |
|
145 | functions in files with other names, due to how Nose discovers tests. | |
|
146 | ||
|
147 | You can use IPython examples in your docstrings. Those can make full use of | |
|
148 | IPython functionality (magics, variable substitution, etc), but be careful to | |
|
149 | keep them generic enough that they run identically on all Operating Systems. | |
|
150 | ||
|
151 | The prompts in your doctests can be either of the plain Python ``>>>`` variety | |
|
152 | or ``In [1]:`` IPython style. Since this is the IPython system, after all, we | |
|
153 | encourage you to use IPython prompts throughout, unless you are illustrating a | |
|
154 | specific aspect of the normal prompts (such as the ``%doctest_mode`` magic). | |
|
155 | ||
|
156 | If a test isn't safe to run inside the main nose process (e.g. because it loads | |
|
157 | a GUI toolkit), consider running it in a subprocess and capturing its output | |
|
158 | for evaluation and test decision later. Here is an example of how to do it, by | |
|
159 | relying on the builtin ``_ip`` object that contains the public IPython api as | |
|
160 | defined in :mod:`IPython.ipapi`:: | |
|
161 | ||
|
162 | def test_obj_del(): | |
|
163 | """Test that object's __del__ methods are called on exit.""" | |
|
164 | test_dir = os.path.dirname(__file__) | |
|
165 | del_file = os.path.join(test_dir,'obj_del.py') | |
|
166 | out = _ip.IP.getoutput('ipython %s' % del_file) | |
|
167 | nt.assert_equals(out,'object A deleted') | |
|
168 | ||
|
169 | ||
|
170 | ||
|
171 | If a doctest contains input whose output you don't want to verify identically | |
|
172 | via doctest (random output, an object id, etc), you can mark a docstring with | |
|
173 | ``#random``. All of these test will have their code executed but no output | |
|
174 | checking will be done:: | |
|
175 | ||
|
176 | >>> 1+3 | |
|
177 | junk goes here... # random | |
|
178 | ||
|
179 | >>> 1+2 | |
|
180 | again, anything goes #random | |
|
181 | if multiline, the random mark is only needed once. | |
|
182 | ||
|
183 | >>> 1+2 | |
|
184 | You can also put the random marker at the end: | |
|
185 | # random | |
|
186 | ||
|
187 | >>> 1+2 | |
|
188 | # random | |
|
189 | .. or at the beginning. | |
|
190 | ||
|
191 | In a case where you want an *entire* docstring to be executed but not verified | |
|
192 | (this only serves to check that the code runs without crashing, so it should be | |
|
193 | used very sparingly), you can put ``# all-random`` in the docstring. | |
|
194 | ||
|
54 | .. [Nose] Nose: a discovery based unittest extension. http://code.google.com/p/python-nose/ |
@@ -1,328 +1,341 b'' | |||
|
1 | 1 | Overview |
|
2 | 2 | ======== |
|
3 | 3 | |
|
4 | 4 | This document describes the steps required to install IPython. IPython is |
|
5 | 5 | organized into a number of subpackages, each of which has its own dependencies. |
|
6 | 6 | All of the subpackages come with IPython, so you don't need to download and |
|
7 | 7 | install them separately. However, to use a given subpackage, you will need to |
|
8 | 8 | install all of its dependencies. |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | Please let us know if you have problems installing IPython or any of its |
|
12 | 12 | dependencies. Officially, IPython requires Python version 2.5 or 2.6. We |
|
13 | 13 | have *not* yet started to port IPython to Python 3.0. |
|
14 | 14 | |
|
15 | 15 | .. warning:: |
|
16 | 16 | |
|
17 | 17 | Officially, IPython supports Python versions 2.5 and 2.6. |
|
18 | 18 | |
|
19 | 19 | IPython 0.10 has only been well tested with Python 2.5 and 2.6. Parts of |
|
20 | 20 | it may work with Python 2.4, but we do not officially support Python 2.4 |
|
21 | 21 | anymore. If you need to use 2.4, you can still run IPython 0.9. |
|
22 | 22 | |
|
23 | 23 | Some of the installation approaches use the :mod:`setuptools` package and its |
|
24 | 24 | :command:`easy_install` command line program. In many scenarios, this provides |
|
25 | 25 | the most simple method of installing IPython and its dependencies. It is not |
|
26 | 26 | required though. More information about :mod:`setuptools` can be found on its |
|
27 | 27 | website. |
|
28 | 28 | |
|
29 | 29 | More general information about installing Python packages can be found in |
|
30 | 30 | Python's documentation at http://www.python.org/doc/. |
|
31 | 31 | |
|
32 | 32 | Quickstart |
|
33 | 33 | ========== |
|
34 | 34 | |
|
35 | 35 | If you have :mod:`setuptools` installed and you are on OS X or Linux (not |
|
36 | 36 | Windows), the following will download and install IPython *and* the main |
|
37 | 37 | optional dependencies: |
|
38 | 38 | |
|
39 | 39 | .. code-block:: bash |
|
40 | 40 | |
|
41 | easy_install ipython[kernel,security,test] | |
|
41 | $ easy_install ipython[kernel,security,test] | |
|
42 | 42 | |
|
43 | 43 | This will get Twisted, zope.interface and Foolscap, which are needed for |
|
44 | 44 | IPython's parallel computing features as well as the nose package, which will |
|
45 |
enable you to run IPython's test suite. |
|
|
46 | :command:`iptest` command: | |
|
45 | enable you to run IPython's test suite. | |
|
46 | ||
|
47 | .. warning:: | |
|
48 | ||
|
49 | IPython's test system is being refactored and currently the | |
|
50 | :command:`iptest` shown below does not work. More details about the | |
|
51 | testing situation can be found :ref:`here <testing>` | |
|
52 | ||
|
53 | To run IPython's test suite, use the :command:`iptest` command: | |
|
47 | 54 | |
|
48 | 55 | .. code-block:: bash |
|
49 | 56 | |
|
50 | iptest | |
|
57 | $ iptest | |
|
51 | 58 | |
|
52 | 59 | Read on for more specific details and instructions for Windows. |
|
53 | 60 | |
|
54 | 61 | Installing IPython itself |
|
55 | 62 | ========================= |
|
56 | 63 | |
|
57 | 64 | Given a properly built Python, the basic interactive IPython shell will work |
|
58 | 65 | with no external dependencies. However, some Python distributions |
|
59 | 66 | (particularly on Windows and OS X), don't come with a working :mod:`readline` |
|
60 | 67 | module. The IPython shell will work without :mod:`readline`, but will lack |
|
61 | 68 | many features that users depend on, such as tab completion and command line |
|
62 | 69 | editing. See below for details of how to make sure you have a working |
|
63 | 70 | :mod:`readline`. |
|
64 | 71 | |
|
65 | 72 | Installation using easy_install |
|
66 | 73 | ------------------------------- |
|
67 | 74 | |
|
68 | 75 | If you have :mod:`setuptools` installed, the easiest way of getting IPython is |
|
69 | 76 | to simple use :command:`easy_install`: |
|
70 | 77 | |
|
71 | 78 | .. code-block:: bash |
|
72 | 79 | |
|
73 | easy_install ipython | |
|
80 | $ easy_install ipython | |
|
74 | 81 | |
|
75 | 82 | That's it. |
|
76 | 83 | |
|
77 | 84 | Installation from source |
|
78 | 85 | ------------------------ |
|
79 | 86 | |
|
80 | 87 | If you don't want to use :command:`easy_install`, or don't have it installed, |
|
81 | 88 | just grab the latest stable build of IPython from `here |
|
82 | 89 | <http://ipython.scipy.org/dist/>`_. Then do the following: |
|
83 | 90 | |
|
84 | 91 | .. code-block:: bash |
|
85 | 92 | |
|
86 | tar -xzf ipython.tar.gz | |
|
87 | cd ipython | |
|
88 | python setup.py install | |
|
93 | $ tar -xzf ipython.tar.gz | |
|
94 | $ cd ipython | |
|
95 | $ python setup.py install | |
|
89 | 96 | |
|
90 | 97 | If you are installing to a location (like ``/usr/local``) that requires higher |
|
91 | 98 | permissions, you may need to run the last command with :command:`sudo`. |
|
92 | 99 | |
|
93 | 100 | Windows |
|
94 | 101 | ------- |
|
95 | 102 | |
|
96 | 103 | There are a few caveats for Windows users. The main issue is that a basic |
|
97 | 104 | ``python setup.py install`` approach won't create ``.bat`` file or Start Menu |
|
98 | 105 | shortcuts, which most users want. To get an installation with these, you can |
|
99 | 106 | use any of the following alternatives: |
|
100 | 107 | |
|
101 | 108 | 1. Install using :command:`easy_install`. |
|
102 | 109 | |
|
103 | 110 | 2. Install using our binary ``.exe`` Windows installer, which can be found at |
|
104 | 111 | `here <http://ipython.scipy.org/dist/>`_ |
|
105 | 112 | |
|
106 | 113 | 3. Install from source, but using :mod:`setuptools` (``python setupegg.py |
|
107 | 114 | install``). |
|
108 | 115 | |
|
109 | 116 | IPython by default runs in a terminal window, but the normal terminal |
|
110 | 117 | application supplied by Microsoft Windows is very primitive. You may want to |
|
111 | 118 | download the excellent and free Console_ application instead, which is a far |
|
112 | 119 | superior tool. You can even configure Console to give you by default an |
|
113 | 120 | IPython tab, which is very convenient to create new IPython sessions directly |
|
114 | 121 | from the working terminal. |
|
115 | 122 | |
|
116 | 123 | .. _Console: http://sourceforge.net/projects/console |
|
117 | 124 | |
|
118 | 125 | |
|
119 | 126 | Installing the development version |
|
120 | 127 | ---------------------------------- |
|
121 | 128 | |
|
122 | 129 | It is also possible to install the development version of IPython from our |
|
123 | 130 | `Bazaar <http://bazaar-vcs.org/>`_ source code repository. To do this you will |
|
124 | 131 | need to have Bazaar installed on your system. Then just do: |
|
125 | 132 | |
|
126 | 133 | .. code-block:: bash |
|
127 | 134 | |
|
128 | bzr branch lp:ipython | |
|
129 | cd ipython | |
|
130 | python setup.py install | |
|
135 | $ bzr branch lp:ipython | |
|
136 | $ cd ipython | |
|
137 | $ python setup.py install | |
|
131 | 138 | |
|
132 | 139 | Again, this last step on Windows won't create ``.bat`` files or Start Menu |
|
133 | 140 | shortcuts, so you will have to use one of the other approaches listed above. |
|
134 | 141 | |
|
135 | 142 | Some users want to be able to follow the development branch as it changes. If |
|
136 | 143 | you have :mod:`setuptools` installed, this is easy. Simply replace the last |
|
137 | 144 | step by: |
|
138 | 145 | |
|
139 | 146 | .. code-block:: bash |
|
140 | 147 | |
|
141 | python setupegg.py develop | |
|
148 | $ python setupegg.py develop | |
|
142 | 149 | |
|
143 | 150 | This creates links in the right places and installs the command line script to |
|
144 | 151 | the appropriate places. Then, if you want to update your IPython at any time, |
|
145 | 152 | just do: |
|
146 | 153 | |
|
147 | 154 | .. code-block:: bash |
|
148 | 155 | |
|
149 | bzr pull | |
|
156 | $ bzr pull | |
|
150 | 157 | |
|
151 | 158 | Basic optional dependencies |
|
152 | 159 | =========================== |
|
153 | 160 | |
|
154 | 161 | There are a number of basic optional dependencies that most users will want to |
|
155 | 162 | get. These are: |
|
156 | 163 | |
|
157 | 164 | * readline (for command line editing, tab completion, etc.) |
|
158 | 165 | * nose (to run the IPython test suite) |
|
159 | 166 | * pexpect (to use things like irunner) |
|
160 | 167 | |
|
161 | 168 | If you are comfortable installing these things yourself, have at it, otherwise |
|
162 | 169 | read on for more details. |
|
163 | 170 | |
|
164 | 171 | readline |
|
165 | 172 | -------- |
|
166 | 173 | |
|
167 | 174 | In principle, all Python distributions should come with a working |
|
168 | 175 | :mod:`readline` module. But, reality is not quite that simple. There are two |
|
169 | 176 | common situations where you won't have a working :mod:`readline` module: |
|
170 | 177 | |
|
171 | 178 | * If you are using the built-in Python on Mac OS X. |
|
172 | 179 | |
|
173 | 180 | * If you are running Windows, which doesn't have a :mod:`readline` module. |
|
174 | 181 | |
|
175 | 182 | On OS X, the built-in Python doesn't not have :mod:`readline` because of |
|
176 | 183 | license issues. Starting with OS X 10.5 (Leopard), Apple's built-in Python has |
|
177 | 184 | a BSD-licensed not-quite-compatible readline replacement. As of IPython 0.9, |
|
178 | 185 | many of the issues related to the differences between readline and libedit have |
|
179 | 186 | been resolved. For many users, libedit may be sufficient. |
|
180 | 187 | |
|
181 | 188 | Most users on OS X will want to get the full :mod:`readline` module. To get a |
|
182 | 189 | working :mod:`readline` module, just do (with :mod:`setuptools` installed): |
|
183 | 190 | |
|
184 | 191 | .. code-block:: bash |
|
185 | 192 | |
|
186 | easy_install readline | |
|
193 | $ easy_install readline | |
|
187 | 194 | |
|
188 | .. note: | |
|
195 | .. note:: | |
|
189 | 196 | |
|
190 | 197 | Other Python distributions on OS X (such as fink, MacPorts and the |
|
191 | 198 | official python.org binaries) already have readline installed so |
|
192 | 199 | you don't have to do this step. |
|
193 | 200 | |
|
194 | 201 | If needed, the readline egg can be build and installed from source (see the |
|
195 | 202 | wiki page at http://ipython.scipy.org/moin/InstallationOSXLeopard). |
|
196 | 203 | |
|
197 | 204 | On Windows, you will need the PyReadline module. PyReadline is a separate, |
|
198 | 205 | Windows only implementation of readline that uses native Windows calls through |
|
199 | 206 | :mod:`ctypes`. The easiest way of installing PyReadline is you use the binary |
|
200 | 207 | installer available `here <http://ipython.scipy.org/dist/>`_. The :mod:`ctypes` |
|
201 | 208 | module, which comes with Python 2.5 and greater, is required by PyReadline. It |
|
202 | 209 | is available for Python 2.4 at http://python.net/crew/theller/ctypes. |
|
203 | 210 | |
|
204 | 211 | nose |
|
205 | 212 | ---- |
|
206 | 213 | |
|
207 | 214 | To run the IPython test suite you will need the :mod:`nose` package. Nose |
|
208 | 215 | provides a great way of sniffing out and running all of the IPython tests. The |
|
209 | 216 | simplest way of getting nose, is to use :command:`easy_install`: |
|
210 | 217 | |
|
211 | 218 | .. code-block:: bash |
|
212 | 219 | |
|
213 | easy_install nose | |
|
220 | $ easy_install nose | |
|
214 | 221 | |
|
215 | 222 | Another way of getting this is to do: |
|
216 | 223 | |
|
217 | 224 | .. code-block:: bash |
|
218 | 225 | |
|
219 | easy_install ipython[test] | |
|
226 | $ easy_install ipython[test] | |
|
220 | 227 | |
|
221 | 228 | For more installation options, see the `nose website |
|
222 |
<http://somethingaboutorange.com/mrl/projects/nose/>`_. |
|
|
223 | installed, you can run IPython's test suite using the iptest command: | |
|
229 | <http://somethingaboutorange.com/mrl/projects/nose/>`_. | |
|
230 | ||
|
231 | .. warning:: | |
|
232 | ||
|
233 | As described above, the :command:`iptest` command currently doesn't work. | |
|
234 | ||
|
235 | Once you have nose installed, you can run IPython's test suite using the | |
|
236 | iptest command: | |
|
224 | 237 | |
|
225 | 238 | .. code-block:: bash |
|
226 | 239 | |
|
227 | iptest | |
|
240 | $ iptest | |
|
228 | 241 | |
|
229 | 242 | pexpect |
|
230 | 243 | ------- |
|
231 | 244 | |
|
232 | 245 | The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's |
|
233 | 246 | :command:`irunner` script. On Unix platforms (including OS X), just do: |
|
234 | 247 | |
|
235 | 248 | .. code-block:: bash |
|
236 | 249 | |
|
237 | easy_install pexpect | |
|
250 | $ easy_install pexpect | |
|
238 | 251 | |
|
239 | 252 | Windows users are out of luck as pexpect does not run there. |
|
240 | 253 | |
|
241 | 254 | Dependencies for IPython.kernel (parallel computing) |
|
242 | 255 | ==================================================== |
|
243 | 256 | |
|
244 | 257 | The IPython kernel provides a nice architecture for parallel computing. The |
|
245 | 258 | main focus of this architecture is on interactive parallel computing. These |
|
246 | 259 | features require a number of additional packages: |
|
247 | 260 | |
|
248 | 261 | * zope.interface (yep, we use interfaces) |
|
249 | 262 | * Twisted (asynchronous networking framework) |
|
250 | 263 | * Foolscap (a nice, secure network protocol) |
|
251 | 264 | * pyOpenSSL (security for network connections) |
|
252 | 265 | |
|
253 | 266 | On a Unix style platform (including OS X), if you want to use |
|
254 | 267 | :mod:`setuptools`, you can just do: |
|
255 | 268 | |
|
256 | 269 | .. code-block:: bash |
|
257 | 270 | |
|
258 | easy_install ipython[kernel] # the first three | |
|
259 | easy_install ipython[security] # pyOpenSSL | |
|
271 | $ easy_install ipython[kernel] # the first three | |
|
272 | $ easy_install ipython[security] # pyOpenSSL | |
|
260 | 273 | |
|
261 | 274 | zope.interface and Twisted |
|
262 | 275 | -------------------------- |
|
263 | 276 | |
|
264 | 277 | Twisted [Twisted]_ and zope.interface [ZopeInterface]_ are used for networking |
|
265 | 278 | related things. On Unix style platforms (including OS X), the simplest way of |
|
266 | 279 | getting the these is to use :command:`easy_install`: |
|
267 | 280 | |
|
268 | 281 | .. code-block:: bash |
|
269 | 282 | |
|
270 | easy_install zope.interface | |
|
271 | easy_install Twisted | |
|
283 | $ easy_install zope.interface | |
|
284 | $ easy_install Twisted | |
|
272 | 285 | |
|
273 | 286 | Of course, you can also download the source tarballs from the Twisted website |
|
274 | [Twisted]_ and the `zope.interface page at PyPI | |
|
275 |
<http://pypi.python.org/pypi/zope.interface>`_ |
|
|
276 | setup.py install`` if you prefer. | |
|
287 | [Twisted]_ and the | |
|
288 | `zope.interface page at PyPI <http://pypi.python.org/pypi/zope.interface>`_ | |
|
289 | and do the usual ``python setup.py install`` if you prefer. | |
|
277 | 290 | |
|
278 | 291 | Windows is a bit different. For zope.interface and Twisted, simply get the |
|
279 | 292 | latest binary ``.exe`` installer from the Twisted website. This installer |
|
280 | 293 | includes both zope.interface and Twisted and should just work. |
|
281 | 294 | |
|
282 | 295 | Foolscap |
|
283 | 296 | -------- |
|
284 | 297 | |
|
285 | 298 | Foolscap [Foolscap]_ uses Twisted to provide a very nice secure RPC protocol that we use to implement our parallel computing features. |
|
286 | 299 | |
|
287 | 300 | On all platforms a simple: |
|
288 | 301 | |
|
289 | 302 | .. code-block:: bash |
|
290 | 303 | |
|
291 | easy_install foolscap | |
|
304 | $ easy_install foolscap | |
|
292 | 305 | |
|
293 | 306 | should work. You can also download the source tarballs from the `Foolscap |
|
294 | 307 | website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install`` |
|
295 | 308 | if you prefer. |
|
296 | 309 | |
|
297 | 310 | pyOpenSSL |
|
298 | 311 | --------- |
|
299 | 312 | |
|
300 | 313 | IPython does not work with version 0.7 of pyOpenSSL [pyOpenSSL]_. It is known |
|
301 | 314 | to work with version 0.6 and will likely work with the more recent 0.8 and 0.9 |
|
302 | 315 | versions. There are a couple of options for getting this: |
|
303 | 316 | |
|
304 | 317 | 1. Most Linux distributions have packages for pyOpenSSL. |
|
305 | 318 | 2. The built-in Python 2.5 on OS X 10.5 already has it installed. |
|
306 | 319 | 3. There are source tarballs on the pyOpenSSL website. On Unix-like |
|
307 | 320 | platforms, these can be built using ``python seutp.py install``. |
|
308 | 321 | 4. There is also a binary ``.exe`` Windows installer on the |
|
309 | 322 | `pyOpenSSL website <http://pyopenssl.sourceforge.net/>`_. |
|
310 | 323 | |
|
311 | 324 | Dependencies for IPython.frontend (the IPython GUI) |
|
312 | 325 | =================================================== |
|
313 | 326 | |
|
314 | 327 | wxPython |
|
315 | 328 | -------- |
|
316 | 329 | |
|
317 | 330 | Starting with IPython 0.9, IPython has a new :mod:`IPython.frontend` package |
|
318 | 331 | that has a nice wxPython based IPython GUI. As you would expect, this GUI |
|
319 | 332 | requires wxPython. Most Linux distributions have wxPython packages available |
|
320 | 333 | and the built-in Python on OS X comes with wxPython preinstalled. For Windows, |
|
321 | 334 | a binary installer is available on the `wxPython website |
|
322 | 335 | <http://www.wxpython.org/>`_. |
|
323 | 336 | |
|
324 | 337 | .. [Twisted] Twisted matrix. http://twistedmatrix.org |
|
325 | 338 | .. [ZopeInterface] http://pypi.python.org/pypi/zope.interface |
|
326 | 339 | .. [Foolscap] Foolscap network protocol. http://foolscap.lothar.com/trac |
|
327 | 340 | .. [pyOpenSSL] pyOpenSSL. http://pyopenssl.sourceforge.net |
|
328 | 341 |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now