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

Skip to content
8000

Commit df46b81

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 b12c761 commit df46b81

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
@@ -63,3 +63,7 @@ it via the *cmap* parameter:
6363
``DateFormatter.illegal_s``
6464
~~~~~~~~~~~~~~~~~~~~~~~~~~~
6565
This attribute is unused and deprecated.
66+
67+
``TexManager.cachedir``
68+
~~~~~~~~~~~~~~~~~~~~~~~
69+
Use `matplotlib.get_cachedir()` instead.

lib/matplotlib/__init__.py

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

512511

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

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