Add make_context Jinja context customization option to JinjaTemplate - #112
Conversation
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds an optional Changesmake_context feature
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant JinjaTemplate
participant JinjaEnvironment
Caller->>JinjaTemplate: htmy(context)
JinjaTemplate->>JinjaTemplate: build jinja_context
alt make_context provided
JinjaTemplate->>JinjaTemplate: update context with make_context(context)
end
JinjaTemplate->>JinjaTemplate: apply reserved slots
JinjaTemplate->>JinjaEnvironment: render template with context
JinjaEnvironment-->>Caller: rendered output
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
htmy/jinja.py (1)
93-124: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAlways reserve
slotsin the final Jinja context
make_contextcan still leave a"slots"entry behind when no template slots are rendered, so the reserved key isn’t consistently enforced. Settingjinja_context["slots"] = slotsunconditionally would match the documented precedence, though it does change behavior for callers that intentionally provide their own"slots"value.🤖 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 `@htmy/jinja.py` around lines 93 - 124, The final Jinja context does not consistently reserve the slots key because make_context can leave an existing "slots" entry when no template slots are rendered. Update the Jinja context assembly in htmy/jinja.py so the rendering path always assigns the reserved "slots" entry after _build_context() and make_context, using the slots value from __init__ and enforcing the documented precedence in the Jinja template context.
🧹 Nitpick comments (1)
tests/test_jinja.py (1)
3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider typing
make_contextwithJinjaContextFactoryinstead ofAny.Other parameters (
jinja_context,slots,default_slots) use preciseMapping/Nonetypes;make_context: Anyloses type-checking benefit here sinceJinjaContextFactoryis already exported fromhtmy.jinja.♻️ Proposed refactor
-from typing import Any +from htmy.jinja import JinjaContextFactory- make_context: Any, + make_context: JinjaContextFactory | None,Also applies to: 143-144
🤖 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/test_jinja.py` at line 3, The type annotation for make_context is too broad and should use JinjaContextFactory instead of Any, matching the other precise parameter types already used in this test. Update the relevant test setup in test_jinja to import and apply JinjaContextFactory from htmy.jinja, and make the same typing adjustment where make_context is repeated in the other referenced spots so type checking remains effective.
🤖 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.
Outside diff comments:
In `@htmy/jinja.py`:
- Around line 93-124: The final Jinja context does not consistently reserve the
slots key because make_context can leave an existing "slots" entry when no
template slots are rendered. Update the Jinja context assembly in htmy/jinja.py
so the rendering path always assigns the reserved "slots" entry after
_build_context() and make_context, using the slots value from __init__ and
enforcing the documented precedence in the Jinja template context.
---
Nitpick comments:
In `@tests/test_jinja.py`:
- Line 3: The type annotation for make_context is too broad and should use
JinjaContextFactory instead of Any, matching the other precise parameter types
already used in this test. Update the relevant test setup in test_jinja to
import and apply JinjaContextFactory from htmy.jinja, and make the same typing
adjustment where make_context is repeated in the other referenced spots so type
checking remains effective.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8f578451-8457-4ff0-a2ea-ee746bb9ec5b
📒 Files selected for processing (3)
htmy/__init__.pyhtmy/jinja.pytests/test_jinja.py
Summary by CodeRabbit
make_contexthook to compute extra context dynamically at render time.slotsentry is set even when no slots are provided).title) without affecting slot values.make_contextbehavior and precedence rules.0.12.1.