arpdf / record_versions.py
syamjithnk's picture
Re-run all 60 rows (9 Oct 2026): neutral name placeholder, rebuilt docx inputs, tool versions recorded
253f65c verified
Raw History Blame Contribute Delete
1.4 kB
#!/usr/bin/env python3
"""Write versions.json: the exact tool versions a pdf_bench.py run used.
The 19 Aug 2026 run did not record these, which made it impossible to say later
whether a moved cell was the input or the extractor. Run right after pdf_bench.py.
"""
import datetime, json, platform, subprocess
import importlib.metadata as md
from pathlib import Path
HERE = Path(__file__).parent
def sh(cmd):
try:
r = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
return (r.stdout or r.stderr).strip().splitlines()[0]
except Exception as e:
return f"unavailable ({type(e).__name__})"
v = {
"run_date": datetime.date.today().isoformat(),
"macOS": platform.mac_ver()[0],
"machine": platform.machine(),
"python": platform.python_version(),
"chrome": sh(["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--version"]),
"libreoffice": sh(["/Applications/LibreOffice.app/Contents/MacOS/soffice", "--version"]),
"poppler_pdftotext": sh(["pdftotext", "-v"]),
}
for pkg in ["pypdf", "pdfminer.six", "reportlab", "arabic_reshaper", "python-bidi", "python-docx"]:
try:
v[pkg] = md.version(pkg)
except md.PackageNotFoundError:
v[pkg] = "not installed"
(HERE / "versions.json").write_text(json.dumps(v, indent=1, ensure_ascii=False) + "\n")
print(json.dumps(v, indent=1, ensure_ascii=False))