Skip to content

Give FormatsConf.FORMATS AST parsing a strategy layer#162

Merged
wpak-ai merged 4 commits into
cppalliance:developfrom
whisper67265:fix/ast-strategy-layer
Jul 7, 2026
Merged

Give FormatsConf.FORMATS AST parsing a strategy layer#162
wpak-ai merged 4 commits into
cppalliance:developfrom
whisper67265:fix/ast-strategy-layer

Conversation

@whisper67265

@whisper67265 whisper67265 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Close #158.

Summary by CodeRabbit

  • New Features

    • Improved Weblate format detection by resolving upstream core formats and merging in plugin-provided formats (deduplicated) for more reliable compatibility.
  • Bug Fixes

    • Made core Weblate format resolution more resilient to upstream changes.
    • Enhanced resolution failure messaging to include the installed Weblate version plus clearer source/detail context.
  • Tests

    • Added contract-style parsing and resolution coverage for upstream core formats, including error-handling and explicit falsy-source behavior.
    • Updated the internal contract test run to include the new formats source test suite.

@coderabbitai

coderabbitai Bot commented Jul 6, 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: 14ce2307-3ad0-4e2f-b179-eb99ab3e3e07

📥 Commits

Reviewing files that changed from the base of the PR and between cbdb694 and fa8ce25.

📒 Files selected for processing (1)
  • tests/formats/test_weblate_formats_source.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/formats/test_weblate_formats_source.py

📝 Walkthrough

Walkthrough

Core Weblate format path resolution is extracted into a dedicated resolver module. settings_override.py now delegates to that resolver, and tests plus the contract check script were updated for the new flow and error handling.

Changes

FormatsConf resolution extraction

Layer / File(s) Summary
Error type and protocol
src/boost_weblate/formats/formats_source.py
Defines FormatsSourceResolutionError, the FormatsSource protocol, and helpers for Weblate version and upstream path lookup.
AST parsing helpers
src/boost_weblate/formats/formats_source.py
Parses FormatsConf.FORMATS from models.py AST and accepts only tuple or list string literals.
AST source and public resolver
src/boost_weblate/formats/formats_source.py
Implements AstFormatsConfSource.core_format_paths() and resolve_core_weblate_formats(), including resolution error wrapping and versioned RuntimeError conversion.
Settings override delegation
src/boost_weblate/settings_override.py
Updates WEBLATE_FORMATS documentation and replaces local AST/file-reading logic in weblate_formats_with_plugin_formats() with resolve_core_weblate_formats().
Resolver and contract tests
tests/formats/test_weblate_formats_source.py, tests/test_settings_override.py, tests/test_weblate_internal_contract.py, scripts/check-weblate-internal-contract.sh
Adds tests for direct AST parity, upstream contract enforcement, versioned resolution errors, falsy explicit sources, the updated settings override imports, and the internal contract script invocation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: henry0816191, wpak-ai

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the new strategy layer for FormatsConf.FORMATS AST parsing.
Linked Issues check ✅ Passed The PR adds the strategy module, delegates settings_override to it, handles falsy sources and error detail, and keeps contract coverage.
Out of Scope Changes check ✅ Passed The changes stay focused on the new format-resolution strategy, related tests, and contract script wiring with no obvious unrelated edits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/formats/test_weblate_formats_source.py (1)

51-53: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Escape version string before using as regex pattern.

match=weblate_version treats the version string as a regex. If the installed Weblate version contains regex metacharacters (e.g. + in a dev/pre-release tag), the match could silently behave differently than intended. Use re.escape() for a precise, robust check.

🔧 Proposed fix
+import re
+
     weblate_version = importlib.metadata.version("Weblate")
-    with pytest.raises(RuntimeError, match=weblate_version) as exc_info:
+    with pytest.raises(RuntimeError, match=re.escape(weblate_version)) as exc_info:
         resolve_core_weblate_formats()
🤖 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 `@tests/formats/test_weblate_formats_source.py` around lines 51 - 53, The test
in resolve_core_weblate_formats uses the Weblate version string directly as the
pytest.raises match pattern, which can be interpreted as a regex. Update the
assertion to escape the imported version from
importlib.metadata.version("Weblate") before passing it to match, so the check
is exact and robust even when the version contains regex metacharacters. Use the
existing resolve_core_weblate_formats and weblate_version symbols to locate the
change.
🤖 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.

Inline comments:
In `@src/boost_weblate/formats/weblate_formats_source.py`:
- Line 121: The source selection in the formats resolver is treating any falsy
value as missing, so explicitly provided strategy objects that implement
__bool__ or __len__ can be incorrectly replaced. Update the source
initialization in the relevant resolver (where resolved is assigned from source
and AstFormatsConfSource) to default only when source is None, preserving any
caller-provided falsy strategy instance.

---

Nitpick comments:
In `@tests/formats/test_weblate_formats_source.py`:
- Around line 51-53: The test in resolve_core_weblate_formats uses the Weblate
version string directly as the pytest.raises match pattern, which can be
interpreted as a regex. Update the assertion to escape the imported version from
importlib.metadata.version("Weblate") before passing it to match, so the check
is exact and robust even when the version contains regex metacharacters. Use the
existing resolve_core_weblate_formats and weblate_version symbols to locate the
change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b68a8f05-f843-47c0-b3c7-8c5371a0ed46

📥 Commits

Reviewing files that changed from the base of the PR and between 1d5983c and 9aa801b.

📒 Files selected for processing (4)
  • src/boost_weblate/formats/weblate_formats_source.py
  • src/boost_weblate/settings_override.py
  • tests/formats/test_weblate_formats_source.py
  • tests/test_weblate_internal_contract.py

Comment thread src/boost_weblate/formats/weblate_formats_source.py Outdated
@whisper67265 whisper67265 requested a review from henry0816191 July 6, 2026 19:36

@henry0816191 henry0816191 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@henry0816191 henry0816191 requested a review from wpak-ai July 6, 2026 21:55
Comment thread src/boost_weblate/settings_override.py Outdated

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@tests/formats/test_weblate_formats_source.py`:
- Around line 43-56: Update the contract test in test_weblate_formats_source.py
so test_weblate_contract_formatsconf_ast handles the same parse failures as the
source helper, not just RuntimeError. Expand the except block around
_parse_formatsconf_formats_ast(_load_weblate_formats_models_source()) to also
catch SyntaxError and ValueError, then wrap them in the existing AssertionError
message using _CONTRACT_PREFIX_FORMATSCONF so any parsing failure is reported
consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 923a4e67-4036-4b7c-a1d5-f2850caac34a

📥 Commits

Reviewing files that changed from the base of the PR and between 9b34cb2 and cbdb694.

📒 Files selected for processing (6)
  • scripts/check-weblate-internal-contract.sh
  • src/boost_weblate/formats/formats_source.py
  • src/boost_weblate/settings_override.py
  • tests/formats/test_weblate_formats_source.py
  • tests/test_settings_override.py
  • tests/test_weblate_internal_contract.py
💤 Files with no reviewable changes (1)
  • tests/test_weblate_internal_contract.py
✅ Files skipped from review due to trivial changes (1)
  • tests/test_settings_override.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/boost_weblate/settings_override.py

Comment thread tests/formats/test_weblate_formats_source.py
@wpak-ai wpak-ai merged commit 1fe343d into cppalliance:develop Jul 7, 2026
12 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.

FormatsConf AST strategy layer + graceful fallback

3 participants