Skip to content

Commit d21caa5

Browse files
committed
support relative paths in examples.directory
svn path=/branches/v1_0_maint/; revision=8899
1 parent a9f3f3a commit d21caa5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

doc/matplotlibrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ docstring.hardcopy : True # set this when you want to generate hardcopy docstri
88
# w/o invoking file downloads for the sampledata (see
99
# matplotlib.cbook.get_sample_data. Unpack
1010
# mpl_sampledata-VERSION.tar.gz and point examples.directory to it.
11+
# You can use a relative path for examples.directory and it must be
12+
# relative to this matplotlibrc file
1113

1214
#examples.download : False # False to bypass downloading mechanism
13-
#examples.directory : /home/titan/johnh/python/svn/matplotlib.trunk/sample_data/ # directory to look in if download is false
15+
#examples.directory : /your/path/to/sample_data/ # directory to look in if download is false

lib/matplotlib/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,21 @@ def rc_params(fail_on_error=False):
762762

763763
# this is the instance used by the matplotlib classes
764764
rcParams = rc_params()
765+
766+
if rcParams['examples.directory']:
767+
# paths that are intended to be relative to matplotlib_fname()
768+
# are allowed for the examples.directory parameter.
769+
# However, we will need to fully qualify the path because
770+
# Sphinx requires absolute paths.
771+
if not os.path.isabs(rcParams['examples.directory']):
772+
_basedir, _fname = os.path.split(matplotlib_fname())
773+
# Sometimes matplotlib_fname() can return relative paths,
774+
# Also, using realpath() guarentees that Sphinx will use
775+
# the same path that matplotlib sees (in case of weird symlinks).
776+
_basedir = os.path.realpath(_basedir)
777+
_fullpath = os.path.join(_basedir, rcParams['examples.directory'])
778+
rcParams['examples.directory'] = _fullpath
779+
765780
rcParamsOrig = rcParams.copy()
766781

767782
rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \
@@ -770,6 +785,8 @@ def rc_params(fail_on_error=False):
770785
rcParams['ps.usedistiller'] = checkdep_ps_distiller(rcParams['ps.usedistiller'])
771786
rcParams['text.usetex'] = checkdep_usetex(rcParams['text.usetex'])
772787

788+
789+
773790
def rc(group, **kwargs):
774791
"""
775792
Set the current rc params. Group is the grouping for the rc, eg.

0 commit comments

Comments
 (0)