From 4f53212cdafd25504a993e481975aa646b645159 Mon Sep 17 00:00:00 2001 From: Matthew Kirk Date: Wed, 12 Nov 2025 12:01:50 +0000 Subject: [PATCH] Improve reference checking code Use a capturing group in the regexp for well-formed references to extract the actual reference for comparison. Add get the list of known references in a more straightforward way by directly parsing the YAML --- eos_pre_commit_hooks/eos_test_check_references.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eos_pre_commit_hooks/eos_test_check_references.py b/eos_pre_commit_hooks/eos_test_check_references.py index 930e552..22ae546 100644 --- a/eos_pre_commit_hooks/eos_test_check_references.py +++ b/eos_pre_commit_hooks/eos_test_check_references.py @@ -5,6 +5,7 @@ import os import re import subprocess +import yaml from typing import Sequence def eos_test_check_references( @@ -33,13 +34,12 @@ def eos_test_check_references( # regexp for correctly formed reference # See eos/utils/reference-name.cc - good_reference_regexp = re.compile(r'\[[a-zA-Z0-9][a-zA-Z0-9+-]*:[0-9]{4}[A-Z]\]') + # Use capturing group to get only the reference, not the external square brackets + good_reference_regexp = re.compile(r'\[([a-zA-Z0-9][a-zA-Z0-9+-]*:[0-9]{4}[A-Z])\]') # Read in all references from references.yaml - known_refs = set() with open("eos/references.yaml") as f: - for line in f: - known_refs.update(good_reference_regexp.findall(line)) + known_refs = set(yaml.safe_load(f)) for filename in filenames_filtered: