Skip to content

Commit 5206cb0

Browse files
committed
MNT: use string.Template for matplotlibrc.template
Switch to using `string.Template` instead of `%` formatting to generate default matplotlibrc file. This is to avoid having to escape any old or new style format strings that we want to put into the default matplotlibrc file.
1 parent 3a5b577 commit 5206cb0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

matplotlibrc.template

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# You can also deploy your own backend outside of matplotlib by
3636
# referring to the module name (which must be in the PYTHONPATH) as
3737
# 'module://my_backend'.
38-
backend : %(backend)s
38+
backend : $TEMPLATE_BACKEND
3939

4040
# If you are using the Qt4Agg backend, you can choose here
4141
# to use the PyQt4 bindings or the newer PySide bindings to
@@ -338,12 +338,12 @@ backend : %(backend)s
338338
# These values map to the scales:
339339
# {'year': 365, 'month': 30, 'day': 1, 'hour': 1/24, 'minute': 1 / (24 * 60)}
340340

341-
# date.autoformatter.year : %%Y
342-
# date.autoformatter.month : %%Y-%%m
343-
# date.autoformatter.day : %%Y-%%m-%%d
344-
# date.autoformatter.hour : %%H:%%M
345-
# date.autoformatter.minute : %%H:%%M:%%S
346-
# date.autoformatter.second : %%H:%%M:%%S.%%f
341+
# date.autoformatter.year : %Y
342+
# date.autoformatter.month : %Y-%m
343+
# date.autoformatter.day : %Y-%m-%d
344+
# date.autoformatter.hour : %H:%M
345+
# date.autoformatter.minute : %H:%M:%S
346+
# date.autoformatter.second : %H:%M:%S.%f
347347

348348
### TICKS
349349
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from __future__ import print_function, absolute_import
7-
7+
from string import Template
88
# This needs to be the very first thing to use distribute
99
from distribute_setup import use_setuptools
1010
use_setuptools()
@@ -230,8 +230,9 @@ def run(self):
230230
default_backend = setupext.options['backend']
231231
with open('matplotlibrc.template') as fd:
232232
template = fd.read()
233+
template = Template(template)
233234
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
234-
fd.write(template % {'backend': default_backend})
235+
fd.write(template.safe_substitute(TEMPLATE_BACKEND=default_backend))
235236

236237
# Build in verbose mode if requested
237238
if setupext.options['verbose']:

0 commit comments

Comments
 (0)