Cleanup Utils
GitHub Link to Code.
Centralized file and directory cleanup helpers with deterministic memmap release.
- class mdxplain.utils.cleanup_utils.CleanupUtils
Utility methods for safe file and directory deletion.
- static close_zarr_store(store: Any) None
Best-effort close for a zarr group/store handle.
Parameters
- storeAny
Zarr group-like object (or None).
Returns
- None
Attempts to close both group and backend store handles.
- static remove_file(path: str | PathLike, *, missing_ok: bool = True, ignore_errors: bool = False, purpose: str = 'file path') bool
Remove a file after closing tracked memmaps for the same path.
Parameters
- pathstr or os.PathLike
File path to remove.
- missing_okbool, default=True
If True, no error is raised when path does not exist.
- ignore_errorsbool, default=False
If True, OSError from delete operations is suppressed.
- purposestr, default=”file path”
Human-readable purpose for path validation errors.
Returns
- bool
True if a file was removed, otherwise False.
- static remove_tree(path: str | PathLike, *, missing_ok: bool = True, ignore_errors: bool = False, purpose: str = 'directory path') bool
Remove a directory tree after closing tracked memmaps.
Parameters
- pathstr or os.PathLike
Directory path to remove.
- missing_okbool, default=True
If True, no error is raised when path does not exist.
- ignore_errorsbool, default=False
If True, shutil.rmtree suppresses delete errors.
- purposestr, default=”directory path”
Human-readable purpose for path validation errors.
Returns
- bool
True if a directory was removed, otherwise False.
- static remove_path(path: str | PathLike, *, missing_ok: bool = True, ignore_errors: bool = False, purpose: str = 'path') bool
Remove a path (file or directory) with memmap cleanup.
Parameters
- pathstr or os.PathLike
Path to remove.
- missing_okbool, default=True
If True, no error is raised when path does not exist.
- ignore_errorsbool, default=False
If True, OSError from delete operations is suppressed.
- purposestr, default=”path”
Human-readable purpose for path validation errors.
Returns
- bool
True if a path was removed, otherwise False.