Skip to content

Fix TexManager's support for openin_any = p #23804

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
Sep 7, 2022
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
15 changes: 15 additions & 0 deletions lib/matplotlib/tests/test_texmanager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
from pathlib import Path
import re
import subprocess
import sys

import matplotlib.pyplot as plt
from matplotlib.texmanager import TexManager
Expand Down Expand Up @@ -57,3 +60,15 @@ def test_unicode_characters():
with pytest.raises(RuntimeError):
ax.set_title('\N{SNOWMAN}')
fig.canvas.draw()


@needs_usetex
def test_openin_any_paranoid():
completed = subprocess.run(
[sys.executable, "-c",
'import matplotlib.pyplot as plt;'
'plt.rcParams.update({"text.usetex": True});'
'plt.title("paranoid");'
'plt.show(block=False);'],
env={**os.environ, 'openin_any': 'p'}, check=True, capture_output=True)
assert completed.stderr == b""
12 changes: 8 additions & 4 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,16 @@ def make_dvi(cls, tex, fontsize):
# and thus replace() works atomically. It also allows referring to
# the texfile with a relative path (for pathological MPLCONFIGDIRs,
# the absolute path may contain characters (e.g. ~) that TeX does
# not support.)
with TemporaryDirectory(dir=Path(dvifile).parent) as tmpdir:
# not support; n.b. relative paths cannot traverse parents, or it
# will be blocked when `openin_any = p` in texmf.cnf).
cwd = Path(dvifile).parent
with TemporaryDirectory(dir=cwd) as tmpdir:
tmppath = Path(tmpdir)
cls._run_checked_subprocess(
["latex", "-interaction=nonstopmode", "--halt-on-error",
f"../{texfile.name}"], tex, cwd=tmpdir)
(Path(tmpdir) / Path(dvifile).name).replace(dvifile)
f"--output-directory={tmppath.name}",
f"{texfile.name}"], tex, cwd=cwd)
(tmppath / Path(dvifile).name).replace(dvifile)
return dvifile

@classmethod
Expand Down