diff --git a/doc/api/matplotlib_configuration_api.rst b/doc/api/matplotlib_configuration_api.rst index e497d80b7c12..a09ef171c9a0 100644 --- a/doc/api/matplotlib_configuration_api.rst +++ b/doc/api/matplotlib_configuration_api.rst @@ -41,9 +41,16 @@ Default values and styling .. autofunction:: rc_params_from_file +.. autofunction:: get_configdir + .. autofunction:: matplotlib_fname Logging ======= .. autofunction:: set_loglevel + +Miscellaneous +============= + +.. autofunction:: get_cachedir diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 3676a75692cc..cae555887193 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -131,3 +131,7 @@ This method is deprecated. Use ``SymmetricalScale.SymmetricalTransform`` and ``SymmetricalScale.InvertedSymmetricalTransform`` are deprecated. Directly access the transform classes from the :mod:`.scale` module. + +``TexManager.cachedir`` +~~~~~~~~~~~~~~~~~~~~~~~ +Use `matplotlib.get_cachedir()` instead. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index cf625110be14..96b04d9c2d82 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -488,19 +488,18 @@ def _get_config_or_cache_dir(xdg_base): @_logged_cached('CONFIGDIR=%s') def get_configdir(): """ - Return the string representing the configuration directory. + Return the string path of the the configuration directory. The directory is chosen as follows: 1. If the MPLCONFIGDIR environment variable is supplied, choose that. - 2a. On Linux, follow the XDG specification and look first in - `$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`. - 2b. On other platforms, choose `$HOME/.matplotlib`. + 2. On Linux, follow the XDG specification and look first in + ``$XDG_CONFIG_HOME``, if defined, or ``$HOME/.config``. On other + platforms, choose ``$HOME/.matplotlib``. 3. If the chosen directory exists and is writable, use that as the configuration directory. - 4. If possible, create a temporary directory, and use it as the - configuration directory. - 5. A writable directory could not be found or created; return None. + 4. Else, create a temporary directory, and use it as the configuration + directory. """ return _get_config_or_cache_dir(_get_xdg_config_dir()) @@ -508,10 +507,10 @@ def get_configdir(): @_logged_cached('CACHEDIR=%s') def get_cachedir(): """ - Return the location of the cache directory. + Return the string path of the cache directory. The procedure used to find the directory is the same as for - _get_config_dir, except using `$XDG_CACHE_HOME`/`~/.cache` instead. + _get_config_dir, except using ``$XDG_CACHE_HOME``/``$HOME/.cache`` instead. """ return _get_config_or_cache_dir(_get_xdg_cache_dir()) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index bdbb38d711d9..59996fe6edfe 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -53,16 +53,8 @@ class TexManager: Repeated calls to this constructor always return the same instance. """ - cachedir = mpl.get_cachedir() - if cachedir is not None: - texcache = os.path.join(cachedir, 'tex.cache') - Path(texcache).mkdir(parents=True, exist_ok=True) - else: - # Should only happen in a restricted environment (such as Google App - # Engine). Deal with this gracefully by not creating a cache directory. - texcache = None - # Caches. + texcache = os.path.join(mpl.get_cachedir(), 'tex.cache') rgba_arrayd = {} grey_arrayd = {} @@ -99,6 +91,11 @@ class TexManager: ('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview', 'font.family') + tuple('font.' + n for n in font_families)) + @cbook.deprecated("3.3", alternative="matplotlib.get_cachedir()") + @property + def cachedir(self): + return mpl.get_cachedir() + @functools.lru_cache() # Always return the same instance. def __new__(cls): self = object.__new__(cls) @@ -106,16 +103,10 @@ def __new__(cls): return self def _reinit(self): - if self.texcache is None: - raise RuntimeError('Cannot create TexManager, as there is no ' - 'cache directory available') - Path(self.texcache).mkdir(parents=True, exist_ok=True) ff = rcParams['font.family'] if len(ff) == 1 and ff[0].lower() in self.font_families: self.font_family = ff[0].lower() - elif isinstance(ff, str) and ff.lower() in self.font_families: - self.font_family = ff.lower() else: _log.info('font.family must be one of (%s) when text.usetex is ' 'True. serif will be used by default.',