@contextlib.contextmanager
def clean_path_on_failure(path):
    try:
        yield
    except BaseException:
        if os.path.exists(path):
            rmtree(path)
        raise
Cleans up the directory on an exceptional failure.
dataset/ETHPy150Open pre-commit/pre-commit/pre_commit/util.py/clean_path_on_failure