8000 [Sprint] Rc fixes by katyhuff · Pull Request #2193 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Sprint] Rc fixes #2193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a85769
adds encoding as a function parameter
katyhuff Jun 29, 2013
b300ef3
when dealing with unicode strings, isinstance(u, basestring) will ret…
katyhuff Jun 29, 2013
7eb7ec0
Merge branch 'master' into unicode_rc
katyhuff Jun 29, 2013
aede120
undid enccoding parameter. This can be added later if the encoding ge…
katyhuff Jun 29, 2013
55475a0
adds a test file and a template rc file for the rc_setup tests.
katyhuff Jun 29, 2013
8df2f0b
default test passes.
katyhuff Jun 29, 2013
55d4b44
autopep8'd the test file.
katyhuff Jun 29, 2013
1cfedb9
The matplotlibrc template docstring.hardcopy must use a colon rather …
katyhuff Jun 29, 2013
09a2450
because of commas, Impact and Western were being merged
katyhuff Jun 29, 2013
6d79027
uncomments the matplotlibrc template
katyhuff Jun 29, 2013
a41204d
errors arose for some (but not all) of these parameters inside apostr…
katyhuff Jun 29, 2013
3840623
The matplotlibrc should match the default, which is (f, ctrl+f)
katyhuff Jun 29, 2013
1042544
template test passes.
katyhuff Jun 30, 2013
be48e7d
got rid of print statements from debugging
katyhuff Jun 30, 2013
09bf2dd
unicode test runs
katyhuff Jun 30, 2013
cda758d
merged unicode solution
katyhuff Jun 30, 2013
1976db5
unicode test passes
katyhuff Jun 30, 2013
7302c31
errant space.
katyhuff Jun 30, 2013
febaa0d
updates matplotlibrc.template to mat the defaults in the rcsetup module
katyhuff Jun 30, 2013
c3bfe6c
Merge branch 'master' into rc_fixes
katyhuff Jun 30, 2013
fa3f07d
getting up to date with master
katyhuff Jul 1, 2013
6bd355f
Merge branch 'master' into rc_fixes
katyhuff Jul 1, 2013
15b8b57
makes a proper docstring and removes the assert
katyhuff Jul 2, 2013
4ce865c
fixed typerror
katyhuff Jul 2, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 66 additions & 55 deletions lib/matplotlib/rcsetup.py
10000
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def validate_path_exists(s):

def validate_bool(b):
"""Convert b to a boolean or raise"""
if type(b) is str:
if isinstance(b, basestring):
b = b.lower()
if b in ('t', 'y', 'yes', 'on', 'true', '1', 1, True):
return True
Expand All @@ -82,8 +82,8 @@ def validate_bool(b):


def validate_bool_maybe_none(b):
'Convert b to a boolean or raise'
if type(b) is str:
"""Convert b to a boolean, None, or raise"""
if isinstance(b, basestring):
b = b.lower()
if b == 'none':
return None
Expand Down Expand Up @@ -144,6 +144,7 @@ def validate_backend(s):
else:
return _validate_standard_backends(s)


validate_qt4 = ValidateInStrings('backend.qt4', ['PyQt4', 'PySide'])


Expand Down Expand Up @@ -177,7 +178,7 @@ def __init__(self, n):

def __call__(self, s):
"""return a seq of n floats or raise"""
if type(s) is str:
if isinstance(s, basestring):
ss = s.split(',')
if len(ss) != self.n:
raise ValueError(
Expand All @@ -200,7 +201,7 @@ def __init__(self, n):

def __call__(self, s):
"""return a seq of n ints or raise"""
if type(s) is str:
if isinstance(s, basestring):
ss = s.split(',')
if len(ss) != self.n:
raise ValueError(
Expand Down Expand Up @@ -252,20 +253,28 @@ def validate_color(s):

def validate_colorlist(s):
'return a list of colorspecs'
if type(s) is str:
if isinstance(s, basestring):
return [validate_color(c.strip()) for c in s.split(',')]
else:
assert type(s) in [list, tuple]
return [validate_color(c) for c in s]


def validate_string(s):
"""if s is a string, returns a clean string, else raises a TypeError"""
if isinstance(s, basestring) :
return s.strip("'").strip()
else :
raise TypeError('%s should be a bytestring or unicode' % (s))


def validate_stringlist(s):
'return a list'
if type(s) in (str, unicode):
return [v.strip() for v in s.split(',')]
if isinstance(s, basestring):
return [validate_string(v) for v in s.split(',')]
else:
assert type(s) in [list, tuple]
return [str(v) for v in s]
return [validate_string(v) for v in s]


validate_orientation = ValidateInStrings(
Expand All @@ -282,7 +291,7 @@ def validate_aspect(s):


def validate_fontsize(s):
if type(s) is str:
if isinstance(s, basestring):
s = s.lower()
if s in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
'xx-large', 'smaller', 'larger']:
Expand Down Expand Up @@ -335,7 +344,7 @@ def update_savefig_format(value):


def validate_ps_distiller(s):
if type(s) is str:
if isinstance(s, basestring):
s = s.lower()

if s in ('none', None):
Expand Down Expand Up @@ -395,17 +404,20 @@ def validate_tkpythoninspect(s):
def deprecate_svg_embed_char_paths(value):
warnings.warn("svg.embed_char_paths is deprecated. Use "
"svg.fonttype instead.")
return value

validate_svg_fonttype = ValidateInStrings('fonttype',
['none', 'path', 'svgfont'])


def validate_hinting(s):
if s in (True, False):
return s
if s.lower() in ('auto', 'native', 'either', 'none'):
return s.lower()
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")
try :
return validate_bool(s)
except ValueError :
if s.lower() in ('auto', 'native', 'either', 'none'):
return s.lower()
else :
raise ValueError("hinting should be 'auto', 'native', 'either' or 'none'")

validate_pgf_texsystem = ValidateInStrings('pgf.texsystem',
['xelatex', 'lualatex', 'pdflatex'])
Expand All @@ -421,7 +433,7 @@ def validate_hinting(s):


def validate_bbox(s):
if type(s) is str:
if isinstance(s, basestring):
s = s.lower()
if s == 'tight':
return s
Expand Down Expand Up @@ -494,7 +506,7 @@ def __call__(self, s):
# line props
'lines.linewidth': [1.0, validate_float], # line width in points
'lines.linestyle': ['-', str], # solid line
'lines.color': ['b', validate_color], # blue
'lines.color': ['blue', validate_color], # b=blue
'lines.marker': ['None', str], # black
'lines.markeredgewidth': [0.5, validate_float],
'lines.markersize': [6, validate_float], # markersize, in points
Expand All @@ -506,17 +518,17 @@ def __call__(self, s):

## patch props
'patch.linewidth': [1.0, validate_float], # line width in points
'patch.edgecolor': ['k', validate_color], # black
'patch.facecolor': ['b', validate_color], # blue
'patch.edgecolor': ['black', validate_color], # k=black
'patch.facecolor': ['blue', validate_color], # b=blue
'patch.antialiased': [True, validate_bool], # antialised (no jaggies)


## font props
'font.family': ['sans-serif', validate_stringlist], # used by text object
'font.style': ['normal', str],
'font.variant': ['normal', str],
'font.stretch': ['normal', str],
'font.weight': ['normal', str],
'font.family': ['sans-serif', validate_string], # used by text object
'font.style': ['normal', validate_string],
'font.variant': ['normal', validate_string],
'font.stretch': ['normal', validate_string],
'font.weight': ['normal', validate_string],
'font.size': [12, validate_float], # Base font size in points
'font.serif': [['Bitstream Vera Serif', 'DejaVu Serif',
'New Century Schoolbook', 'Century Schoolbook L',
Expand All @@ -530,15 +542,15 @@ def __call__(self, s):
validate_stringlist],
'font.cursive': [['Apple Chancery', 'Textile', 'Zapf Chancery',
'Sand', 'cursive'], validate_stringlist],
'font.fantasy': [['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact'
'font.fantasy': [['Comic Sans MS', 'Chicago', 'Charcoal', 'Impact',
'Western', 'fantasy'], validate_stringlist],
'font.monospace': [['Bitstream Vera Sans Mono', 'DejaVu Sans Mono',
'Andale Mono', 'Nimbus Mono L', 'Courier New',
'Courier', 'Fixed', 'Terminal', 'monospace'],
validate_stringlist],

# text props
'text.color': ['k', validate_color], # black
'text.color': ['black', validate_color], # k=black
'text.usetex': [False, validate_bool],
'text.latex.unicode': [False, validate_bool],
'text.latex.preamble': [[''], validate_stringlist],
Expand All @@ -553,7 +565,7 @@ def __call__(self, s):
'mathtext.tt': ['monospace', validate_font_properties],
'mathtext.it': ['serif:italic', validate_font_properties],
'mathtext.bf': ['serif:bold', validate_font_properties],
'mathtext.sf': ['sans\-serif', validate_font_properties],
'mathtext.sf': ['sans', validate_font_properties],
'mathtext.fontset': ['cm', validate_fontset],
'mathtext.default': ['it', validate_mathtext_default],
'mathtext.fallback_to_cm': [True, validate_bool],
Expand All @@ -571,16 +583,16 @@ def __call__(self, s):
# axes props
'axes.axisbelow': [False, validate_bool],
'axes.hold': [True, validate_bool],
'axes.facecolor': ['w', validate_color], # background color; white
'axes.edgecolor': ['k', validate_color], # edge color; black
'axes.facecolor': ['white', validate_color], # background color; w=white
'axes.edgecolor': ['black', validate_color], # edge color; k=black
'axes.linewidth': [1.0, validate_float], # edge linewidth
'axes.titlesize': ['large', validate_fontsize], # fontsize of the
# axes title
'axes.grid': [False, validate_bool], # display grid or not
'axes.labelsize': ['medium', validate_fontsize], # fontsize of the
# x any y labels
'axes.labelweight': ['normal', str], # fontsize of the x any y labels
'axes.labelcolor': ['k', validate_color], # color of axis label
'axes.labelcolor': ['black', validate_color], # color of axis label
'axes.formatter.limits': [[-7, 7], validate_nseq_int(2)],
# use scientific notation if log10
# of the axis range is smaller than the
Expand Down Expand Up @@ -665,7 +677,7 @@ def __call__(self, s):
'ytick.labelsize': ['medium', validate_fontsize],
'ytick.direction': ['in', str], # direction of yticks

'grid.color': ['k', validate_color], # grid color
'grid.color': ['black', validate_color], # grid color
'grid.linestyle': [':', str], # dotted
'grid.linewidth': [0.5, validate_float], # in points
'grid.alpha': [1.0, validate_float],
Expand All @@ -676,7 +688,7 @@ def __call__(self, s):
'figure.figsize': [[8.0, 6.0], validate_nseq_float(2)],
'figure.dpi': [80, validate_float], # DPI
'figure.facecolor': ['0.75', validate_color], # facecolor; scalar gray
'figure.edgecolor': ['w', validate_color], # edgecolor; white
'figure.edgecolor': ['white', validate_color], # edgecolor; w=white
'figure.frameon': [True, validate_bool],
'figure.autolayout': [False, validate_bool],
'figure.max_open_warning': [20, validate_int],
Expand All @@ -696,8 +708,8 @@ def __call__(self, s):

## Saving figure's properties
'savefig.dpi': [100, validate_float], # DPI
'savefig.facecolor': ['w', validate_color], # facecolor; white
'savefig.edgecolor': ['w', validate_color], # edgecolor; white
'savefig.facecolor': ['white', validate_color], # facecolor; w=white
'savefig.edgecolor': ['white', validate_color], # edgecolor; w=white
'savefig.frameon': [True, validate_bool],
'savefig.orientation': ['portrait', validate_orientation], # edgecolor;
#white
Expand Down Expand Up @@ -752,53 +764,52 @@ def __call__(self, s):
'plugins.directory': ['.matplotlib_plugins', str],

'path.simplify': [True, validate_bool],
'path.simplify_threshold': [1.0 / 9.0, ValidateInterval(0.0, 1.0)],
'path.simplify_threshold': [0.1, ValidateInterval(0.0, 1.0)],
'path.snap': [True, validate_bool],
'path.sketch': [None, validate_sketch],
'path.effects': [[], validate_any],
'agg.path.chunksize': [0, validate_int], # 0 to disable chunking;

# key-mappings (multi-character mappings should be a list/tuple)
'keymap.fullscreen': [('f', 'ctrl+f'), validate_stringlist],
'keymap.fullscreen': [['f', 'ctrl+f'], validate_stringlist],
'keymap.home': [['h', 'r', 'home'], validate_stringlist],
'keymap.back': [['left', 'c', 'backspace'], validate_stringlist],
'keymap.forward': [['right', 'v'], validate_stringlist],
'keymap.pan': ['p', validate_stringlist],
'keymap.zoom': ['o', validate_stringlist],
'keymap.save': [('s', 'ctrl+s'), validate_stringlist],
'keymap.quit': [('ctrl+w', 'cmd+w'), validate_stringlist],
'keymap.grid': ['g', validate_stringlist],
'keymap.yscale': ['l', validate_stringlist],
'keymap.pan': [['p'], validate_stringlist],
'keymap.zoom': [['o'], validate_stringlist],
'keymap.save': [['s', 'ctrl+s'], validate_stringlist],
'keymap.quit': [['ctrl+w', 'cmd+w'], validate_stringlist],
'keymap.grid': [['g'], validate_stringlist],
'keymap.yscale': [['l'], validate_stringlist],
'keymap.xscale': [['k', 'L'], validate_stringlist],
'keymap.all_axes': ['a', validate_stringlist],
'keymap.all_axes': [['a'], validate_stringlist],

# sample data
'examples.directory': ['', str],
'examples.directory': ['', validate_string],

# Animation settings
'animation.writer': ['ffmpeg', validate_movie_writer],
'animation.codec': ['mpeg4', str],
'animation.codec': ['mpeg4', validate_string],
'animation.bitrate': [-1, validate_int],
# Controls image format when frames are written to disk
'animation.frame_format': ['png', validate_movie_frame_fmt],
# Path to FFMPEG binary. If just binary name, subprocess uses $PATH.
'animation.ffmpeg_path': ['ffmpeg', str],
'animation.ffmpeg_path': ['ffmpeg', validate_string],

## Additional arguments for ffmpeg movie writer (using pipes)
'animation.ffmpeg_args': ['', validate_stringlist],
'animation.ffmpeg_args': [[''], validate_stringlist],
# Path to AVConv binary. If just binary name, subprocess uses $PATH.
'animation.avconv_path': ['avconv', str],
'animation.avconv_path': ['avconv', validate_string],
# Additional arguments for avconv movie writer (using pipes)
'animation.avconv_args': ['', validate_stringlist],
'animation.avconv_args': [[''], validate_stringlist],
# Path to MENCODER binary. If just binary name, subprocess uses $PATH.
'animation.mencoder_path': ['mencoder', str],
'animation.mencoder_path': ['mencoder', validate_string],
# Additional arguments for mencoder movie writer (using pipes)
'animation.mencoder_args': ['', validate_stringlist],
'animation.mencoder_args': [[''], validate_stringlist],
# Path to convert binary. If just binary name, subprocess uses $PATH
'animation.convert_path': ['convert', str],
'animation.convert_path': ['convert', validate_string],
# Additional arguments for mencoder movie writer (using pipes)

'animation.convert_args': ['', validate_stringlist]}
'animation.convert_args': [[''], validate_stringlist]}


if __name__ == '__main__':
Expand Down
41 changes: 41 additions & 0 deletions lib/matplotlib/tests/test_rcsetup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os

import matplotlib as mpl
from matplotlib.tests import assert_str_equal

templaterc = os.path.join(os.path.dirname(__file__), 'test_rcsetup.rc')
deprecated = ['svg.embed_char_paths', 'savefig.extension']

def test_defaults():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have some unit tests for this! Thanks!

# the default values should be successfully set by this class
with mpl.rc_context(rc=mpl.rcsetup.defaultParams):
for k, v in mpl.rcsetup.defaultParams.iteritems():
if k not in deprecated:
assert mpl.rcParams[k][0] == v[0]


def test_template():
# the current matplotlibrc.template should validate successfully
with mpl.rc_context(fname=templaterc):
for k, v in mpl.rcsetup.defaultParams.iteritems():
if k not in deprecated:
if isinstance(v[0], basestring):
assert mpl.rcParams[k] in [v[0], v[0].lower()]
else :
664E assert mpl.rcParams[k] == v[0]

def test_unicode():
# unicode formatted valid strings should validate successfully
for k, v in mpl.rcsetup.defaultParams.iteritems():
if k not in deprecated:
if isinstance(v[0], basestring):
u = v[1](unicode(v[0]))
if u not in [v[0], v[0].lower()] :
print "Expected : ", v[0]
print "Actual : ", u
assert u in [v[0], v[0].lower()]


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Loading
0