File size: 8,765 Bytes
ceac1e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | #!/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<!-- trackio-cell\n([\s\S]*?)\n-->\n([\s\S]*?)"
r"(?=\n---\n<!-- trackio-cell\n|\s*$)"
)
return cell_re.sub("", text).strip()
def _title_of(index_path: Path) -> str:
for line in index_path.read_text(encoding="utf-8").splitlines():
m = re.match(r"#\s+(.+)", line.strip())
if m:
return m.group(1).strip()
return ""
def _parse_cells(text: str) -> list[dict]:
cell_re = re.compile(
r"(^|\n)---\n<!-- trackio-cell\n([\s\S]*?)\n-->\n([\s\S]*?)"
r"(?=\n---\n<!-- trackio-cell\n|\s*$)"
)
cells = []
for match in cell_re.finditer(text):
try:
meta = json.loads(match.group(2))
except json.JSONDecodeError:
continue
cells.append(
{
"type": meta.get("type"),
"title": meta.get("title"),
"pinned": meta.get("pinned"),
"body": match.group(3),
}
)
return cells
def validate_standalone(space_id: str | None) -> int:
proj = _find_project_dir()
if proj is None:
_fail(
"No logbook in this directory. Scaffold first with scaffold_icml_logbook.py."
)
return 1
errors = 0
warnings = 0
root = proj / "logbook"
metadata_path = proj / "metadata.json"
metadata = json.loads(metadata_path.read_text(encoding="utf-8")) if metadata_path.is_file() else {}
tags = metadata.get("tags") or []
if "icml2026-repro" not in tags:
_fail('metadata.json tags must include "icml2026-repro".')
errors += 1
paper_tags = [t for t in tags if t.startswith("paper-")]
if not paper_tags:
_fail('metadata.json tags must include "paper-<openreview-id>".')
errors += 1
repo = _repo_name(space_id or metadata.get("space_id"))
if not repo:
_fail("Pass --space username/repro-<slugified-title> or set metadata.space_id.")
errors += 1
elif not repo.startswith("repro-"):
_fail(f'Space repo name must start with "repro-" (got "{repo}").')
errors += 1
elif _looks_like_openreview_repo(repo):
_fail(f'Space slug "{repo}" looks like an OpenReview id.')
errors += 1
index_path = root / "pages" / "index.md"
index_text = index_path.read_text(encoding="utf-8")
index_prose = _index_prose(index_text)
title = _title_of(index_path)
if not re.match(r"^Reproduction:\s+.+\S", title, re.I):
_fail('Index heading must be "# Reproduction: <paper title>".')
errors += 1
if not HF_PAPER_URL_RE.search(index_prose) and not OPENREVIEW_URL_RE.search(
index_prose
):
_fail("Index must link to HF papers or OpenReview.")
errors += 1
toc_slugs = _link_order(index_path)
disk_slugs = [
d.name
for d in (root / "pages").iterdir()
if d.is_dir() and (d / "page.md").is_file()
]
if set(disk_slugs) != set(toc_slugs):
_fail("Index Pages table must match sidebar pages exactly.")
errors += 1
if not toc_slugs:
_fail("Index Pages table is empty.")
errors += 1
else:
if toc_slugs[0] != "executive-summary":
_fail('First page must be Executive summary (slug executive-summary).')
errors += 1
if toc_slugs[-1] != "conclusion":
_fail('Last page must be Conclusion.')
errors += 1
for slug in toc_slugs[1:-1]:
if not re.match(r"^claim-\d+", slug):
_fail(f'Claim page slug must start with "claim-" (got "{slug}").')
errors += 1
exec_path = root / "pages" / "executive-summary" / "page.md"
if not exec_path.is_file():
_fail('Missing page "Executive summary".')
errors += 1
else:
exec_cells = _parse_cells(exec_path.read_text(encoding="utf-8"))
if not any(
c["type"] == "markdown"
and c.get("pinned")
and (c.get("title") or "").strip().lower() == "executive summary"
for c in exec_cells
):
_fail('Need pinned markdown cell titled "Executive summary".')
errors += 1
if not any(
c["type"] == "figure"
and c.get("pinned")
and "poster_embed.html" in (c.get("body") or "")
for c in exec_cells
):
_fail("Need pinned figure cell referencing poster_embed.html.")
errors += 1
concl_path = root / "pages" / "conclusion" / "page.md"
if not concl_path.is_file():
_fail('Missing page "Conclusion".')
errors += 1
else:
concl_cells = _parse_cells(concl_path.read_text(encoding="utf-8"))
if not any(c["type"] == "artifact" for c in concl_cells):
_fail("Conclusion needs a reproduction bundle artifact cell.")
errors += 1
combined = ""
has_artifact = False
for page_file in root.rglob("*.md"):
text = page_file.read_text(encoding="utf-8")
combined += text + "\n"
has_artifact = has_artifact or any(
c["type"] == "artifact" for c in _parse_cells(text)
)
has_hub = bool(HUB_URL_RE.search(combined))
has_github = bool(GITHUB_REPO_RE.search(combined))
if not has_hub and not has_github and not has_artifact:
_warn(
"No Hugging Face URLs, GitHub repos, or artifact cells found yet."
)
warnings += 1
if errors:
return 1
if warnings:
print("Logbook validation passed with warnings.")
else:
print("Logbook validation passed.")
return 0
def main() -> int:
parser = argparse.ArgumentParser(
description="Validate ICML reproduction logbook structure."
)
parser.add_argument(
"--space",
dest="space_id",
help="Publish target username/repro-<slugified-title>",
)
args = parser.parse_args()
if _HAS_TRACKIO and hasattr(lb, "validate_logbook"):
try:
return validate_with_trackio(args.space_id)
except lb.LogbookError as exc:
_fail(str(exc))
return 1
if not _HAS_TRACKIO:
_warn("trackio not installed; using built-in validator.")
else:
_warn("trackio is older than validate API; using built-in validator.")
return validate_standalone(args.space_id)
if __name__ == "__main__":
raise SystemExit(main())
|