8000 Remove some dead branches from texmanager code. by anntzer · Pull Request #15847 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Remove some dead branches from texmanager code. #15847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/matplotlib_configuration_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 8 additions & 9 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,30 +488,29 @@ 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())


@_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())

Expand Down
21 changes: 6 additions & 15 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -99,23 +91,22 @@ 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)
self._reinit()
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.',
Expand Down
0