The tables that are a contract opt out of the formatter

Groundwork for the whole-repo `ruff format` sweep, kept separate so that sweep
can be a commit with nothing in it but layout.

An audit of `ruff format --diff` found the sweep is mechanical where it counts —
152 of 153 files come out AST-identical, the suite passes on the formatted tree,
and `meshterm specimen` is byte-identical on both platforms — but it found three
things worth handling first.

One is a defect. `test_a_contact_the_device_never_held_is_still_removed_here`
opens its docstring on a quote character, so the formatter breaks up the run of
four quotes by inserting a space, and that trips `D210`. A straight sweep would
therefore have taken `ruff check .` red — the one commit whose entire point is
that both gates pass. The quoted phrase becomes curly quotes, which is already
how the rest of the tests spell a quotation, and the collision goes away.

One is readability. `sparkline` ends on a subscript of a call that no longer
fits, and the formatter's answer is to hang `[` newline `0` newline `]` off the
end. Naming the intermediate says the same thing in two plain lines.

The rest are fences. Six tables in this codebase are hand-packed on purpose: the
glyph map and the fold table read as two columns because that is how you check a
substitution; `FONT_RANGES` is a device-verified inventory that a reader scans in
rows; `_RAW_ROW_SKIP` groups its fields by which part of a packet they came from;
`_NODE_SLOT_HEXES` runs the wheel in 60-degree steps with the angle in the lane.
The formatter's layout is all-or-nothing — one line, or one item per line — so it
would turn `FONT_RANGES` into two hundred lines and flatten every grouping into
an undifferentiated list. `# fmt: off` says these are data laid out to be read,
not code that happens to be wide.

`test_theme16`'s heat ladder is fenced for a stronger reason: it pairs two steps
per row under one comment naming the band, so exploding it would leave
"under 5 minutes — white" attached to the second half of its own pair and the
first half unlabelled. That is not alignment loss, it is a comment that starts
lying.

Not fenced: the `heat.*` ladder inside `MESH_THEME`. It wants the same treatment
and cannot have it — ruff honours `# fmt: off` for a statement, and those rows
are elements inside a dict inside a call, where the marker is simply ignored. It
loses its aligned comment column in the sweep, along with about ninety other
lanes across the repo. Each comment stays on its own entry, so nothing there
starts lying; if the column is wanted back it needs the whole `Theme(...)` call
fenced, which is a bigger decision than this commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-07 01:04:57 -04:00
1 parent 8d8c8b0f2b
commit 5db0c6adb9
6 files changed
+15 -4

No files matched your search

+2 -3
View File
@@ -251,9 +251,8 @@ def activity_sparkline(
else:
height = min(4, max(1, round(count / scale * 4)))
bars.append((0, height - 1))
return _assemble(
bars, [float(c) for c in reversed(window)], 1, 0, style, "faint", per_column
)[0]
rows = _assemble(bars, [float(c) for c in reversed(window)], 1, 0, style, "faint", per_column)
return rows[0]
#: Default percentile :func:`activity_peak` reads its ceiling at, in place of the raw
+2
View File
@@ -23,6 +23,7 @@ from __future__ import annotations
#: 512 glyphs — aliases (the rounded corners onto the square ones, ``⋯`` onto ``…``) and
#: shared slots give a few glyphs more than one codepoint. Verified against a live table
#: dump of the installed font (2026-08-01, post-P3 build).
# fmt: off
FONT_RANGES: tuple[tuple[int, int], ...] = (
(0x0020, 0x007F), (0x00A0, 0x00A0), (0x00A7, 0x00A7), (0x00A9, 0x00A9),
(0x00B0, 0x00B0), (0x00B2, 0x00B2), (0x00B6, 0x00B7), (0x03C0, 0x03C0),
@@ -46,6 +47,7 @@ FONT_RANGES: tuple[tuple[int, int], ...] = (
(0x2699, 0x2699), (0x26A0, 0x26A0), (0x26BF, 0x26BF), (0x2713, 0x2713),
(0x2717, 0x2717), (0x276F, 0x276F), (0x2800, 0x28FF), (0xFFFD, 0xFFFD),
)
# fmt: on
#: Every codepoint the console font can draw, as one frozen set (built once at import;
#: 520 members, so the set is small and the per-character membership test is a dict hit).
+2
View File
@@ -96,6 +96,7 @@ _PAYLOAD_GLOSS = {
#: parsed into "class"/"route", the channel crypto handled by
#: :meth:`PacketViewer._decrypt_rows`, or an advert field duplicating ``node``/
#: ``lat``/``lon``/etc.) — skipped so the generic dump doesn't repeat them.
# fmt: off
_RAW_ROW_SKIP = frozenset({
"node", "name", "kind", "snr", "rssi", "lat", "lon", "path", "node_type",
"observed_at", "text",
@@ -107,6 +108,7 @@ _RAW_ROW_SKIP = frozenset({
"dest_hash", "src_hash", "src_key", "trace_tag", "ack_crc", "trace_snrs",
"adv_key", "adv_name", "adv_type", "adv_lat", "adv_lon",
})
# fmt: on
#: Display style per packet class, shared by every packet list and the viewer.
KIND_STYLES = {
+6
View File
@@ -507,6 +507,7 @@ _NODE_HUE_VAL = 0.95
#: hex a caller can parse into an RGB (the map canvas and the mesh walk read the hue back
#: out of the style string), and so every downsample on the way out — Rich's, and the
#: fold's :func:`_quantize_sgr` — lands on that exact slot rather than guessing.
# fmt: off
_NODE_SLOT_HEXES: tuple[str, ...] = (
"#ff5555", # 9 red — 0°
"#ffff55", # 11 yellow — 60°
@@ -515,6 +516,7 @@ _NODE_SLOT_HEXES: tuple[str, ...] = (
"#5555ff", # 12 blue — 240°
"#ff55ff", # 13 magenta — 300°
)
# fmt: on
def node_style(key: str) -> str:
@@ -631,6 +633,7 @@ def name_style(name: str, key: str | None = None) -> str:
#: and never appear here. ``glyph()`` consumes this table at explicit icon call sites
#: (a 1-cell lane the screen composes); the render-boundary fold consumes it for
#: everything else, padding to the emoji's measured width so layout survives.
# fmt: off
_GLYPH_MAP: dict[str, str] = {
# Packet classes (KIND_ICONS)
"📢": "☼", # advert — a node radiating its presence
@@ -698,6 +701,7 @@ _GLYPH_MAP: dict[str, str] = {
"⏳": "…", # pending/waiting
"+": "+", # fullwidth plus (channels' add row)
}
# fmt: on
def glyph(icon: str) -> str:
@@ -739,6 +743,7 @@ _FOLD_ALLOWED: frozenset[int] = FONT_CODEPOINTS.union(range(0x00, 0x20))
#: fold's translation table (storage is never touched). Characters *in* the font —
#: ``— … ⋯ ⚠ ⌫ ⇧ ⚙ ↻ ◷ ⌖ ⚿ ← ↑ → ↓ ↔ ↕ • ·`` and the Cyrillic block — never appear
#: here: they pass through untranslated.
# fmt: off
_FOLD_SINGLES: dict[str, str] = {
"–": "-", "−": "-", "‒": "-", "―": "—",
"‘": "'", "’": "'", "‚": "'", "“": '"', "”": '"', "„": '"',
@@ -758,6 +763,7 @@ _FOLD_SINGLES: dict[str, str] = {
# VS16, ZWJ, ZWSP.
"️": "", "‍": "", "​": "",
}
# fmt: on
#: Built lazily on first fold: ``str.translate`` table = accent folds (NFKD, computed
#: over the Latin ranges once) + :data:`_FOLD_SINGLES` + the emoji map padded to each
+1 -1
View File
@@ -744,7 +744,7 @@ async def test_a_refused_removal_is_shown_and_the_contact_stays() -> None:
async def test_a_contact_the_device_never_held_is_still_removed_here() -> None:
""""Not on the device" is not a refusal — the removal finishes on our side, and says so.
"""“Not on the device” is not a refusal — the removal finishes on our side, and says so.
The list a screen removes from is the union of the device's table and the contacts
MeshTerm remembers for it, so the entry may only ever have existed on our side (or the
+2
View File
@@ -295,6 +295,7 @@ def test_heat_ladder_walks_jps_seven_slots_in_order() -> None:
from meshterm.ui.widgets import _recency_style
set_platform(PICOCALC)
# fmt: off
expected = [
(60, 15), (299, 15), # under 5 minutes — white
(300, 11), (3599, 11), # 5 minutes — yellow
@@ -304,6 +305,7 @@ def test_heat_ladder_walks_jps_seven_slots_in_order() -> None:
(2592000, 7), (31535999, 7), # 1 month — light grey
(31536000, 8), (None, 8), # 1 year, and never — dark grey
]
# fmt: on
for secs, slot in expected:
style = MESH_THEME_16.styles[_recency_style(secs)]
assert style.color is not None and style.color.number == slot, (secs, style)