From 1dd35f5f14a71057b80bc6a5f2ccb14dc4120781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20Sch=C3=B6lzel?= Date: Sun, 24 Mar 2024 19:38:43 +0100 Subject: [PATCH] uses duplicates.items() instead of duplicates --- scripts/metadata/check_uuids.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/metadata/check_uuids.py b/scripts/metadata/check_uuids.py index 62904ad..b8125f4 100755 --- a/scripts/metadata/check_uuids.py +++ b/scripts/metadata/check_uuids.py @@ -9,26 +9,31 @@ import os import io + def get_header(exfile: Path) -> str: text = exfile.read_text(encoding="utf-8") header = re.search(r"^---$(.+?)^---$", text, flags=re.M | re.S) if header is None: raise Exception(f"{exfile} does not contain a YAML header") if header.start() != 0: - raise Exception(f"{exfile} has a YAML block, which is not at the beginning of the file but at postion {header.start()}") + raise Exception( + f"{exfile} has a YAML block, which is not at the beginning of the file but at postion {header.start()}" + ) return header.group(1) + def find_duplicates(lst: List[Tuple[Path, str]]) -> List[Tuple[str, List[Path]]]: count = {} for path, id in lst: count.setdefault(id, []) count[id].append(path) - duplicates = { i: l for i, l in count.items() if len(l) > 1} - return list(duplicates) + duplicates = {i: l for i, l in count.items() if len(l) > 1} + return list(duplicates.items()) + if __name__ == "__main__": os.chdir(Path(__file__).parent) - exercises = Path("../../exercises").glob("*/*/*/*.md") + exercises = Path("../../exercises").glob("*/*/*/*.md") headers = [(p, yaml.safe_load(io.StringIO(get_header(p)))) for p in exercises] noid = [(p, h) for p, h in headers if "id" not in h] ids = [(p, h["id"]) for p, h in headers if "id" in h]