2929# ── Paths ──────────────────────────────────────────────────────────────────
3030REPO_ROOT = Path (__file__ ).resolve ().parent .parent .parent
3131
32- HTML_PATH = Path (os .environ .get (
33- "POSTER_HTML" ,
34- REPO_ROOT / "poster" / "html" / "zyra-poster-print.html" ,
35- ))
36- PDF_PATH = Path (os .environ .get (
37- "POSTER_PDF" ,
38- REPO_ROOT / "poster" / "html" / "zyra-poster-print.pdf" ,
39- ))
32+ HTML_PATH = Path (
33+ os .environ .get (
34+ "POSTER_HTML" ,
35+ REPO_ROOT / "poster" / "html" / "zyra-poster-print.html" ,
36+ )
37+ )
38+ PDF_PATH = Path (
39+ os .environ .get (
40+ "POSTER_PDF" ,
41+ REPO_ROOT / "poster" / "html" / "zyra-poster-print.pdf" ,
42+ )
43+ )
4044
4145# ── Poster geometry ─────────────────────────────────────────────────────────
4246# The print CSS defines the poster at exactly 14400 × 10800 CSS pixels,
5054# Text and SVG paths are vector in the PDF, so they print crisply at any size.
5155# PNG/JPEG assets are embedded at their original pixel resolution.
5256
53- PAPER_W_IN = 48 # inches
54- PAPER_H_IN = 36 # inches
55- CSS_PX_W = 14400
56- CSS_PX_H = 10800
57- CSS_DPI = 96 # Playwright's assumed CSS px density
58- SCALE = round ((PAPER_W_IN * CSS_DPI ) / CSS_PX_W , 6 ) # ≈ 0.32
57+ PAPER_W_IN = 48 # inches
58+ PAPER_H_IN = 36 # inches
59+ CSS_PX_W = 14400
60+ CSS_PX_H = 10800
61+ CSS_DPI = 96 # Playwright's assumed CSS px density
62+ SCALE = round ((PAPER_W_IN * CSS_DPI ) / CSS_PX_W , 6 ) # ≈ 0.32
5963
6064
6165# ── Dependency bootstrap ────────────────────────────────────────────────────
6266
67+
6368def _ensure_playwright () -> None :
6469 """Install the playwright Python package and Chromium if missing."""
6570 try :
@@ -73,20 +78,24 @@ def _ensure_playwright() -> None:
7378 # Verify the Chromium browser binary exists; install if not.
7479 try :
7580 from playwright .sync_api import sync_playwright
81+
7682 with sync_playwright () as pw :
7783 exe = pw .chromium .executable_path
7884 if not Path (exe ).exists ():
7985 raise FileNotFoundError (exe )
8086 except Exception :
81- print ("Chromium browser not found — running 'playwright install chromium' …" ,
82- flush = True )
87+ print (
88+ "Chromium browser not found — running 'playwright install chromium' …" ,
89+ flush = True ,
90+ )
8391 subprocess .check_call (
8492 [sys .executable , "-m" , "playwright" , "install" , "chromium" ],
8593 )
8694
8795
8896# ── Main build ──────────────────────────────────────────────────────────────
8997
98+
9099def build_pdf () -> None :
91100 _ensure_playwright ()
92101
@@ -111,7 +120,7 @@ def build_pdf() -> None:
111120 with sync_playwright () as pw :
112121 browser = pw .chromium .launch (
113122 args = [
114- "--no-sandbox" , # required in WSL / container
123+ "--no-sandbox" , # required in WSL / container
115124 "--disable-setuid-sandbox" ,
116125 "--disable-dev-shm-usage" , # avoids /dev/shm crashes in containers
117126 "--font-render-hinting=none" , # crisper font rendering in PDF
@@ -149,6 +158,7 @@ def build_pdf() -> None:
149158def _open_file (path : Path ) -> None :
150159 """Best-effort: open the PDF in the system viewer."""
151160 import shutil
161+
152162 for cmd in ("xdg-open" , "open" , "start" ):
153163 if shutil .which (cmd ):
154164 subprocess .Popen ([cmd , str (path )])
0 commit comments