Give FormatsConf.FORMATS AST parsing a strategy layer#162
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughCore ChangesFormatsConf resolution extraction
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant settings_override
participant resolve_core_weblate_formats
participant AstFormatsConfSource
participant models_py as "weblate formats/models.py"
settings_override->>resolve_core_weblate_formats: call resolve_core_weblate_formats()
resolve_core_weblate_formats->>AstFormatsConfSource: core_format_paths()
AstFormatsConfSource->>models_py: read source file
models_py-->>AstFormatsConfSource: FormatsConf.FORMATS text
AstFormatsConfSource-->>resolve_core_weblate_formats: parsed format paths or FormatsSourceResolutionError
resolve_core_weblate_formats-->>settings_override: tuple of format paths or RuntimeError
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/formats/test_weblate_formats_source.py (1)
51-53: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winEscape version string before using as regex pattern.
match=weblate_versiontreats 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. Usere.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
📒 Files selected for processing (4)
src/boost_weblate/formats/weblate_formats_source.pysrc/boost_weblate/settings_override.pytests/formats/test_weblate_formats_source.pytests/test_weblate_internal_contract.py
Close #158.
Summary by CodeRabbit
New Features
Bug Fixes