8000 Deprecate backend_ps.convert_psfrags. · matplotlib/matplotlib@777f1d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 777f1d2

Browse files
committed
Deprecate backend_ps.convert_psfrags.
It is tightly coupled to Matplotlib's choice of using psfrags to implement ps+usetex (e.g., through the renderer.psfrag attribute) and thus unlikely to be useful elsewhere (unlike the distiller functions, which mplcairo reuses). Making it private also allows getting rid of now unused args (font_preamble and custom_preamble), supporting only pathlib.Path args, and may perhaps later allow getting rid of paper orientation handling too.
1 parent bba8e9e commit 777f1d2

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``backend_ps.convert_psfrags``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated.

lib/matplotlib/backends/backend_ps.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,8 @@ def _print_figure_tex(
10451045

10461046
# write to a temp file, we'll move it to outfile when done
10471047
with TemporaryDirectory() as tmpdir:
1048-
tmpfile = os.path.join(tmpdir, "tmp.ps")
1049-
pathlib.Path(tmpfile).write_text(
1048+
tmppath = pathlib.Path(tmpdir, "tmp.ps")
1049+
tmppath.write_text(
10501050
f"""\
10511051
%!PS-Adobe-3.0 EPSF-3.0
10521052
{dsc_comments}
@@ -1082,27 +1082,21 @@ def _print_figure_tex(
10821082
papertype = _get_papertype(width, height)
10831083
paper_width, paper_height = papersize[papertype]
10841084

1085-
texmanager = ps_renderer.get_texmanager()
1086-
font_preamble = texmanager.get_font_preamble()
1087-
custom_preamble = texmanager.get_custom_preamble()
1088-
1089-
psfrag_rotated = convert_psfrags(tmpfile, ps_renderer.psfrag,
1090-
font_preamble,
1091-
custom_preamble, paper_width,
1092-
paper_height,
1093-
orientation.name)
1085+
psfrag_rotated = _convert_psfrags(
1086+
tmppath, ps_renderer.psfrag, paper_width, paper_height,
1087+
orientation.name)
10941088

10951089
if (mpl.rcParams['ps.usedistiller'] == 'ghostscript'
10961090
or mpl.rcParams['text.usetex']):
10971091
_try_distill(gs_distill,
1098-
tmpfile, is_eps, ptype=papertype, bbox=bbox,
1092+
tmppath, is_eps, ptype=papertype, bbox=bbox,
10991093
rotated=psfrag_rotated)
11001094
elif mpl.rcParams['ps.usedistiller'] == 'xpdf':
11011095
_try_distill(xpdf_distill,
1102-
tmpfile, is_eps, ptype=papertype, bbox=bbox,
1096+
tmppath, is_eps, ptype=papertype, bbox=bbox,
11031097
rotated=psfrag_rotated)
11041098

1105-
_move_path_to_path_or_stream(tmpfile, outfile)
1099+
_move_path_to_path_or_stream(tmppath, outfile)
11061100

11071101
print_ps = functools.partialmethod(_print_ps, "ps")
11081102
print_eps = functools.partialmethod(_print_ps, "eps")
@@ -1112,8 +1106,14 @@ def draw(self):
11121106
return super().draw()
11131107

11141108

1109+
@_api.deprecated("3.6")
11151110
def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11161111
paper_width, paper_height, orientation):
1112+
return _convert_psfrags(
1113+
pathlib.Path(tmpfile), psfrags, paper_width, paper_height, orientation)
1114+
1115+
1116+
def _convert_psfrags(tmppath, psfrags, paper_width, paper_height, orientation):
11171117
"""
11181118
When we want to use the LaTeX backend with postscript, we write PSFrag tags
11191119
to a temporary postscript file, each one marking a position for LaTeX to
@@ -1140,15 +1140,15 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11401140
% {
11411141
"psfrags": "\n".join(psfrags),
11421142
"angle": 90 if orientation == 'landscape' else 0,
1143-
"epsfile": pathlib.Path(tmpfile).resolve().as_posix(),
1143+
"epsfile": tmppath.resolve().as_posix(),
11441144
},
11451145
fontsize=10) # tex's default fontsize.
11461146

11471147
with TemporaryDirectory() as tmpdir:
11481148
psfile = os.path.join(tmpdir, "tmp.ps")
11491149
cbook._check_and_log_subprocess(
11501150
['dvips', '-q', '-R0', '-o', psfile, dvifile], _log)
1151-
shutil.move(psfile, tmpfile)
1151+
shutil.move(psfile, tmppath)
11521152

11531153
# check if the dvips created a ps in landscape paper. Somehow,
11541154
# above latex+dvips results in a ps file in a landscape mode for a
@@ -1157,14 +1157,14 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11571157
# the generated ps file is in landscape and return this
11581158
# information. The return value is used in pstoeps step to recover
11591159
# the correct bounding box. 2010-06-05 JJL
1160-
with open(tmpfile) as fh:
1160+
with open(tmppath) as fh:
11611161
psfrag_rotated = "Landscape" in fh.read(1000)
11621162
return psfrag_rotated
11631163

11641164

1165-
def _try_distill(func, *args, **kwargs):
1165+
def _try_distill(func, tmppath, *args, **kwargs):
11661166
try:
1167-
func(*args, **kwargs)
1167+
func(str(tmppath), *args, **kwargs)
11681168
except mpl.ExecutableNotFoundError as exc:
11691169
_log.warning("%s. Distillation step skipped.", exc)
11701170

0 commit comments

Comments
 (0)
0