File: HOWTO_DOCUMENT.txt

package info (click to toggle)
python-numpy 1%3A1.1.0-3%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,548 kB
  • ctags: 14,321
  • sloc: ansic: 73,119; python: 59,655; cpp: 822; makefile: 179; fortran: 121; f90: 42
file content (336 lines) | stat: -rw-r--r-- 10,891 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
====================================
A Guide to NumPy/SciPy Documentation
====================================

.. Contents::

.. Note::

   For an accompanying example, see `example.py
   <http://svn.scipy.org/svn/numpy/trunk/numpy/doc/example.py>`_.

Overview
--------
In general, we follow the standard Python style conventions as described here:
 * `Style Guide for C Code <http://www.python.org/peps/pep-0007.html>`_
 * `Style Guide for Python Code <http://www.python.org/peps/pep-0008.html>`_
 * `Docstring Conventions <http://www.python.org/peps/pep-0257.html>`_

Additional PEPs of interest regarding documentation of code:
 * `Docstring Processing Framework <http://www.python.org/peps/pep-0256.html>`_
 * `Docutils Design Specification <http://www.python.org/peps/pep-0258.html>`_

Use a code checker:
 * `pylint <http://www.logilab.org/857>`_
 * `pyflakes` easy_install pyflakes
 * `pep8.py <http://svn.browsershots.org/trunk/devtools/pep8/pep8.py>`_

For documentation purposes, use unabbreviated module names.  If you
prefer the use of abbreviated module names in code (*not* the
docstrings), we suggest the import conventions used by NumPy itself::

   import numpy as np
   import scipy as sp
   import matplotlib as mpl
   import matplotlib.pyplot as plt

Docstring Standard
------------------
A documentation string (docstring) is a string that describes a module,
function, class, or method definition.  The docstring is a special attribute
of the object (``object.__doc__``) and, for consistency, is surrounded by
triple double quotes, i.e.::

   """This is the form of a docstring.

   It can be spread over several lines.

   """

NumPy, SciPy_, and the scikits follow a common convention for
docstrings that provides for consistency, while also allowing our
toolchain to produce well-formatted reference guides.  This document
describes the current community consensus for such a standard.  If you
have suggestions for improvements, post them on the `numpy-discussion
list`_, together with the epydoc output.

Our docstring standard uses `re-structured text (reST)
<http://docutils.sourceforge.net/rst.html>`_ syntax and is rendered
using tools like epydoc_ or sphinx_ (pre-processors that understand
the particular documentation style we are using).  While a rich set of
markup is available, we limit ourselves to a very basic subset, in
order to provide docstrings that are easy to read on text-only
terminals.

A guiding principle is that human readers of the text are given
precedence over contorting docstrings so our tools produce nice
output.  Rather than sacrificing the readability of the docstrings, we
have chosen to write pre-processors to assist tools like epydoc_ or
sphinx_ in their task.

Status
------
We are busy converting existing docstrings to the new format,
expanding them where they are lacking, as well as writing new ones for
undocumented functions.  Volunteers are welcome to join the effort on
our new wiki-based documentation system (see the `Developer Zone
<http://www.scipy.org/Developer_Zone/DocMarathon2008>`_).

Sections
--------
The sections of the docstring are:

1. **Short summary**

   A one-line summary that does not use variable names or the function
   name, e.g.

   ::

     def add(a,b):
        """The sum of two numbers.

        """

   The function signature is normally found by introspection and
   displayed by the help function.  For some functions (notably those
   written in C) the signature is not available, so we have to specify
   it as the first line of the docstring::

     """
     add(a,b)

     The sum of two numbers.

     """

2. **Extended summary**

   A few sentences giving an extended description.  This section
   should be used to clarify *functionality*, not to discuss
   implementation detail or background theory, which should rather be
   explored in the **notes** section below.  You may refer to the
   parameters and the function name, but parameter descriptions still
   belong in the **parameters** section.

3. **Parameters**

   Description of the function arguments, keywords and their
   respective types.

   ::

     Parameters
     ----------
     x : type
        Description of parameter `x`.

   Enclose variables in single back-tics.  If it is not necessary to
   specify a keyword argument, use ``optional``::

     x : int, optional

   Optional keyword parameters have default values, which are
   displayed as part of the function signature.  They can also be
   detailed in the description::

     Description of parameter `x` (the default is -1, which implies summation
     over all axes).

   When a parameter can only assume one of a fixed set of values,
   those values can be listed in braces ::

     x : {True, False}
         Description of `x`.

4. **Returns**

   Explanation of the returned values and their types, of the same
   format as **parameters**.

5. **Other parameters**

   An optional section used to describe infrequently used parameters.
   It should only be used if a function has a large number of keyword
   prameters, to prevent cluttering the **parameters** section.

6. **Raises**

   An optional section detailing which errors get raised and under
   what conditions::

     Raises
     ------
     LinAlgException
         If the matrix is not numerically invertible.

7. **See Also**

   An optional section used to refer to related code.  This section
   can be very useful, but should be used judiciously.  The goal is to
   direct users to other functions they may not be aware of, or have
   easy means of discovering (by looking at the module docstring, for
   example).  Routines whose docstrings further explain parameters
   used by this function are good candidates.

   As an example, for ``numpy.mean`` we would have::

     See Also
     --------
     average : Weighted average

8. **Notes**

   An optional section that provides additional information about the
   code, possibly including a discussion of the algorithm. This
   section may include mathematical equations, written in
   `LaTeX <http://www.latex-project.org/>`_ format::

     The FFT is a fast implementation of the discrete Fourier transform:

     .. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n}

   Equations can also be typeset underneath the math directive::

     The discrete-time Fourier time-convolution property states that

     .. math::

          x(n) * y(n) \Leftrightarrow X(e^{j\omega } )Y(e^{j\omega } )\\
          another equation here

   Math can furthermore be used inline, i.e.

   ::

     The value of :math:`omega` is larger than 5.

   Note that LaTeX is not particularly easy to read, so use equations
   sparingly.

   Images are allowed, but should not be central to the explanation;
   users viewing the docstring as text must be able to comprehend its
   meaning without resorting to an image viewer.  These additional
   illustrations are included using::

     .. image:: filename

   where filename is a path relative to the reference guide source
   directory.

9. **References**

   References cited in the **notes** section may be listed here,
   e.g. if you cited the article below using the text ``[1]_``,
   include it as in the list as follows::

     .. [1] O. McNoleg, "The integration of GIS, remote sensing,
        expert systems and adaptive co-kriging for environmental habitat
        modelling of the Highland Haggis using object-oriented, fuzzy-logic
        and neural-network techniques," Computers & Geosciences, vol. 22,
        pp. 585-588, 1996.

   which renders as

   .. [1] O. McNoleg, "The integration of GIS, remote sensing,
      expert systems and adaptive co-kriging for environmental habitat
      modelling of the Highland Haggis using object-oriented, fuzzy-logic
      and neural-network techniques," Computers & Geosciences, vol. 22,
      pp. 585-588, 1996.

   Referencing sources of a temporary nature, like web pages, is
   discouraged.  References are meant to augment the docstring, but
   should not be required to understand it.  Follow the `citation
   format of the IEEE
   <http://www.ieee.org/pubs/transactions/auinfo03.pdf>`_, which
   states that references are numbered, starting from one, in the
   order in which they are cited.

10. **Examples**

    An optional section for examples, using the `doctest
    <http://www.python.org/doc/lib/module-doctest.html>`_ format.
    This section is meant to illustrate usage, not to provide a
    testing framework -- for that, use the ``tests/`` directory.
    While optional, this section is very strongly encouraged. You can
    run these examples by doing::

      >>> import doctest
      >>> doctest.testfile('example.py')

    or, using nose,

    ::

      $ nosetests --with-doctest example.py

    Blank lines are used to seperate doctests.  When they occur in the
    expected output, they should be replaced by ``<BLANKLINE>`` (see
    `doctest options
    <http://docs.python.org/lib/doctest-options.html>`_ for other such
    special strings), e.g.

    ::

      >>> print "a\n\nb"
      a
      <BLANKLINE>
      b

11. **Indexing tags***

    Each function needs to be categorised for indexing purposes.  Use
    the ``index`` directive::

      .. index::
         :refguide: ufunc, trigonometry

    To index a function as a sub-category of a class, separate index
    entries by a semi-colon, e.g.

    ::

      :refguide: ufunc, numpy;reshape, other

    A `list of available categories
    <http://www.scipy.org/Developer_Zone/ReferenceGuide>`_ is
    available.


Common reST concepts
--------------------
For paragraphs, indentation is significant and indicates indentation in the
output. New paragraphs are marked with a blank line.

Use *italics*, **bold**, and ``courier`` if needed in any explanations
(but not for variable names and doctest code or multi-line code).
Variable, module and class names should be written between single
backticks (```numpy```).

A more extensive example of reST markup can be found in `this example
document <http://docutils.sourceforge.net/docs/user/rst/demo.txt>`_;
the `quick reference
<http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_ is
useful while editing.

Line spacing and indentation are significant and should be carefully
followed.

Conclusion
----------

`An example
<http://svn.scipy.org/svn/numpy/trunk/numpy/doc/example.py>`_ of the
format shown here is available.  Refer to `How to Build API/Reference
Documentation <HOWTO_BUILD_DOCS>`_ on how to use epydoc_ or sphinx_ to
construct a manual and web page.

This document itself was written in ReStructuredText, and may be converted to
HTML using::

  $ rst2html HOWTO_DOCUMENT.txt HOWTO_DOCUMENT.html

.. _SciPy: http://www.scipy.org
.. _numpy-discussion list: http://www.scipy.org/Mailing_Lists
.. _epydoc: http://epydoc.sourceforge.net/
.. _sphinx: http://sphinx.pocoo.org