kernelfoundry.eval_pipeline.utils.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 falls back to sudo rm -rf in that case.

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 (e.g. root-owned files left by a container), falls back to sudo rm -rf.