Skip to content

Commit 74b6913

Browse files
authored
Merge pull request #10565 from dstansby/py3-subprocess
Strip python 2 code from subprocess.py
2 parents ca32c2d + af60158 commit 74b6913

File tree

15 files changed

+43
-68
lines changed

15 files changed

+43
-68
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
Deprecations
22
````````````
3+
The following modules are deprecated:
4+
5+
- :mod:`matplotlib.compat.subprocess`. This was a python 2 workaround, but all the
6+
functionality can now be found in the python 3 standard library
7+
:mod:`subprocess`.
8+
39
The following functions and classes are deprecated:
410

511
- ``cbook.GetRealpathAndStat`` (which is only a helper for
612
``get_realpath_and_stat``),
713
- ``cbook.is_numlike`` (use ``isinstance(..., numbers.Number)`` instead),
814
- ``mathtext.unichr_safe`` (use ``chr`` instead),
15+
- ``texmanager.dvipng_hack_alpha``,

examples/tests/backend_driver_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def report_all_missing(directories):
339339
)
340340

341341

342-
from matplotlib.compat import subprocess
342+
import subprocess
343343

344344

345345
def run(arglist):

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
import re
134134
import shutil
135135
import stat
136+
import subprocess
136137
import tempfile
137138
import warnings
138139

@@ -141,7 +142,6 @@
141142
from . import cbook
142143
from matplotlib.cbook import (
143144
_backports, mplDeprecation, dedent, get_label, sanitize_sequence)
144-
from matplotlib.compat import subprocess
145145
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
146146

147147
import numpy

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import logging
3131
import os
3232
import platform
33+
import subprocess
3334
import sys
3435
import tempfile
3536
import uuid
@@ -38,7 +39,6 @@
3839

3940
from matplotlib._animation_data import (DISPLAY_TEMPLATE, INCLUDED_FRAMES,
4041
JS_INCLUDE)
41-
from matplotlib.compat import subprocess
4242
from matplotlib import cbook, rcParams, rcParamsDefault, rc_context
4343

4444
if six.PY2:

lib/matplotlib/backends/backend_pgf.py

Lines changed: 11 additions & 8 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+
['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+
["pdftocairo", "-v"], stderr=subprocess.STDOUT)
177179
tools_available.append("pdftocairo")
178180
except:
179181
pass
@@ -185,9 +187,9 @@ def make_pdf_to_png_converter():
185187
# pick converter
186188
if "pdftocairo" in tools_available:
187189
def cairo_convert(pdffile, pngfile, dpi):
188-
cmd = [str("pdftocairo"), "-singlefile", "-png", "-r", "%d" % dpi,
190+
cmd = ["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
@@ -1292,7 +1292,7 @@ def restrict_dict(d, keys):
12921292

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

lib/matplotlib/compat/subprocess.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
"""
2-
A replacement wrapper around the subprocess module, with a number of
3-
work-arounds:
4-
- Provides a stub implementation of subprocess members on Google App Engine
5-
(which are missing in subprocess).
6-
- Use subprocess32, backport from python 3.2 on Linux/Mac work-around for
7-
https://github.com/matplotlib/matplotlib/issues/5314
2+
A replacement wrapper around the subprocess module, which provides a stub
3+
implementation of subprocess members on Google App Engine
4+
(which are missing in subprocess).
85
96
Instead of importing subprocess, other modules should use this as follows:
107
118
from matplotlib.compat import subprocess
129
1310
This module is safe to import from anywhere within matplotlib.
1411
"""
15-
16-
from __future__ import absolute_import # Required to import subprocess
17-
from __future__ import print_function
18-
import os
19-
import sys
20-
if os.name == 'posix' and sys.version_info[0] < 3:
21-
# work around for https://github.com/matplotlib/matplotlib/issues/5314
22-
try:
23-
import subprocess32 as subprocess
24-
except ImportError:
25-
import subprocess
26-
else:
27-
import subprocess
12+
import subprocess
13+
from matplotlib.cbook import warn_deprecated
14+
warn_deprecated(since='3.0',
15+
name='matplotlib.compat.subprocess',
16+
alternative='the python 3 standard library '
17+
'"subprocess" module',
18+
obj_type='module')
2819

2920
__all__ = ['Popen', 'PIPE', 'STDOUT', 'check_output', 'CalledProcessError']
3021

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import os
2525
import re
2626
import struct
27+
import subprocess
2728
import sys
2829
import textwrap
2930

3031
import numpy as np
3132

3233
from matplotlib import cbook, rcParams
33-
from matplotlib.compat import subprocess
3434

3535
_log = logging.getLogger(__name__)
3636

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
from functools import lru_cache
4949
import json
5050
import os
51+
import subprocess
5152
import sys
5253
from threading import Timer
5354
import warnings
5455
import logging
5556

5657
from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
57-
from matplotlib.compat import subprocess
5858
from matplotlib.fontconfig_pattern import (
5959
parse_fontconfig_pattern, generate_fontconfig_pattern)
6060

0 commit comments

Comments
 (0)