8000 Remove some dead branches from texmanager code. · matplotlib/matplotlib@908b2a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 908b2a3

Browse files
committed
Remove some dead branches from texmanager code.
1) get_cachedir() never returns None (244e8d8). 2) rcParams["font.family"] is always a list of str(s), not a single str (its rc validator in rcsetup is validate_stringlist).
1 parent 4e7360f commit 908b2a3

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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ Revert deprecation \*min, \*max keyword arguments to ``set_x/y/zlim_3d()``
7373
These keyword arguments were deprecated in 3.0, alongside with the respective
7474
parameters in ``set_xlim()`` / ``set_ylim()``. The deprecations of the 2D
7575
versions were already reverted in in 3.1.
76+
77+
``TexManager.cachedir``
78+
~~~~~~~~~~~~~~~~~~~~~~~
79+
Use `matplotlib.get_cachedir()` instead.

lib/matplotlib/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,30 +492,29 @@ def _get_config_or_cache_dir(xdg_base):
492492
@_logged_cached('CONFIGDIR=%s')
493493
def get_configdir():
494494
"""
495-
Return the string representing the configuration directory.
495+
Return the string path of the the configuration directory.
496496
497497
The directory is chosen as follows:
498498
499499
1. If the MPLCONFIGDIR environment variable is supplied, choose that.
500-
2a. On Linux, follow the XDG specification and look first in
501-
`$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`.
502-
2b. On other platforms, choose `$HOME/.matplotlib`.
500+
2. On Linux, follow the XDG specification and look first in
501+
``$XDG_CONFIG_HOME``, if defined, or ``$HOME/.config``. On other
502+
platforms, choose ``$HOME/.matplotlib``.
503503
3. If the chosen directory exists and is writable, use that as the
504504
configuration directory.
505-
4. If possible, create a temporary directory, and use it as the
506-
configuration directory.
507-
5. A writable directory could not be found or created; return None.
505+
4. Else, create a temporary directory, and use it as the configuration
506+
directory.
508507
"""
509508
return _get_config_or_cache_dir(_get_xdg_config_dir())
510509

511510

512511
@_logged_cached('CACHEDIR=%s')
513512
def get_cachedir():
514513
"""
515-
Return the location of the cache directory.
514+
Return the string path of the cache directory.
516515
517516
The procedure used to find the directory is the same as for
518-
_get_config_dir, except using `$XDG_CACHE_HOME`/`~/.cache` instead.
517+
_get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead.
519518
"""
520519
return _get_config_or_cache_dir(_get_xdg_cache_dir())
521520

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)
0