formatting — text formatting helpers
tempura/formatting.py holds small string helpers used by the docs-facing
examples to print compact summaries. There is no physics or math here; it exists
so the worked examples can show readable output without repeating formatting
boilerplate.
Helpers
format_mapping_block(...) renders a titled, indented key: value block (used
for ROI and gate-voltage summaries), format_sequence_inline(...) renders a
short comma-separated list, and format_voltage(...) formats a scalar with a
sign and a trailing V. An optional value_formatter lets the mapping helper
reuse format_voltage for voltage tables.
API
formatting
Small formatting helpers shared by docs-facing examples.
format_mapping_block(title, values, *, value_formatter=None)
Return a compact multi-line block for one keyed mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Heading shown on the first line of the block. |
required |
values
|
Mapping[str, object]
|
Mapping whose items should be rendered one per line. |
required |
value_formatter
|
Callable[[object], object] | None
|
Optional callable used to format each mapping value before it is converted to text. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Multi-line string containing |
str
|
line per mapping entry, or |
Source code in tempura/formatting.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
format_sequence_inline(title, values)
Return one short inline summary for a sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Label shown before the rendered sequence. |
required |
values
|
Sequence[object]
|
Ordered values to render inline. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Single-line string containing |
str
|
list, or |
Source code in tempura/formatting.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
format_voltage(value)
Return one scalar voltage with a sign and units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
Scalar value that can be converted to |
required |
Returns:
| Type | Description |
|---|---|
str
|
Signed voltage string with two decimal places and a trailing |
Source code in tempura/formatting.py
55 56 57 58 59 60 61 62 63 64 | |