[REFACTOR] vendor shared report design tokens, encoder, and CSS - #71
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
Introduces the shared design-token foundation for the report subsystem: a single source of truth for figure sizing, colours, typography, and the report matplotlib style, plus the figure encoder and CSS generator that read from it. These files are vendored from the sister
ctdcastpackage and kept byte-identical so the two projects' reports stay visually consistent. This change is additive — nothing in the live report path imports the new modules yet, so report output is unchanged. The wiring into report generation lands in follow-up work; this establishes the foundation and its tests first.Vendored shared foundation (provenance)
Four files are copied byte-identical from
../ctdcast(both projects are MIT-licensed and maintained underocean-uhh). A cross-repo consistency check is planned but not added yet; for now the copies are kept in sync by hand.oceanarray/config/report_tokens.py— geometry (W_FULL,FIG_DPI, theSLOTStable,USABLE_PX, derivedOVERSAMPLE), colours (COLORS,ROLE_ACCENT,PACKAGE_ACCENT, a neutralGRAYSramp), the page type scale (TYPE), spacing (SPACE/RADII), and theRAISE_ON_PLOT_ERRORpolicy flag.oceanarray/config/report.mplstyle— the report matplotlib profile. It has nosavefig.dpi; the encoder passesdpi=FIG_DPIexplicitly instead.oceanarray/report/_encode.py—render_b64/_fig_to_base64: the single choke point where a figure becomes base64 PNG bytes (constrained-layout guard, full-canvas save, 256-colour palette quantization). Package-neutral — imports only..config.report_tokens.oceanarray/report/_css.py—emit_css(package)generates the shared stylesheet from the tokens.packageis a required argument, so the file carries no project-specific value; oceanarray passes"oceanarray"when the CSS is wired in.The vendored files name no project (only the
PACKAGE_ACCENTdata keys"oceanarray"/"ctdcast"remain), so both projects vendor identical copies.Enforcement tests
tests/unit/test_report_tokens.pypins the sizing invariants without rendering a page: the slot contract (each slot's width in inches equalsW_FULL × fraction), the geometry math (USABLE_PX, the derivedOVERSAMPLE), the exact saved-PNG width for each slot (round(inches × FIG_DPI)= 1350/900/810/675/540/450 px), the width aliases, and an encoder smoke test confirming a full-canvas save is exactlyW_FULL × FIG_DPI= 1350 px wide. Five further enforcement checks that require a rendered page or later wiring (PNG geometry on a real page, stray-typography, self-containment, theoptional=Trueratio, caption classification) are committed as skipped stubs so the full test surface is documented up front.PR #70 review nits
Zero-output-change cleanups on code introduced by PR #70: a shared
_PANEL_HEIGHT = 2.0constant replacing duplicated literals indiagnostic.pyand_plots.py;draw_windows'spanelsparameter moved to signature order in the docstring and passed by keyword at its call site; the_pdf.pymax-heightcomment corrected to describe the cap as a backstop now that multipanel figures are paginated; and removal of a dead_dt_onevariable.CONTRIBUTING and commit convention
Updates
CONTRIBUTING.mdto add a Licensing of contributions section (inbound = outbound; contributors must flag code adapted from elsewhere and name its source and licence — directly relevant to the vendoring above), a stronger testing standard (assert a justifiable value, not merelyresult is not None), a credit and authorship section, an explicit never silently substitute a default provenance rule, and a one logical change per pull request guideline. Switches the project's commit-message and PR-title convention from bracket tags to conventional-commit prefixes (feat:,fix:,refactor:,docs:,test:,ci:,chore:), matching recent history and the sister project.Packaging and lint
pyproject.tomladdsconfig/*.mplstyletopackage-datasoreport.mplstyleships in a built wheel (otherwise a non-editable install would fail to find it at runtime once the encoder is wired in), plus per-file ruff exemptions for the two vendored modules whose docstring/try-except style differs from oceanarray's — kept as configuration so the copies stay byte-identical rather than being edited.Testing
Full suite: 756 passed, 9 skipped.
ruff checkclean. All four vendored files verified byte-identical to../ctdcast;emit_css("oceanarray")verified to emit oceanarray's navy accent (#1a3a5c), not ctdcast's teal.Breaking changes
None. Purely additive: no public API removed or changed; the new modules are unused by the live report path; the PR #70 nits are documentation, dead-variable, and shared-constant edits.