def in_temporary_directory(func):
@wraps(func)<EOL>def wrapped(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>oldpath = os.environ.get('<STR_LIT>', '<STR_LIT>')<EOL>cwd = os.getcwd()<EOL>target = tempfile.mkdtemp()<EOL>os.chdir(target)<EOL>os.environ['<STR_LIT>'] = cwd + oldpath<EOL>try:<EOL><INDENT>return func(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(cwd)<EOL>os.environ['<STR_LIT>'] = oldpath<EOL>shutil.rmtree(target)<EOL><DEDENT><DEDENT>return wrapped<EOL>
A decorator to run a function in a temporary directory, cleaning up
afterwards.