diff --git a/.gitignore b/.gitignore index 6db4c4e..7883772 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ doc/html/ node_modules .node-modules/ +__pycache__/ diff --git a/AGENTS.md b/AGENTS.md index af247e4..0e7ffde 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,9 @@ # Working on lexical webcpp's rules apply here: read the superproject's +[CODING-GUIDELINES.md](../../CODING-GUIDELINES.md) +(), whose +chapter 15 gives lexical's design decisions with their reasons, and its [AGENTS.md](../../AGENTS.md) () first. This file holds only what is specific to lexical. diff --git a/tools/generate_tables.py b/tools/generate_tables.py index 03ee57d..c39fe23 100644 --- a/tools/generate_tables.py +++ b/tools/generate_tables.py @@ -43,6 +43,7 @@ import sys import textwrap import urllib.request +import uuid from collections.abc import Iterator, Sequence from pathlib import Path @@ -99,11 +100,17 @@ def pinned_files(pinned: Path) -> tuple[str, dict[str, dict[str, str]]]: def write(path: Path, data: bytes) -> None: - """Writes the data at the path through a sibling file, so that no reader sees half of it.""" + """Writes the data at the path through a sibling file of its own, so that no reader sees half + of it, and two writers of one path, such as two generators filling one cache at once, never + rename each other's file: the last to finish wins, with the same checked bytes.""" path.parent.mkdir(parents=True, exist_ok=True) - partial = path.with_name(path.name + '.partial') - partial.write_bytes(data) - partial.replace(path) + partial = path.with_name(f'{path.name}.{uuid.uuid4().hex}.partial') + try: + partial.write_bytes(data) + partial.replace(path) + except BaseException: + partial.unlink(missing_ok=True) + raise def checked(data: bytes, source: str, pinned: str) -> bytes: