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