# Makes a variant of the detectors for the pruning: copies to (without .git) and replaces, in (relative), each by (pairs of arguments; each old must occur exactly once). Args: [ ...] import shutil, sys from pathlib import Path src, dst, rel, pairs = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3], sys.argv[4:] if dst.exists(): shutil.rmtree(dst) shutil.copytree(src, dst, ignore=shutil.ignore_patterns(".git", "__pycache__")) f = dst / rel text = f.read_text() for old, new in zip(pairs[::2], pairs[1::2]): n = text.count(old) if n != 1: sys.exit(f"{dst.name}: {n} occurrences of {old!r}") text = text.replace(old, new) f.write_text(text) print(dst.name, "ok")