python-matplotlib/0001-matplotlibrc-path-sear...

112 lines
4.4 KiB
Diff

From 45f0f90c1a4d55f13c6067ef1abaa821d30b9faf Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 27 Sep 2017 19:35:59 -0400
Subject: [PATCH 1/4] matplotlibrc path search fix
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
lib/matplotlib/__init__.py | 31 ++++-----------------------
lib/matplotlib/tests/test_rcparams.py | 15 +++++++++----
2 files changed, 15 insertions(+), 31 deletions(-)
diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py
index fa1caecda..d2bd48800 100644
--- a/lib/matplotlib/__init__.py
+++ b/lib/matplotlib/__init__.py
@@ -654,34 +654,12 @@ def _get_data_path():
"3.1", name="MATPLOTLIBDATA", obj_type="environment variable")
return path
- path = Path(__file__).with_name("mpl-data")
+ path = (Path(__file__).parent.parent.parent.parent.parent /
+ 'share/matplotlib/mpl-data')
if path.is_dir():
defaultParams['datapath'][0] = str(path)
return str(path)
- cbook.warn_deprecated(
- "3.2", message="Matplotlib installs where the data is not in the "
- "mpl-data subdirectory of the package are deprecated since %(since)s "
- "and support for them will be removed %(removal)s.")
-
- def get_candidate_paths():
- # setuptools' namespace_packages may hijack this init file
- # so need to try something known to be in Matplotlib, not basemap.
- import matplotlib.afm
- yield Path(matplotlib.afm.__file__).with_name('mpl-data')
- # py2exe zips pure python, so still need special check.
- if getattr(sys, 'frozen', None):
- yield Path(sys.executable).with_name('mpl-data')
- # Try again assuming we need to step up one more directory.
- yield Path(sys.executable).parent.with_name('mpl-data')
- # Try again assuming sys.path[0] is a dir not a exe.
- yield Path(sys.path[0]) / 'mpl-data'
-
- for path in get_candidate_paths():
- if path.is_dir():
- defaultParams['datapath'][0] = str(path)
- return str(path)
-
raise RuntimeError('Could not find the matplotlib data files')
@@ -712,8 +690,7 @@ def matplotlib_fname():
is not defined)
- On other platforms,
- ``$HOME/.matplotlib/matplotlibrc`` if ``$HOME`` is defined
- - Lastly, it looks in ``$MATPLOTLIBDATA/matplotlibrc``, which should always
- exist.
+ - Lastly, it looks in ``/etc/matplotlibrc``, which should always exist.
"""
def gen_candidates():
@@ -726,7 +703,7 @@ def matplotlib_fname():
yield matplotlibrc
yield os.path.join(matplotlibrc, 'matplotlibrc')
yield os.path.join(get_configdir(), 'matplotlibrc')
- yield os.path.join(_get_data_path(), 'matplotlibrc')
+ yield '/etc/matplotlibrc'
for fname in gen_candidates():
if os.path.exists(fname) and not os.path.isdir(fname):
diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py
index 87dfbeceb..54885da47 100644
--- a/lib/matplotlib/tests/test_rcparams.py
+++ b/lib/matplotlib/tests/test_rcparams.py
@@ -460,10 +460,17 @@ def test_rcparams_reset_after_fail():
assert mpl.rcParams['text.usetex'] is False
-def test_if_rctemplate_is_up_to_date():
+@pytest.fixture
+def mplrc():
+ # This is the Fedora-specific location.
+ return (Path(__file__).parent.parent.parent.parent.parent.parent.parent /
+ 'etc/matplotlibrc')
+
+
+def test_if_rctemplate_is_up_to_date(mplrc):
# This tests if the matplotlibrc.template file contains all valid rcParams.
deprecated = {*mpl._all_deprecated, *mpl._deprecated_remain_as_none}
- with cbook._get_data_path('matplotlibrc').open() as file:
+ with mplrc.open() as file:
rclines = file.readlines()
missing = {}
for k, v in mpl.defaultParams.items():
@@ -483,10 +490,10 @@ def test_if_rctemplate_is_up_to_date():
.format(missing.items()))
-def test_if_rctemplate_would_be_valid(tmpdir):
+def test_if_rctemplate_would_be_valid(tmpdir, mplrc):
# This tests if the matplotlibrc.template file would result in a valid
# rc file if all lines are uncommented.
- with cbook._get_data_path('matplotlibrc').open() as file:
+ with mplrc.open() as file:
rclines = file.readlines()
newlines = []
for line in rclines:
--
2.21.1