Skip to content

Replace settings_override regex-scrape with format AST parsing#107

Merged
wpak-ai merged 2 commits into
cppalliance:developfrom
whisper67265:fix/format-ast-parsing
Jun 12, 2026
Merged

Replace settings_override regex-scrape with format AST parsing#107
wpak-ai merged 2 commits into
cppalliance:developfrom
whisper67265:fix/format-ast-parsing

Conversation

@whisper67265

@whisper67265 whisper67265 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Close #100.

Summary by CodeRabbit

  • Documentation

    • Updated README and deployment runbook to clarify how upstream format definitions are detected and how to update the override if upstream structure changes.
  • Refactor

    • Improved format-detection to be more robust to upstream layout changes and added clearer runtime error guidance when upstream restructuring occurs.
  • Tests

    • Adjusted tests to use the unified format-detection logic and validate the appended QuickBook format.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f21e900d-008f-4438-a527-c5f41dba0ce4

📥 Commits

Reviewing files that changed from the base of the PR and between c6b01ab and 7935553.

📒 Files selected for processing (1)
  • docs/deployment-runbook.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/deployment-runbook.md

📝 Walkthrough

Walkthrough

This PR replaces regex-based scraping of FormatsConf.FORMATS with AST parsing in settings_override.py, moves AST helpers into production, updates tests to use those helpers, and revises README and the deployment runbook to describe AST-based extraction and maintenance guidance.

Changes

AST-based WEBLATE_FORMATS extraction

Layer / File(s) Summary
AST parsing helpers and weblate_formats_with_quickbook implementation
src/boost_weblate/settings_override.py
Module docstring updated to AST approach. re import replaced with ast. New helpers locate FormatsConf, extract the FORMATS assignment, and convert string literals to a list. weblate_formats_with_quickbook() uses these helpers and wraps parse errors in RuntimeError with source context.
Test imports and assertions align with production helpers
tests/test_settings_override.py
Removed local ast usage. test_settings_override_formats_match_ast_parse_of_upstream imports _parse_formatsconf_formats_ast and weblate_formats_with_quickbook from production code and keeps assertions comparing upstream FormatsConf.FORMATS with the generated list plus QuickBook sentinel.
Documentation updated to reference AST parsing and maintenance guidance
README.md, docs/deployment-runbook.md
README and runbook now state WEBLATE_FORMATS is derived via AST-parsing of weblate/formats/models.py. Troubleshooting guidance updated to reference RuntimeError during settings exec() and to instruct maintainers to update AST helpers in settings_override.py if upstream FormatsConf is restructured.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 From regex rows to abstract trees we hop,
AST helpers bloom where scrapers once did stop,
No more indentation made our parsing pop—
Now syntax nodes dance, and maintenance won't flop! 🌳✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: replacing regex-based scraping with AST-based parsing of FormatsConf.FORMATS in settings_override.py.
Linked Issues check ✅ Passed All acceptance criteria from issue #100 are met: AST helpers replace regex scraping, weblate_formats_with_quickbook() reads models.py via AST and appends QuickBook with RuntimeError handling, test imports AST parser from production code, and documentation updates explain AST-based parsing.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objectives in issue #100: AST parsing implementation, test updates, and documentation revisions for deployment guidance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/boost_weblate/settings_override.py (1)

83-89: 💤 Low value

Consider removing redundant RuntimeError catch.

Lines 85-86 catch RuntimeError and immediately re-raise it. Since the helper functions already raise RuntimeError with appropriate messages, this catch-and-re-raise is unnecessary. You can simplify by removing those two lines and letting RuntimeError propagate naturally while still catching SyntaxError and ValueError.

♻️ Simplified exception handling
     try:
         core = tuple(_parse_formatsconf_formats_ast(src))
-    except RuntimeError:
-        raise
     except (SyntaxError, ValueError) as exc:
         msg = f"boost_weblate: could not parse FormatsConf.FORMATS from {models_py}"
         raise RuntimeError(msg) from exc
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/boost_weblate/settings_override.py` around lines 83 - 89, The try/except
block around parsing (where core = tuple(_parse_formatsconf_formats_ast(src)))
has an unnecessary except RuntimeError that only re-raises; remove the two-line
except RuntimeError: raise branch and leave the except (SyntaxError, ValueError)
as exc to convert those into a RuntimeError with the existing msg, so
RuntimeError from _parse_formatsconf_formats_ast will propagate unchanged while
SyntaxError/ValueError are wrapped.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/boost_weblate/settings_override.py`:
- Around line 83-89: The try/except block around parsing (where core =
tuple(_parse_formatsconf_formats_ast(src))) has an unnecessary except
RuntimeError that only re-raises; remove the two-line except RuntimeError: raise
branch and leave the except (SyntaxError, ValueError) as exc to convert those
into a RuntimeError with the existing msg, so RuntimeError from
_parse_formatsconf_formats_ast will propagate unchanged while
SyntaxError/ValueError are wrapped.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24af0985-21bd-45fd-bb0d-cf5e18b4be1a

📥 Commits

Reviewing files that changed from the base of the PR and between b3a9c8c and c6b01ab.

📒 Files selected for processing (4)
  • README.md
  • docs/deployment-runbook.md
  • src/boost_weblate/settings_override.py
  • tests/test_settings_override.py

Comment thread docs/deployment-runbook.md Outdated
@henry0816191 henry0816191 requested a review from wpak-ai June 12, 2026 16:44
@wpak-ai wpak-ai merged commit f425069 into cppalliance:develop Jun 12, 2026
9 checks passed
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.

Replace settings_override regex-scrape with format AST parsing

3 participants