Skip to content

Generate format_presets from a namedtuple spec - #259

Open
rtibblesbot wants to merge 2 commits into
learningequality:mainfrom
rtibblesbot:issue-185-140e1c
Open

rtibblesbot wants to merge 2 commits into
learningequality:mainfrom
rtibblesbot:issue-185-140e1c

Conversation

@rtibblesbot

@rtibblesbot rtibblesbot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • le_utils/constants/format_presets.py and new js/FormatPresets.js are generated from spec/constants-format_presets.json.
  • le_utils/resources/presetlookup.json is deleted.
  • Generator gains lists (for RENDERABLE_PRESETS_ORDER) and namedtuple-level field_constants (field → suffix on every record, for _READABLE constants) spec options.

References

Closes #185. Spec format: #182.

Reviewer guidance

Suggested review: Full code review, then manual QA once the reviewer sets Needs QA.

  • User-visible files changed: js/FormatPresets.js.
  • Confirm RENDERABLE_PRESETS_ORDER listed explicitly in the spec, guarded only by a test, is the bitmask contract later migrations should copy.
  • Confirm kolibri-constants/FormatPresets should export the 33 English _READABLE labels and omit RENDERABLE_PRESETS_ORDER and choices.
  • Confirm field_constants meaning a field→suffix dict under namedtuple but 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 build leaving no diff.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot

🟡 Waiting for feedback

Last updated: 2026-11-11 09:02 UTC

@rtibblesbot
rtibblesbot marked this pull request as ready for review November 5, 2026 04:32
@rtibblesbot
rtibblesbot requested review from a team and leq-bot November 5, 2026 04:32

@rtibbles rtibbles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec and generated output match the pinned API; CI passing.

  • suggestion: label_constant_suffix is another option only one spec uses (see inline).

Comment thread scripts/generate_from_specs.py Outdated
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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-level field_constants, constant_field, mappings, lists. Changed none.
  • file_formats' record-level field_constants: ["mimetype"] stays: 2 of its 20 records have no _MIMETYPE constant, so the namedtuple-level form would add two public constants.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot and others added 2 commits November 11, 2026 00:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate format_presets.py to spec + code generation

2 participants