Skip to content

Commit 84ebbed

Browse files
committed
matplotlibrc path search fix
1 parent bff1e4b commit 84ebbed

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/matplotlib/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,12 @@ def _get_data_path():
738738

739739
_file = _decode_filesystem_path(__file__)
740740
path = os.sep.join([os.path.dirname(_file), 'mpl-data'])
741+
path = '/usr/share/matplotlib/mpl-data'
741742
if os.path.isdir(path):
742743
return path
743744

745+
raise RuntimeError('Could not find the matplotlib data files')
746+
744747
# setuptools' namespace_packages may highjack this init file
745748
# so need to try something known to be in matplotlib, not basemap
746749
import matplotlib.afm
@@ -821,8 +824,7 @@ def matplotlib_fname():
821824
822825
- `$HOME/.matplotlib/matplotlibrc` if `$HOME` is defined.
823826
824-
- Lastly, it looks in `$MATPLOTLIBDATA/matplotlibrc` for a
825-
system-defined copy.
827+
- Lastly, it looks in `/etc/matplotlibrc` for a system-defined copy.
826828
"""
827829

828830
def gen_candidates():
@@ -835,7 +837,7 @@ def gen_candidates():
835837
yield matplotlibrc
836838
yield os.path.join(matplotlibrc, 'matplotlibrc')
837839
yield os.path.join(_get_configdir(), 'matplotlibrc')
838-
yield os.path.join(get_data_path(), 'matplotlibrc')
840+
yield '/etc/matplotlibrc'
839841

840842
for fname in gen_candidates():
841843
if os.path.exists(fname):

lib/matplotlib/tests/test_rcparams.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,25 @@ def test_rcparams_reset_after_fail():
424424
assert mpl.rcParams['text.usetex'] is False
425425

426426

427-
def test_if_rctemplate_is_up_to_date():
427+
@pytest.fixture
428+
def mplrc():
429+
# This is the Fedora-specific location ...
430+
if 'MATPLOTLIBDATA' in os.environ:
431+
# ... in buildroot.
432+
return os.path.join(os.environ['MATPLOTLIBDATA'],
433+
'../../../../etc/matplotlibrc')
434+
else:
435+
# ... on installed systems.
436+
return '/etc/matplotlibrc'
437+
438+
439+
def test_if_rctemplate_is_up_to_date(mplrc):
428440
# This tests if the matplotlibrc.template file
429441
# contains all valid rcParams.
430442
dep1 = mpl._all_deprecated
431443
dep2 = mpl._deprecated_set
432444
deprecated = list(dep1.union(dep2))
433-
path_to_rc = os.path.join(mpl.get_data_path(), 'matplotlibrc')
434-
with open(path_to_rc, "r") as f:
445+
with open(mplrc, "r") as f:
435446
rclines = f.readlines()
436447
missing = {}
437448
for k, v in mpl.defaultParams.items():
@@ -453,11 +464,10 @@ def test_if_rctemplate_is_up_to_date():
453464
.format(missing.items()))
454465

455466

456-
def test_if_rctemplate_would_be_valid(tmpdir):
467+
def test_if_rctemplate_would_be_valid(tmpdir, mplrc):
457468
# This tests if the matplotlibrc.template file would result in a valid
458469
# rc file if all lines are uncommented.
459-
path_to_rc = os.path.join(mpl.get_data_path(), 'matplotlibrc')
460-
with open(path_to_rc, "r") as f:
470+
with open(mplrc, "r") as f:
461471
rclines = f.readlines()
462472
newlines = []
463473
for line in rclines:

0 commit comments

Comments
 (0)