# Makes a copy of the detectors (scripts/, bench/) in with one exact substitution in one script (fails if the old text is not found exactly once). # Usage: python3 variant.py import shutil import sys from pathlib import Path src, dest, rel, old, new = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3], sys.argv[4], sys.argv[5] if dest.exists(): shutil.rmtree(dest) for d in ("scripts", "bench"): shutil.copytree(src / d, dest / d, ignore=shutil.ignore_patterns("__pycache__")) f = dest / rel text = f.read_text() if text.count(old) != 1: sys.exit(f"{rel}: old text found {text.count(old)} times") f.write_text(text.replace(old, new)) print(f"{dest}: {rel} changed")