@contextlib.contextmanager
def pushd(directory):
    prevdir = os.getcwd()
    os.chdir(directory)
    try:
        yield prevdir
    finally:
        os.chdir(prevdir)
CD into the directory inside a 'with' block
dataset/ETHPy150Open mathcamp/pypicloud/git_hooks/hook.py/pushd