Split generated runtime fallback#17
Conversation
Move generated package initialisation to a re-export-only `__init__` and place the optional Rust-extension fallback in a private runtime module. Add the pure module docstring and generated public API test so new projects satisfy the current lint and test gates. Refresh Ruff-formatted rule and scripting guidance, and update the generated packaging settings so Python-only and Rust-backed projects install under custom package names on current Python versions.
Add the root `markdownlint-cli2` config so parent-level Markdown checks use the same rules as rendered projects. Remove the incidental `.rules` formatting churn from the branch and repair the duplicated fenced block in `scripting-standards.md`. Keep the scoped Markdown formatter output for the docs that remain changed by this branch.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughA new ChangesRuntime dispatch refactor
Markdownlint config and doc reformats
Possibly related PRs
Poem
Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (3 errors, 5 warnings)
✅ Passed checks (12 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@template/`{{ package_name }}/_runtime.py.jinja:
- Line 1: The _runtime.py.jinja template file is missing a module-level
docstring. Add a triple-quoted docstring immediately after the `from __future__
import annotations` import statement that documents the purpose of this runtime
module, explains its utility, describes how it should be used, and includes
example usage calls where appropriate, following the coding guideline that every
module must begin with such documentation.
- Around line 11-15: The exception handler in the try-except block is catching
all ModuleNotFoundError exceptions, which can mask real packaging and runtime
faults. Instead of catching all ModuleNotFoundError instances, capture the
exception as a variable and check if it's specifically for the missing Rust
module (_{PACKAGE_NAME}_rs). Construct the expected module name as a string
combining the package name, then compare it against the caught exception's name
attribute. Only fall back to the pure Python implementation when the exception
is specifically about the missing Rust module; if the exception's name does not
match the expected Rust module name, re-raise the exception so that other
ModuleNotFoundError cases are not silently masked.
In `@template/docs/complexity-antipatterns-and-refactoring-strategies.md`:
- Around line 655-657: The footnote reference [^34] in the declarative
programming examples section is not defined in the works-cited section, creating
a dangling citation. Either replace the [^34] reference with [^26] if that
existing footnote contains the appropriate source material, or add a new [^34]
footnote entry to the works-cited section with a matching citation. Ensure the
footnote number you use in the text has a corresponding definition elsewhere in
the document.
In `@template/tests/test_public_api.py.jinja`:
- Line 10: The assert statement in the test_public_api.py.jinja file is missing
an assertion message on the equality check of {{ package_name }}.hello(). Add a
descriptive message as the second argument to the assert statement following the
format assert condition, "message" to provide clear context when the test fails,
helping developers understand what the assertion was checking.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8d8fc41c-12c4-419a-8ff6-b76ea5bab49d
📒 Files selected for processing (7)
.markdownlint-cli2.jsonctemplate/docs/complexity-antipatterns-and-refactoring-strategies.mdtemplate/docs/scripting-standards.mdtemplate/tests/test_public_api.py.jinjatemplate/{{ package_name }}/__init__.py.jinjatemplate/{{ package_name }}/_runtime.py.jinjatests/test_template.py
Document the generated runtime selector and narrow the optional Rust fallback so only the missing extension module falls back to the pure Python backend. Other missing-module failures now propagate. Add generated-template coverage for the fallback and re-raise paths, define the dangling declarative-programming citation, and add context to the public API assertion.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Expand the generated package entry-point documentation so users can see the public import path and a concrete `hello()` example. Keep generated tests easier to diagnose by describing the public API check and adding assertion messages to the runtime source-shape checks. Renumber the SQL citation to keep the Markdown references sequential.
|
@coderabbitai Have the following now been resolved? template/{{ package_name }}/init.py.jinja (1)
📚 Proposed enhancement-"""{{ project_name }} package."""
+"""{{ project_name }} package.
+
+This package provides a greeting function that demonstrates backend selection
+between {% if use_rust %}Rust and {% endif %}Python implementations.
+
+Examples
+--------
+>>> import {{ package_name }}
+>>> {{ package_name }}.hello()
+"{% if use_rust %}hello from Rust{% else %}hello from Python{% endif %}"
+"""As per coding guidelines, every module must explain its purpose, utility, and usage, including example calls if appropriate. 🤖 Detailed instructionsVerify each finding against current code. Fix only still-valid issues, skip the In Source: Coding guidelines |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check the current content of the __init__.py.jinja file
fd --full-path '__init__.py.jinja' --exec cat {}Length of output: 723
The current content goes beyond the minimal proposed enhancement and satisfies the coding guideline requirement. |
|
@coderabbitai Please investigate the cause of the following issue using codegraph exploration and research, identify a fix and provide an AI coding agent prompt for the fix: https://github.com/leynos/agent-template-python/actions/runs/27502113599/job/81286742745?pr=17 |
This comment was marked as resolved.
This comment was marked as resolved.
Move the generated `_runtime.py` documentation string before the future import so Python exposes it through `module.__doc__`. Extend the rendered-template regression check to require the generated file to start with the documentation string and to prove the imported runtime module keeps a non-empty `__doc__` value.
Bump the Rust-extension template to PyO3 0.29.0 so generated Rust-enabled projects no longer fail `cargo audit` before the shared coverage action can run.
|
@coderabbitai Have the following failed checks now been resolved? If further work is required, please provide an AI agent prompt for the remaining work to be done to address these failures. Do not treat warnings as optional or aspirational. Where a change is out of scope for this PR, propose a GitHub issue unless one exists already. (Treat documentation and validation coverage as in scope). ❌ Failed checks (3 errors, 5 warnings)
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check current state of _runtime.py.jinja
fd '_runtime.py.jinja' --exec cat {}
echo "---"
# Check test_public_api.py.jinja
fd 'test_public_api.py.jinja' --exec cat {}
echo "---"
# Check test_template.py (runtime fallback test and assertions)
grep -n 'assert\|def test_runtime\|def test_python_only\|noqa' tests/test_template.py
echo "---"
# Check complexity-antipatterns doc for footnote numbering
grep -n '\[\^3[0-9]\]' "template/docs/complexity-antipatterns-and-refactoring-strategies.md" | tail -20
echo "---"
# Check docs/developers-guide.md exists and its Rust section
fd 'developers-guide.md' --exec grep -n 'rust\|_runtime\|backend' -i {}
echo "---"
# Check for snapshot tests
fd 'snapshots' -t d
fd '__snapshots__' -t d
rg 'snapshot\|syrupy\|assert_match_snapshot' tests/test_template.pyLength of output: 8178 🏁 Script executed: #!/bin/bash
# Get the full test_runtime_module_documents_and_limits_fallback function
sed -n '162,245p' tests/test_template.py
echo "==="
# Read the Rust Integration section of developers-guide.md
fd 'developers-guide.md' --exec cat {}
echo "==="
# List snapshot directory contents
ls tests/__snapshots__/
echo "==="
# Check test_template.py for any _runtime snapshot test
grep -n 'runtime\|_runtime\|snapshot' tests/test_template.pyLength of output: 15902
Status
AI agent prompts1 — Fix tautological
|
Summary
This branch splits generated package backend selection out of the public package initializer so rendered Python/Rust projects keep a small
__init__surface while retaining the optional Rust-extension fallback. It also adds generated public API and runtime fallback regression coverage, and tightens the branch's documentation changes after rebase.No linked issue, roadmap task, or execplan was found for this branch.
Review walkthrough
hellore-export.ModuleNotFoundErrorfailures.Validation
mdtablefix --wrap --renumber --breaks --ellipsis --fences --in-place template/docs/complexity-antipatterns-and-refactoring-strategies.md: passedmarkdownlint-cli2 --fix template/docs/complexity-antipatterns-and-refactoring-strategies.md: passed with 0 errorsmarkdownlint-cli2 template/docs/complexity-antipatterns-and-refactoring-strategies.md: passed with 0 errorsruff format tests template/tests: passed; 1 file reformatted, thenmake check-fmtverified the resultuvx --with pytest-copier --with pyyaml --with syrupy --with make-parser pytest tests/test_template.py::test_runtime_module_documents_and_limits_fallback tests/test_template.py::test_python_only_template tests/test_template.py::test_rust_template -q: passed; 3 passedgit diff --check: passedmake check-fmt: passed; 18 files already formattedmake test: passed; 33 passed, 2 skipped, 3 snapshots passedmake typecheck: passedmake lint: passedNotes
mdformat-allis treated as the canonical Markdown formatter, but the installed wrapper does not expose a scope flag and always walks every Markdown file. Running it across the whole repository would reformat the large copied Copier reference documents under docs/configuring-a-copier-template.md and docs/creating-a-copier-template.md, which already have unrelated Markdown lint failures. This branch therefore applies the same canonicalmdtablefixplusmarkdownlint-cli2 --fixpipeline only to the Markdown files touched by the branch.The installed
ruff formatcommand does not support Markdown as Markdown in this checkout. Forcing.mdthrough--extension md:pythonmakes Ruff parse the entire document as Python, so this branch only runs Ruff formatting on the Python test/template-support targets.