Skip to content

Commit d3d7cb4

Browse files
committed
first draft guidelines for numpification
svn path=/trunk/matplotlib/; revision=3383
1 parent 409de1d commit d3d7cb4

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

CODING_GUIDE

+40-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ and standards. Please edit and extend this document.
55

66
== svn checkouts ==
77

8-
# checking out the main src
8+
# checking out the main src
99
svn co https://svn.sourceforge.net/svnroot/matplotlib/trunk/matplotlib matplotlib
1010

1111
# checking out everything (toolkits, user's guide, htdocs, etc..)
@@ -38,8 +38,29 @@ in mind.
3838
* If you have altered extension code, do you pass
3939
unit/memleak_hawaii.py?
4040

41+
== Importing and name spaces ==
4142

42-
== Naming and spacing conventions ==
43+
For numpy, use:
44+
45+
import numpy as npy
46+
...
47+
a = npy.array([1,2,3])
48+
...
49+
50+
For matplotlib main module, use:
51+
52+
import matplotlib as mpl
53+
...
54+
mpl.rcParams['xtick.major.pad'] = 6
55+
56+
For matplotlib modules, use:
57+
58+
import matplotlib.cbook as cbook
59+
...
60+
if cbook.iterable(z):
61+
...
62+
63+
== Naming, spacing, and formatting conventions ==
4364

4465
In general, we want to hew as closely as possible to the standard
4566
coding guidelines for python written by Guido in
@@ -58,6 +79,22 @@ Also, use an editor that does not put tabs in files. Four spaces
5879
should be used for indentation everywhere and if there is a file with
5980
tabs or more or less spaces it is a bug -- please fix it.
6081

82+
Please avoid spurious invisible spaces at the ends of lines.
83+
(Tell your editor to strip whitespace from line ends when saving
84+
a file.)
85+
86+
Keep docstrings uniformly indented as in the example below, with
87+
nothing to the left of the triple quotes. The dedent() function
88+
is needed to remove excess indentation only if something will be
89+
interpolated into the docstring, again as in the example above.
90+
91+
Limit line length to 80 characters. If a logical line needs to be
92+
longer, use parentheses to break it; do not use an escaped
93+
newline. It may be preferable to use a temporary variable
94+
to replace a single long line with two shorter and more
95+
readable lines.
96+
97+
6198
== Licenses ==
6299

63100
matplotlib only uses BSD compatible code. If you bring in code from
@@ -195,7 +232,6 @@ Then in any function accepting Line2D passthrough kwargs, eg
195232
matplotlib.axes.Axes.plot
196233

197234
# in axes.py
198-
from cbook import dedent
199235
...
200236
def plot(self, *args, **kwargs):
201237
"""
@@ -210,7 +246,7 @@ from cbook import dedent
210246
information
211247
"""
212248
pass
213-
plot.__doc__ = dedent(plot.__doc__) % artist.kwdocd
249+
plot.__doc__ = cbook.dedent(plot.__doc__) % artist.kwdocd
214250

215251
Note there is a problem for Artist __init__ methods, eg Patch.__init__
216252
which supports Patch kwargs, since the artist inspector cannot work
@@ -220,18 +256,3 @@ made some manual hacks in this case which violates the "single entry
220256
point" requirement above; hopefully we'll find a more elegant solution
221257
before too long
222258

223-
== Formatting (editor setup) ==
224-
225-
Indentation is in units of 4 spaces.
226-
227-
Please avoid hard tabs--use only spaces.
228-
229-
Please avoid spurious invisible spaces at the ends of lines.
230-
(Tell your editor to strip whitespace from line ends when saving
231-
a file.)
232-
233-
Keep docstrings uniformly indented as in the example above, with
234-
nothing to the left of the triple quotes. The dedent() function
235-
is needed to remove excess indentation only if something will be
236-
interpolated into the docstring, again as in the example above.
237-

0 commit comments

Comments
 (0)