Skip to content

Commit 66debb9

Browse files
committed
Don't delete transform sandboxes when a bblock temporarily has no transforms
Previously, cleanup_sandbox deleted the entire bblock sandbox directory whenever the bblock had no subprocess transforms with pip/npm deps. This meant renaming transforms.yaml to disable transforms would wipe all sandboxes, forcing a full reinstall when the file was renamed back. Now we only delete a bblock's sandbox if the bblock itself no longer exists in the register. If it exists but currently has zero subprocess transforms, the sandboxes are left intact.
1 parent 6b01f18 commit 66debb9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ogc/bblocks/transform.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def cleanup_sandbox(sandbox_dir: Path, bblocks: list[BuildingBlock]) -> None:
265265
# Transform cleanup: remove sandboxes for deleted/changed bblocks or transforms
266266
transforms_dir = sandbox_dir / 'transforms'
267267
if transforms_dir.exists():
268+
known_ids: set[str] = {b.identifier for b in bblocks}
268269
expected: dict[str, set[str]] = {}
269270
for bblock in bblocks:
270271
for transform in (bblock.transforms or []):
@@ -277,10 +278,12 @@ def cleanup_sandbox(sandbox_dir: Path, bblocks: list[BuildingBlock]) -> None:
277278
for bblock_dir in transforms_dir.iterdir():
278279
if not bblock_dir.is_dir():
279280
continue
280-
if bblock_dir.name not in expected:
281+
if bblock_dir.name not in known_ids:
282+
# Bblock no longer exists — remove the whole sandbox
281283
logger.info("Removing stale transform sandbox for bblock '%s'", bblock_dir.name)
282284
shutil.rmtree(bblock_dir)
283-
else:
285+
elif bblock_dir.name in expected:
286+
# Bblock exists with transforms — remove only sandboxes for dropped transforms
284287
expected_transforms = expected[bblock_dir.name]
285288
for transform_dir in bblock_dir.iterdir():
286289
if transform_dir.is_dir() and transform_dir.name not in expected_transforms:
@@ -289,6 +292,8 @@ def cleanup_sandbox(sandbox_dir: Path, bblocks: list[BuildingBlock]) -> None:
289292
shutil.rmtree(transform_dir)
290293
if not any(bblock_dir.iterdir()):
291294
bblock_dir.rmdir()
295+
# else: bblock exists but currently has no subprocess transforms (e.g. transforms.yaml
296+
# temporarily renamed) — leave sandboxes intact to avoid a full rebuild on rename-back
292297

293298

294299
def apply_transforms(bblock: BuildingBlock,

0 commit comments

Comments
 (0)