Skip to content

Split the Python app entry template into one file per framework - #472

Merged
Marve10s merged 2 commits into
mainfrom
refactor/split-python-go-server
Oct 14, 2026
Merged

Marve10s merged 2 commits into
mainfrom
refactor/split-python-go-server

Conversation

@Marve10s

@Marve10s Marve10s commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

The Python app entry template was one 1,667-line main.py.hbs that held every web framework. Its FastAPI branch alone ran from line 39 to line 1128. This PR splits it into one file per framework under python-base/src/app/main/, the same layout as the Rust split in #471.

File Lines Conditionals
fastapi.py.hbs 1,110 54
django.py.hbs 185 26
flask.py.hbs 123 18
litestar.py.hbs 122 16
starlette.py.hbs 89 10
aiohttp.py.hbs 70 9
none.py.hbs 30 4
streamlit.py.hbs 27 3

None of the new files checks pythonWebFramework. To add a framework, you add one file.

The Python handler picks main/<framework>.py.hbs (falling back to none.py.hbs), writes it to src/app/main.py and skips the other files.

How the files were made

A script fixed pythonWebFramework to each value and removed every branch that value decides. Conditions that mixed the framework with another field keep only the other field's part. For example, (and (eq pythonWebFramework "litestar") (or ...auth...)) becomes the auth check in litestar.py.hbs and disappears from the other files. No code was edited by hand.

Verification

  • main.py renders the same, byte for byte, from the old template and the new files across 3,136 configurations. That covers all 8 frameworks, each with every value of every Python field set one at a time, plus 300 random combinations. A one-character change to flask.py.hbs made all 392 Flask configurations fail, so the check does catch differences.
  • Each framework generates exactly one src/app/main.py and no main/ directory.
  • Template generator: lint and typecheck pass, and all 287 tests pass.
  • CLI suite: 4,811 pass, 4 skip, 0 fail.

The Go main.go.hbs stays as it is. Split the same way, gin and echo would differ by only 72 of about 570 lines, and go-zero, kratos and httprouter would be identical files. That much duplicated code would be harder to maintain than the conditionals.

Summary by CodeRabbit

  • New Features
    • Python project templates now generate an entry point for the selected framework, including aiohttp, Django, Flask, Litestar, Starlette, and Streamlit, with a default option when no framework is selected.
    • Framework templates can include starter root and health endpoints, with optional authentication, GraphQL, metrics, logging, tracing, and error monitoring integrations.

RetriggerConfidence Score: 4/5

The split appears to preserve behavior, but the unused-import rule must be satisfied before merging.

Findings

  1. P2 Sentry imports go unused ▶

Reviews (2) · Last reviewed commit: "Merge branch 'main' into refactor/split-..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
better-fullstack-web Ready Ready Preview Oct 14, 2026 12:21pm UTC

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T11:52:07.855377Z 2b075e9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). labels Oct 14, 2026
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 076637b7-54ff-4def-874f-609852874f6e
📥 Commits

Reviewing files that changed from the base of the PR and between af71814 and 2b075e9.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8785c144-a91a-4aa6-86ed-86a8b2fbffda
📥 Commits

Reviewing files that changed from the base of the PR and between 1995b9c and af71814.

📒 Files selected for processing: 9
  • packages/template-generator/src/template-handlers/ecosystems/python-base.ts
  • packages/template-generator/templates/python-base/src/app/main/aiohttp.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/django.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/fastapi.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/flask.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/litestar.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/none.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/starlette.py.hbs
  • packages/template-generator/templates/python-base/src/app/main/streamlit.py.hbs
💤 Files with no reviewable changes: 1
  • packages/template-generator/templates/python-base/src/app/main/fastapi.py.hbs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Walkthrough

The Python template handler now selects an app-entry template based on the configured web framework. New templates define starter applications for Python frameworks and Streamlit. The FastAPI template no longer contains the Django branch.

Changes: Python application entry templates

Layer / File(s) Summary
Entry-template selection
packages/template-generator/src/template-handlers/ecosystems/python-base.ts
The handler selects the configured entry template, falls back to none when unset or unavailable, and writes the selected entry to src/app/main.py. It skips other app-entry templates and transforms other output paths.
Script and UI starter templates
packages/template-generator/templates/python-base/src/app/main/none.py.hbs, packages/template-generator/templates/python-base/src/app/main/streamlit.py.hbs
The none template adds a script entry point with optional logging and observability imports. The Streamlit template loads environment variables and displays starter content.
ASGI framework entry points
packages/template-generator/templates/python-base/src/app/main/aiohttp.py.hbs, packages/template-generator/templates/python-base/src/app/main/litestar.py.hbs, packages/template-generator/templates/python-base/src/app/main/starlette.py.hbs
The templates define framework-specific application setup, root and health routes, conditional metrics and integrations, and startup behavior.
Flask entry point
packages/template-generator/templates/python-base/src/app/main/flask.py.hbs
The template configures Flask, CORS, logging, and optional integrations. It adds root, health, metrics, and authentication routes, with environment-based startup.
Django entry point and FastAPI cleanup
packages/template-generator/templates/python-base/src/app/main/django.py.hbs, packages/template-generator/templates/python-base/src/app/main/fastapi.py.hbs
The Django template adds routes and conditional API, authentication, GraphQL, metrics, and server integrations. The FastAPI template removes the Django branch and adjusts shared imports.

Priority: ➖ Normal

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to af718

This change reorganizes Python app-entry templates by web framework without intended output changes. The reported equivalence checks and tests pass, and no concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (7 skipped: 7 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: splitting the Python app entry template into framework-specific files.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (7 skipped: 7 unsupported.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@Marve10s
Marve10s enabled auto-merge October 14, 2026 11:47
@Marve10s
Marve10s merged commit fc778f7 into main Oct 14, 2026
13 of 14 checks passed
{{/if}}

{{#if (eq observability "sentry")}}
from app.observability import init_sentry

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Sentry imports go unused

The new Flask template imports init_sentry when Sentry is selected, but never uses it. The repository requires: “Emit helpers, imports, and variables only when the selected branch uses them.” Django and Litestar have the same unused import, and the pattern appears in the other non-FastAPI templates too.

Remove the unused imports or wire them into the intended startup code. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch was successfully deployed

1 active deployment
Preview — 2b075e96 Deployed Oct 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant