##// END OF EJS Templates
Major work on the documentation....
Brian Granger -
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
@@ -140,7 +140,7 b' c.Global.log_level = 20'
140 # AliasManager options
140 # AliasManager options
141 #-----------------------------------------------------------------------------
141 #-----------------------------------------------------------------------------
142
142
143 # Do this to enable all defaults
143 # Do this to disable all defaults
144 # c.AliasManager.default_aliases = []
144 # c.AliasManager.default_aliases = []
145
145
146 # c.AliasManager.user_aliases = [
146 # c.AliasManager.user_aliases = [
@@ -144,8 +144,8 b' def masquerade_as(instance, cls):'
144 masquerade as another. Python, being duck typed, allows this by
144 masquerade as another. Python, being duck typed, allows this by
145 default. But, instances of components are tracked by their class type.
145 default. But, instances of components are tracked by their class type.
146
146
147 After calling this, cls.get_instances() will return ``instance``. This
147 After calling this, ``cls.get_instances()`` will return ``instance``. This
148 does not, however, cause isinstance(instance, cls) to return ``True``.
148 does not, however, cause ``isinstance(instance, cls)`` to return ``True``.
149
149
150 Parameters
150 Parameters
151 ----------
151 ----------
@@ -207,7 +207,7 b' class PrefilterManager(Component):'
207
207
208 Users or developers can change the priority or enabled attribute of
208 Users or developers can change the priority or enabled attribute of
209 transformers or checkers, but they must call the :meth:`sort_checkers`
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 multi_line_specials = CBool(True, config=True)
213 multi_line_specials = CBool(True, config=True)
@@ -439,17 +439,17 b' class HasTraitlets(object):'
439
439
440 Parameters
440 Parameters
441 ----------
441 ----------
442 handler : callable
442 handler : callable
443 A callable that is called when a traitlet changes. Its
443 A callable that is called when a traitlet changes. Its
444 signature can be handler(), handler(name), handler(name, new)
444 signature can be handler(), handler(name), handler(name, new)
445 or handler(name, old, new).
445 or handler(name, old, new).
446 name : list, str, None
446 name : list, str, None
447 If None, the handler will apply to all traitlets. If a list
447 If None, the handler will apply to all traitlets. If a list
448 of str, handler will apply to all names in the list. If a
448 of str, handler will apply to all names in the list. If a
449 str, the handler will apply just to that name.
449 str, the handler will apply just to that name.
450 remove : bool
450 remove : bool
451 If False (the default), then install the handler. If True
451 If False (the default), then install the handler. If True
452 then unintall it.
452 then unintall it.
453 """
453 """
454 if remove:
454 if remove:
455 names = parse_notifier_name(name)
455 names = parse_notifier_name(name)
@@ -4,7 +4,7 b''
4 {% block rootrellink %}
4 {% block rootrellink %}
5 <li><a href="{{ pathto('index') }}">home</a>|&nbsp;</li>
5 <li><a href="{{ pathto('index') }}">home</a>|&nbsp;</li>
6 <li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
6 <li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
7 <li><a href="{{ pathto('whatsnew/index') }}">what's new </a> &raquo;</li>
7 <li><a href="{{ pathto('index') }}">documentation </a> &raquo;</li>
8 {% endblock %}
8 {% endblock %}
9
9
10
10
@@ -5,7 +5,7 b' Configuration and customization'
5 .. toctree::
5 .. toctree::
6 :maxdepth: 2
6 :maxdepth: 2
7
7
8 initial_config.txt
8 overview.txt
9 customization.txt
9 ipython.txt
10 new_config.txt
10 editors.txt
11
11 old.txt
@@ -1,8 +1,13 b''
1 .. _initial config:
1 .. _initial config:
2
2
3 =========================================
3 =============================================================
4 Initial configuration of your environment
4 Outdated configuration information that might still be useful
5 =========================================
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 This section will help you set various things in your environment for
12 This section will help you set various things in your environment for
8 your IPython sessions to be as efficient as possible. All of IPython's
13 your IPython sessions to be as efficient as possible. All of IPython's
@@ -21,69 +26,6 b' can change to suit your taste, you can find more details :ref:`here'
21 <customization>`. Here we discuss the basic things you will want to make sure
26 <customization>`. Here we discuss the basic things you will want to make sure
22 things are working properly from the beginning.
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 Color
29 Color
88 =====
30 =====
89
31
@@ -133,7 +75,6 b' IPython uses colors for two main groups of things: prompts and'
133 tracebacks which are directly printed to the terminal, and the object
75 tracebacks which are directly printed to the terminal, and the object
134 introspection system which passes large sets of data through a pager.
76 introspection system which passes large sets of data through a pager.
135
77
136
137 Input/Output prompts and exception tracebacks
78 Input/Output prompts and exception tracebacks
138 =============================================
79 =============================================
139
80
@@ -191,60 +132,99 b' documentation for details.'
191 If you are on a system which lacks proper data pagers (such as Windows),
132 If you are on a system which lacks proper data pagers (such as Windows),
192 IPython will use a very limited builtin pager.
133 IPython will use a very limited builtin pager.
193
134
194 .. _emacs:
135 .. _Prompts:
195
136
196 (X)Emacs configuration
137 Fine-tuning your prompt
197 ======================
138 =======================
198
139
199 Thanks to the work of Alexander Schmolck and Prabhu Ramachandran,
140 IPython's prompts can be customized using a syntax similar to that of
200 currently (X)Emacs and IPython get along very well.
141 the bash shell. Many of bash's escapes are supported, as well as a few
201
142 additional ones. We list them below::
202 Important note: You will need to use a recent enough version of
143
203 python-mode.el, along with the file ipython.el. You can check that the
144 \#
204 version you have of python-mode.el is new enough by either looking at
145 the prompt/history count number. This escape is automatically
205 the revision number in the file itself, or asking for it in (X)Emacs via
146 wrapped in the coloring codes for the currently active color scheme.
206 M-x py-version. Versions 4.68 and newer contain the necessary fixes for
147 \N
207 proper IPython support.
148 the 'naked' prompt/history count number: this is just the number
208
149 itself, without any coloring applied to it. This lets you produce
209 The file ipython.el is included with the IPython distribution, in the
150 numbered prompts with your own colors.
210 documentation directory (where this manual resides in PDF and HTML
151 \D
211 formats).
152 the prompt/history count, with the actual digits replaced by dots.
212
153 Used mainly in continuation prompts (prompt_in2)
213 Once you put these files in your Emacs path, all you need in your .emacs
154 \w
214 file is::
155 the current working directory
215
156 \W
216 (require 'ipython)
157 the basename of current working directory
217
158 \Xn
218 This should give you full support for executing code snippets via
159 where $n=0\ldots5.$ The current working directory, with $HOME
219 IPython, opening IPython as your Python shell via ``C-c !``, etc.
160 replaced by ~, and filtered out to contain only $n$ path elements
220
161 \Yn
221 You can customize the arguments passed to the IPython instance at startup by
162 Similar to \Xn, but with the $n+1$ element included if it is ~ (this
222 setting the ``py-python-command-args`` variable. For example, to start always
163 is similar to the behavior of the %cn escapes in tcsh)
223 in ``pylab`` mode with hardcoded light-background colors, you can use::
164 \u
224
165 the username of the current user
225 (setq py-python-command-args '("-pylab" "-colors" "LightBG"))
166 \$
226
167 if the effective UID is 0, a #, otherwise a $
227 If you happen to get garbage instead of colored prompts as described in
168 \h
228 the previous section, you may need to set also in your .emacs file::
169 the hostname up to the first '.'
229
170 \H
230 (setq ansi-color-for-comint-mode t)
171 the hostname
231
172 \n
232 Notes:
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,39 +1,36 b''
1 ==============
1 ============
2 Coding guide
2 Coding guide
3 ==============
3 ============
4
4
5
5 General coding conventions
6 Coding conventions
6 ==========================
7 ==================
8
7
9 In general, we'll try to follow the standard Python style conventions as
8 In general, we'll try to follow the standard Python style conventions as
10 described in Python's `PEP 8`_, the official Python Style Guide.
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:
13 * In a large file, top level classes and functions should be separated by 2
15
16 - In a large file, top level classes and functions should be separated by 2-3
17 lines to make it easier to separate them visually.
14 lines to make it easier to separate them visually.
18
15
19 - Use 4 spaces for indentation, *never* use hard tabs.
16 * Use 4 spaces for indentation, **never** use hard tabs.
20
17
21 - Keep the ordering of methods the same in classes that have the same methods.
18 * Keep the ordering of methods the same in classes that have the same methods.
22 This is particularly true for classes that implement similar interfaces and
19 This is particularly true for classes that implement similar interfaces and
23 for interfaces that are similar.
20 for interfaces that are similar.
24
21
25 Naming conventions
22 Naming conventions
26 ------------------
23 ==================
27
24
28 In terms of naming conventions, we'll follow the guidelines of PEP 8. Some of
25 In terms of naming conventions, we'll follow the guidelines of PEP 8 [PEP8]_.
29 the existing code doesn't honor this perfectly, but for all new IPython code
26 Some of the existing code doesn't honor this perfectly, but for all new
30 (and much existing code is being refactored), we'll use:
27 IPython code (and much existing code is being refactored), we'll use:
31
28
32 - All ``lowercase`` module names.
29 * All ``lowercase`` module names.
33
30
34 - ``CamelCase`` for class names.
31 * ``CamelCase`` for class names.
35
32
36 - ``lowercase_with_underscores`` for methods, functions, variables and
33 * ``lowercase_with_underscores`` for methods, functions, variables and
37 attributes.
34 attributes.
38
35
39 This may be confusing as some of the existing codebase uses a different
36 This may be confusing as some of the existing codebase uses a different
@@ -48,80 +45,6 b' standards at all times. In particular, when subclassing classes that use other'
48 naming conventions, you must follow their naming conventions. To deal with
45 naming conventions, you must follow their naming conventions. To deal with
49 cases like this, we propose the following policy:
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 * If you are subclassing a class that uses different conventions, use its
48 * If you are subclassing a class that uses different conventions, use its
126 naming conventions throughout your subclass. Thus, if you are creating a
49 naming conventions throughout your subclass. Thus, if you are creating a
127 Twisted Protocol class, used Twisted's
50 Twisted Protocol class, used Twisted's
@@ -134,7 +57,7 b' cases like this, we propose the following policy:'
134 sparingly!
57 sparingly!
135
58
136 Implementation-specific *private* methods will use
59 Implementation-specific *private* methods will use
137 ``_single_underscore_prefix``. Names with a leading double underscore will
60 ``_single_underscore_prefix``. Names with a leading double underscore will
138 *only* be used in special cases, as they makes subclassing difficult (such
61 *only* be used in special cases, as they makes subclassing difficult (such
139 names are not easily seen by child classes).
62 names are not easily seen by child classes).
140
63
@@ -148,9 +71,8 b' explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned'
148 upon, as namespaces offer cleaner prefixing. The only case where this approach
71 upon, as namespaces offer cleaner prefixing. The only case where this approach
149 is justified is for classes which are expected to be imported into external
72 is justified is for classes which are expected to be imported into external
150 namespaces and a very generic name (like Shell) is too likely to clash with
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
74 something else. However, if a prefix seems absolutely necessary the more
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
154 specific ``IPY`` or ``ipy`` are preferred.
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,30 +1,38 b''
1 .. _contributing:
2
3 ============================
1 How to contribute to IPython
4 How to contribute to IPython
2 ============================
5 ============================
3
6
7 Overview
8 ========
9
4 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
10 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
5 This makes it easy for people to contribute to the development of IPython.
11 This makes it easy for people to contribute to the development of IPython.
6 There are several ways in which you can join in.
12 There are several ways in which you can join in.
7
13
8 If you have a small change that you want to send to the team, you can edit your
14 If you have a small change that you want to contribute, you can edit your
9 bazaar checkout of IPython (see below) in-place, and ask bazaar for the
15 Bazaar checkout of IPython (see below) in-place, and ask Bazaar for the
10 differences::
16 differences:
17
18 .. code-block:: bash
11
19
12 $ cd /path/to/your/copy/of/ipython
20 $ cd /path/to/your/copy/of/ipython
13 $ bzr diff > my_fixes.diff
21 $ bzr diff > my_fixes.diff
14
22
15 This produces a patch file with your fixes, which we can apply to the source
23 This produces a patch file with your fixes, which we can apply to the source
16 tree. This file should then be attached to a ticket in our `bug tracker
24 tree. This file should then be attached to a ticket in our `bug tracker
17 <https://bugs.launchpad.net/ipython>`_, indicating what it does.
25 <https://bugs.launchpad.net/ipython>`_, indicating what it does.
18
26
19 This model of creating small, self-contained patches works very well and there
27 This model of creating small, self-contained patches works very well and there
20 are open source projects that do their entire development this way. However,
28 are open source projects that do their entire development this way. However,
21 in IPython we have found that for tracking larger changes, making use of
29 in IPython we have found that for tracking larger changes, making use of
22 bazaar's full capabilities in conjunction with Launchpad's code hosting
30 Bazaar's full capabilities in conjunction with Launchpad's code hosting
23 services makes for a much better experience.
31 services makes for a much better experience.
24
32
25 Making your own branch of IPython allows you to refine your changes over time,
33 Making your own branch of IPython allows you to refine your changes over time,
26 track the development of the main team, and propose your own full version of
34 track the development of the main team, and propose your own full version of
27 the code for others to use and review, with a minimum amount of fuss. The next
35 the code for others to use and review, with a minimum amount of fuss. The next
28 parts of this document will explain how to do this.
36 parts of this document will explain how to do this.
29
37
30 Install Bazaar and create a Launchpad account
38 Install Bazaar and create a Launchpad account
@@ -32,7 +40,9 b' Install Bazaar and create a Launchpad account'
32
40
33 First make sure you have installed Bazaar (see their `website
41 First make sure you have installed Bazaar (see their `website
34 <http://bazaar-vcs.org/>`_). To see that Bazaar is installed and knows about
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 $ bzr whoami
47 $ bzr whoami
38 Joe Coder <jcoder@gmail.com>
48 Joe Coder <jcoder@gmail.com>
@@ -46,7 +56,9 b' Get the main IPython branch from Launchpad'
46 ------------------------------------------
56 ------------------------------------------
47
57
48 Now, you can get a copy of the main IPython development branch (we call this
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 $ bzr branch lp:ipython
63 $ bzr branch lp:ipython
52
64
@@ -56,7 +68,9 b' Create a working branch'
56 When working on IPython, you won't actually make edits directly to the
68 When working on IPython, you won't actually make edits directly to the
57 :file:`lp:ipython` branch. Instead, you will create a separate branch for your
69 :file:`lp:ipython` branch. Instead, you will create a separate branch for your
58 changes. For now, let's assume you want to do your work in a branch named
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 $ bzr branch ipython ipython-mybranch
75 $ bzr branch ipython ipython-mybranch
62
76
@@ -70,7 +84,9 b' Make edits in your working branch'
70 Now you are ready to actually make edits in your :file:`ipython-mybranch`
84 Now you are ready to actually make edits in your :file:`ipython-mybranch`
71 branch. Before doing this, it is helpful to install this branch so you can
85 branch. Before doing this, it is helpful to install this branch so you can
72 test your changes as you work. This is easiest if you have setuptools
86 test your changes as you work. This is easiest if you have setuptools
73 installed. Then, just do::
87 installed. Then, just do:
88
89 .. code-block:: bash
74
90
75 $ cd ipython-mybranch
91 $ cd ipython-mybranch
76 $ python setupegg.py develop
92 $ python setupegg.py develop
@@ -78,7 +94,9 b' installed. Then, just do::'
78 Now, make some changes. After a while, you will want to commit your changes.
94 Now, make some changes. After a while, you will want to commit your changes.
79 This let's Bazaar know that you like the changes you have made and gives you
95 This let's Bazaar know that you like the changes you have made and gives you
80 an opportunity to keep a nice record of what you have done. This looks like
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 $ ...do work in ipython-mybranch...
101 $ ...do work in ipython-mybranch...
84 $ bzr commit -m "the commit message goes here"
102 $ bzr commit -m "the commit message goes here"
@@ -98,7 +116,9 b' approach in the commit messages (including the second line being left'
98 As you work, you will repeat this edit/commit cycle many times. If you work on
116 As you work, you will repeat this edit/commit cycle many times. If you work on
99 your branch for a long time, you will also want to get the latest changes from
117 your branch for a long time, you will also want to get the latest changes from
100 the :file:`lp:ipython` branch. This can be done with the following sequence of
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 $ ls
123 $ ls
104 ipython
124 ipython
@@ -110,82 +130,80 b' commands::'
110 $ bzr merge ../ipython
130 $ bzr merge ../ipython
111 $ bzr commit -m "Merging changes from trunk"
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 Post your branch and request a code review
133 Post your branch and request a code review
126 ------------------------------------------
134 ------------------------------------------
127
135
128 Once you are done with your edits, you should post your branch on Launchpad so
136 Once you are done with your edits, you should post your branch on Launchpad so
129 that other IPython developers can review the changes and help you merge your
137 that other IPython developers can review the changes and help you merge your
130 changes into the main development branch. To post your branch on Launchpad,
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 $ cd ipython-mybranch
143 $ cd ipython-mybranch
134 $ bzr push lp:~yourusername/ipython/ipython-mybranch
144 $ bzr push lp:~yourusername/ipython/ipython-mybranch
135
145
136 Then, go to the `IPython Launchpad site <www.launchpad.net/ipython>`_, and you
146 Then, go to the `IPython Launchpad site <http://www.launchpad.net/ipython>`_,
137 should see your branch under the "Code" tab. If you click on your branch, you
147 and you 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 status. Most
148 branch, you can provide a short description of the branch as well as mark its
139 importantly, you should click the link that reads "Propose for merging into
149 status. Most importantly, you should click the link that reads "Propose for
140 another branch". What does this do?
150 merging into another branch". What does this do?
141
151
142 This let's the other IPython developers know that your branch is ready to be
152 This let's the other IPython developers know that your branch is ready to be
143 reviewed and merged into the main development branch. During this review
153 reviewed and merged into the main development branch. During this review
144 process, other developers will give you feedback and help you get your code
154 process, other developers will give you feedback and help you get your code
145 ready to be merged. What types of things will we be looking for:
155 ready to be merged. What types of things will we be looking for:
146
156
147 * All code is documented.
157 * All code is documented. How to document your code is described in
148 * All code has tests.
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 * The entire IPython test suite passes.
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 Once your changes have been reviewed and approved, someone will merge them
167 Once your changes have been reviewed and approved, someone will merge them
152 into the main development branch.
168 into the main development branch.
153
169
154
170
155 Some notes for core developers when merging third-party contributions
171 Merging a branch into trunk
156 =====================================================================
172 ===========================
157
173
158 Core developers, who ultimately merge any approved branch (from themselves,
174 Core developers, who ultimately merge any approved branch (from themselves,
159 another developer, or any third-party contribution) will typically use
175 another developer, or any third-party contribution) will typically use
160 :command:`bzr merge` to merge the branch into the trunk and push it to the
176 :command:`bzr merge` to merge the branch into the trunk and push it to the
161 main Launcphad site. This is a short list of things to keep in mind when doing
177 main Launchpad site. There are a number of things to keep in mind when doing
162 this process, so that the project history is easy to understand in the long
178 this, so that the project history is easy to understand in the long
163 run, and that generating release notes is as painless and accurate as
179 run, and that generating release notes is as painless and accurate as
164 possible.
180 possible.
165
181
166 - When you merge any non-trivial functionality (from one small bug fix to a
182 * When you merge any non-trivial functionality (from one small bug fix to a
167 big feature branch), please remember to always edit the :file:`changes.txt`
183 big feature branch), please remember to always edit the appropriate file in
168 file accordingly. This file has one main section for each release, and if
184 the :ref:`What's new <whatsnew_index>` section of our documentation.
169 you edit it as you go, noting what new features, bug fixes or API changes
185 Ideally, the author of the branch should provide this content when they
170 you have made, the release notes will be almost finished when they are
186 submit the branch for review. But if they don't it is the responsibility of
171 needed later. This is much easier if done when you merge the work, rather
187 the developer doing the merge to add this information.
172 than weeks or months later by re-reading a massive Bazaar log.
188
173
189 * When merges are done, the practice of putting a summary commit message in
174 - When big merges are done, the practice of putting a summary commit message
190 the merge is *extremely* useful. It is probably easiest if you simply use
175 in the merge is *extremely* useful. It makes this kind of job much nicer,
191 the same list of changes that were added to the :ref:`What's new
176 because that summary log message can be almost copy/pasted without changes,
192 <whatsnew_index>` section of the documentation.
177 if it was well written, rather than dissecting the next-level messages from
193
178 the individual commits.
194 * It's important that we remember to always credit who gave us something if
179
180 - It's important that we remember to always credit who gave us something if
181 it's not the committer. In general, we have been fairly good on this front,
195 it's not the committer. In general, we have been fairly good on this front,
182 this is just a reminder to keep things up. As a note, if you are ever
196 this is just a reminder to keep things up. As a note, if you are ever
183 committing something that is completely (or almost so) a third-party
197 committing something that is completely (or almost so) a third-party
184 contribution, do the commit as::
198 contribution, do the commit as::
185
199
186 $ bzr commit --author="Someone Else"
200 $ bzr commit --author="Someone Else"
187
201
188 This way it will show that name separately in the log, which makes it even
202 This way it will show that name separately in the log, which makes it even
189 easier to spot. Obviously we often rework third party contributions
203 easier to spot. Obviously we often rework third party contributions
190 extensively, but this is still good to keep in mind for cases when we don't
204 extensively, but this is still good to keep in mind for cases when we don't
191 touch the code too much. No newline at end of file
205 touch the code too much.
206
207
208 .. [Bazaar] Bazaar. http://bazaar-vcs.org/
209 .. [Launchpad] Launchpad. http://www.launchpad.net/ipython
@@ -8,31 +8,30 b' Standalone documentation'
8 ========================
8 ========================
9
9
10 All standalone documentation should be written in plain text (``.txt``) files
10 All standalone documentation should be written in plain text (``.txt``) files
11 using `reStructuredText`_ for markup and formatting. All such documentation
11 using reStructuredText [reStructuredText]_ for markup and formatting. All such
12 should be placed in the top level directory ``docs`` of the IPython source
12 documentation should be placed in the directory :file:`docs/source` of the
13 tree. Or, when appropriate, a suitably named subdirectory should be used. The
13 IPython source tree. Or, when appropriate, a suitably named subdirectory
14 documentation in this location will serve as the main source for IPython
14 should be used. The documentation in this location will serve as the main
15 documentation and all existing documentation should be converted to this
15 source for IPython documentation.
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.
22
16
23 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
17 The actual HTML and PDF docs are built using the Sphinx [Sphinx]_
24 .. _Sphinx: http://sphinx.pocoo.org/
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
23 $ cd ipython-mybranch/docs
28 documentation`__; we are using a number of Sphinx tools and extensions written
24 $ make html
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.
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 A bit of Python code::
36 A bit of Python code::
38
37
@@ -46,7 +45,6 b' An interactive Python session::'
46 >>> genutils.get_ipython_dir()
45 >>> genutils.get_ipython_dir()
47 '/home/fperez/.ipython'
46 '/home/fperez/.ipython'
48
47
49
50 An IPython session:
48 An IPython session:
51
49
52 .. code-block:: ipython
50 .. code-block:: ipython
@@ -68,12 +66,11 b' A bit of shell code:'
68 echo "My home directory is: $HOME"
66 echo "My home directory is: $HOME"
69 ls
67 ls
70
68
71
72 Docstring format
69 Docstring format
73 ================
70 ================
74
71
75 Good docstrings are very important. Unfortunately, Python itself only provides
72 Good docstrings are very important. Unfortunately, Python itself only provides
76 a rather loose standard for docstrings (`PEP 257`_), and there is no universally
73 a rather loose standard for docstrings [PEP257]_, and there is no universally
77 accepted convention for all the different parts of a complete docstring.
74 accepted convention for all the different parts of a complete docstring.
78 However, the NumPy project has established a very reasonable standard, and has
75 However, the NumPy project has established a very reasonable standard, and has
79 developed some tools to support the smooth inclusion of such docstrings in
76 developed some tools to support the smooth inclusion of such docstrings in
@@ -82,60 +79,26 b' IPython will be henceforth documented using the NumPy conventions; we carry'
82 copies of some of the NumPy support tools to remain self-contained, but share
79 copies of some of the NumPy support tools to remain self-contained, but share
83 back upstream with NumPy any improvements or fixes we may make to the tools.
80 back upstream with NumPy any improvements or fixes we may make to the tools.
84
81
85 The `NumPy documentation guidelines`_ contain detailed information on this
82 The NumPy documentation guidelines [NumPyDocGuide]_ contain detailed
86 standard, and for a quick overview, the NumPy `example docstring`_ is a useful
83 information on this standard, and for a quick overview, the NumPy example
87 read.
84 docstring [NumPyExampleDocstring]_ is a useful read.
88
85
89 As in the past IPython used epydoc, currently many docstrings still use epydoc
86 In the past IPython used epydoc so currently many docstrings still use epydoc
90 conventions. We will update them as we go, but all new code should be fully
87 conventions. We will update them as we go, but all new code should be
91 documented using the NumPy standard.
88 documented using the NumPy standard.
92
89
93 .. _PEP 257: http://www.python.org/peps/pep-0257.html
90 Here are two additional PEPs of interest regarding documentation of code.
94 .. _NumPy documentation guidelines: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
91 While both of these were rejected, the ideas therein form much of the basis of
95
92 docutils (the machinery to process reStructuredText):
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 ------------------------
113
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
93
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 * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
94 * `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
140 * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
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
@@ -5,7 +5,7 b" IPython developer's guide"
5 =========================
5 =========================
6
6
7 .. toctree::
7 .. toctree::
8 :maxdepth: 2
8 :maxdepth: 1
9
9
10 contributing.txt
10 contributing.txt
11 coding_guide.txt
11 coding_guide.txt
@@ -13,13 +13,6 b" IPython developer's guide"
13 testing.txt
13 testing.txt
14 release.txt
14 release.txt
15 roadmap.txt
15 roadmap.txt
16
17 notification_blueprint.txt
18 reorg.txt
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,6 +1,12 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 Most of the release process is automated by the :file:`release` script in the
10 Most of the release process is automated by the :file:`release` script in the
5 :file:`tools` directory. This is just a handy reminder for the release manager.
11 :file:`tools` directory. This is just a handy reminder for the release manager.
6
12
@@ -13,12 +19,13 b' Most of the release process is automated by the :file:`release` script in the'
13 #. Run the release script, which makes the tar.gz, eggs and Win32 .exe
19 #. Run the release script, which makes the tar.gz, eggs and Win32 .exe
14 installer. It posts them to the site and registers the release with PyPI.
20 installer. It posts them to the site and registers the release with PyPI.
15
21
16 #. Updating the website with announcements and links to the updated
22 #. Update the website with announcements and links to the updated changes.txt
17 changes.txt in html form. Remember to put a short note both on the news
23 in html form. Remember to put a short note both on the news page of the
18 page of the site and on Launcphad.
24 site and on Launcphad.
19
25
20 #. Drafting a short release announcement with i) highlights and ii) a link to
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 #. Make sure that the released version of the docs is live on the site.
30 #. Make sure that the released version of the docs is live on the site.
24
31
@@ -1,85 +1,64 b''
1 =============================
1 .. _module_reorg:
2 IPython module reorganization
3 =============================
4
2
5 Currently, IPython has many top-level modules that serve many different
3 ===========================
6 purposes. The lack of organization make it very difficult for developers to
4 IPython module organization
7 work on IPython and understand its design. This document contains notes about
5 ===========================
8 how we will reorganize the modules into sub-packages.
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
11 Subpackage descriptions
13 a library or hack on the IPython internals.
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 * :mod:`IPython.core`. This sub-package contains the core of the IPython
18 that are not used anymore, don't currently work, are unmaintained, etc.
19 interpreter, but none of its extended capabilities.
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
20
36 * :mod:`IPython.kernel`
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.
37
27
38 * :mod:`IPython.testing`
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.
39
31
40 * :mod:`IPython.tests`
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.
41
35
42 * :mod:`IPython.tools`
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.
43
39
44 * :mod:`IPython.UserConfig`
40 * :mod:`IPython.gui`. Another semi-experimental wxPython based IPython GUI.
45
41
46 New Subpackages to be created
42 * :mod:`IPython.kernel`. This contains IPython's parallel computing system.
47 =============================
48
43
49 We propose to create the following new sub-packages:
44 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
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.
50
48
51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
49 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
52 interpreter, but none of its extended capabilities.
50 standards, but that we plan on keeping. To be moved out of this sub-package
51 a module needs to have approval of the core IPython developers, tests and
52 documentation.
53
53
54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
54 * :mod:`IPython.scripts`. This package contains a variety of top-level
55 of the IPython core. These things will go here.
55 command line scripts. Eventually, these should be moved to the
56 :file:`scripts` subdirectory of the appropriate IPython subpackage.
56
57
57 * :mod:`IPython.utils`. This sub-package will contain anything that might
58 * :mod:`IPython.utils`. This sub-package will contain anything that might
58 eventually be found in the Python standard library, like things in
59 eventually be found in the Python standard library, like things in
59 :mod:`genutils`. Each sub-module in this sub-package should contain
60 :mod:`genutils`. Each sub-module in this sub-package should contain
60 functions and classes that serve a single purpose.
61 functions and classes that serve a single purpose and that don't
61
62 depend on things in the rest of IPython.
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.
68
69 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
70 standards, but that we plan on keeping. To be moved out of this sub-package
71 a module needs to have a maintainer, tests and documentation.
72
73 Procedure
74 =========
75
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.
80
81 Status
82 ======
83
63
84 This branch was merged into trunk in early August of 2009.
85
64
@@ -42,26 +42,26 b' Major areas of work'
42 Refactoring the main IPython core
42 Refactoring the main IPython core
43 ---------------------------------
43 ---------------------------------
44
44
45 During the summer of 2009, we began refactoring IPython's core. The main
45 During the summer of 2009, we began refactoring IPython's core. The main
46 thrust in this work was make the IPython core into a set of loosely coupled
46 thrust in this work was to make the IPython core into a set of loosely coupled
47 components. The base component class for this is
47 components. The base component class for this is
48 :class:`IPython.core.component.Component`. This section outlines the status
48 :class:`IPython.core.component.Component`. This section outlines the status of
49 of this work.
49 this work.
50
50
51 Parts of the IPython core that have been turned into components:
51 Parts of the IPython core that have been turned into components:
52
52
53 * The main :class:`InteractiveShell` class.
53 * The main :class:`~IPython.core.iplib.InteractiveShell` class.
54 * The aliases (:mod:`IPython.core.aliases`).
54 * The aliases (:mod:`IPython.core.alias`).
55 * The display and builtin traps (:mod:`IPython.core.display_trap` and
55 * The display and builtin traps (:mod:`IPython.core.display_trap` and
56 :mod:`IPython.core.builtin_trap`).
56 :mod:`IPython.core.builtin_trap`).
57 * The prefilter machinery (:mod:`IPython.core.prefilter`).
57 * The prefilter machinery (:mod:`IPython.core.prefilter`).
58
58
59 Parts of the IPythoncore that need to be turned into components:
59 Parts of the IPythoncore that still need to be turned into components:
60
60
61 * Magics.
61 * Magics.
62 * Input and output history management.
62 * Input and output history management.
63 * Prompts.
63 * Prompts.
64 * Completers.
64 * Tab completers.
65 * Logging.
65 * Logging.
66 * Exception handling.
66 * Exception handling.
67 * Anything else.
67 * Anything else.
@@ -69,6 +69,13 b' Parts of the IPythoncore that need to be turned into components:'
69 Process management for :mod:`IPython.kernel`
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 Performance problems
79 Performance problems
73 --------------------
80 --------------------
74
81
@@ -103,9 +110,9 b' things that will need to be considered when doing such a port especially'
103 if we want to have a codebase that works directly on both 2.x and 3.x.
110 if we want to have a codebase that works directly on both 2.x and 3.x.
104
111
105 1. The syntax for exceptions changed (PEP 3110). The old `except exc, var`
112 1. The syntax for exceptions changed (PEP 3110). The old `except exc, var`
106 changed to `except exc as var`. At last count there was 78 occurrences of this
113 changed to `except exc as var`. At last count there was 78 occurrences of this
107 usage in the code base. This is a particularly problematic issue, because it's
114 usage in the code base. This is a particularly problematic issue, because it's
108 not easy to implement it in a 2.5-compatible way.
115 not easy to implement it in a 2.5-compatible way.
109
116
110 Because it is quite difficult to support simultaneously Python 2.5 and 3.x, we
117 Because it is quite difficult to support simultaneously Python 2.5 and 3.x, we
111 will likely at some point put out a release that requires strictly 2.6 and
118 will likely at some point put out a release that requires strictly 2.6 and
@@ -28,13 +28,14 b' Status'
28 Currently IPython's testing system is being reworked. In the meantime,
28 Currently IPython's testing system is being reworked. In the meantime,
29 we recommend the following testing practices:
29 we recommend the following testing practices:
30
30
31 * To run regular tests, use the :cmd:`nosetests` command on a per file basis:
31 * To run regular tests, use the :command:`nosetests` command that Nose [Nose]_
32 provides on a per file basis:
32
33
33 .. code-block:: bash
34 .. code-block:: bash
34
35
35 nosetests -vvs IPython.core.tests.test_component
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 basis:
39 basis:
39
40
40 .. code-block:: bash
41 .. code-block:: bash
@@ -45,150 +46,9 b' we recommend the following testing practices:'
45 unit tests. They should be subclasses of :class:`unittest.TestCase`.
46 unit tests. They should be subclasses of :class:`unittest.TestCase`.
46
47
47 * Tests of Twisted [Twisted]_ using code should be written by subclassing the
48 * Tests of Twisted [Twisted]_ using code should be written by subclassing the
48 ``TestCase`` class that comes with ``twisted.trial.unittest``.
49 ``TestCase`` class that comes with ``twisted.trial.unittest``. Furthermore,
49
50 all :class:`Deferred` instances that are created in the test must be
50 .. _devel_testing:
51 properly chained and the final one *must* be the return value of the test
51
52 method.
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
67 properly chained and the final one *must* be the return value of the test
68 method.
69
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
53
54 .. [Nose] Nose: a discovery based unittest extension. http://code.google.com/p/python-nose/
@@ -38,16 +38,23 b' optional dependencies:'
38
38
39 .. code-block:: bash
39 .. code-block:: bash
40
40
41 easy_install ipython[kernel,security,test]
41 $ easy_install ipython[kernel,security,test]
42
42
43 This will get Twisted, zope.interface and Foolscap, which are needed for
43 This will get Twisted, zope.interface and Foolscap, which are needed for
44 IPython's parallel computing features as well as the nose package, which will
44 IPython's parallel computing features as well as the nose package, which will
45 enable you to run IPython's test suite. To run IPython's test suite, use the
45 enable you to run IPython's test suite.
46 :command:`iptest` command:
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 .. code-block:: bash
55 .. code-block:: bash
49
56
50 iptest
57 $ iptest
51
58
52 Read on for more specific details and instructions for Windows.
59 Read on for more specific details and instructions for Windows.
53
60
@@ -70,7 +77,7 b' to simple use :command:`easy_install`:'
70
77
71 .. code-block:: bash
78 .. code-block:: bash
72
79
73 easy_install ipython
80 $ easy_install ipython
74
81
75 That's it.
82 That's it.
76
83
@@ -83,9 +90,9 b' just grab the latest stable build of IPython from `here'
83
90
84 .. code-block:: bash
91 .. code-block:: bash
85
92
86 tar -xzf ipython.tar.gz
93 $ tar -xzf ipython.tar.gz
87 cd ipython
94 $ cd ipython
88 python setup.py install
95 $ python setup.py install
89
96
90 If you are installing to a location (like ``/usr/local``) that requires higher
97 If you are installing to a location (like ``/usr/local``) that requires higher
91 permissions, you may need to run the last command with :command:`sudo`.
98 permissions, you may need to run the last command with :command:`sudo`.
@@ -125,9 +132,9 b' need to have Bazaar installed on your system. Then just do:'
125
132
126 .. code-block:: bash
133 .. code-block:: bash
127
134
128 bzr branch lp:ipython
135 $ bzr branch lp:ipython
129 cd ipython
136 $ cd ipython
130 python setup.py install
137 $ python setup.py install
131
138
132 Again, this last step on Windows won't create ``.bat`` files or Start Menu
139 Again, this last step on Windows won't create ``.bat`` files or Start Menu
133 shortcuts, so you will have to use one of the other approaches listed above.
140 shortcuts, so you will have to use one of the other approaches listed above.
@@ -138,7 +145,7 b' step by:'
138
145
139 .. code-block:: bash
146 .. code-block:: bash
140
147
141 python setupegg.py develop
148 $ python setupegg.py develop
142
149
143 This creates links in the right places and installs the command line script to
150 This creates links in the right places and installs the command line script to
144 the appropriate places. Then, if you want to update your IPython at any time,
151 the appropriate places. Then, if you want to update your IPython at any time,
@@ -146,7 +153,7 b' just do:'
146
153
147 .. code-block:: bash
154 .. code-block:: bash
148
155
149 bzr pull
156 $ bzr pull
150
157
151 Basic optional dependencies
158 Basic optional dependencies
152 ===========================
159 ===========================
@@ -183,9 +190,9 b' working :mod:`readline` module, just do (with :mod:`setuptools` installed):'
183
190
184 .. code-block:: bash
191 .. code-block:: bash
185
192
186 easy_install readline
193 $ easy_install readline
187
194
188 .. note:
195 .. note::
189
196
190 Other Python distributions on OS X (such as fink, MacPorts and the
197 Other Python distributions on OS X (such as fink, MacPorts and the
191 official python.org binaries) already have readline installed so
198 official python.org binaries) already have readline installed so
@@ -210,21 +217,27 b' simplest way of getting nose, is to use :command:`easy_install`:'
210
217
211 .. code-block:: bash
218 .. code-block:: bash
212
219
213 easy_install nose
220 $ easy_install nose
214
221
215 Another way of getting this is to do:
222 Another way of getting this is to do:
216
223
217 .. code-block:: bash
224 .. code-block:: bash
218
225
219 easy_install ipython[test]
226 $ easy_install ipython[test]
220
227
221 For more installation options, see the `nose website
228 For more installation options, see the `nose website
222 <http://somethingaboutorange.com/mrl/projects/nose/>`_. Once you have nose
229 <http://somethingaboutorange.com/mrl/projects/nose/>`_.
223 installed, you can run IPython's test suite using the iptest command:
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 .. code-block:: bash
238 .. code-block:: bash
226
239
227 iptest
240 $ iptest
228
241
229 pexpect
242 pexpect
230 -------
243 -------
@@ -234,7 +247,7 b" The `pexpect <http://www.noah.org/wiki/Pexpect>`_ package is used in IPython's"
234
247
235 .. code-block:: bash
248 .. code-block:: bash
236
249
237 easy_install pexpect
250 $ easy_install pexpect
238
251
239 Windows users are out of luck as pexpect does not run there.
252 Windows users are out of luck as pexpect does not run there.
240
253
@@ -255,8 +268,8 b' On a Unix style platform (including OS X), if you want to use'
255
268
256 .. code-block:: bash
269 .. code-block:: bash
257
270
258 easy_install ipython[kernel] # the first three
271 $ easy_install ipython[kernel] # the first three
259 easy_install ipython[security] # pyOpenSSL
272 $ easy_install ipython[security] # pyOpenSSL
260
273
261 zope.interface and Twisted
274 zope.interface and Twisted
262 --------------------------
275 --------------------------
@@ -267,13 +280,13 b' getting the these is to use :command:`easy_install`:'
267
280
268 .. code-block:: bash
281 .. code-block:: bash
269
282
270 easy_install zope.interface
283 $ easy_install zope.interface
271 easy_install Twisted
284 $ easy_install Twisted
272
285
273 Of course, you can also download the source tarballs from the Twisted website
286 Of course, you can also download the source tarballs from the Twisted website
274 [Twisted]_ and the `zope.interface page at PyPI
287 [Twisted]_ and the
275 <http://pypi.python.org/pypi/zope.interface>`_ and do the usual ``python
288 `zope.interface page at PyPI <http://pypi.python.org/pypi/zope.interface>`_
276 setup.py install`` if you prefer.
289 and do the usual ``python setup.py install`` if you prefer.
277
290
278 Windows is a bit different. For zope.interface and Twisted, simply get the
291 Windows is a bit different. For zope.interface and Twisted, simply get the
279 latest binary ``.exe`` installer from the Twisted website. This installer
292 latest binary ``.exe`` installer from the Twisted website. This installer
@@ -288,7 +301,7 b' On all platforms a simple:'
288
301
289 .. code-block:: bash
302 .. code-block:: bash
290
303
291 easy_install foolscap
304 $ easy_install foolscap
292
305
293 should work. You can also download the source tarballs from the `Foolscap
306 should work. You can also download the source tarballs from the `Foolscap
294 website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install``
307 website <http://foolscap.lothar.com/trac>`_ and do ``python setup.py install``
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now