Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c198c6e

Browse files
committed
addressed eric's review comments
svn path=/trunk/matplotlib/; revision=5456
1 parent 84b3422 commit c198c6e

3 files changed

Lines changed: 153 additions & 78 deletions

File tree

doc/devel/coding_guide.rst

Lines changed: 127 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,30 @@ in mind.
5454

5555
* install ``svnmerge.py`` in your PATH::
5656

57-
wget http://svn.collab.net/repos/svn/trunk/contrib/client-side/\
58-
svnmerge/svnmerge.py
57+
> wget http://svn.collab.net/repos/svn/trunk/contrib/client-side/\
58+
svnmerge/svnmerge.py
5959

6060
* get a svn copy of the maintenance branch and the trunk (see above)
6161
* Michael advises making the change on the branch and committing
6262
it. Make sure you svn upped on the trunk and have no local
6363
modifications, and then from the svn trunk do::
6464

65-
> svnmerge.py merge
65+
> svnmerge.py merge
6666

6767
If you wish to merge only specific revisions (in an unusual
6868
situation), do::
6969

70-
> svnmerge.py merge -rNNN1-NNN2
70+
> svnmerge.py merge -rNNN1-NNN2
7171

7272
where the ``NNN`` are the revision numbers. Ranges are also
7373
acceptable.
7474

7575
The merge may have found some conflicts (code that must be
7676
manually resolved). Correct those conflicts, build matplotlib and
77-
test your choices.
77+
test your choices. If you have resolved any conflicts, you can
78+
let svn clean up the conflict files for you::
79+
80+
> svn -R resolved .
7881

7982
``svnmerge.py`` automatically creates a file containing the commit
8083
messages, so you are ready to make the commit::
@@ -97,14 +100,7 @@ For `numpy <http://www.numpy.org>`_, use::
97100

98101
For masked arrays, use::
99102

100-
from numpy import ma
101-
102-
(The earlier recommendation, :samp:`import matplotlib.numerix.npyma as ma`,
103-
was needed temporarily during the development of the maskedarray
104-
implementation as a separate package. As of numpy 1.1, it replaces the
105-
old implementation. Note: ``from numpy import ma`` works with numpy < 1.1
106-
*and* with numpy >= 1.1. ``import numpy.ma as ma`` works *only* with
107-
numpy >= 1.1, so for now we must not use it.)
103+
import numpy.ma as ma
108104

109105
For matplotlib main module, use::
110106

@@ -120,8 +116,17 @@ For matplotlib modules (or any other modules), use::
120116

121117
We prefer this over the equivalent ``from matplotlib import cbook``
122118
because the latter is ambiguous whether ``cbook`` is a module or a
123-
function to the new developer. The former makes it explcit that
124-
you are importing a module or package.
119+
function to the new developer. The former makes it explicit that you
120+
are importing a module or package. There are some modules whose names
121+
may be ambiguous in the context of local variables, eg
122+
:mod:`matplotlib.lines` or :mod:`matplotlib.colors`. When you want to
123+
disambiguate, use the prefix 'm' with the ``import some.thing as
124+
mthing`` syntax, eg::
125+
126+
import matplotlib.lines as mlines
127+
import matplotlib.transforms as transforms # OK
128+
import matplotlib.transforms as mtransforms # OK, if you want to disambiguate
129+
import matplotlib.transforms as mtrans # OK, if you want to abbreviate
125130

126131
Naming, spacing, and formatting conventions
127132
-------------------------------------------
@@ -138,15 +143,26 @@ throughout.
138143

139144
* classes: ``Upper`` or ``MixedCase``
140145

141-
Personally, I prefer the shortest names that are still readable.
146+
Prefer the shortest names that are still readable.
142147

143148
Also, use an editor that does not put tabs in files. Four spaces
144149
should be used for indentation everywhere and if there is a file with
145-
tabs or more or less spaces it is a bug -- please fix it.
150+
tabs or more or less spaces it is a bug -- please fix it. There are
151+
some tools to help automate this checking, such as `tabnanny
152+
<http://effbot.org/librarybook/tabnanny.htm>`_, which is part of the
153+
standard library::
154+
155+
In [3]: cd /home/titan/johnh/mpl/lib/matplotlib/
156+
/home/titan/johnh/python/svn/matplotlib.trunk/matplotlib/lib/matplotlib
157+
158+
In [4]: import tabnanny
146159

147-
Please avoid spurious invisible spaces at the ends of lines.
148-
(Tell your editor to strip whitespace from line ends when saving
149-
a file.)
160+
In [5]: tabnanny.check('axis.py')
161+
162+
There is also `reindent.py
163+
<http://svn.python.org/projects/doctools/trunk/utils/reindent.py>`_
164+
which can be used to automatically change python files to use 4-space
165+
indents with no hard tab characters.
150166

151167
Keep docstrings uniformly indented as in the example below, with
152168
nothing to the left of the triple quotes. The
@@ -160,10 +176,10 @@ It may be preferable to use a temporary variable to replace a single
160176
long line with two shorter and more readable lines.
161177

162178
Please do not commit lines with trailing white space, as it causes
163-
noise in svn diffs.
164-
165-
If you are an emacs user, the following in your ``.emacs`` will cause
166-
emacs to strip trailing white space upon saving for python, C and C++:
179+
noise in svn diffs. Tell your editor to strip whitespace from line
180+
ends when saving a file. If you are an emacs user, the following in
181+
your ``.emacs`` will cause emacs to strip trailing white space upon
182+
saving for python, C and C++:
167183

168184
.. code-block:: cl
169185
@@ -172,7 +188,7 @@ emacs to strip trailing white space upon saving for python, C and C++:
172188
(lambda ()
173189
(add-hook 'write-file-functions 'delete-trailing-whitespace)))
174190
175-
for older versions of emacs (emacs<22) you need to do:
191+
for older versions of emacs (emacs<22) you need to do:
176192

177193
.. code-block:: cl
178194
@@ -218,17 +234,17 @@ artist constructor which looks for suitably named methods and calls
218234
them with the value.
219235

220236
As a general rule, the use of ``**kwargs`` should be reserved for
221-
pass-through keyword arguments, as in the examaple above. If I intend
222-
for all the keyword args to be used in some function and not passed
223-
on, I just use the key/value keyword args in the function definition
224-
rather than the ``**kwargs`` idiom.
225-
226-
In some cases I want to consume some keys and pass through the others,
227-
in which case I pop the ones I want to use locally and pass on the
228-
rest, eg., I pop ``scalex`` and ``scaley`` in
229-
:meth:`~matplotlib.axes.Axes.plot` and assume the rest are
230-
:meth:`~matplotlib.lines.Line2D` keyword arguments. As an example of
231-
a pop, passthrough usage, see :meth:`~matplotlib.axes.Axes.plot`::
237+
pass-through keyword arguments, as in the example above. If all the
238+
keyword args to be used in the function being declared, and not passed
239+
on, use the key/value keyword args in the function definition rather
240+
than the ``**kwargs`` idiom.
241+
242+
In some cases, you may want to consume some keys in the local
243+
function, and let others pass through. You can ``pop`` the ones to be
244+
used locally and pass on the rest. For example, in
245+
:meth:`~matplotlib.axes.Axes.plot`, ``scalex`` and ``scaley`` are
246+
local arguments and the rest are passed on as
247+
:meth:`~matplotlib.lines.Line2D` keyword arguments::
232248

233249
# in axes.py
234250
def plot(self, *args, **kwargs):
@@ -240,10 +256,6 @@ a pop, passthrough usage, see :meth:`~matplotlib.axes.Axes.plot`::
240256
self.add_line(line)
241257
lines.append(line)
242258

243-
The :mod:`matplotlib.cbook` function :func:`~matplotlib.cbook.popd` is rendered
244-
obsolete by the :func:`~dict.pop` dictionary method introduced in Python 2.3,
245-
so it should not be used for new code.
246-
247259
Note there is a use case when ``kwargs`` are meant to be used locally
248260
in the function (not passed on), but you still need the ``**kwargs``
249261
idiom. That is when you want to use ``*args`` to allow variable
@@ -269,7 +281,7 @@ forced to use ``**kwargs``. An example is
269281
Documentation and Docstrings
270282
============================
271283

272-
matplotlib uses artist instrospection of docstrings to support
284+
matplotlib uses artist introspection of docstrings to support
273285
properties. All properties that you want to support through ``setp``
274286
and ``getp`` should have a ``set_property`` and ``get_property``
275287
method in the :class:`~matplotlib.artist.Artist` class. Yes, this is
@@ -290,8 +302,8 @@ Since matplotlib uses a lot of pass through ``kwargs``, eg. in every
290302
function that creates a line (:func:`~matplotlib.pyplot.plot`,
291303
:func:`~matplotlib.pyplot.semilogx`,
292304
:func:`~matplotlib.pyplot.semilogy`, etc...), it can be difficult for
293-
the new user to know which ``kwargs`` are supported. I have developed a
294-
docstring interpolation scheme to support documentation of every
305+
the new user to know which ``kwargs`` are supported. matplotlib uses
306+
a docstring interpolation scheme to support documentation of every
295307
function that takes a ``**kwargs``. The requirements are:
296308

297309
1. single point of configuration so changes to the properties don't
@@ -300,12 +312,13 @@ function that takes a ``**kwargs``. The requirements are:
300312
2. as automated as possible so that as properties change the docs
301313
are updated automagically.
302314

303-
I have added a :attr:`matplotlib.artist.kwdocd` and
304-
:func:`matplotlib.artist.kwdoc` to faciliate this. They combine
315+
The functions :attr:`matplotlib.artist.kwdocd` and
316+
:func:`matplotlib.artist.kwdoc` to facilitate this. They combine
305317
python string interpolation in the docstring with the matplotlib
306-
artist introspection facility that underlies ``setp`` and ``getp``. The
307-
``kwdocd`` is a single dictionary that maps class name to a docstring of
308-
``kwargs``. Here is an example from :mod:`matplotlib.lines`::
318+
artist introspection facility that underlies ``setp`` and ``getp``.
319+
The ``kwdocd`` is a single dictionary that maps class name to a
320+
docstring of ``kwargs``. Here is an example from
321+
:mod:`matplotlib.lines`::
309322

310323
# in lines.py
311324
artist.kwdocd['Line2D'] = artist.kwdoc(Line2D)
@@ -331,12 +344,12 @@ passthrough ``kwargs``, eg. :meth:`matplotlib.axes.Axes.plot`::
331344

332345
Note there is a problem for :class:`~matplotlib.artist.Artist`
333346
``__init__`` methods, eg. :meth:`matplotlib.patches.Patch.__init__`,
334-
which supports ``Patch`` ``kwargs``, since the artist inspector cannot work
335-
until the class is fully defined and we can't modify the
336-
``Patch.__init__.__doc__`` docstring outside the class definition. I have
337-
made some manual hacks in this case which violates the "single entry
338-
point" requirement above; hopefully we'll find a more elegant solution
339-
before too long.
347+
which supports ``Patch`` ``kwargs``, since the artist inspector cannot
348+
work until the class is fully defined and we can't modify the
349+
``Patch.__init__.__doc__`` docstring outside the class definition.
350+
There are some some manual hacks in this case which violates theqq
351+
"single entry point" requirement above -- see the
352+
``artist.kwdocd['Patch']`` setting in :mod:`matplotlib.patches`.
340353

341354

342355
.. _licenses:
@@ -345,11 +358,66 @@ Licenses
345358
========
346359

347360
Matplotlib only uses BSD compatible code. If you bring in code from
348-
another project make sure it has a PSF, BSD, MIT or compatible
349-
license. If not, you may consider contacting the author and asking
350-
them to relicense it. GPL and LGPL code are not acceptible in the
351-
main code base, though we are considering an alternative way of
361+
another project make sure it has a PSF, BSD, MIT or compatible license
362+
(see the Open Source Initiative `licenses page
363+
<http://www.opensource.org/licenses>`_ for details on individual
364+
licenses). If it doesn't, you may consider contacting the author and
365+
asking them to relicense it. GPL and LGPL code are not acceptable in
366+
the main code base, though we are considering an alternative way of
352367
distributing L/GPL code through an separate channel, possibly a
353368
toolkit. If you include code, make sure you include a copy of that
354369
code's license in the license directory if the code's license requires
355-
you to distribute the license with it.
370+
you to distribute the license with it. Non-BSD compatible licenses
371+
are acceptable in matplotlib toolkits (eg basemap), but make sure you
372+
clearly state the licenses you are using.
373+
374+
Why BSD compatible?
375+
-------------------
376+
377+
The two dominant license variants in the wild are GPL-style and
378+
BSD-style. There are countless other licenses that place specific
379+
restrictions on code reuse, but there is an important different to be
380+
considered in the GPL and BSD variants. The best known and perhaps
381+
most widely used license is the GPL, which in addition to granting you
382+
full rights to the source code including redistribution, carries with
383+
it an extra obligation. If you use GPL code in your own code, or link
384+
with it, your product must be released under a GPL compatible
385+
license. I.e., you are required to give the source code to other
386+
people and give them the right to redistribute it as well. Many of the
387+
most famous and widely used open source projects are released under
388+
the GPL, including sagemath, linux, gcc and emacs.
389+
390+
The second major class are the BSD-style licenses (which includes MIT
391+
and the python PSF license). These basically allow you to do whatever
392+
you want with the code: ignore it, include it in your own open source
393+
project, include it in your proprietary product, sell it,
394+
whatever. python itself is released under a BSD compatible license, in
395+
the sense that, quoting from the PSF license page::
396+
397+
There is no GPL-like "copyleft" restriction. Distributing
398+
binary-only versions of Python, modified or not, is allowed. There
399+
is no requirement to release any of your source code. You can also
400+
write extension modules for Python and provide them only in binary
401+
form.
402+
403+
Famous projects released under a BSD-style license in the permissive
404+
sense of the last paragraph are the BSD operating system, python and
405+
TeX.
406+
407+
There are two primary reasons why early matplotlib developers selected
408+
a BSD compatible license. We wanted to attract as many users and
409+
developers as possible, and many software companies will not use GPL code
410+
in software they plan to distribute, even those that are highly
411+
committed to open source development, such as `enthought
412+
<http://enthought.com>`_, out of legitimate concern that use of the
413+
GPL will "infect" their code base by its viral nature. In effect, they
414+
want to retain the right to release some proprietary code. Companies,
415+
and institutions in general, who use matplotlib often make significant
416+
contributions, since they have the resources to get a job done, even a
417+
boring one, if they need it in their code. Two of the matplotlib
418+
backends (FLTK and WX) were contributed by private companies.
419+
420+
The other reason is licensing compatibility with the other python
421+
extensions for scientific computing: ipython, numpy, scipy, the
422+
enthought tool suite and python itself are all distributed under BSD
423+
compatible licenses.

doc/devel/outline.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ the canvas John has author ?
6262
the artist John has author ?
6363
transforms Michael submitted John
6464
documenting mpl Darren submitted ?
65-
coding guide John submitted Eric
65+
coding guide John in review Eric
6666
and_much_more ? ? ?
6767
=============================== ==================== =========== ===================
6868

@@ -103,11 +103,11 @@ If you want to make notes for the authorwhen you have reviewed a
103103
submission, you can put them here. As the author cleans them up or
104104
addresses them, they should be removed.
105105

106-
mathtext user's guide (reviewd by JDH)
106+
mathtext user's guide-- reviewd by JDH
107107
--------------------------------------
108108

109-
This looks good -- there are a few minor things to close the book on
110-
this chapter.
109+
This looks good (see :ref:`mathtext-tutorial`) -- there are a few
110+
minor things to close the book on this chapter.
111111

112112
#. The main thing to wrap this up is getting the mathtext module
113113
ported over to rest and included in the API so the links from the
@@ -123,12 +123,12 @@ ghte rc file, but it might be helpful to a newbie.
123123
coding guide (reviewed by EF)
124124
-----------------------------
125125

126-
Mostly fine, just a few comments. Also, there are a couple
127-
of typos, but I would rather just edit those directly in
128-
another pass (if you don't happen to find them) than include
129-
them as formal review notes.
126+
Mostly fine (see :ref:`coding-guide`), just a few comments.
127+
Also, there are a couple of typos, but I would rather just edit those
128+
directly in another pass (if you don't happen to find them) than
129+
include them as formal review notes.
130130

131-
#. Import recommendation for ma: given that the trunk is
131+
#. DONE - Import recommendation for ma: given that the trunk is
132132
requiring numpy 1.1, perhaps we should be consistent and
133133
recommend the form::
134134

@@ -152,26 +152,26 @@ them as formal review notes.
152152
rc() function and using that instead of setting the
153153
dictionary entries directly), if necessary.
154154

155-
#. You give the example::
155+
#. DONE - You give the example::
156156

157157
import matplotlib.cbook as cbook
158158

159159
Should there also be a list of the standard variants like
160160
``mtransforms``? (And, again peripherally, I would
161161
shorten that one to ``mtrans``.)
162162

163-
#. The treatment of whitespace is split into two parts
163+
#. DONE - The treatment of whitespace is split into two parts
164164
separated by paragraphs on docstrings and line length;
165165
this can be consolidated. It might be worth mentioning
166166
the ``reindent.py`` and ``tabnanny.py`` utilities here.
167167

168-
#. Minor question of literary style: should use of the first
169-
person be avoided in most places? It is used, for
170-
example, in the discussion of the automatic kwarg doc
171-
generation. I don't mind leaving the first person in,
172-
with the general understanding that it means you.
168+
#. DONE - (removed first person usage) - Minor question of literary
169+
style: should use of the first person be avoided in most places?
170+
It is used, for example, in the discussion of the automatic kwarg
171+
doc generation. I don't mind leaving the first person in, with the
172+
general understanding that it means you.
173173

174-
#. Licenses: you might want to add a link to your
174+
#. DONE - Licenses: you might want to add a link to your
175175
explanation of your BSD choice. Peripheral question: is
176176
there any problem with basemap's inclusion of
177177
sub-packages with the gamut of licenses, GPL to MIT?

doc/users/text_intro.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface
3434
* :func:`~matplotlib.pyplot.xlabel` - add an axis label to the x-axis;
3535
:meth:`matplotlib.axes.Axes.set_xlabel` in the API.
3636

37-
* :func:`~matplotlib.pyplot.ylabel` - add an axis label to the y-axis;;
37+
* :func:`~matplotlib.pyplot.ylabel` - add an axis label to the y-axis;
3838
:meth:`matplotlib.axes.Axes.set_ylabel` in the API.
3939

4040
* :func:`~matplotlib.pyplot.title` - add a title to the ``Axes``;
@@ -52,4 +52,11 @@ interface
5252

5353
All of these functions create and return a
5454
:func:`matplotlib.text.Text` instance, which can bew configured with a
55-
variety of font and other properties.
55+
variety of font and other properties. The example below shows all of
56+
these commands in action.
57+
58+
.. literalinclude:: figures/text_commands.py
59+
60+
.. image:: figures/text_commands.png
61+
:scale: 50
62+

0 commit comments

Comments
 (0)