Subtraction, Simplicity & Conventions review — PR #690 (ignition/cli/environment.py)
Key findings
- The production diff is already lean. The whole functional change is 9 lines inside
applyplus one module constant (ignition/cli/environment.py:22,:54-67,:78-81). No new config key, no CLI flag, no schema change (ignition/cli/config.pyuntouched), no wrapper function, no speculative generality, no dead code. Everything below is one deletion, one test-fixture rewrite and some prose collisions. - F1 (high) — delete
configured_cudaand the 3-lineTRITON_PTXAS_PATHcondition (ignition/cli/environment.py:58-59,:78-81). It is the only consumer of that alias and it exists solely for a second, unrequested precedence flip (#636 asks only aboutCUDA_HOME). Reverting to the base one-liner deletes a variable, a 3-line condition and a.strip(), and costs two lines in one test. - F2 (medium) — the leak-free test fixture is over-engineered (
tests/cli/test_environment.py:15-28,:45-58): a 14-entry_ENV_KEYStuple that duplicates the variable namesapplywrites, plus amonkeypatch.setenv(...)/os.environ.pop(...)trick that needs a 3-line comment to justify itself. A plain snapshot/restore ofos.environis ~18 lines shorter and stays correct whenapplygains a variable. - F4 (medium) — the same 4-step toolkit order is now written out three times in three wordings (
docs/cli-design.md:1480,docs/model-preparation.md:123-132,AGENTS.md:466-473), while the umbrella statements that are now false (docs/cli-design.md:46-53) were left alone. The cheap subtraction is to keep the table row plus a pointer and amend the umbrella bullets, not to grow the prose. - F3, F5 (low) — six identical
skipifdecorators where the repo uses a module-levelpytestmark; and a new 3-line comment atenvironment.py:55-57that restates the branch below it and leaves the pre-existing cuTile line orphaned. - Explicitly not removable:
_DEFAULT_LINUX_CUDA(it is the monkeypatch seam the tests need),os.environ.pop("CUDA_HOME", None)(1 line, covered by tests), andconfiguration.directory("cuda")(an existing helper that already handles""→Noneand~expansion — the PR correctly reuses it).
F1 (high) — Delete the configured_cuda alias and the TRITON_PTXAS_PATH condition; it is an unrequested second precedence flip
ignition/cli/environment.py:58-59:
configured_cuda = configuration.directory("cuda")
cuda = configured_cuda
ignition/cli/environment.py:76-81:
else:
ptxas = cuda / "bin/ptxas"
if ptxas.is_file() and (
configured_cuda is not None or not os.environ.get("TRITON_PTXAS_PATH", "").strip()
):
os.environ["TRITON_PTXAS_PATH"] = str(ptxas)
Base (from pr_diff) was the single line if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ:.
Why this is the subtraction lens's business rather than a correctness nit: configured_cuda has exactly one purpose — to invert precedence for a second variable that #636 never mentions. Issue #636 asks only that an inherited CUDA_HOME stop being overwritten by /usr/local/cuda. The extra condition makes [paths] cuda overwrite a caller's exported TRITON_PTXAS_PATH with no warning, which is behaviour beyond the defect being fixed (and sits against docs/design-review.md:89-92 "explicit user values win over defaults" — the correctness lens owns that judgement). Structurally, the whole thing collapses back to the base form:
if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ:
with cuda = configuration.directory("cuda") replacing lines 58-59. Deleted: one alias variable, a 3-line multi-line boolean, one .strip(), and one more precedence rule that has to be documented (see F4) and tested.
Cost of the deletion is two lines in one test: tests/cli/test_environment.py:62-75 drops monkeypatch.setenv("TRITON_PTXAS_PATH", "/ambient/ptxas") (:68) and its assertion (:74). Under the base condition the ambient value is preserved — which is already asserted by the neighbouring test at tests/cli/test_environment.py:93-106 (assert os.environ["TRITON_PTXAS_PATH"] == "/custom/ptxas"). The other 8 parameterisations pass unchanged.
If maintainers do decide [paths] cuda should beat a blank-but-present ambient value, the minimal form is not os.environ.get("TRITON_PTXAS_PATH") — but then the alias stays, so the simplification only lands if the inversion goes. Recommendation: delete the inversion, keep the alias out.
F2 (medium) — Replace _ENV_KEYS + the setenv/pop fixture with an os.environ snapshot
tests/cli/test_environment.py:15-28 (the whole tuple, abbreviated here; all 12 names are verbatim in the file) plus :45-58:
_ENV_KEYS = (
"TORCH_CUSTOM_PYTHONPATH",
...
"CPATH",
)
@pytest.fixture
def clean_environment(monkeypatch, tmp_path):
monkeypatch.setattr(environment.runtime_patches, "apply", lambda: None)
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("USERPROFILE", str(tmp_path))
# Register an undo entry for every managed variable, including keys absent
# before the test, so mutations inside environment.apply never leak across tests.
for key in _ENV_KEYS:
if key in os.environ:
monkeypatch.delenv(key)
else:
monkeypatch.setenv(key, "")
os.environ.pop(key, None)
yield tmp_path
Two distinct costs:
_ENV_KEYShand-copies the namesapplywrites (ignition/cli/environment.py:43-52,:69,:71-72,:81,:86). It goes stale silently: add a variable toapplyand the new fixture keeps leaking while every test still passes.- The
setenv-then-immediate-popdance exists only to register a monkeypatch undo entry for absent keys; it is unreadable enough to need the 3-line comment above it.
Replace both blocks with a snapshot, which needs no key list, no comment, and covers future variables automatically:
@pytest.fixture
def clean_environment(monkeypatch, tmp_path):
monkeypatch.setattr(environment.runtime_patches, "apply", lambda: None)
saved = dict(os.environ)
os.environ.clear()
os.environ.update({"HOME": str(tmp_path), "USERPROFILE": str(tmp_path)})
yield tmp_path
os.environ.clear()
os.environ.update(saved)
Net ≈ −18 lines, _ENV_KEYS deleted entirely. monkeypatch.setenv/delenv calls inside the test bodies keep working (finalizers run in reverse setup order, so the two setenv calls at :48-49 are dropped from monkeypatch and re-created directly; the per-key loop is gone). No conftest.py (not opened) exists anywhere in the repo (checked), so this stays local to the file; the only in-repo env-snapshotting precedent is tests/preparation/test_compile_pool.py:338 env = dict(os.environ), so dict(os.environ) matches existing style.
Footnote (not a finding): _load_config at tests/cli/test_environment.py:38-42 mirrors load() at tests/cli/test_config.py:16-19 (write config.toml (not opened) in tmp_path, return Configuration.load(path)). The cuda=None default earns its keep at six call sites; this is consistent with existing practice, not a violation. Leave it.
F4 (medium) — The toolkit order is now stated three times; the two umbrella statements it contradicts were not touched
docs/model-preparation.md:123-132 grew from 4 lines to 10:
`kernel_cache` is unset or unwritable. `[paths] cuda` selects an explicit
toolkit directory and overrides the process environment. When `[paths] cuda` is
unset on non-Windows hosts, Ignition preserves a non-empty inherited
`CUDA_HOME`, falls back to `/usr/local/cuda` when that directory exists, and
otherwise leaves `CUDA_HOME` unset so native build libraries discover the system
toolkit. On non-Windows hosts, Ignition also sets `TRITON_PTXAS_PATH`
(overriding the environment when `[paths] cuda` is configured, or populating it
when unset) and prepends the toolkit's `include` directory to `CPATH` from the
selected toolkit. On Windows, when `[paths] cuda` is unset, native build
libraries discover the system toolkit.
The same 4-step order is already stated in full by the one-line table row at docs/cli-design.md:1480:
| CUDA toolkit | `[paths] cuda`; otherwise on non-Windows hosts inherited `CUDA_HOME`, then `/usr/local/cuda` when present; otherwise native build libraries discover the system toolkit |
and again at AGENTS.md:466-473:
`ignition.cli.environment` sets the variables that
PyTorch, b12x, Triton, and the Hugging Face hub read, from Flare's
configuration, before importing them; when `[paths] cuda` is unset on
non-Windows hosts, it preserves a non-empty inherited `CUDA_HOME` before
falling back to `/usr/local/cuda` as specified in
[the CLI design](docs/cli-design.md) and
[model preparation](docs/model-preparation.md).
Three copies, three wordings, and the model-preparation one hardcodes /usr/local/cuda in prose. If the order changes again — and per the case file this decision has already been revised three times in six weeks (#71, c9935887, this PR) — two copies go stale. Lean form for docs/model-preparation.md:123-132: keep the first sentence's [paths] cuda behaviour, then one pointer — "otherwise the CUDA toolkit order in the CLI design applies." The AGENTS.md addition is defensible on its own terms because AGENTS.md:452-455 forbids environment reads and needs the cross-reference.
The cheaper edit the PR skipped is at docs/cli-design.md:46-53, which after this change is simply false:
- **No environment variables.** Flare reads none, with one exception:
`CUDA_VISIBLE_DEVICES` restricts which GPUs the caller exposed, which changes
the GPU each index names, so Flare inspects it to interpret `--gpus`.
Variables that underlying libraries read are set by Flare from its own
configuration, and b12x's from the recipe's declared settings, before those
libraries are imported.
- **Two levels of precedence.** Flags override the configuration file, which
overrides the recipe. Nothing else exists.
CUDA_HOME is now a second interpreted variable, and the toolkit has a third source, yet the policy is documented only in a table row 1,400 lines later (:1480). Collapsing the new prose into a pointer at model-preparation.md and spending the two bullets here — where the policy belongs — is both less text and the only version a reviewer of AGENTS.md:452-455 can accept.
F3 (low) — Six identical skipif decorators should be one module-level pytestmark
tests/cli/test_environment.py:61, 78, 92, 109, 123, 138 each repeat verbatim:
@pytest.mark.skipif(os.name == "nt", reason="POSIX CUDA toolkit environment precedence")
The repo convention for a whole-module condition is a single pytestmark after the imports — 33 modules use it, e.g. tests/preparation/test_scratch_cuda.py:14 (not opened), tests/components/test_engram_cuda.py:21 (not opened), tests/server/test_scheduler.py:23 (not opened). Replace all six with one line:
pytestmark = pytest.mark.skipif(os.name == "nt", reason="POSIX CUDA toolkit environment precedence")
Net −5 lines and one place to change if Windows coverage is added later (currently zero, per the case file). Harmless if left as is.
F5 (low) — The new 3-line comment restates the branch and orphans the pre-existing cuTile line
ignition/cli/environment.py:54-57:
# cuTile discovers its compiler bundle independently of the native toolkit.
# Explicit `[paths] cuda` overrides the process environment; on non-Windows hosts
# without `[paths] cuda`, preserve a non-empty inherited `CUDA_HOME` before
# falling back to `/usr/local/cuda`.
Lines 55-57 are a second English copy of exactly the nine lines beneath them, and a fourth copy of the policy in F4. Line 54 (pre-existing, from #71) is now orphaned: the code it introduced no longer concerns cuTile. One line that ties 54 to the new selection and points at the doc instead:
# cuTile discovers its compiler bundle independently of the native toolkit; the
# toolkit for native builds follows the CUDA toolkit row in docs/cli-design.md.
Net −2 lines and one fewer place to edit when the order changes. Not a blocker.
What should NOT be deleted (stated plainly, so the diff is not over-trimmed)
_DEFAULT_LINUX_CUDA = Path("/usr/local/cuda")(ignition/cli/environment.py:22) is not a knob; it is the seam the tests monkeypatch (tests/cli/test_environment.py:66, 82, 96, 113, 127, 141) so they do not require a real/usr/local/cudaon the CI host. Keep. The duplicated literal atignition/preparation/kv_codec.py:32(Path("/usr/local/cuda/bin/nvcc")) is not worth a shared helper across two modules — do not propose consolidation.os.environ.pop("CUDA_HOME", None)(ignition/cli/environment.py:66-67) is 1 line, covered bytests/cli/test_environment.py:138-149. Whether clearing is right is the correctness lens's call; it is not extra machinery.configuration.directory("cuda"): the PR reuses the existing helper (ignition/cli/config.py:172-175), which already returnsNonefor the built-in""default and expands~. No new path-resolution code was written — correct call, no duplication.runtime_patches.apply()stays last (:87), unchanged.
Open questions
- Is the ambient-
TRITON_PTXAS_PATHoverride (environment.py:78-81) intended as part of this fix, or incidental? It is not in #636's ask; if incidental, F1's deletion is free. - Is the three-way prose duplication (F4) acceptable to a maintainer, or should
model-preparation.mdpoint atcli-design.md:1480and the umbrella bullets atdocs/cli-design.md:46-53be amended instead? Nothing recorded on #636 (labelledtriage:design-review, zero comments), so no owner has ruled on where the policy lives. - Whether Windows behaviour — claimed unchanged, the whole reason all six tests skip — will get a test; if so, F3's module-level
pytestmarkbecomes mandatory, not cosmetic.
Verdict: lean diff, one real deletion (F1) plus one fixture rewrite (F2). Nothing else in the 5 changed files is removable machinery; the remaining value is prose subtraction (F4) and two cosmetic cleanups (F3, F5).