From 21c4db600df624022e12d49e26265906bba756f8 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 25 Jan 2018 17:10:19 -0800 Subject: [PATCH] Linewrap backend_pgf to 79 characters. --- lib/matplotlib/backends/backend_pgf.py | 85 ++++++++++++++++++-------- pytest.ini | 2 +- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/lib/matplotlib/backends/backend_pgf.py b/lib/matplotlib/backends/backend_pgf.py index fc5882596843..f67aeb592c7a 100644 --- a/lib/matplotlib/backends/backend_pgf.py +++ b/lib/matplotlib/backends/backend_pgf.py @@ -191,9 +191,11 @@ def cairo_convert(pdffile, pngfile, dpi): return cairo_convert elif "gs" in tools_available: def gs_convert(pdffile, pngfile, dpi): - cmd = [str(gs), '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT', - '-sDEVICE=png16m', '-dUseCIEColor', '-dTextAlphaBits=4', - '-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', '-sOutputFile=%s' % pngfile, + cmd = [str(gs), + '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT', + '-dUseCIEColor', '-dTextAlphaBits=4', + '-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', + '-sDEVICE=png16m', '-sOutputFile=%s' % pngfile, '-r%d' % dpi, pdffile] check_output(cmd, stderr=subprocess.STDOUT) return gs_convert @@ -242,8 +244,8 @@ class LatexManager(object): def _build_latex_header(): latex_preamble = get_preamble() latex_fontspec = get_fontspec() - # Create LaTeX header with some content, else LaTeX will load some - # math fonts later when we don't expect the additional output on stdout. + # Create LaTeX header with some content, else LaTeX will load some math + # fonts later when we don't expect the additional output on stdout. # TODO: is this sufficient? latex_header = [r"\documentclass{minimal}", latex_preamble, @@ -300,16 +302,17 @@ def __init__(self): cwd=self.tmpdir) except OSError as e: if e.errno == errno.ENOENT: - raise RuntimeError("Latex command not found. " - "Install '%s' or change pgf.texsystem to the desired command." - % self.texcommand - ) + raise RuntimeError( + "Latex command not found. Install %r or change " + "pgf.texsystem to the desired command." % self.texcommand) else: - raise RuntimeError("Error starting process '%s'" % self.texcommand) + raise RuntimeError( + "Error starting process %r" % self.texcommand) test_input = self.latex_header + latex_end stdout, stderr = latex.communicate(test_input.encode("utf-8")) if latex.returncode != 0: - raise LatexError("LaTeX returned an error, probably missing font or error in preamble:\n%s" % stdout) + raise LatexError("LaTeX returned an error, probably missing font " + "or error in preamble:\n%s" % stdout) # open LaTeX process for real work latex = subprocess.Popen([str(self.texcommand), "-halt-on-error"], @@ -429,7 +432,8 @@ def __init__(self, figure, fh, dummy=False): UserWarning) self.__dict__["draw_image"] = lambda *args, **kwargs: None - def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None): + def draw_markers(self, gc, marker_path, marker_trans, path, trans, + rgbFace=None): writeln(self.fh, r"\begin{pgfscope}") # convert from display units to in @@ -442,7 +446,9 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None) # build marker definition bl, tr = marker_path.get_extents(marker_trans).get_points() coords = bl[0] * f, bl[1] * f, tr[0] * f, tr[1] * f - writeln(self.fh, r"\pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords) + writeln(self.fh, + r"\pgfsys@defobject{currentmarker}" + r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{" % coords) self._print_pgf_path(None, marker_path, marker_trans) self._pgf_path_draw(stroke=gc.get_linewidth() != 0.0, fill=rgbFace is not None) @@ -479,9 +485,13 @@ def draw_path(self, gc, path, transform, rgbFace=None): writeln(self.fh, r"\pgfusepath{clip}") # build pattern definition - writeln(self.fh, r"\pgfsys@defobject{currentpattern}{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{") + writeln(self.fh, + r"\pgfsys@defobject{currentpattern}" + r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{") writeln(self.fh, r"\begin{pgfscope}") - writeln(self.fh, r"\pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}") + writeln(self.fh, + r"\pgfpathrectangle" + r"{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}") writeln(self.fh, r"\pgfusepath{clip}") scale = mpl.transforms.Affine2D().scale(self.dpi) self._print_pgf_path(None, gc.get_hatch_path(), scale) @@ -490,11 +500,13 @@ def draw_path(self, gc, path, transform, rgbFace=None): writeln(self.fh, r"}") # repeat pattern, filling the bounding rect of the path f = 1. / self.dpi - (xmin, ymin), (xmax, ymax) = path.get_extents(transform).get_points() + (xmin, ymin), (xmax, ymax) = \ + path.get_extents(transform).get_points() xmin, xmax = f * xmin, f * xmax ymin, ymax = f * ymin, f * ymax repx, repy = int(math.ceil(xmax-xmin)), int(math.ceil(ymax-ymin)) - writeln(self.fh, r"\pgfsys@transformshift{%fin}{%fin}" % (xmin, ymin)) + writeln(self.fh, + r"\pgfsys@transformshift{%fin}{%fin}" % (xmin, ymin)) for iy in range(repy): for ix in range(repx): writeln(self.fh, r"\pgfsys@useobject{currentpattern}{}") @@ -512,7 +524,10 @@ def _print_pgf_clip(self, gc): p1, p2 = bbox.get_points() w, h = p2 - p1 coords = p1[0] * f, p1[1] * f, w * f, h * f - writeln(self.fh, r"\pgfpathrectangle{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}} " % coords) + writeln(self.fh, + r"\pgfpathrectangle" + r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" + % coords) writeln(self.fh, r"\pgfusepath{clip}") # check for clip path @@ -544,7 +559,9 @@ def _print_pgf_path_styles(self, gc, rgbFace): fillopacity = rgbFace[3] if has_fill and len(rgbFace) > 3 else 1.0 if has_fill: - writeln(self.fh, r"\definecolor{currentfill}{rgb}{%f,%f,%f}" % tuple(rgbFace[:3])) + writeln(self.fh, + r"\definecolor{currentfill}{rgb}{%f,%f,%f}" + % tuple(rgbFace[:3])) writeln(self.fh, r"\pgfsetfillcolor{currentfill}") if has_fill and fillopacity != 1.0: writeln(self.fh, r"\pgfsetfillopacity{%f}" % fillopacity) @@ -553,7 +570,9 @@ def _print_pgf_path_styles(self, gc, rgbFace): lw = gc.get_linewidth() * mpl_pt_to_in * latex_in_to_pt stroke_rgba = gc.get_rgb() writeln(self.fh, r"\pgfsetlinewidth{%fpt}" % lw) - writeln(self.fh, r"\definecolor{currentstroke}{rgb}{%f,%f,%f}" % stroke_rgba[:3]) + writeln(self.fh, + r"\definecolor{currentstroke}{rgb}{%f,%f,%f}" + % stroke_rgba[:3]) writeln(self.fh, r"\pgfsetstrokecolor{currentstroke}") if strokeopacity != 1.0: writeln(self.fh, r"\pgfsetstrokeopacity{%f}" % strokeopacity) @@ -582,22 +601,32 @@ def _print_pgf_path(self, gc, path, transform, rgbFace=None): for points, code in path.iter_segments(transform, clip=clip): if code == Path.MOVETO: x, y = tuple(points) - writeln(self.fh, r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" % + writeln(self.fh, + r"\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}" % (f * x, f * y)) elif code == Path.CLOSEPOLY: writeln(self.fh, r"\pgfpathclose") elif code == Path.LINETO: x, y = tuple(points) - writeln(self.fh, r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" % + writeln(self.fh, + r"\pgfpathlineto{\pgfqpoint{%fin}{%fin}}" % (f * x, f * y)) elif code == Path.CURVE3: cx, cy, px, py = tuple(points) coords = cx * f, cy * f, px * f, py * f - writeln(self.fh, r"\pgfpathquadraticcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" % coords) + writeln(self.fh, + r"\pgfpathquadraticcurveto" + r"{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" + % coords) elif code == Path.CURVE4: c1x, c1y, c2x, c2y, px, py = tuple(points) coords = c1x * f, c1y * f, c2x * f, c2y * f, px * f, py * f - writeln(self.fh, r"\pgfpathcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}" % coords) + writeln(self.fh, + r"\pgfpathcurveto" + r"{\pgfqpoint{%fin}{%fin}}" + r"{\pgfqpoint{%fin}{%fin}}" + r"{\pgfqpoint{%fin}{%fin}}" + % coords) def _pgf_path_draw(self, stroke=True, fill=False): actions = [] @@ -805,7 +834,9 @@ def _print_pgf_to_fh(self, fh, *args, **kwargs): writeln(fh, r"\begingroup") writeln(fh, r"\makeatletter") writeln(fh, r"\begin{pgfpicture}") - writeln(fh, r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" % (w, h)) + writeln(fh, + r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}" + % (w, h)) writeln(fh, r"\pgfusepath{use as bounding box, clip}") _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None) renderer = MixedModeRenderer(self.figure, w, h, dpi, @@ -872,7 +903,9 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs): try: check_output(cmdargs, stderr=subprocess.STDOUT, cwd=tmpdir) except subprocess.CalledProcessError as e: - raise RuntimeError("%s was not able to process your file.\n\nFull log:\n%s" % (texcommand, e.output)) + raise RuntimeError( + "%s was not able to process your file.\n\nFull log:\n%s" + % (texcommand, e.output)) # copy file contents to target with open(fname_pdf, "rb") as fh_src: diff --git a/pytest.ini b/pytest.ini index d30a885c90db..2efba30479c7 100644 --- a/pytest.ini +++ b/pytest.ini @@ -31,7 +31,7 @@ pep8ignore = matplotlib/backends/backend_gtkagg.py E211 E225 E231 E261 E302 E501 E701 matplotlib/backends/backend_gtkcairo.py E211 E225 E231 E402 E701 matplotlib/backends/backend_macosx.py E222 E225 E231 E261 E701 E711 - matplotlib/backends/backend_pgf.py E261 E302 E303 E501 E731 + matplotlib/backends/backend_pgf.py E261 E302 E303 E731 matplotlib/backends/backend_ps.py E202 E203 E225 E228 E231 E261 E262 E271 E301 E302 E303 E401 E402 E501 E701 matplotlib/backends/backend_svg.py E203 E221 E225 E228 E231 E261 E302 E401 E501 matplotlib/backends/backend_template.py E302 E303