printing — console formatting helpers
Purpose
Pretty-print nested dicts,
Packagerecords, and numpy arrays as aligned, precision-controlled
console text.formatted_dictis the entry point; the_format_*helpers dispatch by value type.
Role in the system
- Consumed lazily by
save_dictin infra (from utils.printing import formatted_dict) when
writing a timestamped summary.txt. - Used by target_finder (
ee_guidancetower) to print EE-pose score dicts. - Stateless support library — no config or sim dependencies; pure string formatting.
Single source since 2026-06-22 — was duplicated in infra
infra used to carry its own inline copy of
formatted_dict+ the_format_*family (kept in sync by
hand). That copy was removed on 2026-06-22;infranow doesfrom utils.printing import formatted_dict,
so this is the one definition (Package.__repr__/SuperPackageroute through here too). The
consolidation was driven by the AST clone-detector (validation/ast_duplication.py, which scored the two
_format_*families J=1.00) and was byte-identical on 9/10 inputs. The one intended behaviour change:
a non-square 2-D array (e.g. a 6×7 Jacobian) now prints its rows —infra’s old copy raised
RuntimeError('Tenser, said the tensor.'). (logs/logs_Jun22_26/CLAIMS.mdC2–C3)
Inputs / Outputs
- In: a dict (values may be scalars, numpy arrays, nested
Mappings, or any object with a
.log()method), plustitle,precision,indent. - Out: a single aligned multi-line
str(keys left-padded to a common width; floats rounded).
Key functions
formatted_dict— aligned, recursive dict pretty-printer (the public entry point) —utils/printing.py:8snake_to_Title—snake_casekey →Title Caselabel (module-level lambda) —utils/printing.py:5_format_array— formats a 0/1/2-D array by rank; column vectors flatten to a row, 2-D prints
tab-indented rows —utils/printing.py:40_format_package_value— value dispatch: array, nestedMapping,.log()-able package, or
passthrough (this is what makes the printer recurse) —utils/printing.py:57
Pseudocode
formatted_dict(d, title, precision, indent):
width = max key length + 1
for k, v in d:
s = _format_package_value(v, ...) # array | nested dict | package.log() | passthrough
if s is multiline: append "<k>:" then the block
elif s is float: append "<k>: <rounded>"
else: append "<k>: <s>"
return joined string