Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
"""BUG-2107: store the Narayana report extras in the packet, whoever needs them first.
|
|
|
|
`narayana_dasha_report_extras` (the start-sign candidates and both sub-period direction
|
|
readings, BUG-2088 / BUG-2105) used to be written only while the data chapters were rendered,
|
|
so a caller that built the reading facts without rendering first silently went without the
|
|
second reading. Both the renderer and the reading facts now call this.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
EXTRAS_KEY = "narayana_dasha_report_extras"
|
|
|
|
|
|
def ensure_narayana_report_extras(packet: Any) -> dict:
|
|
"""Write `worksheets.timing_and_predictive_systems.narayana_dasha_report_extras` once.
|
|
|
|
Idempotent: a stored non-empty value is returned as it is. Nothing is written (and nothing is
|
|
raised) when the packet has no Narayana module or lacks the Lagna or planet longitudes. Only
|
|
that one key is written; the pinned `narayana_dasha` object and everything else are untouched.
|
|
Returns the stored extras, or {} when there are none.
|
|
"""
|
|
if not isinstance(packet, dict):
|
|
return {}
|
|
worksheets = packet.get("worksheets")
|
|
timing = worksheets.get("timing_and_predictive_systems") if isinstance(worksheets, dict) else None
|
|
stored = timing.get(EXTRAS_KEY) if isinstance(timing, dict) else None
|
|
if isinstance(stored, dict) and stored:
|
|
return stored
|
|
try:
|
|
from scripts.report_render.parity_chapters import narayana_extras_for_packet
|
|
except ModuleNotFoundError: # pragma: no cover - scripts/ on sys.path
|
|
from report_render.parity_chapters import narayana_extras_for_packet
|
|
extras = narayana_extras_for_packet(packet)
|
|
if not extras:
|
|
return {}
|
|
if not isinstance(worksheets, dict):
|
|
worksheets = packet.setdefault("worksheets", {})
|
|
if not isinstance(timing, dict):
|
|
timing = worksheets.setdefault("timing_and_predictive_systems", {})
|
|
timing[EXTRAS_KEY] = extras
|
|
return extras
|