# One-off: put back the noqa comments a too-narrow `ruff --select RUF100 --fix` removed. import re import subprocess import sys from pathlib import Path ROOT = Path(sys.argv[1]) diff = subprocess.run( ["git", "diff", "-U0", "--", "scripts", "src", "tests"], cwd=ROOT, capture_output=True, text=True, check=True, ).stdout current = None removed: dict[str, list[str]] = {} for line in diff.splitlines(): if line.startswith("+++ b/"): current = line[6:] elif line.startswith("-") and not line.startswith("---") and "# noqa" in line: removed.setdefault(current, []).append(line[1:]) for name, lines in removed.items(): path = ROOT / name text = path.read_text("utf-8").splitlines(keepends=True) for old in lines: bare = re.sub(r"\s+# noqa.*$", "", old) for i, cur in enumerate(text): if cur.rstrip("\n") == bare: text[i] = old + "\n" break else: print("NOT FOUND", name, old) path.write_text("".join(text), "utf-8") print("restored", name, len(lines))