Skip to content

Commit eb08075

Browse files
committed
python22 fixes; verbose class
svn path=/trunk/matplotlib/; revision=554
1 parent 19ca582 commit eb08075

File tree

18 files changed

+251
-89
lines changed

18 files changed

+251
-89
lines changed

.matplotlibrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ numerix : Numeric # Numeric or numarray
3232
interactive : False # see http://matplotlib.sourceforge.net/interactive.html
3333
toolbar : toolbar2 # None | classic | toolbar2
3434
timezone : UTC # a pytz timezone string, eg US/Central or Europe/Paris
35+
36+
# Set the verbose flags
37+
verbose.level : silent # one of silent, helpful, annoying
38+
verbose.fileo : sys.stdout # a log filename, sys.stdout or sys.stderr
39+
40+
3541
# Where your matplotlib data lives if you installed to a non-default
3642
# location. This is where the matplotlib fonts, bitmaps, etc reside
3743
#datapath : /home/jdhunter/mpldata

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ New entries should be added at the top
33
==============================================================
44
2004-09-30 Add GTK+ 2.4 support for the message in the toolbar. SC
55

6+
2004-09-30 Made some changes to support python22 - lots of doc
7+
fixes. - JDH
68

9+
2004-09-29 Added a Verbose class for reporting - JDH
710

811
==============================================================
12+
913
2004-09-28 Released 0.63.0
1014

1115
2004-09-28 Added save to file object for agg - see

LICENSE/LICENSE

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LICENSE AGREEMENT FOR MATPLOTLIB 0.63.0
1+
LICENSE AGREEMENT FOR MATPLOTLIB 0.63.4
22
--------------------------------------
33

44
1. This LICENSE AGREEMENT is between the John D. Hunter ("JDH"), and the
@@ -9,30 +9,30 @@ documentation.
99
2. Subject to the terms and conditions of this License Agreement, JDH
1010
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
1111
to reproduce, analyze, test, perform and/or display publicly, prepare
12-
derivative works, distribute, and otherwise use matplotlib 0.63.0
12+
derivative works, distribute, and otherwise use matplotlib 0.63.4
1313
alone or in any derivative version, provided, however, that JDH's
1414
License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
1515
2002-2004 John D. Hunter; All Rights Reserved" are retained in
16-
matplotlib 0.63.0 alone or in any derivative version prepared by
16+
matplotlib 0.63.4 alone or in any derivative version prepared by
1717
Licensee.
1818

1919
3. In the event Licensee prepares a derivative work that is based on or
20-
incorporates matplotlib 0.63.0 or any part thereof, and wants to
20+
incorporates matplotlib 0.63.4 or any part thereof, and wants to
2121
make the derivative work available to others as provided herein, then
2222
Licensee hereby agrees to include in any such work a brief summary of
23-
the changes made to matplotlib 0.63.0.
23+
the changes made to matplotlib 0.63.4.
2424

25-
4. JDH is making matplotlib 0.63.0 available to Licensee on an "AS
25+
4. JDH is making matplotlib 0.63.4 available to Licensee on an "AS
2626
IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
2727
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
2828
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
29-
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 0.63.0
29+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 0.63.4
3030
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
3131

3232
5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
33-
0.63.0 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
33+
0.63.4 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
3434
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
35-
MATPLOTLIB 0.63.0, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
35+
MATPLOTLIB 0.63.4, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
3636
THE POSSIBILITY THEREOF.
3737

3838
6. This License Agreement will automatically terminate upon a material
@@ -44,6 +44,6 @@ Licensee. This License Agreement does not grant permission to use JDH
4444
trademarks or trade name in a trademark sense to endorse or promote
4545
products or services of Licensee, or any third party.
4646

47-
8. By copying, installing or otherwise using matplotlib 0.63.0,
47+
8. By copying, installing or otherwise using matplotlib 0.63.4,
4848
Licensee agrees to be bound by the terms and conditions of this License
4949
Agreement.

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GOALS
55
INSTALL
66
INTERACTIVE
77
KNOWN_BUGS
8+
MANIFEST
89
MANIFEST.in
910
Makefile
1011
README

TODO

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
570570

571571
-- post hacking points memo on site, ann and send copy to Fernando
572572

573-
-- loadrc() function, possibly replacing per-directory .matplotlibrc
573+
-- loadrc() function, possibly replacing per-directory .matplotlibrc
574574
files.
575575

576576
-- file save dialog for Tk? See Mayavi for the right call to make.
@@ -582,4 +582,8 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
582582

583583
-- DONE an rrulewrapper demo
584584

585-
-- implement a new data clipping method with more exensive cache interval
585+
-- implement a new data clipping method with more exensive cache
586+
interval
587+
588+
-- DONE Humufr errorbar and font bug
589+

lib/matplotlib/__init__.py

Lines changed: 121 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import generators
12
"""
23
This is a matlab style functional interface the matplotlib.
34
@@ -113,7 +114,7 @@
113114
the exception of those in mlab.py provided by matplotlib.
114115
"""
115116

116-
__version__ = '0.63.0'
117+
__version__ = '0.63.4'
117118
__revision__ = '$Revision$'
118119
__date__ = '$Date$'
119120

@@ -140,15 +141,89 @@ def warn(s):
140141

141142
import sys, os
142143

144+
143145
major, minor1, minor2, s, tmp = sys.version_info
144-
if major<2 or (major==2 and minor1<3):
145-
True = 1
146-
False = 0
147-
else:
148-
True = True
149-
False = False
146+
_python23 = major>=2 and minor1>=3
147+
148+
_havemath = _python23
149+
150+
try:
151+
import datetime
152+
import dateutil
153+
import pytz
154+
except ImportError: _havedate = False
155+
else: _havedate = True
156+
157+
if not _python23:
158+
def enumerate(seq):
159+
for i in range(len(seq)):
160+
yield i, seq[i]
161+
162+
163+
class Verbose:
164+
"""
165+
A class to handle reporting. Set the fileo attribute to any file
166+
instance to handle the output. Default is sys.stdout
167+
"""
168+
levels = ('silent', 'helpful', 'annoying')
169+
vald = dict( [(level, i) for i,level in enumerate(levels)])
170+
171+
def __init__(self, level):
172+
self.set_level(level)
173+
self.fileo = sys.stdout
174+
175+
def set_level(self, level):
176+
'set the verbosity to one of the Verbose.levels strings'
177+
assert level in self.levels
178+
self.level = level
179+
180+
def silent(self):
181+
return self.level=='silent'
150182

183+
def helpful(self):
184+
return self.vald[self.level]>=self.vald['helpful']
151185

186+
def annoying(self):
187+
return self.vald[self.level]>=self.vald['annoying']
188+
189+
def report(self, s, level='helpful'):
190+
"""
191+
print message s to self.fileo if self.level>=level. Return
192+
value indicates whether a message was issued
193+
194+
"""
195+
if self.ge(level):
196+
print >>self.fileo, s
197+
return True
198+
return False
199+
200+
201+
def wrap(self, fmt, func, level='helpful', always=True):
202+
"""
203+
return a callable function that wraps func and reports it
204+
output through the verbose handler if current verbosity level
205+
is higher than level
206+
207+
if always is True, the report will occur on every function
208+
call; otherwise only on the first time the function is called
209+
"""
210+
assert(callable, func)
211+
def wrapper(*args, **kwargs):
212+
ret = func(*args, **kwargs)
213+
214+
if (always or not wrapper._spoke):
215+
spoke = self.report(fmt%ret, level)
216+
if not wrapper._spoke: wrapper._spoke = spoke
217+
return ret
218+
wrapper._spoke = False
219+
wrapper.__doc__ = func.__doc__
220+
return wrapper
221+
222+
def ge(self, level):
223+
'return true if self.level is >= level'
224+
return self.vald[self.level]>=self.vald[level]
225+
226+
verbose=Verbose('silent') # silent until rc is parsed
152227

153228
def get_home():
154229
"""
@@ -168,8 +243,9 @@ def get_home():
168243

169244
return None
170245

171-
def get_data_path():
172246

247+
def _get_data_path():
248+
'get the path to matplotlib data'
173249
path = os.path.join(distutils.sysconfig.PREFIX, 'share', 'matplotlib')
174250
if os.path.isdir(path): return path
175251

@@ -195,6 +271,8 @@ def get_data_path():
195271
return path
196272
raise RuntimeError('Could not find the matplotlib data files')
197273

274+
get_data_path = verbose.wrap('matplotlib data path %s', _get_data_path, always=False)
275+
198276

199277
def validate_path_exists(s):
200278
'If s is a path, return s, else False'
@@ -302,6 +380,26 @@ def validate_fontsize(s):
302380
raise ValueError('not a valid font size')
303381

304382

383+
def validate_verbose(s):
384+
verbose.set_level(s)
385+
return verbose
386+
387+
388+
def validate_verbose_fileo(s):
389+
d = {'sys.stdout':sys.stdout,
390+
'sys.stderr':sys.stderr,
391+
}
392+
if d.has_key(s): verbose.fileo = d[s]
393+
else:
394+
try: fileo = file(s, 'w')
395+
except IOError:
396+
raise ValueError('Verbose object could not open log file "%s" for writing.\nCheck your matplotlibrc verbose.fileo setting'%s)
397+
398+
399+
else:
400+
verbose.fileo = fileo
401+
return verbose.fileo
402+
305403
# a map from key -> value, converter
306404
defaultParams = {
307405
'backend' : ['GTK', str],
@@ -311,6 +409,10 @@ def validate_fontsize(s):
311409
'interactive' : [False, validate_bool],
312410
'timezone' : ['UTC', str],
313411

412+
# the verbosity setting
413+
'verbose.level' : ['silent', validate_verbose],
414+
'verbose.fileo' : ['sys.stdout', validate_verbose_fileo],
415+
314416
# line props
315417
'lines.linewidth' : [0.5, validate_float], # line width in points
316418
'lines.linestyle' : ['-', str], # solid line
@@ -434,6 +536,8 @@ def matplotlib_fname():
434536
print >> sys.stderr, 'Could not find .matplotlibrc; using defaults'
435537
return fname
436538

539+
540+
437541
def rc_params():
438542
'Return the default params updated from the values in the rc file'
439543

@@ -448,8 +552,11 @@ def rc_params():
448552

449553
fname = matplotlib_fname()
450554
if not os.path.exists(fname):
451-
return dict([ (key, tup[0]) for key, tup in defaultParams.items()])
452-
555+
message = 'could not find rc file; returning defaults'
556+
ret = dict([ (key, tup[0]) for key, tup in defaultParams.items()])
557+
verbose.report(message)
558+
return ret
559+
453560
cnt = 0
454561
for line in file(fname):
455562
cnt +=1
@@ -488,7 +595,10 @@ def rc_params():
488595
defaultParams[key][0] = cval
489596

490597
# strip the conveter funcs and return
491-
return dict([ (key, tup[0]) for key, tup in defaultParams.items()])
598+
ret = dict([ (key, tup[0]) for key, tup in defaultParams.items()])
599+
verbose.report('loaded rc file %s'%fname)
600+
return ret
601+
492602

493603
# this is the instance used by the matplotlib classes
494604
rcParams = rc_params()

0 commit comments

Comments
 (0)