Skip to content

Replace settings_override regex-scrape with format AST parsing #100

@whisper67265

Description

@whisper67265

Problem

settings_override.py built WEBLATE_FORMATS by regex-scraping FormatsConf.FORMATS from upstream weblate/formats/models.py. That approach was layout-sensitive (it assumed a specific indentation pattern and a following class Meta: block) and duplicated AST parsing logic that already existed only in tests. Upstream reformatting of FormatsConf could break format registration at boot with opaque parse failures.

Acceptance Criteria

  • settings_override.py extracts FormatsConf.FORMATS via AST helpers instead of _FORMATS_BLOCK / _STRING_LITERAL regex
  • weblate_formats_with_quickbook() reads upstream models.py, parses string literals from the FORMATS tuple/list assignment, appends QuickBook, and raises RuntimeError on missing class, missing assignment, or unexpected literal shapes
  • test_settings_override_formats_match_ast_parse_of_upstream imports _parse_formatsconf_formats_ast from production code and asserts parity with weblate_formats_with_quickbook() output
  • README and deployment runbook describe AST-based parsing and direct maintainers to update AST helpers when upstream restructures FormatsConf

Implementation Notes

  • Move _parse_formatsconf_formats_ast, _formats_assignment_to_strings, and _string_tuple_or_list into settings_override.py; use RuntimeError (not AssertionError) for production parse failures
  • Replace re with ast for parsing; catch SyntaxError / ValueError from ast.parse and wrap with a contextual RuntimeError
  • Docs no longer reference updating a _FORMATS_BLOCK regex when upstream changes layout

References

  • README.md
  • docs/deployment-runbook.md
  • src/boost_weblate/settings_override.py
  • tests/test_settings_override.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions