##// END OF EJS Templates
Updating development.txt with a short description of a typical IPython development workflow using...
Brian E Granger -
Show More
@@ -1,315 +1,344 b''
1 1 .. _development:
2 2
3 3 ==================================
4 4 IPython development guidelines
5 5 ==================================
6 6
7 7 .. contents::
8 ..
9 1 Overview
10 2 Project organization
11 2.1 Subpackages
12 2.2 Installation and dependencies
13 2.3 Specific subpackages
14 3 Version control
15 4 Documentation
16 4.1 Standalone documentation
17 4.2 Docstring format
18 5 Coding conventions
19 5.1 General
20 5.2 Naming conventions
21 6 Testing
22 7 Configuration
23 ..
24 8
25 9
26 10 Overview
27 11 ========
28 12
29 13 IPython is the next generation of IPython. It is named such for two reasons:
30 14
31 15 - Eventually, IPython will become IPython version 1.0.
32 16 - This new code base needs to be able to co-exist with the existing IPython until
33 17 it is a full replacement for it. Thus we needed a different name. We couldn't
34 18 use ``ipython`` (lowercase) as some files systems are case insensitive.
35 19
36 20 There are two, no three, main goals of the IPython effort:
37 21
38 22 1. Clean up the existing codebase and write lots of tests.
39 23 2. Separate the core functionality of IPython from the terminal to enable IPython
40 24 to be used from within a variety of GUI applications.
41 25 3. Implement a system for interactive parallel computing.
42 26
43 27 While the third goal may seem a bit unrelated to the main focus of IPython, it turns
44 28 out that the technologies required for this goal are nearly identical with those
45 29 required for goal two. This is the main reason the interactive parallel computing
46 30 capabilities are being put into IPython proper. Currently the third of these goals is
47 31 furthest along.
48 32
49 33 This document describes IPython from the perspective of developers.
50 34
51 35
52 36 Project organization
53 37 ====================
54 38
55 39 Subpackages
56 40 -----------
57 41
58 42 IPython is organized into semi self-contained subpackages. Each of the subpackages will have its own:
59 43
60 44 - **Dependencies**. One of the most important things to keep in mind in
61 45 partitioning code amongst subpackages, is that they should be used to cleanly
62 46 encapsulate dependencies.
63 47 - **Tests**. Each subpackage shoud have its own ``tests`` subdirectory that
64 48 contains all of the tests for that package. For information about writing tests
65 49 for IPython, see the `Testing System`_ section of this document.
66 50 - **Configuration**. Each subpackage should have its own ``config`` subdirectory
67 51 that contains the configuration information for the components of the
68 52 subpackage. For information about how the IPython configuration system
69 53 works, see the `Configuration System`_ section of this document.
70 54 - **Scripts**. Each subpackage should have its own ``scripts`` subdirectory that
71 55 contains all of the command line scripts associated with the subpackage.
72 56
73 57 Installation and dependencies
74 58 -----------------------------
75 59
76 60 IPython will not use `setuptools`_ for installation. Instead, we will use standard
77 61 ``setup.py`` scripts that use `distutils`_. While there are a number a extremely nice
78 62 features that `setuptools`_ has (like namespace packages), the current implementation
79 63 of `setuptools`_ has performance problems, particularly on shared file systems. In
80 64 particular, when Python packages are installed on NSF file systems, import times
81 65 become much too long (up towards 10 seconds).
82 66
83 67 Because IPython is being used extensively in the context of high performance
84 68 computing, where performance is critical but shared file systems are common, we feel
85 69 these performance hits are not acceptable. Thus, until the performance problems
86 70 associated with `setuptools`_ are addressed, we will stick with plain `distutils`_. We
87 71 are hopeful that these problems will be addressed and that we will eventually begin
88 72 using `setuptools`_. Because of this, we are trying to organize IPython in a way that
89 73 will make the eventual transition to `setuptools`_ as painless as possible.
90 74
91 75 Because we will be using `distutils`_, there will be no method for automatically installing dependencies. Instead, we are following the approach of `Matplotlib`_ which can be summarized as follows:
92 76
93 77 - Distinguish between required and optional dependencies. However, the required
94 78 dependencies for IPython should be only the Python standard library.
95 79 - Upon installation check to see which optional dependencies are present and tell
96 80 the user which parts of IPython need which optional dependencies.
97 81
98 82 It is absolutely critical that each subpackage of IPython has a clearly specified set
99 83 of dependencies and that dependencies are not carelessly inherited from other IPython
100 84 subpackages. Furthermore, tests that have certain dependencies should not fail if
101 85 those dependencies are not present. Instead they should be skipped and print a
102 86 message.
103 87
104 88 .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
105 89 .. _distutils: http://docs.python.org/lib/module-distutils.html
106 90 .. _Matplotlib: http://matplotlib.sourceforge.net/
107 91
108 92 Specific subpackages
109 93 --------------------
110 94
111 95 ``core``
112 96 This is the core functionality of IPython that is independent of the
113 97 terminal, network and GUIs. Most of the code that is in the current
114 98 IPython trunk will be refactored, cleaned up and moved here.
115 99
116 100 ``kernel``
117 101 The enables the IPython core to be expose to a the network. This is
118 102 also where all of the parallel computing capabilities are to be found.
119 103
120 104 ``config``
121 105 The configuration package used by IPython.
122 106
123 107 ``frontends``
124 108 The various frontends for IPython. A frontend is the end-user application
125 109 that exposes the capabilities of IPython to the user. The most basic frontend
126 110 will simply be a terminal based application that looks just like today 's
127 111 IPython. Other frontends will likely be more powerful and based on GUI toolkits.
128 112
129 113 ``notebook``
130 114 An application that allows users to work with IPython notebooks.
131 115
132 116 ``tools``
133 117 This is where general utilities go.
134 118
135 119
136 120 Version control
137 121 ===============
138 122
139 In the past, IPython development has been done using `Subversion`__. We are currently trying out `Bazaar`__ and `Launchpad`__.
123 In the past, IPython development has been done using `Subversion`__. Recently, we made the transition to using `Bazaar`__ and `Launchpad`__. This makes it much easier for people
124 to contribute code to IPython. Here is a sketch of how to use Bazaar for IPython
125 development. First, you should install Bazaar. After you have done that, make
126 sure that it is working by getting the latest main branch of IPython::
127
128 $ bzr branch lp:ipython
129
130 Now you can create a new branch for you to do your work in::
131
132 $ bzr branch ipython ipython-mybranch
133
134 The typical work cycle in this branch will be to make changes in `ipython-mybranch`
135 and then commit those changes using the commit command::
136
137 $ ...do work in ipython-mybranch...
138 $ bzr ci -m "the commit message goes here"
139
140 While working with this branch, it is a good idea to merge in changes that have been
141 made upstream in the parent branch. This can be done by doing::
142
143 $ bzr pull
144
145 If this command shows that the branches have diverged, then you should do a merge
146 instead::
147
148 $ bzr merge lp:ipython
149
150 If you want others to be able to see your branch, you can create an account with
151 launchpad and push the branch to your own workspace::
152
153 $ bzr push bzr+ssh://<me>@bazaar.launchpad.net/~<me>/+junk/ipython-mybranch
154
155 Finally, once the work in your branch is done, you can merge your changes back into
156 the `ipython` branch by using merge::
157
158 $ cd ipython
159 $ merge ../ipython-mybranch
160 [resolve any conflicts]
161 $ bzr ci -m "Fixing that bug"
162 $ bzr push
163
164 But this will require you to have write permissions to the `ipython` branch. It you don't
165 you can tell one of the IPython devs about your branch and they can do the merge for you.
166
167 More information about Bazaar workflows can be found `here`__.
140 168
141 169 .. __: http://subversion.tigris.org/
142 170 .. __: http://bazaar-vcs.org/
143 171 .. __: http://www.launchpad.net/ipython
172 .. __: http://doc.bazaar-vcs.org/bzr.dev/en/user-guide/index.html
144 173
145 174 Documentation
146 175 =============
147 176
148 177 Standalone documentation
149 178 ------------------------
150 179
151 180 All standalone documentation should be written in plain text (``.txt``) files using
152 181 `reStructuredText`_ for markup and formatting. All such documentation should be placed
153 182 in the top level directory ``docs`` of the IPython source tree. Or, when appropriate,
154 183 a suitably named subdirectory should be used. The documentation in this location will
155 184 serve as the main source for IPython documentation and all existing documentation
156 185 should be converted to this format.
157 186
158 187 In the future, the text files in the ``docs`` directory will be used to generate all
159 188 forms of documentation for IPython. This include documentation on the IPython website
160 189 as well as *pdf* documentation.
161 190
162 191 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
163 192
164 193 Docstring format
165 194 ----------------
166 195
167 196 Good docstrings are very important. All new code will use `Epydoc`_ for generating API
168 197 docs, so we will follow the `Epydoc`_ conventions. More specifically, we will use
169 198 `reStructuredText`_ for markup and formatting, since it is understood by a wide
170 199 variety of tools. This means that if in the future we have any reason to change from
171 200 `Epydoc`_ to something else, we'll have fewer transition pains.
172 201
173 202 Details about using `reStructuredText`_ for docstrings can be found `here
174 203 <http://epydoc.sourceforge.net/manual-othermarkup.html>`_.
175 204
176 205 .. _Epydoc: http://epydoc.sourceforge.net/
177 206
178 207 Additional PEPs of interest regarding documentation of code:
179 208
180 209 - `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_
181 210 - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
182 211 - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
183 212
184 213
185 214 Coding conventions
186 215 ==================
187 216
188 217 General
189 218 -------
190 219
191 220 In general, we'll try to follow the standard Python style conventions as described here:
192 221
193 222 - `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_
194 223
195 224
196 225 Other comments:
197 226
198 227 - In a large file, top level classes and functions should be
199 228 separated by 2-3 lines to make it easier to separate them visually.
200 229 - Use 4 spaces for indentation.
201 230 - Keep the ordering of methods the same in classes that have the same
202 231 methods. This is particularly true for classes that implement
203 232 similar interfaces and for interfaces that are similar.
204 233
205 234 Naming conventions
206 235 ------------------
207 236
208 237 In terms of naming conventions, we'll follow the guidelines from the `Style Guide for
209 238 Python Code`_.
210 239
211 240 For all new IPython code (and much existing code is being refactored), we'll use:
212 241
213 242 - All ``lowercase`` module names.
214 243
215 244 - ``CamelCase`` for class names.
216 245
217 246 - ``lowercase_with_underscores`` for methods, functions, variables and attributes.
218 247
219 248 This may be confusing as most of the existing IPython codebase uses a different convention (``lowerCamelCase`` for methods and attributes). Slowly, we will move IPython over to the new
220 249 convention, providing shadow names for backward compatibility in public interfaces.
221 250
222 251 There are, however, some important exceptions to these rules. In some cases, IPython
223 252 code will interface with packages (Twisted, Wx, Qt) that use other conventions. At some level this makes it impossible to adhere to our own standards at all times. In particular, when subclassing classes that use other naming conventions, you must follow their naming conventions. To deal with cases like this, we propose the following policy:
224 253
225 254 - If you are subclassing a class that uses different conventions, use its
226 255 naming conventions throughout your subclass. Thus, if you are creating a
227 256 Twisted Protocol class, used Twisted's ``namingSchemeForMethodsAndAttributes.``
228 257
229 258 - All IPython's official interfaces should use our conventions. In some cases
230 259 this will mean that you need to provide shadow names (first implement ``fooBar``
231 260 and then ``foo_bar = fooBar``). We want to avoid this at all costs, but it
232 261 will probably be necessary at times. But, please use this sparingly!
233 262
234 263 Implementation-specific *private* methods will use ``_single_underscore_prefix``.
235 264 Names with a leading double underscore will *only* be used in special cases, as they
236 265 makes subclassing difficult (such names are not easily seen by child classes).
237 266
238 267 Occasionally some run-in lowercase names are used, but mostly for very short names or
239 268 where we are implementing methods very similar to existing ones in a base class (like
240 269 ``runlines()`` where ``runsource()`` and ``runcode()`` had established precedent).
241 270
242 271 The old IPython codebase has a big mix of classes and modules prefixed with an
243 272 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned upon, as
244 273 namespaces offer cleaner prefixing. The only case where this approach is justified is
245 274 for classes which are expected to be imported into external namespaces and a very
246 275 generic name (like Shell) is too likely to clash with something else. We'll need to
247 276 revisit this issue as we clean up and refactor the code, but in general we should
248 277 remove as many unnecessary ``IP``/``ip`` prefixes as possible. However, if a prefix
249 278 seems absolutely necessary the more specific ``IPY`` or ``ipy`` are preferred.
250 279
251 280 .. _devel_testing:
252 281
253 282 Testing system
254 283 ==============
255 284
256 285 It is extremely important that all code contributed to IPython has tests. Tests should
257 286 be written as unittests, doctests or as entities that the `Nose`_ testing package will
258 287 find. Regardless of how the tests are written, we will use `Nose`_ for discovering and
259 288 running the tests. `Nose`_ will be required to run the IPython test suite, but will
260 289 not be required to simply use IPython.
261 290
262 291 .. _Nose: http://code.google.com/p/python-nose/
263 292
264 293 Tests of `Twisted`__ using code should be written by subclassing the ``TestCase`` class
265 294 that comes with ``twisted.trial.unittest``. When this is done, `Nose`_ will be able to
266 295 run the tests and the twisted reactor will be handled correctly.
267 296
268 297 .. __: http://www.twistedmatrix.com
269 298
270 299 Each subpackage in IPython should have its own ``tests`` directory that contains all
271 300 of the tests for that subpackage. This allows each subpackage to be self-contained. If
272 301 a subpackage has any dependencies beyond the Python standard library, the tests for
273 302 that subpackage should be skipped if the dependencies are not found. This is very
274 303 important so users don't get tests failing simply because they don't have dependencies.
275 304
276 305 We also need to look into use Noses ability to tag tests to allow a more modular
277 306 approach of running tests.
278 307
279 308 .. _devel_config:
280 309
281 310 Configuration system
282 311 ====================
283 312
284 313 IPython uses `.ini`_ files for configuration purposes. This represents a huge
285 314 improvement over the configuration system used in IPython. IPython works with these
286 315 files using the `ConfigObj`_ package, which IPython includes as
287 316 ``ipython1/external/configobj.py``.
288 317
289 318 Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of IPython
290 319 should contain a ``config`` subdirectory that contains all of the configuration
291 320 information for the subpackage. To see how configuration information is defined (along
292 321 with defaults) see at the examples in ``ipython1/kernel/config`` and
293 322 ``ipython1/core/config``. Likewise, to see how the configuration information is used,
294 323 see examples in ``ipython1/kernel/scripts/ipengine.py``.
295 324
296 325 Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We are
297 326 calling this new layer, ``tconfig``, as it will use a `Traits`_-like validation model.
298 327 We won't actually use `Traits`_, but will implement something similar in pure Python.
299 328 But, even in this new system, we will still use `ConfigObj`_ and `.ini`_ files
300 329 underneath the hood. Talk to Fernando if you are interested in working on this part of
301 330 IPython. The current prototype of ``tconfig`` is located in the IPython sandbox.
302 331
303 332 .. _.ini: http://docs.python.org/lib/module-ConfigParser.html
304 333 .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html
305 334 .. _Traits: http://code.enthought.com/traits/
306 335
307 336
308 337
309 338
310 339
311 340
312 341
313 342
314 343
315 344
General Comments 0
You need to be logged in to leave comments. Login now