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

Skip to content

Commit 952b56e

Browse files
sandrotosimdboom
authored andcommitted
Reintroduce examples.directory rc parameter
The main reason is that in Debian we store sample_data in a directory outside the Python modules location. This way we're able to specify that directory in a more appropriate way, also to allow examples to work during package building (in particular for the documentation part). The code introduced is a partial revert of 6c5e961 (with very tiny changes).
1 parent 32c302c commit 952b56e

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/matplotlib/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,20 @@ def rc_params_from_file(fname, fail_on_error=False):
823823
# this is the instance used by the matplotlib classes
824824
rcParams = rc_params()
825825

826+
if rcParams['examples.directory']:
827+
# paths that are intended to be relative to matplotlib_fname()
828+
# are allowed for the examples.directory parameter.
829+
# However, we will need to fully qualify the path because
830+
# Sphinx requires absolute paths.
831+
if not os.path.isabs(rcParams['examples.directory']):
832+
_basedir, _fname = os.path.split(matplotlib_fname())
833+
# Sometimes matplotlib_fname() can return relative paths,
834+
# Also, using realpath() guarentees that Sphinx will use
835+
# the same path that matplotlib sees (in case of weird symlinks).
836+
_basedir = os.path.realpath(_basedir)
837+
_fullpath = os.path.join(_basedir, rcParams['examples.directory'])
838+
rcParams['examples.directory'] = _fullpath
839+
826840
rcParamsOrig = rcParams.copy()
827841

828842
rcParamsDefault = RcParams([ (key, default) for key, (default, converter) in \

lib/matplotlib/cbook.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import warnings
2222
from weakref import ref, WeakKeyDictionary
2323

24+
import matplotlib
2425

2526
import numpy as np
2627
import numpy.ma as ma
@@ -570,9 +571,17 @@ def get_sample_data(fname, asfileobj=True):
570571
`mpl-data/sample_data` directory. If *asfileobj* is `True`
571572
return a file object, otherwise just a file path.
572573
574+
Set the rc parameter examples.directory to the directory where we should
575+
look, if sample_data files are stored in a location different than
576+
default (which is 'mpl-data/sample_data` at the same level of 'matplotlib`
577+
Python module files).
578+
573579
If the filename ends in .gz, the file is implicitly ungzipped.
574580
"""
575-
root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
581+
if matplotlib.rcParams['examples.directory']:
582+
root = matplotlib.rcParams['examples.directory']
583+
else:
584+
root = os.path.join(os.path.dirname(__file__), "mpl-data", "sample_data")
576585
path = os.path.join(root, fname)
577586

578587
if asfileobj:

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ def __call__(self, s):
617617
'keymap.xscale' : [['k', 'L'], validate_stringlist],
618618
'keymap.all_axes' : ['a', validate_stringlist],
619619

620+
# sample data
621+
'examples.directory' : ['', str],
622+
620623
# Animation settings
621624
'animation.writer' : ['ffmpeg', validate_movie_writer],
622625
'animation.codec' : ['mpeg4', str],

matplotlibrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
423423
#keymap.xscale : L, k # toggle scaling of x-axes ('log'/'linear')
424424
#keymap.all_axes : a # enable all axes
425425

426+
# Control location of examples data files
427+
#examples.directory : '' # directory to look in for custom installation
428+
426429
###ANIMATION settings
427430
#animation.writer : ffmpeg # MovieWriter 'backend' to use
428431
#animation.codec : mp4 # Codec to use for writing movie

0 commit comments

Comments
 (0)