Skip to content

Commit 802d943

Browse files
Resolve record tags against canonical vocabulary
1 parent 76f89b2 commit 802d943

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

‎scripts/validate_repo.py‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,36 @@ def validate_references(records: list[tuple[Path, dict]]) -> list[str]:
138138
return errors
139139

140140

141+
def validate_tags(records: list[tuple[Path, dict]]) -> list[str]:
142+
available = {
143+
record["tag_slug"]
144+
for _, record in records
145+
if record.get("record_type") == "tag"
146+
and record.get("status") in {"proposed", "accepted"}
147+
and isinstance(record.get("tag_slug"), str)
148+
}
149+
errors: list[str] = []
150+
for path, record in records:
151+
tags = record.get("tags")
152+
if not isinstance(tags, list):
153+
continue
154+
for tag in tags:
155+
if not isinstance(tag, str) or tag not in available:
156+
errors.append(
157+
f"{path}: tags: no proposed or accepted tag record for {tag!r} "
158+
"in the validation set"
159+
)
160+
return errors
161+
162+
141163
def main() -> int:
142164
parser = argparse.ArgumentParser()
143165
parser.add_argument("paths", nargs="*", type=Path)
144166
parser.add_argument("--fixtures", action="store_true")
145167
parser.add_argument("--examples", action="store_true")
146168
parser.add_argument("--enforce-filename", action="store_true")
147169
parser.add_argument("--check-references", action="store_true")
170+
parser.add_argument("--check-tags", action="store_true")
148171
args = parser.parse_args()
149172

150173
paths = list(args.paths)
@@ -159,11 +182,13 @@ def main() -> int:
159182
(path, *validate_document(path, args.enforce_filename)) for path in paths
160183
]
161184
errors = [item for _, _, messages in documents for item in messages]
185+
valid_records = [
186+
(path, record) for path, record, _ in documents if record is not None
187+
]
162188
if args.check_references:
163-
valid_records = [
164-
(path, record) for path, record, _ in documents if record is not None
165-
]
166189
errors.extend(validate_references(valid_records))
190+
if args.check_tags:
191+
errors.extend(validate_tags(valid_records))
167192

168193
print("\n".join(errors) if errors else f"validated {len(paths)} record(s)")
169194
return 1 if errors else 0

0 commit comments

Comments
 (0)