def override_temp(replacement):
    """
    Monkey-patch tempfile.tempdir with replacement, ensuring it exists
    """
    os.makedirs(replacement, exist_ok=True)

    saved = tempfile.tempdir

    tempfile.tempdir = replacement

    try:
        yield
    finally:
        tempfile.tempdir = saved

    Monkey-patch tempfile.tempdir with replacement, ensuring it exists
    
product/gradle-plugin/src/main/python/setuptools/sandbox.py