#!/usr/bin/env python3 """Validate ICML 2026 reproduction logbook structure before publish.""" from __future__ import annotations import argparse import json import re import sys from pathlib import Path try: from trackio import logbook as lb _HAS_TRACKIO = True except ImportError: lb = None _HAS_TRACKIO = False ROOT_SLUG = "index" OPENREVIEW_ID_RE = re.compile(r"^[A-Za-z0-9]{8,12}$") HF_PAPER_URL_RE = re.compile(r"https://huggingface\.co/papers/\S+") OPENREVIEW_URL_RE = re.compile(r"https://openreview\.net/forum\?id=\S+") HUB_URL_RE = re.compile( r"https://huggingface\.co/(models|datasets|spaces|jobs|buckets)/[^\s<>\"'`]+" ) GITHUB_REPO_RE = re.compile(r"https://github\.com/[^\s<>\"'`]+") def _fail(msg: str) -> None: print(f"error: {msg}", file=sys.stderr) def _warn(msg: str) -> None: print(f"warning: {msg}", file=sys.stderr) def _repo_name(space_id: str | None) -> str | None: if not space_id or "/" not in space_id: return None return space_id.partition("/")[2] def _looks_like_openreview_repo(name: str) -> bool: if OPENREVIEW_ID_RE.fullmatch(name): return True if name.startswith("repro-"): suffix = name[6:] if OPENREVIEW_ID_RE.fullmatch(suffix): return True return False def validate_with_trackio(space_id: str | None) -> int: proj = lb.require_project_dir() result = lb.validate_logbook(proj, profile="icml2026", space_id=space_id) for warning in result["warnings"]: _warn(warning) if result["errors"]: for err in result["errors"]: _fail(err) return 1 print("Logbook validation passed.") return 0 def _find_project_dir(start: Path | None = None) -> Path | None: start = Path(start or Path.cwd()).resolve() for d in (start, *start.parents): candidate = d / ".trackio" if (candidate / "logbook" / "pages" / "index.md").is_file(): return candidate return None def _link_order(index_path: Path) -> list[str]: text = index_path.read_text(encoding="utf-8") seen: list[str] = [] for slug in re.findall(r"\(#/([A-Za-z0-9._-]+)\)", text): if slug not in seen: seen.append(slug) return seen def _index_prose(text: str) -> str: cell_re = re.compile( r"(^|\n)---\n\n([\s\S]*?)" r"(?=\n---\n\n([\s\S]*?)" r"(?=\n---\n