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

Skip to content

Commit b09fb5f

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 4ef1da9 commit b09fb5f

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
@@ -47,3 +47,7 @@ PDF and PS character tracking internals
4747
The ``used_characters`` attribute and ``track_characters`` and
4848
``merge_used_characters`` methods of `.RendererPdf`, `.PdfFile`, and
4949
`.RendererPS` are deprecated.
50+
51+
``TexManager.cachedir``
52+
~~~~~~~~~~~~~~~~~~~~~~~
53+
Use `matplotlib.get_cachedir()` instead.

lib/matplotlib/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,30 +572,29 @@ def _get_config_or_cache_dir(xdg_base):
572572
@_logged_cached('CONFIGDIR=%s')
573573
def get_configdir():
574574
"""
575-
Return the string representing the configuration directory.
575+
Return the string path of the the configuration directory.
576576
577577
The directory is chosen as follows:
578578
579579
1. If the MPLCONFIGDIR environment variable is supplied, choose that.
580-
2a. On Linux, follow the XDG specification and look first in
581-
`$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`.
582-
2b. On other platforms, choose `$HOME/.matplotlib`.
580+
2. On Linux, follow the XDG specification and look first in
581+
`$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`. On other platforms,
582+
choose `$HOME/.matplotlib`.
583583
3. If the chosen directory exists and is writable, use that as the
584584
configuration directory.
585-
4. If possible, create a temporary directory, and use it as the
586-
configuration directory.
587-
5. A writable directory could not be found or created; return None.
585+
4. Else, create a temporary directory, and use it as the configuration
586+
directory.
588587
"""
589588
return _get_config_or_cache_dir(_get_xdg_config_dir())
590589

591590

592591
@_logged_cached('CACHEDIR=%s')
593592
def get_cachedir():
594593
"""
595-
Return the location of the cache directory.
594+
Return the string path of the cache directory.
596595
597596
The procedure used to find the directory is the same as for
598-
_get_config_dir, except using `$XDG_CACHE_HOME`/`~/.cache` instead.
597+
_get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead.
599598
"""
600599
return _get_config_or_cache_dir(_get_xdg_cache_dir())
601600

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