From f4a19be7cdd8135006163b1897fcab56dae0c6b8 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 3 Jun 2023 11:30:08 +0200 Subject: [PATCH 1/2] Deprecate TexManager.texcache --- .../next_api_changes/deprecations/26056-OG.rst | 5 +++++ lib/matplotlib/__init__.py | 2 +- lib/matplotlib/texmanager.py | 16 ++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/26056-OG.rst diff --git a/doc/api/next_api_changes/deprecations/26056-OG.rst b/doc/api/next_api_changes/deprecations/26056-OG.rst new file mode 100644 index 000000000000..66b7a3221d0d --- /dev/null +++ b/doc/api/next_api_changes/deprecations/26056-OG.rst @@ -0,0 +1,5 @@ +``TexManager.texcache`` +~~~~~~~~~~~~~~~~~~~~~~~ + +... is considered private and deprecated. The location of the cache directory is +clarified in the doc-string. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index fb3f7288b550..f18fa6b761fe 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -574,7 +574,7 @@ def get_cachedir(): 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``/``$HOME/.cache`` instead. + `get_configdir`, 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 931093e8e5af..29a4d8a2043b 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -31,7 +31,7 @@ import numpy as np import matplotlib as mpl -from matplotlib import cbook, dviread +from matplotlib import _api, cbook, dviread _log = logging.getLogger(__name__) @@ -57,10 +57,14 @@ class TexManager: """ Convert strings to dvi files using TeX, caching the results to a directory. + The cache directory is called ``tex.cache`` and is located is the directory + returned by `.get_cachedir`. + Repeated calls to this constructor always return the same instance. """ - texcache = os.path.join(mpl.get_cachedir(), 'tex.cache') + texcache = _api.deprecate_privatize_attribute("3.8") + _texcache = os.path.join(mpl.get_cachedir(), 'tex.cache') _grey_arrayd = {} _font_families = ('serif', 'sans-serif', 'cursive', 'monospace') @@ -102,7 +106,7 @@ class TexManager: @functools.lru_cache # Always return the same instance. def __new__(cls): - Path(cls.texcache).mkdir(parents=True, exist_ok=True) + Path(cls._texcache).mkdir(parents=True, exist_ok=True) return object.__new__(cls) @classmethod @@ -168,7 +172,7 @@ def get_basefile(cls, tex, fontsize, dpi=None): """ src = cls._get_tex_source(tex, fontsize) + str(dpi) filehash = hashlib.md5(src.encode('utf-8')).hexdigest() - filepath = Path(cls.texcache) + filepath = Path(cls._texcache) num_letters, num_levels = 2, 2 for i in range(0, num_letters*num_levels, num_letters): @@ -244,7 +248,7 @@ def _run_checked_subprocess(cls, command, tex, *, cwd=None): _log.debug(cbook._pformat_subprocess(command)) try: report = subprocess.check_output( - command, cwd=cwd if cwd is not None else cls.texcache, + command, cwd=cwd if cwd is not None else cls._texcache, stderr=subprocess.STDOUT) except FileNotFoundError as exc: raise RuntimeError( @@ -330,7 +334,7 @@ def get_grey(cls, tex, fontsize=None, dpi=None): alpha = cls._grey_arrayd.get(key) if alpha is None: pngfile = cls.make_png(tex, fontsize, dpi) - rgba = mpl.image.imread(os.path.join(cls.texcache, pngfile)) + rgba = mpl.image.imread(os.path.join(cls._texcache, pngfile)) cls._grey_arrayd[key] = alpha = rgba[:, :, -1] return alpha From b529cb17438e35c2ed263305e3c4208739736874 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Tue, 20 Jun 2023 08:48:26 +0200 Subject: [PATCH 2/2] Update lib/matplotlib/texmanager.py Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/texmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 29a4d8a2043b..812eab58b877 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -57,7 +57,7 @@ class TexManager: """ Convert strings to dvi files using TeX, caching the results to a directory. - The cache directory is called ``tex.cache`` and is located is the directory + The cache directory is called ``tex.cache`` and is located in the directory returned by `.get_cachedir`. Repeated calls to this constructor always return the same instance. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy