Skip to content

Commit e05681f

Browse files
authored
Merge pull request #15847 from anntzer/texman
MNT: Remove some dead branches from texmanager code.
2 parents 4130dab + 3e21d60 commit e05681f

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

doc/api/matplotlib_configuration_api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ Default values and styling
4141

4242
.. autofunction:: rc_params_from_file
4343

44+
.. autofunction:: get_configdir
45+
4446
.. autofunction:: matplotlib_fname
4547

4648
Logging
4749
=======
4850

4951
.. autofunction:: set_loglevel
52+
53+
Miscellaneous
54+
=============
55+
56+
.. autofunction:: get_cachedir

doc/api/next_api_changes/deprecations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,7 @@ This method is deprecated. Use
131131
``SymmetricalScale.SymmetricalTransform`` and
132132
``SymmetricalScale.InvertedSymmetricalTransform`` are deprecated. Directly
133133
access the transform classes from the :mod:`.scale` module.
134+
135+
``TexManager.cachedir``
136+
~~~~~~~~~~~~~~~~~~~~~~~
137+
Use `matplotlib.get_cachedir()` instead.

lib/matplotlib/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,30 +488,29 @@ def _get_config_or_cache_dir(xdg_base):
488488
@_logged_cached('CONFIGDIR=%s')
489489
def get_configdir():
490490
"""
491-
Return the string representing the configuration directory.
491+
Return the string path of the the configuration directory.
492492
493493
The directory is chosen as follows:
494494
495495
1. If the MPLCONFIGDIR environment variable is supplied, choose that.
496-
2a. On Linux, follow the XDG specification and look first in
497-
`$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`.
498-
2b. On other platforms, choose `$HOME/.matplotlib`.
496+
2. On Linux, follow the XDG specification and look first in
497+
``$XDG_CONFIG_HOME``, if defined, or ``$HOME/.config``. On other
498+
platforms, choose ``$HOME/.matplotlib``.
499499
3. If the chosen directory exists and is writable, use that as the
500500
configuration directory.
501-
4. If possible, create a temporary directory, and use it as the
502-
configuration directory.
503-
5. A writable directory could not be found or created; return None.
501+
4. Else, create a temporary directory, and use it as the configuration
502+
directory.
504503
"""
505504
return _get_config_or_cache_dir(_get_xdg_config_dir())
506505

507506

508507
@_logged_cached('CACHEDIR=%s')
509508
def get_cachedir():
510509
"""
511-
Return the location of the cache directory.
510+
Return the string path of the cache directory.
512511
513512
The procedure used to find the directory is the same as for
514-
_get_config_dir, except using `$XDG_CACHE_HOME`/`~/.cache` instead.
513+
_get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead.
515514
"""
516515
return _get_config_or_cache_dir(_get_xdg_cache_dir())
517516

lib/matplotlib/texmanager.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,8 @@ class TexManager:
5353
Repeated calls to this constructor always return the same instance.
5454
"""
5555

56-
cachedir = mpl.get_cachedir()
57-
if cachedir is not None:
58-
texcache = os.path.join(cachedir, 'tex.cache')
59-
Path(texcache).mkdir(parents=True, exist_ok=True)
60-
else:
61-
# Should only happen in a restricted environment (such as Google App
62-
# Engine). Deal with this gracefully by not creating a cache directory.
63-
texcache = None
64-
6556
# Caches.
57+
texcache = os.path.join(mpl.get_cachedir(), 'tex.cache')
6658
rgba_arrayd = {}
6759
grey_arrayd = {}
6860

@@ -99,23 +91,22 @@ class TexManager:
9991
('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview',
10092
'font.family') + tuple('font.' + n for n in font_families))
10193

94+
@cbook.deprecated("3.3", alternative="matplotlib.get_cachedir()")
95+
@property
96+
def cachedir(self):
97+
return mpl.get_cachedir()
98+
10299
@functools.lru_cache() # Always return the same instance.
103100
def __new__(cls):
104101
self = object.__new__(cls)
105102
self._reinit()
106103
return self
107104

108105
def _reinit(self):
109-
if self.texcache is None:
110-
raise RuntimeError('Cannot create TexManager, as there is no '
111-
'cache directory available')
112-
113106
Path(self.texcache).mkdir(parents=True, exist_ok=True)
114107
ff = rcParams['font.family']
115108
if len(ff) == 1 and ff[0].lower() in self.font_families:
116109
self.font_family = ff[0].lower()
117-
elif isinstance(ff, str) and ff.lower() in self.font_families:
118-
self.font_family = ff.lower()
119110
else:
120111
_log.info('font.family must be one of (%s) when text.usetex is '
121112
'True. serif will be used by default.',

0 commit comments

Comments
 (0)