quemb.shared.manage_scratch.WorkDir¶
- class quemb.shared.manage_scratch.WorkDir(path, cleanup_at_end=True, ensure_empty=False)¶
 Manage a scratch area.
Upon initialisation of the object the workdir
pathis created, if it does not exist yet. One can either enter apaththemselves, or if it isNone, then the path is automatically determined by the environment, i.e. are we on SLURM, where is the scratch etc. Read more atfrom_environment()for more details.Note that the
/is overloaded for this class and it can be used aspathlib.Pathin that regard, see example below.If
cleanup_at_endis true, thencleanup()method is registered to be called when the program terminates with no errors and deletes the scratch directory. TheWorkDiralso exists as a ContextManager; then the cleanup is performed when leaving the ContextManager. Again, assuming thatcleanup_at_endis true.Examples
>>> with WorkDir('./test_dir', cleanup_at_end=True) as scratch: >>> with open(scratch / 'test.txt', 'w') as f: >>> f.write('hello world') './test_dir' does not exist anymore, if the outer contextmanager is left without errors.
Attributes
Methods
__init__(path[, cleanup_at_end, ensure_empty])Method generated by attrs for class WorkDir.
cleanup([ignore_error])Conditionally cleanup the working directory.
from_environment(*[, user_defined_root, ...])Create a WorkDir based on the environment.
make_subdir(name[, ensure_empty])Create a subdirectory with the same cleanup settings as
self.