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/util/osutil.py | |
parent | 636c14ef4a6ccf3493bf82595977b3bacf3ab192 (diff) | |
download | sphinx-git-0a25e61effbc3cbd7ce8f9648a70ca9e53f8aa8c.tar.gz |
refactoring by using `with cd`
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index d7b292b3e..e98c49b20 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -18,6 +18,7 @@ import locale import shutil import gettext from os import path +import contextlib # Errnos that we need. EEXIST = getattr(errno, 'EEXIST', 0) @@ -196,3 +197,14 @@ def abspath(pathdir): if isinstance(pathdir, bytes): pathdir = pathdir.decode(fs_encoding) return pathdir + + +@contextlib.contextmanager +def cd(target_dir): + from sphinx.util.pycompat import getcwd + cwd = getcwd() + try: + os.chdir(target_dir) + yield + finally: + os.chdir(cwd) |