Skip to content

Commit

Permalink
Issue sympy#24304 fix
Browse files Browse the repository at this point in the history
Add "-nogs" option for dvipng call
Add 10s timeout for subprocess calls
  • Loading branch information
Denis Shuvalov committed Dec 6, 2022
1 parent 900caa3 commit 07cab6d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sympy/printing/preview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from os.path import join
import shutil
import tempfile
from os.path import join

try:
from subprocess import STDOUT, CalledProcessError, check_output
Expand All @@ -13,16 +13,17 @@
from .latex import latex

__doctest_requires__ = {('preview',): ['pyglet']}
CALLS_TIMEOUT = 10.0 # Time-out system command calls


def _check_output_no_window(*args, **kwargs):
# Avoid showing a cmd.exe window when running this
# on Windows
if os.name == 'nt':
creation_flag = 0x08000000 # CREATE_NO_WINDOW
creation_flag = 0x08000000 # CREATE_NO_WINDOW
else:
creation_flag = 0 # Default value
return check_output(*args, creationflags=creation_flag, **kwargs)
creation_flag = 0 # Default value
return check_output(*args, creationflags=creation_flag, timeout=CALLS_TIMEOUT, **kwargs)


def system_default_viewer(fname, fmt):
Expand Down Expand Up @@ -67,8 +68,8 @@ def pyglet_viewer(fname, fmt):

config = gl.Config(double_buffer=False)
win = window.Window(
width=img.width + 2*offset,
height=img.height + 2*offset,
width=img.width + 2 * offset,
height=img.height + 2 * offset,
caption="SymPy",
resizable=False,
config=config
Expand Down Expand Up @@ -148,7 +149,7 @@ def _get_latex_main(expr, *, preamble=None, packages=(), extra_preamble=None,


@doctest_depends_on(exe=('latex', 'dvipng'), modules=('pyglet',),
disable_viewers=('evince', 'gimp', 'superior-dvi-viewer'))
disable_viewers=('evince', 'gimp', 'superior-dvi-viewer'))
def preview(expr, output='png', viewer=None, euler=True, packages=(),
filename=None, outputbuffer=None, preamble=None, dvioptions=None,
outputTexFile=None, extra_preamble=None, fontsize=None,
Expand Down Expand Up @@ -266,9 +267,9 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
# sorted in order from most pretty to most ugly
# very discussable, but indeed 'gv' looks awful :)
candidates = {
"dvi": [ "evince", "okular", "kdvi", "xdvi" ],
"ps": [ "evince", "okular", "gsview", "gv" ],
"pdf": [ "evince", "okular", "kpdf", "acroread", "xpdf", "gv" ],
"dvi": ["evince", "okular", "kdvi", "xdvi"],
"ps": ["evince", "okular", "gsview", "gv"],
"pdf": ["evince", "okular", "kpdf", "acroread", "xpdf", "gv"],
}

for candidate in candidates.get(output, []):
Expand Down Expand Up @@ -346,7 +347,7 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
raise RuntimeError("%s is not installed" % cmd_variants[0])

defaultoptions = {
"dvipng": ["-T", "tight", "-z", "9", "--truecolor"],
"dvipng": ["-T", "tight", "--nogs", "-z", "9", "--truecolor"],
"dvisvgm": ["--no-fonts"],
}

Expand All @@ -372,7 +373,6 @@ def preview(expr, output='png', viewer=None, euler=True, packages=(),
"'%s' exited abnormally with the following output:\n%s" %
(' '.join(cmd), e.output))


if viewer == "file":
shutil.move(join(workdir, src), filename)
elif viewer == "BytesIO":
Expand Down

0 comments on commit 07cab6d

Please sign in to comment.