From 3db6946590d1f67582b159e869c651123a132b6a Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sat, 21 Nov 2026 17:48:44 +0100 Subject: [PATCH] Pair old and new metrics files by path in the grammar check tasks Given two directories, json-minimal-tests walks them in parallel and compares two entries only if their file names match. The walks quickly get misaligned, so files with the same name in different directories were compared with each other, and most other files were never compared. Compare each old file with the new file at the same path instead, and only run json-minimal-tests on the pairs that differ. Fixes #1261. --- check-grammar-crate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/check-grammar-crate.py b/check-grammar-crate.py index c96d48257..a984ea928 100755 --- a/check-grammar-crate.py +++ b/check-grammar-crate.py @@ -27,6 +27,7 @@ """ import argparse +import filecmp import pathlib import subprocess import sys @@ -199,9 +200,15 @@ def compare_metrics(args: argparse.Namespace) -> None: # Create compare directory compare_dir.mkdir(parents=True, exist_ok=True) - # Get JSON differences and minimal tests + # Get JSON differences and minimal tests. + # Pair the files by their relative path: given two directories, + # json-minimal-tests walks them in parallel, so it compares unrelated files + # sharing the same name and skips most of the others. print("\nSave minimal tests in", compare_dir) - run_subprocess("json-minimal-tests", "-o", compare_dir, old_dir, new_dir) + for old_file in sorted(old_dir.rglob("*.json")): + new_file = new_dir / old_file.relative_to(old_dir) + if new_file.is_file() and not filecmp.cmp(old_file, new_file, shallow=False): + run_subprocess("json-minimal-tests", "-o", compare_dir, old_file, new_file) def main() -> None: