[FEAT] PDF output for mooring reports (report --pdf) + print-layout fixes - #69
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires up single-file PDF output for mooring reports and fixes the print layout so the merged PDF is usable on A4. The per-page HTML reports remain the single source of truth; the PDF is a post-processing step (WeasyPrint) that renders the existing pages, applies a print stylesheet, and concatenates them — report generation and the Jinja templates are unchanged except for one genuine consistency bug fixed along the way.
The combine logic (
oceanarray/report/_pdf.py,combine_mooring_pdf) existed from an earlier session but was unreachable: not exported, not in the CLI, no install path for its dependency. This PR closes those gaps and then makes the rendered output actually fit the page.PDF wiring
oceanarray report MOORING --pdf— combines the generated HTML pages into{mooring}_report.pdf(reading order summary → per-instrument → stack → grid; only pages that exist are included).--allalso builds the PDF.pdf—pip install oceanarray[pdf]installs WeasyPrint (kept out of core because it pulls in native libs: pango, cairo, gdk-pixbuf).combine_mooring_pdfexported fromoceanarray.report.paths.resolve_report_dir(--output-dir→--report-dir/{mooring}→proc/{mooring}/report/), called by both the CLI PDF path andMooringReport.generate()so the PDF always reads exactly where the HTML was written (no drift).--array+--pdfwarns that PDF isn't supported in array mode (the array index is HTML-only) rather than silently ignoring the flag.Print-layout fixes (all in
_pdf._PRINT_CSSunless noted)These correct WeasyPrint-vs-browser divergences without changing the on-screen HTML:
.figconvention (inlinemax-width:50%/33%/300px, etc.). An earlierimg { max-width:100% !important }in the print CSS was overriding all of them and blowing every plot up to full page; removed the!important(kept a non-importantmax-width:100%overflow ceiling) so the per-figure caps win again..meta-gridusesrepeat(auto-fill, minmax(...)), which WeasyPrint collapses to one column; forced a fixed 3-column layout in print..badge/.arrowand set the pipelineflex-wrap: nowrapso each instrument's status fits on one line.<textarea rows="2">rendered too short and clipped the second line; forced enough height.<th>allowed to wrap; body-text measure capped (~78ch) so explanatory notes don't run the full page width._mooring.py) — removed a stray inlinefont-sizeon the Model cell so it matches the rest of the table (fixes both screen and PDF).Housekeeping
.gitignore: ignore generated report output undertests/fixtures/proc/*/report/(multi-MB HTML + PDFs) so it never enters history.Tests
tests/unit/test_pdf_report.py: reading-order resolution; empty-dirFileNotFoundError; PDF render (valid%PDF-); custom output path; real Jinja summary rendered to PDF; and thecmd_report --pdfCLI path end-to-end +--dry-run. Render tests gated onimportorskip("weasyprint").tests/unit/test_cli.py:--pdfparser assertions.Docs
reports.rst(new "PDF output" section),cli_reference.rst(--pdfflag),project_structure.md(_pdf.py).Exit-code behaviour (no breaking change)
--allnow also builds the PDF, but treats it as best-effort: if WeasyPrint isn't installed it warns and still returns 0 on the (successful) HTML, so existingreport --allcallers/CI without thepdfextra keep working. Only an explicit--pdfthat cannot be honoured returns non-zero (you asked for a PDF and didn't get one). Locked by a test that mocks WeasyPrint away and asserts--all→ 0,--pdf→ 1.