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
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
Problem
settings_override.pybuiltWEBLATE_FORMATSby regex-scrapingFormatsConf.FORMATSfrom upstreamweblate/formats/models.py. That approach was layout-sensitive (it assumed a specific indentation pattern and a followingclass Meta:block) and duplicated AST parsing logic that already existed only in tests. Upstream reformatting ofFormatsConfcould break format registration at boot with opaque parse failures.Acceptance Criteria
settings_override.pyextractsFormatsConf.FORMATSvia AST helpers instead of_FORMATS_BLOCK/_STRING_LITERALregexweblate_formats_with_quickbook()reads upstreammodels.py, parses string literals from theFORMATStuple/list assignment, appends QuickBook, and raisesRuntimeErroron missing class, missing assignment, or unexpected literal shapestest_settings_override_formats_match_ast_parse_of_upstreamimports_parse_formatsconf_formats_astfrom production code and asserts parity withweblate_formats_with_quickbook()outputFormatsConfImplementation Notes
_parse_formatsconf_formats_ast,_formats_assignment_to_strings, and_string_tuple_or_listintosettings_override.py; useRuntimeError(notAssertionError) for production parse failuresrewithastfor parsing; catchSyntaxError/ValueErrorfromast.parseand wrap with a contextualRuntimeError_FORMATS_BLOCKregex when upstream changes layoutReferences
README.mddocs/deployment-runbook.mdsrc/boost_weblate/settings_override.pytests/test_settings_override.py