Skip to content

Add option for lazy JinjaTemplateSource creation to JinjaTemplates - #117

Merged
volfpeter merged 1 commit into
mainfrom
feat/lazy-JinjaTemplates
Jul 22, 2026
Merged

Add option for lazy JinjaTemplateSource creation to JinjaTemplates#117
volfpeter merged 1 commit into
mainfrom
feat/lazy-JinjaTemplates

Conversation

@volfpeter

@volfpeter volfpeter commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Jinja template sources can now be created lazily when first accessed, supporting both synchronous and asynchronous rendering scenarios.
    • Template providers can be supplied as either ready-to-use sources or factory functions.
  • Bug Fixes

    • Improved template type-checking support.
  • Chores

    • Updated the package version to 0.13.1.
    • Refined development-directory ignore rules.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Lazy Jinja template sources

Layer / File(s) Summary
Lazy source construction and coverage
htmy/jinja.py, tests/test_jinja.py
JinjaTemplates accepts an existing source or a zero-argument factory, initializes factory-backed sources on first access, and tests synchronous and asynchronous lazy rendering.

Repository metadata updates

Layer / File(s) Summary
Ignore rules and version update
.gitignore, .ignore, htmy/__init__.py
Ignore patterns now address dev/ paths, and the package version changes to 0.13.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TemplateCaller
  participant JinjaTemplates
  participant SourceFactory
  participant JinjaTemplateSource

  TemplateCaller->>JinjaTemplates: Access source or request template
  JinjaTemplates->>SourceFactory: Create source on first access
  SourceFactory->>JinjaTemplateSource: Construct source
  JinjaTemplates->>JinjaTemplateSource: Get named template
Loading
🚥 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 matches the main change: JinjaTemplates now supports lazy JinjaTemplateSource creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/lazy-JinjaTemplates

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.

❤️ Share

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.

🧹 Nitpick comments (1)
tests/test_jinja.py (1)

24-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert deferred, one-time construction explicitly.

These cases would still pass if the factory were invoked in __init__ or rebuilt on every access. Add a counted factory test that asserts zero calls after construction, one call after the first access, and still one call after subsequent accesses or renders.

Also applies to: 37-40

🤖 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` around lines 24 - 34, Add counted-factory tests for both
lazy template instances, asserting the factory has zero calls immediately after
construction, exactly one after the first template access, and remains at one
across subsequent accesses and renders. Use a mutable counter or equivalent
around the Environment factory while preserving the existing async and sync
behavior.
🤖 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 `@tests/test_jinja.py`:
- Around line 24-34: Add counted-factory tests for both lazy template instances,
asserting the factory has zero calls immediately after construction, exactly one
after the first template access, and remains at one across subsequent accesses
and renders. Use a mutable counter or equivalent around the Environment factory
while preserving the existing async and sync behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a4303d63-6ee1-430b-af65-631158809890

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfa111 and 395d322.

📒 Files selected for processing (5)
  • .gitignore
  • .ignore
  • htmy/__init__.py
  • htmy/jinja.py
  • tests/test_jinja.py

@volfpeter
volfpeter merged commit 184e01a into main Jul 22, 2026
3 checks passed
@volfpeter
volfpeter deleted the feat/lazy-JinjaTemplates branch July 22, 2026 15:37
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.

1 participant