Skip to content

feat: convert template to copier so projects can pull template updates - #32

Open
NKeleher wants to merge 4 commits into
update-templatefrom
copier-template
Open

NKeleher wants to merge 4 commits into
update-templatefrom
copier-template

Conversation

@NKeleher

@NKeleher NKeleher commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Pull Request Summary 🚀

Stacked on #15. Retarget to main after #15 merges.

What does this PR do? 📝

Converts the template to copier, so projects created from it can pull later template updates with one command: just update-template.

  • copier.yml asks five questions: project name, slug, package name, description, and Python version. The questions include help text and validators, and the suggested defaults work if users just press Enter.
  • template/ holds every file a new project gets. Only the files that need an answer use .jinja: pyproject.toml, README.md, the docs titles, .python-version, the test import, and the src/{{ package_name }}/ folder name. The Justfile and workflows stay plain so their own {{ }} syntax is untouched.
  • just update-template (Windows and Mac/Linux) checks that the user's work is committed, runs copier update, lists the changed files, and says what to do next in plain language.
  • .gitattributes (eol=lf) fixes a Windows problem. Git for Windows' default core.autocrlf=true turned every changed file into a single whole-file conflict on update. With .gitattributes, conflicts cover only the lines that actually changed.
  • [tool.uv.build-backend] module-name fixes a crash. uv_build looks for the package under the project name, so builds broke whenever a user picked a package name that differed from the slug.
  • No uv.lock is shipped. Each project creates its own lock file on the first just get-started.
  • Root README is a step-by-step guide for IPA staff who are new to git and copier. It covers one-time setup, creating a project, getting updates, resolving conflicts in VS Code (with an undo escape hatch), linking projects made from the old GitHub template, a glossary, and a maintainer section.
  • Root CI (template-ci.yml) renders the template, checks that no Jinja leaked into the output, runs the generated project's pre-commit hooks and tests, then runs copier update and checks that it leaves no changes. The root has its own zizmor and check-yaml hooks, and Dependabot (with a 7-day cooldown) watches actions in / and /template.

Why is this change needed? 🤔

Asana: Evaluate a template update mechanism (cookiecutter or similar) for all templates.

Projects created with GitHub's "Use this template" button get a one-time copy. Fixes like the zizmor hardening and the security bumps in #15 never reach them.

Option Can existing projects pull updates? Notes
GitHub "Use this template" No One-time copy
cookiecutter No Creates projects only
cruft (on cookiecutter) Yes Applies template diffs as patches with weaker conflict handling; needs {{cookiecutter.x}}/ folders
copier Yes, built in 3-way merge with inline conflicts; records answers; works for any language; runs with uvx, no install

Recommendation for the Stata, R and PPI templates: use the same pattern: copier with _subdirectory: template, a few questions, .gitattributes with eol=lf, a just update-template recipe, and CI that renders the template and tests the result. copier runs through uvx, so Stata and R users need no Python project of their own.

How was this implemented? 🛠️

git mv keeps the file history. I followed the docs literally on Windows, in fresh temp folders, for each path:

  • create → git init → just venv → first commit: all hooks pass on the first try
  • just update-template with unsaved work: refuses, with a friendly message
  • update with a template change: the change is applied, .copier-answers.yml is bumped
  • update where the template and the user changed the same line: an inline conflict scoped to that line (before updating = yours = VS Code "Current"; after updating = template = "Incoming")
  • linking an old GitHub-template project (CRLF line endings) with copier copy --overwrite, then renormalizing: tests pass, and a later just update-template works
  • package_name=my-pkg: rejected by the validator
  • the CI steps, replayed locally: no Jinja leaks, hooks and tests pass, the update leaves a clean tree

How to test or reproduce ? 🧪

uvx copier copy --defaults --vcs-ref copier-template -d project_name="Test Project" gh:PovertyAction/ipa-python-template test-project
cd test-project
git init && just venv && git add -A && git commit -m init
just check-all
just update-template

Please also try the root README as if you were new to it. The goal is that someone unfamiliar with git can follow it.

After merge (manual steps)

  • Tag v1.0.0 on main. copier update follows tags; until then users see "No git tags found; using HEAD".
  • Turn off the GitHub "Template repository" flag (gh repo edit --template=false). The button would copy unrendered .jinja files.
  • Post the recommendation on the Asana task.

Checklist ✅

  • I have run and tested my changes locally
  • I have limited this PR to less than 1000 lines of code change (if not, explain why)
  • I have updated/added tests to cover my changes (if applicable): template CI renders and tests the output
  • I have updated/added requirements to cover my changes (if applicable)
  • I have run linting and formatting on any code changes (if applicable)
  • I have updated the documentation (README, etc.) accordingly

Reviewer Emoji Legend

:code: Meaning
😃👍💯 :smiley: :+1: :100: I like this...

...and I want the author to know it! This is a way to highlight positive parts of a code review.
⭐⭐⭐ :star: :star: :star: Important to fix before PR can be approved...

And I am providing reasons why it needs to be addressed as well as suggested improvements.
⭐⭐ :star: :star: Important to fix but non-blocking for PR approval...

And I am providing suggestions where it could be improved either in this PR or later.
⭐ :star: Give this some thought but non-blocking for PR approval...

...and consider this a suggestion, not a requirement.
❓ :question: I have a question.

This should be a fully formed question with sufficient information and context that requires a response.
📝 :memo: This is an explanatory note, fun fact, or relevant commentary that does not require any action.
⛏ :pick: This is a nitpick.

This does not require any changes and is often better left unsaid. This may include stylistic, formatting, or organization suggestions and should likely be prevented/enforced by linting if they really matter
♻️ :recycle: Suggestion for refactoring.

Should include enough context to be actionable and not be considered a nitpick.

NKeleher and others added 2 commits December 2, 2026 17:06
Move project files into template/ (copier _subdirectory), template the
project name, package name, description, and Python version, and record
answers in .copier-answers.yml. Add a just update-template recipe that
wraps copier update with plain-language guidance. Stop shipping uv.lock;
generated projects create their own on first just get-started.

Co-Authored-By: Claude <noreply@anthropic.com>
Add a root README that walks IPA staff through creating a project with
copier, pulling template updates, resolving conflicts, and linking
projects made from the old GitHub template. Add template CI that renders
the template and runs the generated project's checks and an update.
Ship .gitattributes (eol=lf) so updates on Windows do not turn every
line into a conflict.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI 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.

🟡 Changes recommended

Accepted inputs can generate invalid YAML, TOML, distribution names, or Python imports, while CI’s fixed Python 3.12 breaks projects requiring Python 3.13.

4 open issues
What changed in this PR

Converts the Python project template to Copier so generated projects can receive future template updates, building on the tooling introduced in #15.

Changes:

  • Adds project questions, parameterized files, and saved Copier answers.
  • Adds update commands and guides for creation, migration, and conflict resolution.
  • Adds render-and-update CI, LF normalization, and template-aware dependency maintenance.
File Description
template/​tests/​test_example.py.jinja Parameterizes the test import.
template/​src/​{{ package_name }}/​example.py Supplies example package code.
template/​src/​{{ package_name }}/​__init__.py Initializes the generated package.
template/​README.md.jinja Documents generated-project workflows.
template/​pyproject.toml.jinja Parameterizes metadata and build configuration.
template/​panache.toml Preserves Markdown formatting configuration.
template/​LICENSE Includes the project license.
template/​Justfile Adds cross-platform template updates.
template/​docs/​index.qmd.jinja Parameterizes the documentation title.
template/​docs/​.gitignore Excludes Quarto artifacts.
template/​docs/​_quarto.yml.jinja Parameterizes the site title.
template/​{{ _copier_conf.answers_file }}.jinja Records answers for future updates.
template/​.vscode/​extensions.json Includes editor recommendations.
template/​.python-version.jinja Records the selected Python version.
template/​.pre-commit-config.yaml Preserves generated-project quality checks.
template/​.gitignore Includes Python project ignore rules.
template/​.github/​workflows/​ci.yml Supplies generated-project CI.
template/​.github/​pull_request_template.md Includes contribution guidance.
template/​.github/​dependabot.yml Configures generated-project dependency updates.
template/​.github/​CODEOWNERS Includes an ownership placeholder.
template/​.github/​CODE_OF_CONDUCT Includes community guidelines.
template/​.gitattributes Normalizes generated files to LF.
README.md Explains creation, updates, migration, and maintenance.
copier.yml Defines questions, defaults, and validators.
.python-version Removes the root Python pin.
.pre-commit-config.yaml Limits root hooks to template-repository checks.
.gitignore Simplifies root ignore rules.
.github/​workflows/​template-ci.yml Checks rendering, generated projects, and updates.
.github/​dependabot.yml Tracks root and template Actions dependencies.
.gitattributes Normalizes repository files to LF.

Review effort: Balanced

Comment thread copier.yml Resolved
Comment thread copier.yml Resolved
Comment thread template/docs/index.qmd.jinja Resolved
Comment thread template/pyproject.toml.jinja Resolved
@NKeleher
NKeleher added this pull request to stack #33 December 3, 2026 03:59
- CI: render from an absolute template path. copier stores the source
  path in .copier-answers.yml, so '.' made copier update look inside the
  generated project (Unknown revision error). Same fix in maintainer docs.
- CI: test both Python version choices (3.12, 3.13).
- Generated ci.yml: take the Python version from .python-version instead
  of hard-coding 3.12, so 3.13 projects can sync.
- project_slug: must end with a letter or number (valid distribution
  name); default now strips punctuation from the project name.
- package_name: reject Python keywords such as class.
- Serialize project_name and description with to_json so quotes and
  backslashes produce valid YAML and TOML.

Co-Authored-By: Claude <noreply@anthropic.com>
@NKeleher

NKeleher commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the Copilot review in 3c4d91b (replies inline). Also fixed the point from the review summary: the generated project's ci.yml no longer hard-codes Python 3.12. setup-uv/uv now read .python-version, and template CI runs the full render → checks → update cycle for both 3.12 and 3.13.

CI failure (Unknown revision in the update step): CI rendered with copier copy ... . "$RUNNER_TEMP/out". copier records the source path in .copier-answers.yml, so _src_path: . made copier update look for the template inside the generated project. CI now passes "$GITHUB_WORKSPACE", and the maintainer docs use "$PWD" with a note explaining why. Template CI is now green on 3.12 and 3.13.

Copilot AI 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.

🔵 Needs a closer look

The template still contains an actionable contact placeholder and several inaccurate setup/documentation instructions that could mislead or block users of generated projects.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Low severity Clarify that uv.lock is generated during setup

template/​README.md.jinja:15

This layout promises that uv.lock is part of every generated project, but this template intentionally ships no lockfile and uv sync creates it during just get-started. New users will look for a file that does not exist until setup runs; label it as generated by just get-started (or otherwise explain that it is not shipped).

Low severity Mac/Linux setup does not install Quarto

template/​README.md.jinja:39

The Mac/Linux install command does not install Quarto, although the following text says this setup installs it and the project exposes preview-docs/build-docs recipes. A fresh Mac/Linux project therefore cannot use its documented documentation commands; add the appropriate Quarto installation commands or remove that claim.

Low severity Document the correct Bash activation path

template/​README.md.jinja:84

On macOS/Linux, Bash uses .venv/bin/activate, but this table documents the Windows Scripts path. Following these instructions on a Unix machine will fail even after just get-started; use the Unix path for Bash and document the Windows Git Bash case separately if needed.

4 resolved since last review

Review effort: Lite

- Note that uv.lock is created by `just get-started`, not shipped
- Add Quarto install steps for Mac and Linux
- Split venv activation commands by OS (bin vs Scripts)
@NKeleher

NKeleher commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the 3 previously missed issues from the follow-up review in 8b4e1dd (template/README.md.jinja):

  • uv.lock: the layout comment now says it is created by just get-started (and should be committed), since the template ships no lockfile.
  • Quarto on Mac/Linux: split the install table. Mac adds brew install --cask quarto; Linux links to the Quarto installer page (Homebrew casks are macOS-only).
  • venv activation: the table now has Mac/Linux (.venv/bin/...) and Windows (.venv/Scripts/...) columns for Bash, PowerShell, and Nushell.

Checked by rendering a project with copier and running the project's panache format / panache lint on the generated README (no issues).

Not changed yet: template/.github/CODE_OF_CONDUCT still has [INSERT CONTACT METHOD], pending a decision on the reporting contact.

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.

2 participants