b0c798d
From 9776757607af144c824d72920f8983efc35face3 Mon Sep 17 00:00:00 2001
c9345fa
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
c9345fa
Date: Wed, 27 Sep 2017 19:35:59 -0400
9046bbb
Subject: [PATCH 1/4] matplotlibrc path search fix
c9345fa
c9345fa
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
c9345fa
---
9046bbb
 lib/matplotlib/__init__.py            | 19 ++++---------------
9046bbb
 lib/matplotlib/tests/test_rcparams.py | 18 ++++++++++++------
9046bbb
 2 files changed, 16 insertions(+), 21 deletions(-)
c9345fa
c9345fa
diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py
1f37c6a
index 825303171..7a4115491 100644
c9345fa
--- a/lib/matplotlib/__init__.py
c9345fa
+++ b/lib/matplotlib/__init__.py
1f37c6a
@@ -624,18 +624,8 @@ def _get_data_path():
12e8a62
         return path
12e8a62
 
1dcb7af
     def get_candidate_paths():
1dcb7af
-        yield Path(__file__).with_name('mpl-data')
9046bbb
-        # setuptools' namespace_packages may hijack this init file
1dcb7af
-        # so need to try something known to be in Matplotlib, not basemap.
1dcb7af
-        import matplotlib.afm
1dcb7af
-        yield Path(matplotlib.afm.__file__).with_name('mpl-data')
1dcb7af
-        # py2exe zips pure python, so still need special check.
1dcb7af
-        if getattr(sys, 'frozen', None):
1dcb7af
-            yield Path(sys.executable).with_name('mpl-data')
1dcb7af
-            # Try again assuming we need to step up one more directory.
1dcb7af
-            yield Path(sys.executable).parent.with_name('mpl-data')
1dcb7af
-            # Try again assuming sys.path[0] is a dir not a exe.
1dcb7af
-            yield Path(sys.path[0]) / 'mpl-data'
9046bbb
+        yield (Path(__file__).parent.parent.parent.parent.parent /
9046bbb
+               'share/matplotlib/mpl-data')
1dcb7af
 
1dcb7af
     for path in get_candidate_paths():
1dcb7af
         if path.is_dir():
1f37c6a
@@ -678,8 +668,7 @@ def matplotlib_fname():
9046bbb
           is not defined)
9046bbb
     - On other platforms,
9046bbb
         - ``$HOME/.matplotlib/matplotlibrc`` if ``$HOME`` is defined
9046bbb
-    - Lastly, it looks in ``$MATPLOTLIBDATA/matplotlibrc``, which should always
9046bbb
-      exist.
9046bbb
+    - Lastly, it looks in ``/etc/matplotlibrc``, which should always exist.
b11ac26
     """
b11ac26
 
b11ac26
     def gen_candidates():
1f37c6a
@@ -692,7 +681,7 @@ def matplotlib_fname():
5ff9cbe
             yield matplotlibrc
5ff9cbe
             yield os.path.join(matplotlibrc, 'matplotlibrc')
1dcb7af
         yield os.path.join(get_configdir(), 'matplotlibrc')
5ff9cbe
-        yield os.path.join(get_data_path(), 'matplotlibrc')
5ff9cbe
+        yield '/etc/matplotlibrc'
12e8a62
 
5ff9cbe
     for fname in gen_candidates():
9046bbb
         if os.path.exists(fname) and not os.path.isdir(fname):
b11ac26
diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py
1f37c6a
index d8fe73ceb..c3aeb58ef 100644
b11ac26
--- a/lib/matplotlib/tests/test_rcparams.py
b11ac26
+++ b/lib/matplotlib/tests/test_rcparams.py
9046bbb
@@ -1,6 +1,7 @@
9046bbb
 from collections import OrderedDict
9046bbb
 import copy
9046bbb
 import os
9046bbb
+from pathlib import Path
9046bbb
 from unittest import mock
9046bbb
 import warnings
9046bbb
 
1f37c6a
@@ -457,11 +458,17 @@ def test_rcparams_reset_after_fail():
b11ac26
         assert mpl.rcParams['text.usetex'] is False
b11ac26
 
b11ac26
 
b11ac26
-def test_if_rctemplate_is_up_to_date():
b11ac26
+@pytest.fixture
b11ac26
+def mplrc():
9046bbb
+    # This is the Fedora-specific location.
9046bbb
+    return (Path(__file__).parent.parent.parent.parent.parent.parent.parent /
9046bbb
+            'etc/matplotlibrc')
b11ac26
+
b11ac26
+
b11ac26
+def test_if_rctemplate_is_up_to_date(mplrc):
1dcb7af
     # This tests if the matplotlibrc.template file contains all valid rcParams.
1dcb7af
     deprecated = {*mpl._all_deprecated, *mpl._deprecated_remain_as_none}
a6c4a06
-    path_to_rc = os.path.join(mpl.get_data_path(), 'matplotlibrc')
b11ac26
-    with open(path_to_rc, "r") as f:
b11ac26
+    with open(mplrc, "r") as f:
b11ac26
         rclines = f.readlines()
b11ac26
     missing = {}
a6c4a06
     for k, v in mpl.defaultParams.items():
1f37c6a
@@ -484,11 +491,10 @@ def test_if_rctemplate_is_up_to_date():
b11ac26
                          .format(missing.items()))
b11ac26
 
b11ac26
 
b11ac26
-def test_if_rctemplate_would_be_valid(tmpdir):
b11ac26
+def test_if_rctemplate_would_be_valid(tmpdir, mplrc):
b11ac26
     # This tests if the matplotlibrc.template file would result in a valid
b11ac26
     # rc file if all lines are uncommented.
a6c4a06
-    path_to_rc = os.path.join(mpl.get_data_path(), 'matplotlibrc')
b11ac26
-    with open(path_to_rc, "r") as f:
b11ac26
+    with open(mplrc, "r") as f:
b11ac26
         rclines = f.readlines()
b11ac26
     newlines = []
b11ac26
     for line in rclines:
c9345fa
-- 
b0c798d
2.21.1
c9345fa