"""Benchmark discovery pool. A copy of ~/prog/fin/benchmarks.txt (the user's curated benchmark universe), augmented with a few common index ETFs that exist in the data universe. The ORIGINAL file outside this repository is never modified. Format: section header lines (ending in ':' or free-standing), then 'symbollabel' lines. """ from __future__ import annotations import re from dataclasses import dataclass from pathlib import Path POOL_FILE = Path(__file__).parent / "pool" / "benchmarks.txt" _ENTRY = re.compile(r"^(\S{1,6})[\t ]{2,}(.+)$") @dataclass(frozen=True) class PoolEntry: section: str symbol: str # lowercase label: str def load_pool(path: Path = POOL_FILE) -> list[PoolEntry]: entries: list[PoolEntry] = [] section = "" for line in path.read_text().splitlines(): line = line.rstrip() if not line.strip(): continue m = _ENTRY.match(line) if m: entries.append(PoolEntry(section, m.group(1).lower(), m.group(2).strip())) else: section = line.strip().rstrip(":") return entries def pool_labels(entries: list[PoolEntry] | None = None) -> dict[str, str]: """symbol -> 'section: label' (for keyword matching and display).""" if entries is None: entries = load_pool() return {e.symbol: f"{e.section}: {e.label}" for e in entries if e.section}