toolbox: projection rendering + world-frame check; gel centre fix
Browse files- toolbox/staging.py +39 -0
toolbox/staging.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A staging directory that removes itself.
|
| 2 |
+
|
| 3 |
+
`load_calibration` wants a directory holding `calibration/`, so scripts that
|
| 4 |
+
have a bare epoch directory copy it into a temporary one first. Twenty-three
|
| 5 |
+
call sites did `tempfile.mkdtemp()`; none removed it. On the author's machine
|
| 6 |
+
that left 1,296 orphaned directories, and with the clean-room rebuild staging
|
| 7 |
+
273 MB of episodes per run it filled a 469 GB disk -- after which unrelated
|
| 8 |
+
commands failed on ENOSPC with nothing pointing at the cause.
|
| 9 |
+
|
| 10 |
+
These scripts are published. A reader who runs them fills their disk too.
|
| 11 |
+
|
| 12 |
+
atexit rather than a context manager because most call sites hold the path for
|
| 13 |
+
the whole run and wrapping each in a `with` would reindent the body of every
|
| 14 |
+
main() -- a large diff for a small fix, and large diffs are where the real
|
| 15 |
+
mistakes hide.
|
| 16 |
+
"""
|
| 17 |
+
from __future__ import annotations
|
| 18 |
+
|
| 19 |
+
import atexit
|
| 20 |
+
import shutil
|
| 21 |
+
import tempfile
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
|
| 24 |
+
_MADE: list[Path] = []
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _sweep() -> None:
|
| 28 |
+
for d in _MADE:
|
| 29 |
+
shutil.rmtree(d, ignore_errors=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
atexit.register(_sweep)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def staging_dir(prefix: str = "react-stage-") -> Path:
|
| 36 |
+
"""A fresh temporary directory, deleted when the process exits."""
|
| 37 |
+
d = Path(tempfile.mkdtemp(prefix=prefix))
|
| 38 |
+
_MADE.append(d)
|
| 39 |
+
return d
|