Skip to content

Add built-in render-engine init without cookiecutter - #1353

Merged
brass75 merged 32 commits into
render-engine:mainfrom
tystar86:issue-45-init-module
Nov 24, 2026
Merged

brass75 merged 32 commits into
render-engine:mainfrom
tystar86:issue-45-init-module

Conversation

@tystar86

Copy link
Copy Markdown
Contributor

Part of render-engine/render-engine-cli#45.

Moves render-engine init into render-engine, as a runnable render_engine.init
module with a built-in Jinja site template. Cookiecutter is no longer used.
render-engine-cli's init will just call it (separate PR, after this is released).

It works without render-engine-cli:

uvx --from render-engine render-engine-init
python -m render_engine.init

What's in it

  • render_engine/init/site_template/: the built-in site template (app file,
    pyproject.toml, README, home page, styles, favicon), styled after render-engine.org.
  • InitOptions: the answers, validated with clear errors (title, URL, project slug,
    app filename, output path, types).
  • create_site(): renders .jinja files and copies the rest. Leaves out the
    example collection or blog if the user doesn't want them. If anything fails,
    nothing is left behind.
  • main(argv, prog): asks the questions (argparse + rich, no click), or uses the
    defaults with --no-input. Supports -e/--extra-context and -o/--output-dir.
    render-engine-cli can call it with prog="render-engine init".
  • Fixes from the old cookiecutter template: the [tool.render-engine.cli] section,
    unused imports, module now follows the app filename, pageParser → Parser.
  • New question: "Use the Render Engine CLI?". If yes, render-engine-cli is added
    to the new site's pyproject.toml.
  • A small easter egg in the generated home page's source.

Breaking changes (compared to the current render-engine init)

  • --template is removed: custom templates are no longer supported (discussed with
    @brass75 on Discord). --help says so.
  • --config-file is removed (it was a cookiecutter config).
  • -e keys are renamed: SITE_TITLE → site_title, SITE_URL → site_url, and
    skip_collection / skip_blog → include_collection / include_blog (reversed).
    include_cli is new.

How to try it

uv run render-engine-init

The generated site imports MarkdownPageParser from render_engine.parsers, which
isn't released yet. Until it is, point the new site at your local checkout:

cd <new-site>
uv add --editable <path-to-render-engine>
uv run python app.py

Contributing guidelines

  • I have read and abided by all of the contributing guidelines for this project.
  • The issue this PR resolves has been assigned to me.

Type of Issue

  • 🐛 (bug)
  • 📖 (Documentation)
  • ⬆️ (Update)
  • 💫 (New Feature)
  • ☢️ (Deprecation)
  • 🚫 (Removal)
  • 🛠️ (Refactor)

Changes have been Documented (If Applicable)

  • YES - Changes have been documented

The docs will be updated in a separate PR (#1313 ). Every option is
described in --help, and the generated README explains the next steps.

Changes have been Tested

  • YES - Changes have been tested

tests/test_init/:

  • test_options.py: which answers are accepted or rejected
  • test_create_site.py: which files are created from which answers
  • test_command.py: the command (questions, flags, errors, exit codes)
  • test_build.py: generated sites really build, in a separate process

I also tested it by hand: creating, building and serving sites with different answers.

Next Steps

  • render-engine-cli: init calls render_engine.init.__main__.main, and the
    cookiecutter dependency is removed (after this is released).
  • Docs: [Bug]:Update Getting Started with Render Engine documentation #1313 >
  • Separate issues: better examples in the built-in template, and the
    {{collection_title}} heading in archive.html.
  • Maybe a proper square favicon. The current one is the official logo from
    render-engine.org, which is hard to see at 16×16 and in dark browser themes.

AI Attestation

I wrote and tested the code manually. I used Claude Code to explain concepts, review the code and find
bugs, try out changes before I applied them, and draft commit messages and this
description.

🤖 Generated with Claude Code

tystar86 and others added 21 commits November 19, 2026 07:29
Start moving `render-engine init` from render-engine-cli into the
engine (render-engine-cli#45).

- Add `render_engine/init/__main__.py` with the `init` options ported
  from the CLI to argparse (no new dependencies)
- Runnable via `python -m render_engine.init` and the new
  `render-engine-init` console script

The site generation itself is still to be done; it will render built-in
Jinja2 templates instead of using cookiecutter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port the starter site from cookiecutter-render-engine-site (MIT, same
organization) into `render_engine/init/site_template/` so it can be
rendered without cookiecutter (render-engine-cli#45).

- Copy the static assets, base/page/archive templates and example
  content unchanged
- Add `app.py.jinja`, rendered with the init answers:
  - only import `Collection`, `Blog` and `MarkdownPageParser` when used
  - use `Parser` instead of the ignored `pageParser`, so blog posts are
    actually parsed as Markdown
  - import `Blog` as `BaseBlog` instead of shadowing it
  - quote values with `tojson` so titles containing quotes stay valid
  - inline the former `site_vars.html` include

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The generated pyproject.toml is now a real project definition and
fixes the CLI config from the cookiecutter template
(render-engine-cli#45).

- Add a `[project]` section with name, version, description,
  requires-python and dependencies
- Depend on `render-engine-markdown` only when a blog is included and
  on `render-engine-cli` only when the user opts in to the CLI
- Use `[tool.render-engine.cli]`, which is where the CLI reads its
  config, instead of `[render-engine.cli]`; it is always written so the
  CLI works if it is installed later
- Derive `module` from the chosen app filename instead of hard-coding
  "app"

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `templates/index.html.jinja`, the home page of a newly generated
site, as requested in render-engine-cli#45.

- Congratulate the user and explain which files to edit next,
  naming the app file they chose during init
- Link to the example page and blog only when they were included
- Inline the former `check_for_collections.html` include
- Wrap only the build-time Jinja (`extends`, `SITE_TITLE`, `block`)
  in `{% raw %}` so it survives the init render
- Link to the Render Engine documentation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `README.md.jinja`, the README of a newly generated site
(render-engine-cli#45).

- Explain how to install the dependencies with uv or pip
- Show building and previewing both with the Render Engine CLI and
  with plain Python, so users can see what the CLI adds and how to
  install it later
- Use the app filename and output path chosen during init
- Add `--include-date` to the `new-entry` example, which blog posts
  need for sorting
- Bind the plain-Python preview server to 127.0.0.1
- Describe the generated `pyproject.toml` and project layout
- Fix typos from the cookiecutter README and drop the section about
  the example GitHub workflows, which are not part of the template

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Redesign the generated site to match the look of render-engine.org (render-engine-cli#45).

- `_base.html`: black header with the site title, navigation and
  logo on every page, and a matching black footer with the site URL
- `index.html.jinja`: content only, with a congratulations heading,
  numbered next steps, cards for the example content (shown only
  when included) and a link to the documentation
- `style.css`: header and footer bars, divider lines, code styling
  and render-engine.org-style cards; responsive logo and card grid

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Push the footer down, so it stays at the bottom of the window on pages with little content (e.g. the blog archive).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hold the answers used to render the built-in site template in one
place and validate them on creation (render-engine-cli#45), so every
entry point (prompts, --no-input, --extra-context, direct use) is
checked the same way.

- Strip the site title and require it to be non-empty
- Require the site URL to use http(s) and have a host
- Derive the project slug from the title unless given, and slugify
  given slugs too; reject titles/slugs that produce an empty name
- Require the app filename to be a valid, non-dunder Python module
  name in the project root that doesn't shadow an existing module
- Require the output path to be a relative folder inside the
  project, and not `content`, `templates` or `static`, which
  `--clean` would delete
- Add tests for all validation rules, including site titles in
  non-Latin scripts

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `create_site`, the start of the rendering step of
`render-engine init` (render-engine-cli#45):

- Create the project folder, named after the project slug, inside
  the given destination (creating missing parent folders), and
  refuse to continue if it already exists so existing work is never
  overwritten
- Copy every file from the template folder except `.jinja` files,
  keeping the folder structure; skip hidden files and anything inside
  hidden folders (e.g. `.DS_Store`, `.git/`)
- Accept a `template_dir`, defaulting to the built-in site template,
  so a custom template can be used later
- Make `project_slug` a plain `str` defaulting to "" so its type is
  always a string after validation
- Rename the `-o/--output-dir` destination to `destination` in code
  and clarify its help text, to avoid confusion with the site's
  output path
- Add tests for creating the folder, copying the built-in template
  (all files, essential files, no `.jinja` files) and copying a
  custom template without hidden files

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`create_site` now renders `.jinja` files with the init answers instead
of skipping them, and writes them without the `.jinja` suffix. Other
files are still copied as they are.

- Use a single Jinja environment.
- Pass the answers to the templates.
- Name the top-level `app.py.jinja` after the chosen app filename.
- Read and write templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When the user answers "no" to the blog or the collection, `create_site`
no longer copies `content/blog/` or `content/pages/`. Previously the
example files were always copied, even though the generated `app.py`
didn't use them.

The templates (`page.html`, `archive.html`) are still copied, so a blog
or collection can be added later.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Generate a site for every blog/collection combination and build it by
running its app file, the way a user would. Check that the home page
has the site title, the CSS is copied, and the blog post and example
page are built only when they were asked for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`InitOptions` and `create_site` accepted several kinds of bad input
silently, which led to broken or surprising sites, or to lost files.
They now raise an error that explains what's wrong:

- Answers of the wrong type raise a `TypeError`. Most importantly, a
  string like "no" for a yes/no question was accepted and counted as
  yes. This matters for answers passed on the command line, which
  arrive as text.
- The output path can't be a site folder in any letter case (on macOS
  and Windows, "Content" is the same folder as "content") or a hidden
  folder like `.git` or `.venv`. Cleaning the output would delete them.
- A template folder that doesn't exist raises `FileNotFoundError`
  before anything is created, instead of creating an empty project.
  The template folder can also be given as a string.
- Site URLs with spaces or an invalid port are rejected, and spaces
  around the URL are removed.
- Site titles with control characters (line breaks, tabs) are rejected,
  since they break the generated files. Emoji and other Unicode text
  are still allowed.

`create_site` is also more robust:

- The template files are listed before the project folder is created.
  Previously, creating a site inside its own template folder (e.g.
  `--template .`) copied the project into itself until the path got
  too long.
- A half-built project folder is now also removed when the user
  presses Ctrl-C, not only after an error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix several problems with `create_site` and `InitOptions`, mostly
around custom templates:

- Copy dot-files like `.gitignore`, `.github/` and `.python-version`
  from templates, as cookiecutter did. Only names that never belong in
  a new project are skipped: version control folders, OS junk files,
  caches, virtual environments and `.env`.
- Reject templates with two files that create the same file, such as
  `README.md` and `README.md.jinja`, or a plain file with the chosen
  app filename next to `app.py.jinja`. Previously one silently
  overwrote the other, depending on file order.
- When creating a site fails, also remove the parent folders that were
  created for it, while keeping a destination that already existed.
- Reject the Unicode line and paragraph separators (U+2028, U+2029) in
  site titles, like other line breaks.
- Check answer types based on the dataclass fields, so a new answer is
  checked automatically. A test makes sure every answer has a text or
  True/False default.
- Add a timeout to the build test, so a generated app that hangs fails
  the test instead of blocking the test run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`python -m render_engine.init` (or `render-engine-init`) now creates a
new site:

- Ask the old init's questions plus "Use the Render Engine CLI?", and
  ask again after an invalid answer or an existing folder.
- Support `--no-input`, `--extra-context` (JSON answers) and
  `--template` (a local folder), checking them before any question.
- Show errors as one line on stderr instead of a traceback.
- Drop `--config-file`, which configured cookiecutter.

`create_site` now names the broken file when a template can't be
rendered. Rename `test_render.py` to `test_create_site.py`, add module
docstrings to the init tests, and add tests for the command.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Custom templates are no longer supported, so init always uses the
built-in template. The help says so, and -t/--template is rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Example blocks in app.py now bring their own blank lines, so there are
always exactly two between top-level blocks. The header and footer no
longer move between pages with and without a scrollbar.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MarkdownPageParser is now part of render-engine (render_engine.parsers),
so generated blog sites no longer need render-engine-markdown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Check the app filename against a fixed list of module names instead of find_spec(), which depended on the folder init was run from
- Escape the site title and URL in the generated HTML
- Reject output paths that are project files (app file, pyproject.toml, README.md) or contain spaces
- Leave out archive.html when the blog is left out
- Follow the CLI answer in the README's pip instructions
- Don't let a cleanup error hide the original error
- Link the docs at the top of the README
- Add the Render Engine logo as favicon

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An ASCII-art comment, only visible in the page source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Covers invalid JSON, JSON that isn't an object, and invalid values, and checks that nothing is created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@brass75 brass75 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know this is a lot of comments but it's a big PR. A couple of general things here:

  1. Tests need doc strings too. Just to say what they test. Those do not need parameter descriptions.
  2. Regular functions and methods do need parameter and return value descriptions.
  3. Should be asking for the name of the Site variable - perhaps we don't currently but we should.

Comment thread src/render_engine/init/__init__.py Resolved
Comment thread src/render_engine/init/__init__.py Resolved
Comment thread src/render_engine/init/__main__.py Resolved
Comment thread src/render_engine/init/__main__.py Resolved
Comment thread src/render_engine/init/__main__.py Resolved
tystar86 and others added 3 commits November 20, 2026 08:21
Use reference links and notes in the README, one import statement in the app file, and a set intersection for the title check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Show how to set the project folder name in the slug error
- Add .py to the app filename if it's missing
- Accept any app filename the CLI can import
- Allow the output folder anywhere, as long as it has a folder name

Co-Authored-By: Claude Opus 5.5 <[email protected]>
New question (default 'app'), also settable with -e. It's used in the app file, in [tool.render-engine.cli] and in the README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tystar86 and others added 2 commits November 20, 2026 10:10
- The collection lives under /pages, and the nav links to its archive page
- Fix the empty heading on archive pages
- Make render-engine-cli a dev dependency of new sites

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ask_options() stores each answer itself, and asking for the project folder is its own function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>"
Tests say what they check; functions and methods describe their parameters, return values and errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tystar86
tystar86 requested a review from brass75 November 20, 2026 09:34

@brass75 brass75 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Answered some questions.

tystar86 and others added 2 commits November 24, 2026 08:06
Spaces in the output path are allowed again: the questions ask 'Are you sure?', and --no-input shows a warning. The README quotes the path. The project file check uses the whole path, and the content/templates/static rule is dropped. The README explains that uv sync creates .venv.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Output paths like .site are allowed now: we give sensible defaults and let the user decide. The long error message test compares the quoted path, so it passes on Windows, where repr() doubles the backslashes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tystar86
tystar86 requested a review from brass75 November 24, 2026 12:54
Comment thread tests/test_init/test_create_site.py Resolved
tystar86 and others added 2 commits November 24, 2026 16:34
Render Engine writes pages with the system's encoding, which on Windows often can't write emoji, so the page came out empty and the build tests failed. The encoding fix has its own issue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows raised FileNotFoundError and FileExistsError instead of NotADirectoryError when the destination was a file, so the test failed there. create_site now checks it first and raises the same error everywhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tystar86
tystar86 requested a review from brass75 November 24, 2026 15:44
@brass75
brass75 merged commit e9a2544 into render-engine:main Nov 24, 2026
18 of 19 checks passed
@tystar86
tystar86 deleted the issue-45-init-module branch November 25, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants