diff options
author | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-09-26 01:46:29 +0900 |
---|---|---|
committer | Takayuki Shimizukawa <shimizukawa@gmail.com> | 2014-09-26 01:46:29 +0900 |
commit | 0a25e61effbc3cbd7ce8f9648a70ca9e53f8aa8c (patch) | |
tree | f3bd4e5572a33c036dffa83e431592922b93474d /sphinx/ext/pngmath.py | |
parent | 636c14ef4a6ccf3493bf82595977b3bacf3ab192 (diff) | |
download | sphinx-git-0a25e61effbc3cbd7ce8f9648a70ca9e53f8aa8c.tar.gz |
refactoring by using `with cd`
Diffstat (limited to 'sphinx/ext/pngmath.py')
-rw-r--r-- | sphinx/ext/pngmath.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index b6546301c..abac15cd3 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -8,13 +8,14 @@ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import with_statement import re import codecs import shutil import tempfile import posixpath -from os import path, getcwd, chdir +from os import path from subprocess import Popen, PIPE try: from hashlib import sha1 as sha @@ -25,7 +26,7 @@ from docutils import nodes from sphinx.errors import SphinxError from sphinx.util.png import read_png_depth, write_png_depth -from sphinx.util.osutil import ensuredir, ENOENT +from sphinx.util.osutil import ensuredir, ENOENT, cd from sphinx.util.pycompat import b, sys_encoding from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath @@ -117,10 +118,7 @@ def render_math(self, math): ltx_args.extend(self.builder.config.pngmath_latex_args) ltx_args.append('math.tex') - curdir = getcwd() - chdir(tempdir) - - try: + with cd(tempdir): try: p = Popen(ltx_args, stdout=PIPE, stderr=PIPE) except OSError, err: @@ -131,8 +129,6 @@ def render_math(self, math): self.builder.config.pngmath_latex) self.builder._mathpng_warned_latex = True return None, None - finally: - chdir(curdir) stdout, stderr = p.communicate() if p.returncode != 0: |