8000 Deprecate rcParams["datapath"] in favor of mpl.get_data_path(). · matplotlib/matplotlib@26ab43e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 26ab43e

Browse files
committed
Deprecate rcParams["datapath"] in favor of mpl.get_data_path().
The rcParam cannot be meaningfully set by the end user from their matplotlibrc or Python code. (This is a manual backport to 3.2.x.)
1 parent 9b22934 commit 26ab43e

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

doc/api/matplotlib_configuration_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Default values and styling
4343

4444
.. autofunction:: matplotlib_fname
4545

46+
.. autofunction:: get_data_path
47+
4648
Logging
4749
=======
4850

doc/api/prev_api_changes/api_changes_3.2.0/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,8 @@ from the public API in future versions.
290290

291291
``style.core.is_style_file`` and ``style.core.iter_style_files``
292292
are deprecated.
293+
294+
The ``datapath`` rcParam
295+
~~~~~~~~~~~~~~~~~~~~~~~~
296+
Use `.get_data_path` instead. (The rcParam is deprecated because it cannot be
297+
meaningfully set by an end user.) This was deprecated only in 3.2.1.

lib/matplotlib/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,9 @@ def get_cachedir():
619619
return _get_config_or_cache_dir(_get_xdg_cache_dir())
620620

621621

622-
def _get_data_path():
623-
"""Return the path to matplotlib data."""
622+
@_logged_cached('matplotlib data path: %s')
623+
def get_data_path():
624+
"""Return the path to Matplotlib data."""
624625

625626
if 'MATPLOTLIBDATA' in os.environ:
626627
path = os.environ['MATPLOTLIBDATA']
@@ -633,6 +634,7 @@ def _get_data_path():
633634

634635
path = Path(__file__).with_name("mpl-data")
635636
if path.is_dir():
637+
defaultParams['datapath'][0] = str(path)
636638
return str(path)
637639

638640
cbook.warn_deprecated(
@@ -655,18 +657,12 @@ def get_candidate_paths():
655657

656658
for path in get_candidate_paths():
657659
if path.is_dir():
660+
defaultParams['datapath'][0] = str(path)
658661
return str(path)
659662

660663
raise RuntimeError('Could not find the matplotlib data files')
661664

662665

663-
@_logged_cached('matplotlib data path: %s')
664-
def get_data_path():
665-
if defaultParams['datapath'][0] is None:
666-
defaultParams['datapath'][0] = _get_data_path()
667-
return defaultParams['datapath'][0]
668-
669-
670666
@cbook.deprecated("3.1")
671667
def get_py2exe_datafiles():
672668
data_path = Path(get_data_path())
@@ -736,6 +732,7 @@ def gen_candidates():
736732
'savefig.frameon': ('3.1',),
737733
'verbose.fileo': ('3.1',),
738734
'verbose.level': ('3.1',),
735+
'datapath': ('3.2.1',),
739736
}
740737

741738

@@ -973,8 +970,9 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
973970
if key not in _all_deprecated])
974971
config.update(config_from_file)
975972

976-
if config['datapath'] is None:
977-
config['datapath'] = get_data_path()
973+
with cbook._suppress_matplotlib_deprecation_warning():
974+
if config['datapath'] is None:
975+
config['datapath'] = get_data_path()
978976

979977
if "".join(config['text.latex.preamble']):
980978
_log.info("""

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def get_sample_data(fname, asfileobj=True):
439439
440440
If the filename ends in .gz, the file is implicitly ungzipped.
441441
"""
442-
path = Path(matplotlib._get_data_path(), 'sample_data', fname)
442+
path = Path(matplotlib.get_data_path(), 'sample_data', fname)
443443
if asfileobj:
444444
suffix = path.suffix.lower()
445445
if suffix == '.gz':

matplotlibrc.template

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@
103103
#toolbar : toolbar2 ## {None, toolbar2}
104104
#timezone : UTC ## a pytz timezone string, e.g., US/Central or Europe/Paris
105105

106-
## Where your matplotlib data lives if you installed to a non-default
107-
## location. This is where the matplotlib fonts, bitmaps, etc reside
108-
#datapath : /home/jdhunter/mpldata
109-
110106

111107
## ***************************************************************************
112108
## * LINES *

0 commit comments

Comments
 (0)
0