Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7706201

Browse files
committed
Switch internal subprocess calls to python stdlib
1 parent 3e66ac0 commit 7706201

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

lib/matplotlib/backends/backend_pgf.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import re
1212
import shutil
13+
import subprocess
1314
import sys
1415
import tempfile
1516
import warnings
@@ -22,8 +23,6 @@
2223
RendererBase)
2324
from matplotlib.backends.backend_mixed import MixedModeRenderer
2425
from matplotlib.cbook import is_writable_file_like
25-
from matplotlib.compat import subprocess
26-
from matplotlib.compat.subprocess import check_output
2726
from matplotlib.path import Path
2827

2928

@@ -42,13 +41,15 @@
4241
# assuming fontconfig is installed and the command 'fc-list' exists
4342
try:
4443
# list scalable (non-bitmap) fonts
45-
fc_list = check_output([str('fc-list'), ':outline,scalable', 'family'])
44+
fc_list = subprocess.check_output(
45+
[str('fc-list'), ':outline,scalable', 'family'])
4646
fc_list = fc_list.decode('utf8')
4747
system_fonts = [f.split(',')[0] for f in fc_list.splitlines()]
4848
system_fonts = list(set(system_fonts))
4949
except:
5050
warnings.warn('error getting fonts from fc-list', UserWarning)
5151

52+
5253
def get_texcommand():
5354
"""Get chosen TeX system from rc."""
5455
texsystem_options = ["xelatex", "lualatex", "pdflatex"]
@@ -173,7 +174,8 @@ def make_pdf_to_png_converter():
173174
tools_available = []
174175
# check for pdftocairo
175176
try:
176-
check_output([str("pdftocairo"), "-v"], stderr=subprocess.STDOUT)
177+
subprocess.check_output(
178+
[str("pdftocairo"), "-v"], stderr=subprocess.STDOUT)
177179
tools_available.append("pdftocairo")
178180
except:
179181
pass
@@ -187,7 +189,7 @@ def make_pdf_to_png_converter():
187189
def cairo_convert(pdffile, pngfile, dpi):
188190
cmd = [str("pdftocairo"), "-singlefile", "-png", "-r", "%d" % dpi,
189191
pdffile, os.path.splitext(pngfile)[0]]
190-
check_output(cmd, stderr=subprocess.STDOUT)
192+
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
191193
return cairo_convert
192194
elif "gs" in tools_available:
193195
def gs_convert(pdffile, pngfile, dpi):
@@ -197,7 +199,7 @@ def gs_convert(pdffile, pngfile, dpi):
197199
'-dGraphicsAlphaBits=4', '-dDOINTERPOLATE',
198200
'-sDEVICE=png16m', '-sOutputFile=%s' % pngfile,
199201
'-r%d' % dpi, pdffile]
200-
check_output(cmd, stderr=subprocess.STDOUT)
202+
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
201203
return gs_convert
202204
else:
203205
raise RuntimeError("No suitable pdf to png renderer found.")
@@ -900,7 +902,8 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
900902
cmdargs = [str(texcommand), "-interaction=nonstopmode",
901903
"-halt-on-error", "figure.tex"]
902904
try:
903-
check_output(cmdargs, stderr=subprocess.STDOUT, cwd=tmpdir)
905+
subprocess.check_output(
906+
cmdargs, stderr=subprocess.STDOUT, cwd=tmpdir)
904907
except subprocess.CalledProcessError as e:
905908
raise RuntimeError(
906909
"%s was not able to process your file.\n\nFull log:\n%s"

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import glob, os, shutil, sys, time, datetime
1212
import io
1313
import logging
14+
import subprocess
1415

1516
from tempfile import mkstemp
1617
from matplotlib import cbook, __version__, rcParams, checkdep_ghostscript
@@ -21,7 +22,6 @@
2122

2223
from matplotlib.cbook import (get_realpath_and_stat, is_writable_file_like,
2324
maxdict, file_requires_unicode)
24-
from matplotlib.compat.subprocess import subprocess
2525

2626
from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font
2727
from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING
@@ -78,8 +78,8 @@ def gs_version(self):
7878
except KeyError:
7979
pass
8080

81-
from matplotlib.compat.subprocess import Popen, PIPE
82-
s = Popen([self.gs_exe, "--version"], stdout=PIPE)
81+
s = subprocess.Popen(
82+
[self.gs_exe, "--version"], stdout=subprocess.PIPE)
8383
pipe, stderr = s.communicate()
8484
if six.PY3:
8585
ver = pipe.decode('ascii')

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ def restrict_dict(d, keys):
12951295

12961296
def report_memory(i=0): # argument may go away
12971297
"""return the memory consumed by process"""
1298-
from matplotlib.compat.subprocess import Popen, PIPE
1298+
from subprocess import Popen, PIPE
12991299
pid = os.getpid()
13001300
if sys.platform == 'sunos5':
13011301
try:

lib/matplotlib/testing/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def skip_if_command_unavailable(cmd):
568568
return a non zero exit code, something like
569569
["latex", "-version"]
570570
"""
571-
from matplotlib.compat.subprocess import check_output
571+
from subprocess import check_output
572572
try:
573573
check_output(cmd)
574574
except:

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import importlib
22
import os
3+
import subprocess
34
import sys
45

5-
from matplotlib.compat.subprocess import Popen
66
import pytest
77

88

99
# Minimal smoke-testing of the backends for which the dependencies are
1010
# PyPI-installable on Travis. They are not available for all tested Python
1111
# versions so we don't fail on missing backends.
12-
#
13-
# We also don't test on Py2 because its subprocess module doesn't support
14-
# timeouts, and it would require a separate code path to check for module
15-
# existence without actually trying to import the module (which may install
16-
# an undesirable input hook).
17-
1812

1913
def _get_testable_interactive_backends():
2014
backends = []
@@ -53,6 +47,6 @@ def _get_testable_interactive_backends():
5347
def test_backend(backend):
5448
environ = os.environ.copy()
5549
environ["MPLBACKEND"] = backend
56-
proc = Popen([sys.executable, "-c", _test_script], env=environ)
50+
proc = subprocess.Popen([sys.executable, "-c", _test_script], env=environ)
5751
# Empirically, 1s is not enough on Travis.
5852
assert proc.wait(timeout=10) == 0

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import os
4545
from pathlib import Path
4646
import shutil
47+
import subprocess
4748
import sys
4849
import warnings
4950

@@ -53,7 +54,6 @@
5354
from matplotlib import rcParams
5455
from matplotlib._png import read_png
5556
from matplotlib.cbook import Locked
56-
from matplotlib.compat.subprocess import subprocess, Popen, PIPE, STDOUT
5757
import matplotlib.dviread as dviread
5858
import re
5959

0 commit comments

Comments
 (0)