##// END OF EJS Templates
Added a python3.0 porting section to the development.txt document
Jorgen Stenarson -
Show More
@@ -1,446 +1,461 b''
1 1 .. _development:
2 2
3 3 ==============================
4 4 IPython development guidelines
5 5 ==============================
6 6
7 7
8 8 Overview
9 9 ========
10 10
11 11 IPython is the next generation of IPython. It is named such for two reasons:
12 12
13 13 - Eventually, IPython will become IPython version 1.0.
14 14 - This new code base needs to be able to co-exist with the existing IPython until
15 15 it is a full replacement for it. Thus we needed a different name. We couldn't
16 16 use ``ipython`` (lowercase) as some files systems are case insensitive.
17 17
18 18 There are two, no three, main goals of the IPython effort:
19 19
20 20 1. Clean up the existing codebase and write lots of tests.
21 21 2. Separate the core functionality of IPython from the terminal to enable IPython
22 22 to be used from within a variety of GUI applications.
23 23 3. Implement a system for interactive parallel computing.
24 24
25 25 While the third goal may seem a bit unrelated to the main focus of IPython, it
26 26 turns out that the technologies required for this goal are nearly identical
27 27 with those required for goal two. This is the main reason the interactive
28 28 parallel computing capabilities are being put into IPython proper. Currently
29 29 the third of these goals is furthest along.
30 30
31 31 This document describes IPython from the perspective of developers.
32 32
33 33
34 34 Project organization
35 35 ====================
36 36
37 37 Subpackages
38 38 -----------
39 39
40 40 IPython is organized into semi self-contained subpackages. Each of the
41 41 subpackages will have its own:
42 42
43 43 - **Dependencies**. One of the most important things to keep in mind in
44 44 partitioning code amongst subpackages, is that they should be used to cleanly
45 45 encapsulate dependencies.
46 46
47 47 - **Tests**. Each subpackage shoud have its own ``tests`` subdirectory that
48 48 contains all of the tests for that package. For information about writing
49 49 tests for IPython, see the `Testing System`_ section of this document.
50 50
51 51 - **Configuration**. Each subpackage should have its own ``config``
52 52 subdirectory that contains the configuration information for the components
53 53 of the subpackage. For information about how the IPython configuration
54 54 system works, see the `Configuration System`_ section of this document.
55 55
56 56 - **Scripts**. Each subpackage should have its own ``scripts`` subdirectory
57 57 that contains all of the command line scripts associated with the subpackage.
58 58
59 59 Installation and dependencies
60 60 -----------------------------
61 61
62 62 IPython will not use `setuptools`_ for installation. Instead, we will use
63 63 standard ``setup.py`` scripts that use `distutils`_. While there are a number a
64 64 extremely nice features that `setuptools`_ has (like namespace packages), the
65 65 current implementation of `setuptools`_ has performance problems, particularly
66 66 on shared file systems. In particular, when Python packages are installed on
67 67 NSF file systems, import times become much too long (up towards 10 seconds).
68 68
69 69 Because IPython is being used extensively in the context of high performance
70 70 computing, where performance is critical but shared file systems are common, we
71 71 feel these performance hits are not acceptable. Thus, until the performance
72 72 problems associated with `setuptools`_ are addressed, we will stick with plain
73 73 `distutils`_. We are hopeful that these problems will be addressed and that we
74 74 will eventually begin using `setuptools`_. Because of this, we are trying to
75 75 organize IPython in a way that will make the eventual transition to
76 76 `setuptools`_ as painless as possible.
77 77
78 78 Because we will be using `distutils`_, there will be no method for
79 79 automatically installing dependencies. Instead, we are following the approach
80 80 of `Matplotlib`_ which can be summarized as follows:
81 81
82 82 - Distinguish between required and optional dependencies. However, the required
83 83 dependencies for IPython should be only the Python standard library.
84 84
85 85 - Upon installation check to see which optional dependencies are present and
86 86 tell the user which parts of IPython need which optional dependencies.
87 87
88 88 It is absolutely critical that each subpackage of IPython has a clearly
89 89 specified set of dependencies and that dependencies are not carelessly
90 90 inherited from other IPython subpackages. Furthermore, tests that have certain
91 91 dependencies should not fail if those dependencies are not present. Instead
92 92 they should be skipped and print a message.
93 93
94 94 .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
95 95 .. _distutils: http://docs.python.org/lib/module-distutils.html
96 96 .. _Matplotlib: http://matplotlib.sourceforge.net/
97 97
98 98 Specific subpackages
99 99 --------------------
100 100
101 101 ``core``
102 102 This is the core functionality of IPython that is independent of the
103 103 terminal, network and GUIs. Most of the code that is in the current
104 104 IPython trunk will be refactored, cleaned up and moved here.
105 105
106 106 ``kernel``
107 107 The enables the IPython core to be expose to a the network. This is
108 108 also where all of the parallel computing capabilities are to be found.
109 109
110 110 ``config``
111 111 The configuration package used by IPython.
112 112
113 113 ``frontends``
114 114 The various frontends for IPython. A frontend is the end-user application
115 115 that exposes the capabilities of IPython to the user. The most basic
116 116 frontend will simply be a terminal based application that looks just like
117 117 today 's IPython. Other frontends will likely be more powerful and based
118 118 on GUI toolkits.
119 119
120 120 ``notebook``
121 121 An application that allows users to work with IPython notebooks.
122 122
123 123 ``tools``
124 124 This is where general utilities go.
125 125
126 126
127 127 Version control
128 128 ===============
129 129
130 130 In the past, IPython development has been done using `Subversion`__. Recently,
131 131 we made the transition to using `Bazaar`__ and `Launchpad`__. This makes it
132 132 much easier for people to contribute code to IPython. Here is a sketch of how
133 133 to use Bazaar for IPython development. First, you should install Bazaar.
134 134 After you have done that, make sure that it is working by getting the latest
135 135 main branch of IPython::
136 136
137 137 $ bzr branch lp:ipython
138 138
139 139 Now you can create a new branch for you to do your work in::
140 140
141 141 $ bzr branch ipython ipython-mybranch
142 142
143 143 The typical work cycle in this branch will be to make changes in
144 144 ``ipython-mybranch`` and then commit those changes using the commit command::
145 145
146 146 $ ...do work in ipython-mybranch...
147 147 $ bzr ci -m "the commit message goes here"
148 148
149 149 Please note that since we now don't use an old-style linear ChangeLog (that
150 150 tends to cause problems with distributed version control systems), you should
151 151 ensure that your log messages are reasonably detailed. Use a docstring-like
152 152 approach in the commit messages (including the second line being left
153 153 *blank*)::
154 154
155 155 Single line summary of changes being committed.
156 156
157 157 - more details when warranted ...
158 158 - including crediting outside contributors if they sent the
159 159 code/bug/idea!
160 160
161 161 If we couple this with a policy of making single commits for each reasonably
162 162 atomic change, the bzr log should give an excellent view of the project, and
163 163 the `--short` log option becomes a nice summary.
164 164
165 165 While working with this branch, it is a good idea to merge in changes that have
166 166 been made upstream in the parent branch. This can be done by doing::
167 167
168 168 $ bzr pull
169 169
170 170 If this command shows that the branches have diverged, then you should do a
171 171 merge instead::
172 172
173 173 $ bzr merge lp:ipython
174 174
175 175 If you want others to be able to see your branch, you can create an account
176 176 with launchpad and push the branch to your own workspace::
177 177
178 178 $ bzr push bzr+ssh://<me>@bazaar.launchpad.net/~<me>/+junk/ipython-mybranch
179 179
180 180 Finally, once the work in your branch is done, you can merge your changes back
181 181 into the `ipython` branch by using merge::
182 182
183 183 $ cd ipython
184 184 $ merge ../ipython-mybranch
185 185 [resolve any conflicts]
186 186 $ bzr ci -m "Fixing that bug"
187 187 $ bzr push
188 188
189 189 But this will require you to have write permissions to the `ipython` branch.
190 190 It you don't you can tell one of the IPython devs about your branch and they
191 191 can do the merge for you.
192 192
193 193 More information about Bazaar workflows can be found `here`__.
194 194
195 195 .. __: http://subversion.tigris.org/
196 196 .. __: http://bazaar-vcs.org/
197 197 .. __: http://www.launchpad.net/ipython
198 198 .. __: http://doc.bazaar-vcs.org/bzr.dev/en/user-guide/index.html
199 199
200 200 Documentation
201 201 =============
202 202
203 203 Standalone documentation
204 204 ------------------------
205 205
206 206 All standalone documentation should be written in plain text (``.txt``) files
207 207 using `reStructuredText`_ for markup and formatting. All such documentation
208 208 should be placed in the top level directory ``docs`` of the IPython source
209 209 tree. Or, when appropriate, a suitably named subdirectory should be used. The
210 210 documentation in this location will serve as the main source for IPython
211 211 documentation and all existing documentation should be converted to this
212 212 format.
213 213
214 214 In the future, the text files in the ``docs`` directory will be used to
215 215 generate all forms of documentation for IPython. This include documentation on
216 216 the IPython website as well as *pdf* documentation.
217 217
218 218 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
219 219
220 220 Docstring format
221 221 ----------------
222 222
223 223 Good docstrings are very important. All new code will use `Epydoc`_ for
224 224 generating API docs, so we will follow the `Epydoc`_ conventions. More
225 225 specifically, we will use `reStructuredText`_ for markup and formatting, since
226 226 it is understood by a wide variety of tools. This means that if in the future
227 227 we have any reason to change from `Epydoc`_ to something else, we'll have fewer
228 228 transition pains.
229 229
230 230 Details about using `reStructuredText`_ for docstrings can be found `here
231 231 <http://epydoc.sourceforge.net/manual-othermarkup.html>`_.
232 232
233 233 .. _Epydoc: http://epydoc.sourceforge.net/
234 234
235 235 Additional PEPs of interest regarding documentation of code:
236 236
237 237 - `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_
238 238 - `Docstring Processing System Framework <http://www.python.org/peps/pep-0256.html>`_
239 239 - `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_
240 240
241 241
242 242 Coding conventions
243 243 ==================
244 244
245 245 General
246 246 -------
247 247
248 248 In general, we'll try to follow the standard Python style conventions as
249 249 described here:
250 250
251 251 - `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_
252 252
253 253
254 254 Other comments:
255 255
256 256 - In a large file, top level classes and functions should be
257 257 separated by 2-3 lines to make it easier to separate them visually.
258 258 - Use 4 spaces for indentation.
259 259 - Keep the ordering of methods the same in classes that have the same
260 260 methods. This is particularly true for classes that implement
261 261 similar interfaces and for interfaces that are similar.
262 262
263 263 Naming conventions
264 264 ------------------
265 265
266 266 In terms of naming conventions, we'll follow the guidelines from the `Style
267 267 Guide for Python Code`_.
268 268
269 269 For all new IPython code (and much existing code is being refactored), we'll use:
270 270
271 271 - All ``lowercase`` module names.
272 272
273 273 - ``CamelCase`` for class names.
274 274
275 275 - ``lowercase_with_underscores`` for methods, functions, variables and
276 276 attributes.
277 277
278 278 This may be confusing as most of the existing IPython codebase uses a different
279 279 convention (``lowerCamelCase`` for methods and attributes). Slowly, we will
280 280 move IPython over to the new convention, providing shadow names for backward
281 281 compatibility in public interfaces.
282 282
283 283 There are, however, some important exceptions to these rules. In some cases,
284 284 IPython code will interface with packages (Twisted, Wx, Qt) that use other
285 285 conventions. At some level this makes it impossible to adhere to our own
286 286 standards at all times. In particular, when subclassing classes that use other
287 287 naming conventions, you must follow their naming conventions. To deal with
288 288 cases like this, we propose the following policy:
289 289
290 290 - If you are subclassing a class that uses different conventions, use its
291 291 naming conventions throughout your subclass. Thus, if you are creating a
292 292 Twisted Protocol class, used Twisted's
293 293 ``namingSchemeForMethodsAndAttributes.``
294 294
295 295 - All IPython's official interfaces should use our conventions. In some cases
296 296 this will mean that you need to provide shadow names (first implement
297 297 ``fooBar`` and then ``foo_bar = fooBar``). We want to avoid this at all
298 298 costs, but it will probably be necessary at times. But, please use this
299 299 sparingly!
300 300
301 301 Implementation-specific *private* methods will use
302 302 ``_single_underscore_prefix``. Names with a leading double underscore will
303 303 *only* be used in special cases, as they makes subclassing difficult (such
304 304 names are not easily seen by child classes).
305 305
306 306 Occasionally some run-in lowercase names are used, but mostly for very short
307 307 names or where we are implementing methods very similar to existing ones in a
308 308 base class (like ``runlines()`` where ``runsource()`` and ``runcode()`` had
309 309 established precedent).
310 310
311 311 The old IPython codebase has a big mix of classes and modules prefixed with an
312 312 explicit ``IP``. In Python this is mostly unnecessary, redundant and frowned
313 313 upon, as namespaces offer cleaner prefixing. The only case where this approach
314 314 is justified is for classes which are expected to be imported into external
315 315 namespaces and a very generic name (like Shell) is too likely to clash with
316 316 something else. We'll need to revisit this issue as we clean up and refactor
317 317 the code, but in general we should remove as many unnecessary ``IP``/``ip``
318 318 prefixes as possible. However, if a prefix seems absolutely necessary the more
319 319 specific ``IPY`` or ``ipy`` are preferred.
320 320
321 321 .. _devel_testing:
322 322
323 323 Testing system
324 324 ==============
325 325
326 326 It is extremely important that all code contributed to IPython has tests. Tests
327 327 should be written as unittests, doctests or as entities that the `Nose`_
328 328 testing package will find. Regardless of how the tests are written, we will use
329 329 `Nose`_ for discovering and running the tests. `Nose`_ will be required to run
330 330 the IPython test suite, but will not be required to simply use IPython.
331 331
332 332 .. _Nose: http://code.google.com/p/python-nose/
333 333
334 334 Tests of `Twisted`__ using code should be written by subclassing the
335 335 ``TestCase`` class that comes with ``twisted.trial.unittest``. When this is
336 336 done, `Nose`_ will be able to run the tests and the twisted reactor will be
337 337 handled correctly.
338 338
339 339 .. __: http://www.twistedmatrix.com
340 340
341 341 Each subpackage in IPython should have its own ``tests`` directory that
342 342 contains all of the tests for that subpackage. This allows each subpackage to
343 343 be self-contained. If a subpackage has any dependencies beyond the Python
344 344 standard library, the tests for that subpackage should be skipped if the
345 345 dependencies are not found. This is very important so users don't get tests
346 346 failing simply because they don't have dependencies.
347 347
348 348 We also need to look into use Noses ability to tag tests to allow a more
349 349 modular approach of running tests.
350 350
351 351 .. _devel_config:
352 352
353 353 Configuration system
354 354 ====================
355 355
356 356 IPython uses `.ini`_ files for configuration purposes. This represents a huge
357 357 improvement over the configuration system used in IPython. IPython works with
358 358 these files using the `ConfigObj`_ package, which IPython includes as
359 359 ``ipython1/external/configobj.py``.
360 360
361 361 Currently, we are using raw `ConfigObj`_ objects themselves. Each subpackage of
362 362 IPython should contain a ``config`` subdirectory that contains all of the
363 363 configuration information for the subpackage. To see how configuration
364 364 information is defined (along with defaults) see at the examples in
365 365 ``ipython1/kernel/config`` and ``ipython1/core/config``. Likewise, to see how
366 366 the configuration information is used, see examples in
367 367 ``ipython1/kernel/scripts/ipengine.py``.
368 368
369 369 Eventually, we will add a new layer on top of the raw `ConfigObj`_ objects. We
370 370 are calling this new layer, ``tconfig``, as it will use a `Traits`_-like
371 371 validation model. We won't actually use `Traits`_, but will implement
372 372 something similar in pure Python. But, even in this new system, we will still
373 373 use `ConfigObj`_ and `.ini`_ files underneath the hood. Talk to Fernando if you
374 374 are interested in working on this part of IPython. The current prototype of
375 375 ``tconfig`` is located in the IPython sandbox.
376 376
377 377 .. _.ini: http://docs.python.org/lib/module-ConfigParser.html
378 378 .. _ConfigObj: http://www.voidspace.org.uk/python/configobj.html
379 379 .. _Traits: http://code.enthought.com/traits/
380 380
381 381
382 382 Installation and testing scenarios
383 383 ==================================
384 384
385 385 This section outlines the various scenarios that we need to test before we
386 386 release an IPython version. These scenarios represent different ways of
387 387 installing IPython and its dependencies.
388 388
389 389 Installation scenarios under Linux and OS X
390 390 -------------------------------------------
391 391
392 392 1. Install from tarball using ``python setup.py install``.
393 393 a. With only readline+nose dependencies installed.
394 394 b. With all dependencies installed (readline, zope.interface, Twisted,
395 395 foolscap, Sphinx, nose, pyOpenSSL).
396 396
397 397 2. Install using easy_install.
398 398
399 399 a. With only readline+nose dependencies installed.
400 400 i. Default dependencies: ``easy_install ipython-0.9.beta3-py2.5.egg``
401 401 ii. Optional dependency sets: ``easy_install -f ipython-0.9.beta3-py2.5.egg IPython[kernel,doc,test,security]``
402 402
403 403 b. With all dependencies already installed.
404 404
405 405
406 406 Installation scenarios under Win32
407 407 ----------------------------------
408 408
409 409 1. Install everything from .exe installers
410 410 2. easy_install?
411 411
412 412
413 413 Tests to run for these scenarios
414 414 --------------------------------
415 415
416 416 1. Run the full test suite.
417 417 2. Start a controller and engines and try a few things by hand.
418 418 a. Using ipcluster.
419 419 b. Using ipcontroller/ipengine by hand.
420 420
421 421 3. Run a few of the parallel examples.
422 422 4. Try the kernel with and without security with and without PyOpenSSL
423 423 installed.
424 424 5. Beat on the IPython terminal a bunch.
425 425 6. Make sure that furl files are being put in proper locations.
426 426
427 427
428 428 Release checklist
429 429 =================
430 430
431 431 Most of the release process is automated by the :file:`release` script in the
432 432 :file:`tools` directory. This is just a handy reminder for the release manager.
433 433
434 434 #. Run the release script, which makes the tar.gz, eggs and Win32 .exe
435 435 installer. It posts them to the site and registers the release with PyPI.
436 436
437 437 #. Updating the website with announcements and links to the updated changes.txt
438 438 in html form. Remember to put a short note both on the news page of the site
439 439 and on launcphad.
440 440
441 441 #. Drafting a short release announcement with i) highlights and ii) a link to
442 442 the html changes.txt.
443 443
444 444 #. Make sure that the released version of the docs is live on the site.
445 445
446 446 #. Celebrate!
447
448
449 Porting to 3.0
450 ==============
451 There are no definite plans for porting of IPython to python 3. The major
452 issue is the dependency on twisted framework for the networking/threading
453 stuff. It is possible that it the traditional IPython interactive console
454 could be ported more easily since it has no such dependency. Here are a few
455 things that will need to be considered when doing such a port especially
456 if we want to have a codebase that works directly on both 2.x and 3.x.
457
458 1. The syntax for exceptions changed (PEP 3110). The old
459 `except exc, var` changed to `except exc as var`. At last
460 count there was 78 occurences of this usage in the codebase
461
General Comments 0
You need to be logged in to leave comments. Login now