#!/usr/bin/env python3 """Write paper_gp/refs.bib from ../paper/refs.bib without the internal `annote` fields (submission copy).""" import re, pathlib src = pathlib.Path(__file__).resolve().parent.parent / "paper" / "refs.bib" t = src.read_text(encoding="utf-8"); out = []; i = 0 pat = re.compile(r"\n\s*annote\s*=\s*", re.I) while True: m = pat.search(t, i) if not m: out.append(t[i:]); break out.append(t[i:m.start()]); j = m.end() if t[j] == "{": d = 0 while True: d += (t[j] == "{") - (t[j] == "}"); j += 1 if d == 0: break else: j = t.index('"', j + 1) + 1 while t[j] in " \t": j += 1 if t[j] == ",": j += 1 i = j (pathlib.Path(__file__).parent / "refs.bib").write_text("".join(out), encoding="utf-8")