tmp_dir#

Custom TemporaryDirectory with container-aware cleanup.

When container processes run as root they can leave root-owned files behind, making normal shutil.rmtree cleanup fail with PermissionError. This module provides a drop-in replacement for tempfile.TemporaryDirectory that retries in that case: sudo rm -rf on POSIX, and clearing read-only bits before a second rmtree on Windows, where there is no usable sudo.

Classes

TemporaryDirectory([suffix, prefix, dir, ...])

A tempfile.TemporaryDirectory that can clean up root-owned files.

class kernelfoundry.eval_pipeline.utils.tmp_dir.TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False)[source]#

A tempfile.TemporaryDirectory that can clean up root-owned files.

After containerized runs (Docker / Podman), files inside the temporary directory may be owned by root. Normal cleanup raises PermissionError in that situation. This subclass detects that and retries the deletion via sudo rm -rf, which must be available and permitted for the running user.

All constructor arguments are forwarded to tempfile.TemporaryDirectory unchanged.

cleanup() → None[source]#

Clean up the temporary directory.

Tries the standard cleanup first. If that raises a PermissionError, falls back to a platform-appropriate retry. (_sudo_cleanup on POSIX, _force_cleanup on Windows)