ddp_utils.temp.temp_dir

import ddp_utils.temp.temp_dir

Wrap a temporary directory path with optional automatic cleanup.

TempDir exposes path helpers and can remove its directory tree when a managed context exits.

Examples

Use this public operation:

from pathlib import Path
from ddp_utils.temp.temp_dir import TempDir

temporary = TempDir(Path("work"), auto_cleanup=True)
class ddp_utils.temp.temp_dir.TempDir(path: Path, auto_cleanup: bool = True)

Bases: object

Wrapper around a temporary directory path.

This class provides a small, explicit API around a directory path and supports context-manager cleanup.

Parameters

Name

Type

Description

path

Path

Filesystem path of the directory.

auto_cleanup

bool

If True, the directory is removed when exiting the context manager.

Examples

Use this public operation:

instance = TempDir(...)

Bind directory helpers to a path without creating it.

Parameters

Name

Type

Description

path

Path

Directory represented by this wrapper.

auto_cleanup

bool

Remove the directory tree when a managed context exits.

Examples

Configure a wrapper that preserves its directory after context exit:

temporary = TempDir(Path("work"), auto_cleanup=False)
property path: Path

Return the underlying directory path.

Returns

Directory path.

Examples

Use this public operation:

result = instance.path()
exists() → bool

Check whether the directory exists.

Returns

Type

Description

bool

True if the directory exists, else False.

Examples

Use this public operation:

result = instance.exists()
mkdir(parents: bool = True, exist_ok: bool = True) → Path

Ensure the directory exists.

Parameters

Name

Type

Description

parents

bool

Create parent directories if needed.

exist_ok

bool

Do not fail if the directory already exists.

Returns

Type

Description

Path

The directory path.

Examples

Use this public operation:

result = instance.mkdir()
child(*parts: str) → Path

Return a child path inside this directory.

Parameters

Name

Type

Description

parts

str

Relative path components.

Returns

Type

Description

Path

Combined child path.

Examples

Use this public operation:

result = instance.child()
cleanup() → None

Remove the directory tree if it exists.

Examples

Use this public operation:

result = instance.cleanup()