quantlab.runs.directory.staged#

quantlab.runs.directory.staged(final)[source]#

Yield a hidden staging directory that becomes final when the block succeeds.

The run’s files are written into .{name}.partial beside final, which is renamed into place when the block exits normally (a rename within one filesystem is atomic). On any exception, including KeyboardInterrupt, the staging directory is removed and the error re-raised, so final is complete or absent.

Raises:
RuntimeError

If final already exists; it is never overwritten.

Examples

>>> with staged(root / "run_1") as staging:
...     write_files(staging)
>>> (root / "run_1").is_dir()
True