Sibling of #95, which guarded prefix_census.py. Two scripts still do real work at import:
build_subsets.py scans record corpora and builds MECHS at module level.
build_data.py reads subsets_summary.json and prefix_census.json at module level and writes fleet_data.json.
So neither can be imported to read a constant, which is why the tests added in #96 parse VOC and PREF out of the source text with ast rather than importing the modules that define them.
That works and is guarded — the parse requires exactly one module-level binding and reads it with literal_eval, so a second binding or a computed value fails loudly rather than being half-read (verified against a VOC = VOC + ["BOGUSVOC"] mutation). But it is a workaround. A test that reads source cannot see:
- a list built at runtime from a loop or comprehension
- a list mutated by
.append() later in the module
- a list assembled across an
if
None of those shapes exist today. The guard catches the two that would be silent; the rest would need the real object.
Fix
Same shape as #95: move the module-level work into main() behind an if __name__ == "__main__": guard, leaving the constants importable. Then literal() in tests/test_fleet_page.py can be replaced with a plain import, and the three-list invariants would be checked against the values the pipeline actually uses rather than the text that defines them.
build_subsets.py is the harder of the two: its module level builds MECHS and opens checkouts, so the refactor has to separate "declare the constants" from "prepare the scan". Worth doing before anyone extends the prefix lists for #84, since that is exactly when the guard's blind spots would start to matter.
Sibling of #95, which guarded
prefix_census.py. Two scripts still do real work at import:build_subsets.pyscans record corpora and buildsMECHSat module level.build_data.pyreadssubsets_summary.jsonandprefix_census.jsonat module level and writesfleet_data.json.So neither can be imported to read a constant, which is why the tests added in #96 parse
VOCandPREFout of the source text withastrather than importing the modules that define them.That works and is guarded — the parse requires exactly one module-level binding and reads it with
literal_eval, so a second binding or a computed value fails loudly rather than being half-read (verified against aVOC = VOC + ["BOGUSVOC"]mutation). But it is a workaround. A test that reads source cannot see:.append()later in the moduleifNone of those shapes exist today. The guard catches the two that would be silent; the rest would need the real object.
Fix
Same shape as #95: move the module-level work into
main()behind anif __name__ == "__main__":guard, leaving the constants importable. Thenliteral()intests/test_fleet_page.pycan be replaced with a plain import, and the three-list invariants would be checked against the values the pipeline actually uses rather than the text that defines them.build_subsets.pyis the harder of the two: its module level buildsMECHSand opens checkouts, so the refactor has to separate "declare the constants" from "prepare the scan". Worth doing before anyone extends the prefix lists for #84, since that is exactly when the guard's blind spots would start to matter.