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
|
A |
- class kernelfoundry.eval_pipeline.utils.tmp_dir.TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False)[source]#
A
tempfile.TemporaryDirectorythat can clean up root-owned files.After containerized runs (Docker / Podman), files inside the temporary directory may be owned by root. Normal cleanup raises
PermissionErrorin that situation. This subclass detects that and retries the deletion viasudo rm -rf, which must be available and permitted for the running user.All constructor arguments are forwarded to
tempfile.TemporaryDirectoryunchanged.- 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_cleanupon POSIX,_force_cleanupon Windows)