livery.toolroom.bench._colorprobe¶
livery.toolroom.bench._colorprobe ¶
Probe a tool's colour control by running it — the engine behind
fm toolroom.color.
footman forces colour into the tools it spawns (see context.color_env): by the
environment for the modern set, by the tool's own flag for the few that ignore
it. Which is which is a fact about each tool, and the honest way to learn it is
to run the tool and look at the bytes. This module does that: for each tool it
forces colour on and off, first by environment then by flag, and records whether
each direction obeys the environment (env), needs the flag (flag), or can be
forced neither way (none).
The result generates _colordata.py — read by tools.py for its forcing table
and by the docs for the support table. A maintainer runs it against the
provisioned binaries; nothing here is imported on a normal fm run.
A tool only colourises when it has something to colour, so each needs a
hardcoded trigger: a command (and any fixture files) that produces colourable
output. Figured out once per tool; one without a trigger reports unprobed.
Classes:
| Name | Description |
|---|---|
Trigger |
How to make a tool emit colour: its argv, and the fixture it needs. |
ColourFlag |
The tokens that force a tool's colour on/off, and where they go. |
Verdict |
One tool's probed colour control, each direction categorised. |
Functions:
| Name | Description |
|---|---|
flag_candidate |
The colour switch to try for a tool: a curated quirk (git), else a |
probe |
Categorise one tool by running its trigger with colour forced each way. |
probe_all |
Probe each |
merged |
fresh over stored: a probe records what it ran and leaves the rest. |
render |
The text of |
Attributes:
| Name | Type | Description |
|---|---|---|
TRIGGERS |
dict[str, Trigger]
|
|
Row |
One stored line of |
TRIGGERS
module-attribute
¶
TRIGGERS: dict[str, Trigger] = {'ruff': Trigger(('check', 'bad.py'), {'bad.py': 'import os\n'}), 'ruff_format': Trigger(('format', '--diff', 'bad.py'), {'bad.py': 'x=1\n'}), 'basedpyright': Trigger(('bad.py',), {'bad.py': _PY_TYPE}), 'mypy': Trigger(('bad.py',), {'bad.py': _PY_TYPE}), 'ty': Trigger(('check', 'bad.py'), {'bad.py': _PY_TYPE}), 'pytest': Trigger(('t.py',), {'t.py': 'def test():\n assert True\n'}), 'cspell': Trigger(('lint', 'bad.txt'), {'bad.txt': _SPELL}), 'uv': Trigger(('python', 'list')), 'gh': Trigger(('--help',)), 'bun': Trigger(('--help',)), 'prek': Trigger(('--help',)), 'mkdocs': Trigger(('--help',)), 'twine': Trigger(('check', 's.py'), {'s.py': 'print(1)\n'}), 'cmake': Trigger(('-S', '.', '-B', 'b')), 'ninja': Trigger((), {'build.ninja': 'rule f\n command = false\nbuild x: f\n'}), 'build': Trigger(('--sdist',), {'pyproject.toml': '[project]\nname="x"\nversion="1"\n'}), 'git': Trigger(('log', '--oneline', '-1'), {'a.txt': 'hi\n'}, git=True), 'git_cliff': Trigger((), {'a.txt': 'hi\n'}, git=True), 'git_changelog': Trigger(('.',), {'a.txt': 'hi\n'}, git=True), 'djlint': Trigger(('bad.html',), {'bad.html': '<div ></div>\n'}), 'markdownlint': Trigger(('bad.md',), {'bad.md': '#x\n'}), 'eclint': Trigger(('-h',)), 'coverage': Trigger(('report',)), 'python': Trigger(('--version',)), 'zensical': Trigger(('--help',)), 'claude': Trigger(('--help',)), 'tea': Trigger(('--help',))}
Row
module-attribute
¶
One stored line of _colordata.py — see its _Row.
Trigger
dataclass
¶
ColourFlag
dataclass
¶
Verdict
dataclass
¶
Verdict(on: str, off: str, flag: ColourFlag | None = None)
flag_candidate ¶
flag_candidate(key: str, spec: ToolSpec) -> ColourFlag | None
The colour switch to try for a tool: a curated quirk (git), else a
--color=always/never detected from its stub (ToolSpec.color_flags).
Source code in packages/toolroom-bench/src/livery/toolroom/bench/_colorprobe.py
probe ¶
Categorise one tool by running its trigger with colour forced each way.
Source code in packages/toolroom-bench/src/livery/toolroom/bench/_colorprobe.py
probe_all ¶
Probe each (key, argv0, binary, spec); return {key: (argv0, verdict)}.
Source code in packages/toolroom-bench/src/livery/toolroom/bench/_colorprobe.py
merged ¶
merged(stored: dict[str, Row], fresh: dict[str, tuple[str, Verdict]]) -> dict[str, tuple[str, Verdict]]
fresh over stored: a probe records what it ran and leaves the rest.
A probe needs a binary, and the man tier provisions pages — so git, ssh
and their siblings are in no prefix, and a run that wrote only what it
saw would drop git's -c color.ui=always and take the bridge's colour
forcing out with it. The same shape as a platform's reading folding
into the option history: what was looked at is recorded, and what was
not is left exactly as it was.
Source code in packages/toolroom-bench/src/livery/toolroom/bench/_colorprobe.py
render ¶
The text of _colordata.py for a batch of probe results.