Skip to content

Commit

Permalink
uses duplicates.items() instead of duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
CSchoel committed Mar 24, 2024
1 parent a7610ca commit 1dd35f5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/metadata/check_uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 1dd35f5

Please sign in to comment.