Repository navigation
Generate format_presets from a namedtuple spec - #259
rtibblesbot wants to merge 2 commits into
Conversation
0799be7 to
ffec48d
Compare
rtibbles
left a comment
There was a problem hiding this comment.
Spec and generated output match the pinned API; CI passing.
- suggestion:
label_constant_suffixis another option only one spec uses (see inline).
| raise ValueError("Record {} {} is defined twice".format(constant_field, record[constant_field])) | ||
| values.add(record[constant_field]) | ||
| define_constant(constants, record["constant"], record[constant_field]) | ||
| if label_constant_suffix: |
There was a problem hiding this comment.
suggestion: This is field_constants hardcoded to label with a different suffix. Each migration has added an option only its own spec uses (getter/tuples/field_constants for file_formats, constant_field for licenses, mappings for content_kinds, now this). Could a namedtuple-level field_constants: {"label": "READABLE"} (field → suffix, every record) replace it, so the next per-record constant needs no new code?
There was a problem hiding this comment.
Done: label_constant_suffix is gone; namedtuple.field_constants: {"label": "READABLE"} emits <CONSTANT>_<suffix> = record[field] for every record, any field. Generated format_presets.py/FormatPresets.js unchanged.
- Searched the generator for other single-spec options:
getter,tuples, record-levelfield_constants,constant_field,mappings,lists. Changed none. - file_formats' record-level
field_constants: ["mimetype"]stays: 2 of its 20 records have no_MIMETYPEconstant, so the namedtuple-level form would add two public constants.
Written by rtibblesbot, an LLM-based coding agent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ffec48d to
e7f8c9e
Compare
Summary
le_utils/constants/format_presets.pyand newjs/FormatPresets.jsare generated fromspec/constants-format_presets.json.le_utils/resources/presetlookup.jsonis deleted.lists(forRENDERABLE_PRESETS_ORDER) and namedtuple-levelfield_constants(field → suffix on every record, for_READABLEconstants) spec options.References
Closes #185. Spec format: #182.
Reviewer guidance
Suggested review: Full code review, then manual QA once the reviewer sets Needs QA.
js/FormatPresets.js.RENDERABLE_PRESETS_ORDERlisted explicitly in the spec, guarded only by a test, is the bitmask contract later migrations should copy.kolibri-constants/FormatPresetsshould export the 33 English_READABLElabels and omitRENDERABLE_PRESETS_ORDERandchoices.field_constantsmeaning a field→suffix dict undernamedtuplebut a field list on records is the spec shape Migrate languages.py to spec + code generation #186 should copy.AI usage
Used Claude Code to add the generator options, build the spec from the existing module and JSON, and write the tests. Verified with the full test suite, prek, and a repeated
make buildleaving no diff.Written by rtibblesbot, an LLM-based coding agent.
🟡 Waiting for feedback
Last updated: 2026-11-11 09:02 UTC