Skip to content

build_subsets.py also does its work at import, so its prefix list still cannot be imported #97

Description

@realmarcin

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions