diff --git a/.github/workflows/render-template.yml b/.github/workflows/render-template.yml new file mode 100644 index 0000000..d776603 --- /dev/null +++ b/.github/workflows/render-template.yml @@ -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 diff --git a/copier.yml b/copier.yml new file mode 100644 index 0000000..d6c12fe --- /dev/null +++ b/copier.yml @@ -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/ diff --git a/postmodern/__main__.py b/postmodern/__main__.py deleted file mode 100644 index 655c511..0000000 --- a/postmodern/__main__.py +++ /dev/null @@ -1,3 +0,0 @@ -from postmodern.hello import main - -main() diff --git a/postmodern/hello.py b/postmodern/hello.py deleted file mode 100644 index fd96006..0000000 --- a/postmodern/hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def main() -> None: - print("Hello from postmodern!") diff --git a/pyproject.toml b/pyproject.toml.jinja similarity index 90% rename from pyproject.toml rename to pyproject.toml.jinja index 37526d4..b348966 100644 --- a/pyproject.toml +++ b/pyproject.toml.jinja @@ -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", ] @@ -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 diff --git a/test_import.py b/test_import.py deleted file mode 100644 index 7d66837..0000000 --- a/test_import.py +++ /dev/null @@ -1,5 +0,0 @@ -from postmodern.hello import main - - -def test_hello(): - main() diff --git a/test_import.py.jinja b/test_import.py.jinja new file mode 100644 index 0000000..f2cc955 --- /dev/null +++ b/test_import.py.jinja @@ -0,0 +1,5 @@ +from {{module_name}}.hello import main + + +def test_hello(): + main() diff --git a/.dockerignore b/{{ '.dockerignore' if include_dockerfile }}.jinja similarity index 100% rename from .dockerignore rename to {{ '.dockerignore' if include_dockerfile }}.jinja diff --git a/Dockerfile b/{{ 'Dockerfile' if include_dockerfile }}.jinja similarity index 74% rename from Dockerfile rename to {{ 'Dockerfile' if include_dockerfile }}.jinja index a2c0617..dee1fd2 100644 --- a/Dockerfile +++ b/{{ 'Dockerfile' if include_dockerfile }}.jinja @@ -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 @@ -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 @@ -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"] diff --git a/rename.sh b/{{ 'rename.sh' if project_name == 'postmodern-python' }}.jinja similarity index 100% rename from rename.sh rename to {{ 'rename.sh' if project_name == 'postmodern-python' }}.jinja diff --git a/{{ _copier_conf.answers_file }}.jinja b/{{ _copier_conf.answers_file }}.jinja new file mode 100644 index 0000000..69141bb --- /dev/null +++ b/{{ _copier_conf.answers_file }}.jinja @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +{{ _copier_answers|to_nice_yaml -}} diff --git a/postmodern/__init__.py b/{{ module_name }}/__init__.py similarity index 100% rename from postmodern/__init__.py rename to {{ module_name }}/__init__.py diff --git a/{{ module_name }}/__main__.py.jinja b/{{ module_name }}/__main__.py.jinja new file mode 100644 index 0000000..12443e6 --- /dev/null +++ b/{{ module_name }}/__main__.py.jinja @@ -0,0 +1,3 @@ +from {{module_name}}.hello import main + +main() diff --git a/postmodern/adder.py b/{{ module_name }}/adder.py similarity index 100% rename from postmodern/adder.py rename to {{ module_name }}/adder.py diff --git a/postmodern/cli.py b/{{ module_name }}/cli.py similarity index 100% rename from postmodern/cli.py rename to {{ module_name }}/cli.py diff --git a/{{ module_name }}/hello.py.jinja b/{{ module_name }}/hello.py.jinja new file mode 100644 index 0000000..f62cf02 --- /dev/null +++ b/{{ module_name }}/hello.py.jinja @@ -0,0 +1,2 @@ +def main() -> None: + print("Hello from {{module_name}}!") diff --git a/postmodern/server.py b/{{ module_name }}/server.py similarity index 100% rename from postmodern/server.py rename to {{ module_name }}/server.py