Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/render-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Render Copier Template

on:
push:
branches:
- template

jobs:
render:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
path: main

- name: Checkout template branch
uses: actions/checkout@v4
with:
ref: template
path: template

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install uv
run: pip install uv
working-directory: ${{ github.workspace }}/template

# comment
- name: Render template
run: |
cd ${{ github.workspace }}/template
uvx copier copy \
--overwrite \
--defaults \
-d description="Add your description here" \
-d include_dockerfile=true \
-d module_name=postmodern \
-d project_name=postmodern-python \
-d python_version=3.13 \
-d user_email=you@example.com \
-d user_name="Your Name" \
. ../main/

- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Commit and Push Changes
run: |
cd ${{ github.workspace }}/main
rm -f .copier-answers.yml
git add .
if ! git diff --cached --exit-code; then
git commit -m "Auto-render main template: ${{ github.event.head_commit.message }}"
git push origin main
else
echo "No changes to commit."
fi
60 changes: 60 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---

project_name:
type: str
help: Give your project an amazing name

module_name:
type: str
help: Give the module a name
default: "{{ project_name }}"

description:
type: str
help: Make a short description for the project (optional).
default: ""

user_name:
type: str
help: Set your full name

user_email:
type: str
help: Set your email

python_version:
type: str
help: What python version do you want to use? (optional)
default: 3.13
validators:
- >-
{{
(
value.isdigit() # X format
or (
value.replace('.', '').isdigit() and
value.count('.') == 1 and
(value.split('.') | length) == 2 and
value.split('.')[0].isdigit() and
value.split('.')[1].isdigit()
) # X.Y format
or (
value.replace('.', '').isdigit() and
value.count('.') == 2 and
(value.split('.') | length) == 3 and
value.split('.')[0].isdigit() and
value.split('.')[1].isdigit() and
value.split('.')[2].isdigit()
) # X.Y.Z format
)
or 'Version must be in X, X.Y, or X.Y.Z format (e.g., 3, 3.13, or 3.13.4) with numbers only, no <, >, =, or other characters.'
}}
include_dockerfile:
type: bool
help: "Include a Dockerfile in the project?"
default: yes

_src_path: project_template
_exlude:
- .venv/
- .git/
3 changes: 0 additions & 3 deletions postmodern/__main__.py

This file was deleted.

2 changes: 0 additions & 2 deletions postmodern/hello.py

This file was deleted.

10 changes: 5 additions & 5 deletions pyproject.toml → pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ all = [ {ref="fmt"}, {ref="lint"}, {ref="check"}, {ref="test"} ]
"ci:lint" = "ruff check"

[project]
name = "postmodern"
name = "{{module_name}}"
version = "0.1.0"
description = "Add your description here"
description = "{{description}}"
readme = "README.md"
authors = [
{ name = "Your Name", email = "you@example.com" }
{ name = "{{ user_name | title }}", email = "{{ user_email }}" }
]

# Public libraries should be more lenient
# Internal stuff should enforce ~=3.13!
requires-python = ">=3.11"
requires-python = ">={{python_version}}"
dependencies = [
"pydantic>=2.10.4",
]
Expand Down Expand Up @@ -69,7 +69,7 @@ select = [

[tool.ruff.lint.isort]
# so it knows to group first-party stuff last
known-first-party = ["postmodern"]
known-first-party = ["{{ module_name }}"]

[tool.pyright]
venvPath = "." # uv installs the venv in the current dir
Expand Down
5 changes: 0 additions & 5 deletions test_import.py

This file was deleted.

5 changes: 5 additions & 0 deletions test_import.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from {{module_name}}.hello import main


def test_hello():
main()
File renamed without changes.
6 changes: 3 additions & 3 deletions Dockerfile → ...ockerfile' if include_dockerfile }}.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --- Base Stage: Install Dependencies ---
FROM python:3.13.1-slim-bookworm AS base
FROM python:{{python_version}}-slim-bookworm AS base

ENV PYTHONUNBUFFERED=True
WORKDIR /app
Expand All @@ -14,7 +14,7 @@ COPY pyproject.toml uv.lock ./
RUN uv sync --frozen

# --- Final Stage: Build Application Image ---
FROM python:3.13.1-slim-bookworm AS runner
FROM python:{{python_version}}-slim-bookworm AS runner

WORKDIR /app

Expand All @@ -25,4 +25,4 @@ COPY --from=base /app/.venv ./.venv
COPY . /app

# Set the entrypoint
CMD ["/app/.venv/bin/python", "/app/postmodern/server.py"]
CMD ["/app/.venv/bin/python", "/app/{{module_name}}/server.py"]
File renamed without changes.
2 changes: 2 additions & 0 deletions {{ _copier_conf.answers_file }}.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
{{ _copier_answers|to_nice_yaml -}}
File renamed without changes.
3 changes: 3 additions & 0 deletions {{ module_name }}/__main__.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from {{module_name}}.hello import main

main()
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions {{ module_name }}/hello.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main() -> None:
print("Hello from {{module_name}}!")
File renamed without changes.
Loading