add skill: scaffold/build-py-project (uv + Docker + justfile)

This commit is contained in:
Łukasz Boryń 2026-06-08 23:00:15 +02:00
parent 1ea175df53
commit 66907fc37f
6 changed files with 257 additions and 0 deletions

View File

@ -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/<package_name>
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"
WORKDIR /usr/<package_name>
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 <package_name>; print('<package_name> 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"]

View File

@ -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:
```
<project>/
├── src/<package>/__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
- `<project-name>` — kebab-case project name.
- `<package_name>` — snake_case Python package name.
- `<author-name>`, `<author-email>` — for `pyproject.toml`.
- `<description>` — one-line project description.
- `<license>` — 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`.

View File

@ -0,0 +1,18 @@
services:
dev:
build:
context: .
dockerfile: Dockerfile
target: development
container_name: <project-name>-dev
volumes:
- .:/usr/<package_name>
production:
build:
context: .
dockerfile: Dockerfile
target: production
container_name: <project-name>-prod
volumes:
- .:/usr/<package_name>

View File

@ -0,0 +1,9 @@
__pycache__/
*.py[cod]
.venv/
dist/
.coverage
htmlcov/
.mypy_cache/
.ruff_cache/
*.egg-info/

View File

@ -0,0 +1,55 @@
# <project-name> — 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

View File

@ -0,0 +1,60 @@
[project]
name = "<project-name>"
version = "0.1.0"
description = "<description>"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "<license>" }
authors = [{ name = "<author-name>", email = "<author-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/<package_name>"]
[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 = ["<package_name>"]
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
addopts = ["-ra", "--strict-markers", "-q", "--cov=<package_name>", "--cov-report=term-missing"]
markers = [
"slow: marks tests as slow",
"integration: marks tests as integration tests",
]
[tool.coverage.run]
source = ["<package_name>"]
branch = true
omit = ["tests/*"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise NotImplementedError",
"if TYPE_CHECKING:",
]