From 66907fc37ff12620c39a5000e7e6239126cdba5e Mon Sep 17 00:00:00 2001 From: lukabor Date: Mon, 8 Jun 2026 23:00:15 +0200 Subject: [PATCH] add skill: scaffold/build-py-project (uv + Docker + justfile) --- .../scaffold/build-py-project/Dockerfile.tpl | 50 ++++++++++++++ skills/scaffold/build-py-project/SKILL.md | 65 +++++++++++++++++++ .../build-py-project/docker-compose.yml.tpl | 18 +++++ .../scaffold/build-py-project/gitignore.tpl | 9 +++ skills/scaffold/build-py-project/justfile.tpl | 55 ++++++++++++++++ .../build-py-project/pyproject.toml.tpl | 60 +++++++++++++++++ 6 files changed, 257 insertions(+) create mode 100644 skills/scaffold/build-py-project/Dockerfile.tpl create mode 100644 skills/scaffold/build-py-project/SKILL.md create mode 100644 skills/scaffold/build-py-project/docker-compose.yml.tpl create mode 100644 skills/scaffold/build-py-project/gitignore.tpl create mode 100644 skills/scaffold/build-py-project/justfile.tpl create mode 100644 skills/scaffold/build-py-project/pyproject.toml.tpl diff --git a/skills/scaffold/build-py-project/Dockerfile.tpl b/skills/scaffold/build-py-project/Dockerfile.tpl new file mode 100644 index 0000000..60bf7dc --- /dev/null +++ b/skills/scaffold/build-py-project/Dockerfile.tpl @@ -0,0 +1,50 @@ +FROM python:3.11-slim AS base + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + git \ + curl \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /usr/ + +RUN curl -LsSf https://astral.sh/uv/install.sh | sh +ENV PATH="/root/.local/bin:$PATH" + +WORKDIR /usr/ + +ENV UV_LINK_MODE=copy \ + UV_COMPILE_BYTECODE=1 \ + UV_PYTHON_DOWNLOADS=never \ + UV_PROJECT_ENVIRONMENT=/opt/venv + +# ── production ────────────────────────────────────────────────────────── +FROM base AS production + +COPY pyproject.toml uv.lock* ./ +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-dev --no-install-project 2>/dev/null \ + || uv sync --no-dev --no-install-project + +COPY . . +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --no-dev 2>/dev/null || uv sync --no-dev + +ENV PATH="/opt/venv/bin:$PATH" +CMD ["python", "-c", "import ; print(' ready')"] + +# ── development ──────────────────────────────────────────────────────── +FROM base AS development + +COPY pyproject.toml uv.lock* ./ +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --group dev --no-install-project 2>/dev/null \ + || uv sync --group dev --no-install-project + +COPY . . +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --frozen --group dev 2>/dev/null || uv sync --group dev + +ENV PATH="/opt/venv/bin:$PATH" \ + PYTHONDONTWRITEBYTECODE=1 +CMD ["bash"] diff --git a/skills/scaffold/build-py-project/SKILL.md b/skills/scaffold/build-py-project/SKILL.md new file mode 100644 index 0000000..b2f5031 --- /dev/null +++ b/skills/scaffold/build-py-project/SKILL.md @@ -0,0 +1,65 @@ +--- +name: build-py-project +description: Scaffold a new Python project with uv for dependency management, a three-stage Docker setup (base/production/development), docker-compose, justfile task runner, and pyproject.toml configured with ruff, ty, and pytest. Materialises files into a target directory and stops on `jj diff` for review before any commit. Use when the user says "new python project", "scaffold python", "create python project", "set up python repo", "bootstrap python", "/build-py-project". +--- + +# build-py-project + +## When to use +- User says "new python project", "scaffold python", "/build-py-project". +- A fresh empty directory needs the standard uv + Docker + justfile setup. + +## Inputs to collect (one grouped prompt) +- **Project name** (kebab-case, e.g. `my-project`). +- **Package name** (derived: lowercase, hyphens → underscores; confirm). +- **Author name + email** for `pyproject.toml`. +- **One-line description** for `pyproject.toml`. +- **License** (default: MIT). + +## Process + +1. **Confirm target directory.** Refuse to write into a non-empty + directory unless the user explicitly opts in. +2. **Materialise files** from sibling templates with placeholder + substitution. Files written: + ``` + / + ├── src//__init__.py + ├── tests/fixtures/.gitkeep + ├── Dockerfile ← Dockerfile.tpl + ├── docker-compose.yml ← docker-compose.yml.tpl + ├── justfile ← justfile.tpl + ├── pyproject.toml ← pyproject.toml.tpl + └── .gitignore ← gitignore.tpl + ``` +3. **Stop. Do not run `jj describe`.** Tell the user: + > "Review with `jj diff` (or `git status` + `git diff`). Then run + > `just build-dev` to verify the toolchain. Describe the change with + > [`/jj-atomic`](../../productivity/jj-atomic/SKILL.md) when satisfied." +4. **Suggest** running [`/write-readme-py`](../../engineering/write-readme-py/SKILL.md) + after the first successful build to generate the README. + +## Placeholders used by templates +- `` — kebab-case project name. +- `` — snake_case Python package name. +- ``, `` — for `pyproject.toml`. +- `` — one-line project description. +- `` — SPDX identifier (default `MIT`). + +## Guardrails +- **Never** scaffold into a non-empty directory without explicit user + confirmation. +- **Never** invoke `jj describe` — the first commit is the user's call. +- **Never** invent dependency versions beyond the conservative pins in + `pyproject.toml.tpl`. +- **Never** add packages outside the templates without asking — keep + the scaffold lean and let the user grow it. + +## See also +- [`../../../concepts/three-stage-dockerfile.md`](../../_concepts/three-stage-dockerfile.md) + — rationale for the base/production/development pattern in `Dockerfile.tpl`. +- [`../../engineering/dev-python/SKILL.md`](../../engineering/dev-python/SKILL.md) + — workflow that this scaffold sets up. +- [`../../engineering/write-readme-py/SKILL.md`](../../engineering/write-readme-py/SKILL.md) + — README generator that reads the scaffolded `pyproject.toml` and + `justfile`. diff --git a/skills/scaffold/build-py-project/docker-compose.yml.tpl b/skills/scaffold/build-py-project/docker-compose.yml.tpl new file mode 100644 index 0000000..50bb88d --- /dev/null +++ b/skills/scaffold/build-py-project/docker-compose.yml.tpl @@ -0,0 +1,18 @@ +services: + dev: + build: + context: . + dockerfile: Dockerfile + target: development + container_name: -dev + volumes: + - .:/usr/ + + production: + build: + context: . + dockerfile: Dockerfile + target: production + container_name: -prod + volumes: + - .:/usr/ diff --git a/skills/scaffold/build-py-project/gitignore.tpl b/skills/scaffold/build-py-project/gitignore.tpl new file mode 100644 index 0000000..0959b98 --- /dev/null +++ b/skills/scaffold/build-py-project/gitignore.tpl @@ -0,0 +1,9 @@ +__pycache__/ +*.py[cod] +.venv/ +dist/ +.coverage +htmlcov/ +.mypy_cache/ +.ruff_cache/ +*.egg-info/ diff --git a/skills/scaffold/build-py-project/justfile.tpl b/skills/scaffold/build-py-project/justfile.tpl new file mode 100644 index 0000000..cb850f8 --- /dev/null +++ b/skills/scaffold/build-py-project/justfile.tpl @@ -0,0 +1,55 @@ +# — task runner +# `just --list` for all recipes. + +set dotenv-load := false + +default: + @just --list + +# ── Docker ────────────────────────────────────────────────────────────── +build-dev: + docker compose build dev + +build-prod: + docker compose build production + +up: + docker compose run --rm dev bash + +up-prod: + docker compose run --rm production + +down: + docker compose down + +rebuild: + docker compose build --no-cache dev + +# ── Linting & Formatting ──────────────────────────────────────────────── +lint: + docker compose run --rm --no-deps dev ruff check src/ tests/ + +lint-fix: + docker compose run --rm --no-deps dev ruff check --fix src/ tests/ + +fmt-check: + docker compose run --rm --no-deps dev ruff format --check src/ tests/ + +fmt: + docker compose run --rm --no-deps dev ruff format src/ tests/ + +# ── Type Checking ─────────────────────────────────────────────────────── +typecheck: + docker compose run --rm --no-deps dev ty check src/ + +# ── Testing ───────────────────────────────────────────────────────────── +test: + docker compose run --rm dev pytest + +test-verbose: + docker compose run --rm dev pytest -v + +# ── Combined ──────────────────────────────────────────────────────────── +check: lint fmt-check typecheck test + +fix-and-check: lint-fix fmt typecheck test diff --git a/skills/scaffold/build-py-project/pyproject.toml.tpl b/skills/scaffold/build-py-project/pyproject.toml.tpl new file mode 100644 index 0000000..bde25fb --- /dev/null +++ b/skills/scaffold/build-py-project/pyproject.toml.tpl @@ -0,0 +1,60 @@ +[project] +name = "" +version = "0.1.0" +description = "" +readme = "README.md" +requires-python = ">=3.11" +license = { text = "" } +authors = [{ name = "", email = "" }] + +dependencies = [] + +[dependency-groups] +dev = [ + "ruff>=0.9", + "ty>=0.0.1", + "pytest>=8.0", + "pytest-cov>=5.0", +] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["src/"] + +[tool.ruff] +src = ["src"] +line-length = 90 +target-version = "py311" +exclude = [".git", "__pycache__", "dist", ".venv"] + +[tool.ruff.lint] +select = ["E", "W", "F", "I", "N", "UP", "B", "SIM", "PTH"] +ignore = ["E501"] + +[tool.ruff.lint.isort] +known-first-party = [""] + +[tool.pytest.ini_options] +testpaths = ["tests"] +python_files = ["test_*.py"] +addopts = ["-ra", "--strict-markers", "-q", "--cov=", "--cov-report=term-missing"] +markers = [ + "slow: marks tests as slow", + "integration: marks tests as integration tests", +] + +[tool.coverage.run] +source = [""] +branch = true +omit = ["tests/*"] + +[tool.coverage.report] +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "raise NotImplementedError", + "if TYPE_CHECKING:", +]