<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def temp_dir(suffix='', prefix='tmp', parent_dir=None, make_cwd=False):
 """ Create a temporary directory and optionally change the current working directory to it. The directory is deleted when the context exits. The temporary directory is created when entering the context manager, and deleted when exiting it: This time let's make the temporary directory our working directory: The suffix, prefix, and parent_dir options are passed to the standard ``tempfile.mkdtemp()`` function: This function can also be used as a decorator, with the in_temp_dir alias: """

    prev_cwd = os.getcwd()
    parent_dir = parent_dir if parent_dir is None else str(parent_dir)
    abs_path = tempfile.mkdtemp(suffix, prefix, parent_dir)
    path = pathlib.Path(abs_path)
    try:
        if make_cwd:
            os.chdir(str(abs_path))
        yield path.resolve()
    finally:
        if make_cwd:
            os.chdir(prev_cwd)
        with temporary.util.allow_missing_file():
            shutil.rmtree(str(abs_path))