From fb5f5251b3439d05a5a9050a40d5fe1e7dfaa07f Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:13:45 +0100 Subject: [PATCH 1/2] feat(template): add uv validation contract via scripts/check.sh Co-Authored-By: Claude Sonnet 5.5 --- copier.yml | 5 +++++ docs/development.md | 2 ++ docs/migration-guide.md | 6 +++--- scripts/tests/agent-template.sh | 5 +++++ .../{% if test_workflow %}test.yml{% endif %} | 17 +++++------------ template/pyproject.toml.jinja | 2 +- template/scripts/check.sh.jinja | 8 ++++++++ .../{% if agent_guidance %}AGENTS.md{% endif %} | 2 +- 8 files changed, 30 insertions(+), 17 deletions(-) create mode 100755 template/scripts/check.sh.jinja diff --git a/copier.yml b/copier.yml index b16f297..08e2a96 100644 --- a/copier.yml +++ b/copier.yml @@ -24,3 +24,8 @@ agent_guidance: type: bool default: false help: Add starter agent guidance and a pinned agent drift workflow (existing files are preserved) + +uv_sync_args: + type: str + default: "" + help: Extra arguments for `uv sync` in scripts/check.sh (for example `--extra processing`) diff --git a/docs/development.md b/docs/development.md index 836c036..647e5af 100644 --- a/docs/development.md +++ b/docs/development.md @@ -26,6 +26,8 @@ Further style rules may be added under `docs/` over time; this page will link th Baseline **pre-commit**, **`pyproject.toml`** tooling sections and **`baselines/ruff.toml`** ship as a **Copier template** ([`template/`](../template/), [`copier.yml`](../copier.yml)), described in the [README](../README.md) (**Repository layout**, **What Is Standardized**, **Quick Start**) and [migration-guide.md](migration-guide.md). +**Validation contract:** every repo validates with `bash scripts/check.sh` (managed by Copier, so `copier update` keeps it current). It needs uv, runs `uv sync --frozen` from `uv.lock` (failing instead of re-locking if the lock is missing or stale), then pre-commit and pytest, and CI runs the same script. Set the Copier `uv_sync_args` answer (for example `--extra processing`) for extras the checks need. Dev tools live in `[dependency-groups] dev`. + ## Portable agent guidance Projects may opt in to the Copier `agent_guidance` question to bootstrap `AGENTS.md`, its Claude import, and a drift-check workflow pinned to github-workflows `v4.8.0`. These are project-owned bootstrap files: existing files are preserved, and teams maintain them after creation. If existing instructions are present, reconcile them with the [agent-config project contract](https://github.com/BehindTheMusicTree/agent-config-public) before enabling the check. Shared Python style stays in these standards; architecture and operational commands stay in the consuming repository. diff --git a/docs/migration-guide.md b/docs/migration-guide.md index 989ebd3..1e542f2 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -38,16 +38,16 @@ Questions (`copier.yml`): - **`reusable_lint`** — `true` renders `.github/workflows/lint.yml` delegating to [reusable-pre-commit.yml](../.github/workflows/reusable-pre-commit.yml); `false` when the repo already runs pre-commit in its own workflow (e.g. Tier B services). - **`test_workflow`** — `true` renders a starter `.github/workflows/test.yml`; `false` when tests run in a differently named workflow (otherwise `copier update` re-creates the deleted file). -`pyproject.toml` and `.github/workflows/test.yml` are **bootstrap-only** (`_skip_if_exists`): rendered for new repos, never touched in existing ones. Merge relevant sections from [`template/pyproject.toml.jinja`](../template/pyproject.toml.jinja) by hand (metadata, dependencies, **`[tool.mypy]`**, pytest). Tests stay in the consumer repo; there is no org reusable test workflow (see [reusable-workflows.md](reusable-workflows.md)). +`pyproject.toml` and `.github/workflows/test.yml` are **bootstrap-only** (`_skip_if_exists`): rendered for new repos, never touched in existing ones. Move dev tools into `[dependency-groups] dev` (PEP 735) and merge relevant sections from [`template/pyproject.toml.jinja`](../template/pyproject.toml.jinja) by hand (metadata, dependencies, **`[tool.mypy]`**, pytest). Tests stay in the consumer repo; there is no org reusable test workflow (see [reusable-workflows.md](reusable-workflows.md)). Commit **`.copier-answers.yml`**: it records the adopted release (`_commit`) and answers so later updates know what to merge. ## 2. Install and validate ```bash -pip install -e ".[dev]" +uv lock +bash scripts/check.sh pre-commit install -pre-commit run --all-files ``` ## 3. Add project-specific overrides diff --git a/scripts/tests/agent-template.sh b/scripts/tests/agent-template.sh index 69ab6d6..0db89a7 100644 --- a/scripts/tests/agent-template.sh +++ b/scripts/tests/agent-template.sh @@ -8,6 +8,11 @@ cp "$root/copier.yml" "$tmp/source/" cp -R "$root/template" "$tmp/source/" copier copy --defaults --data package_name=demo "$tmp/source" "$tmp/default" >/dev/null [[ ! -e "$tmp/default/AGENTS.md" ]] +[[ -x "$tmp/default/scripts/check.sh" ]] +grep -qx 'uv sync --frozen' "$tmp/default/scripts/check.sh" +copier copy --defaults --data package_name=demo --data 'uv_sync_args=--extra processing' "$tmp/source" "$tmp/extra" >/dev/null +[[ -x "$tmp/extra/scripts/check.sh" ]] +grep -qx 'uv sync --frozen --extra processing' "$tmp/extra/scripts/check.sh" copier copy --defaults --data package_name=demo --data agent_guidance=true "$tmp/source" "$tmp/enabled" >/dev/null [[ -f "$tmp/enabled/AGENTS.md" && -f "$tmp/enabled/CLAUDE.md" ]] python3 "$1" "$tmp/enabled" diff --git a/template/.github/workflows/{% if test_workflow %}test.yml{% endif %} b/template/.github/workflows/{% if test_workflow %}test.yml{% endif %} index 3a459a3..fcee89c 100644 --- a/template/.github/workflows/{% if test_workflow %}test.yml{% endif %} +++ b/template/.github/workflows/{% if test_workflow %}test.yml{% endif %} @@ -1,4 +1,4 @@ -# Copy-paste starter. Extend with strategy.matrix, coverage, or service containers as needed. +# Copy-paste starter: runs the shared validation contract. Extend with strategy.matrix or service containers as needed. name: Test on: @@ -8,19 +8,12 @@ on: jobs: tests: - name: Pytest + name: Validate runs-on: ubuntu-latest steps: - uses: actions/checkout@v5.0.1 - - uses: actions/setup-python@v5 - with: - python-version: "3.12" + - uses: astral-sh/setup-uv@v6 - - name: Install dev dependencies - run: | - python -m pip install --upgrade pip - pip install -e ".[dev]" - - - name: Run tests - run: pytest -q + - name: Validate + run: bash scripts/check.sh diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 9ebd5b8..f92d294 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -8,7 +8,7 @@ version = "0.1.0" requires-python = ">=3.12" dependencies = [] -[project.optional-dependencies] +[dependency-groups] dev = [ "pre-commit==4.5.1", "ruff==0.15.9", diff --git a/template/scripts/check.sh.jinja b/template/scripts/check.sh.jinja new file mode 100755 index 0000000..0063872 --- /dev/null +++ b/template/scripts/check.sh.jinja @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Single validation entry point: CI runs this same script. +set -euo pipefail +cd "$(dirname "$0")/.." +command -v uv >/dev/null || { echo 'uv is required: https://docs.astral.sh/uv/' >&2; exit 1; } +uv sync --frozen{% if uv_sync_args %} {{ uv_sync_args }}{% endif %} +uv run --frozen pre-commit run --all-files +uv run --frozen pytest diff --git a/template/{% if agent_guidance %}AGENTS.md{% endif %} b/template/{% if agent_guidance %}AGENTS.md{% endif %} index f505a9d..a54e0db 100644 --- a/template/{% if agent_guidance %}AGENTS.md{% endif %} +++ b/template/{% if agent_guidance %}AGENTS.md{% endif %} @@ -1,3 +1,3 @@ # Project guidance -Consult `README.md`, the project's contribution guide, and `pyproject.toml` for setup and validation. Keep project-specific architecture and constraints in this file. Follow the shared Python standards documented at https://github.com/BehindTheMusicTree/python-project-standards. +Validate with `bash scripts/check.sh` (requires uv; installs dependencies from `uv.lock`). Consult `README.md` and the project's contribution guide for the rest. Keep project-specific architecture and constraints in this file. Follow the shared Python standards documented at https://github.com/BehindTheMusicTree/python-project-standards. From bb2de34aa22e9670ab53d1b50ea86b470e264ba7 Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 16:14:56 +0100 Subject: [PATCH 2/2] fix(template): align lint workflow and lock hint with uv contract Co-Authored-By: Claude Sonnet 5.5 --- README.md | 1 + docs/development.md | 2 +- docs/migration-guide.md | 2 ++ scripts/tests/agent-template.sh | 2 ++ .../{% if reusable_lint %}lint.yml{% endif %}.jinja | 6 ++++++ template/scripts/check.sh.jinja | 1 + 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e639a4b..32e6f30 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Portable agent guidance is an optional Copier bootstrap; see [development guidan uv tool install copier==9.18.2 copier copy gh:BehindTheMusicTree/python-project-standards /path/to/repo # new repo copier update # later, from the repo root +uv lock && bash scripts/check.sh # new repo: lock once, then validate ``` For an existing repository, see [docs/migration-guide.md](docs/migration-guide.md). Keep **`[tool.ruff] extend = "baselines/ruff.toml"`** in `pyproject.toml`; shared rule changes arrive through `copier update`. diff --git a/docs/development.md b/docs/development.md index 647e5af..323a7de 100644 --- a/docs/development.md +++ b/docs/development.md @@ -26,7 +26,7 @@ Further style rules may be added under `docs/` over time; this page will link th Baseline **pre-commit**, **`pyproject.toml`** tooling sections and **`baselines/ruff.toml`** ship as a **Copier template** ([`template/`](../template/), [`copier.yml`](../copier.yml)), described in the [README](../README.md) (**Repository layout**, **What Is Standardized**, **Quick Start**) and [migration-guide.md](migration-guide.md). -**Validation contract:** every repo validates with `bash scripts/check.sh` (managed by Copier, so `copier update` keeps it current). It needs uv, runs `uv sync --frozen` from `uv.lock` (failing instead of re-locking if the lock is missing or stale), then pre-commit and pytest, and CI runs the same script. Set the Copier `uv_sync_args` answer (for example `--extra processing`) for extras the checks need. Dev tools live in `[dependency-groups] dev`. +**Validation contract:** every repo validates with `bash scripts/check.sh` (managed by Copier, so `copier update` keeps it current). It needs uv, runs `uv sync --frozen` from `uv.lock` (failing instead of re-locking if the lock is missing or stale), then pre-commit and pytest, and CI runs the same script. Run `uv lock` and commit `uv.lock` once on a new repo; the script stops with that hint when it is missing. Set the Copier `uv_sync_args` answer (for example `--extra processing`) for extras the checks need; it is interpolated verbatim into the shell command, so keep it to simple, unquoted arguments. Dev tools live in `[dependency-groups] dev`. ## Portable agent guidance diff --git a/docs/migration-guide.md b/docs/migration-guide.md index 1e542f2..e2e7f0b 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -42,6 +42,8 @@ Questions (`copier.yml`): Commit **`.copier-answers.yml`**: it records the adopted release (`_commit`) and answers so later updates know what to merge. +A repo that already has its own `scripts/check.sh` gets a Copier conflict on the first update: reconcile it with the template version. + ## 2. Install and validate ```bash diff --git a/scripts/tests/agent-template.sh b/scripts/tests/agent-template.sh index 0db89a7..b1ea541 100644 --- a/scripts/tests/agent-template.sh +++ b/scripts/tests/agent-template.sh @@ -12,6 +12,8 @@ copier copy --defaults --data package_name=demo "$tmp/source" "$tmp/default" >/d grep -qx 'uv sync --frozen' "$tmp/default/scripts/check.sh" copier copy --defaults --data package_name=demo --data 'uv_sync_args=--extra processing' "$tmp/source" "$tmp/extra" >/dev/null [[ -x "$tmp/extra/scripts/check.sh" ]] +actionlint "$tmp/extra/.github/workflows/test.yml" "$tmp/extra/.github/workflows/lint.yml" +grep -q -- 'uv sync --frozen --extra processing' "$tmp/extra/.github/workflows/lint.yml" grep -qx 'uv sync --frozen --extra processing' "$tmp/extra/scripts/check.sh" copier copy --defaults --data package_name=demo --data agent_guidance=true "$tmp/source" "$tmp/enabled" >/dev/null [[ -f "$tmp/enabled/AGENTS.md" && -f "$tmp/enabled/CLAUDE.md" ]] diff --git a/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja b/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja index d980388..6baa95f 100644 --- a/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja +++ b/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja @@ -9,3 +9,9 @@ on: jobs: lint: uses: BehindTheMusicTree/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1{# x-release-please-version #} + with: + install-command: | + python -m pip install --upgrade pip uv + uv sync --frozen{% if uv_sync_args %} {{ uv_sync_args }}{% endif %} + + pre-commit-command: uv run --frozen pre-commit run --all-files diff --git a/template/scripts/check.sh.jinja b/template/scripts/check.sh.jinja index 0063872..9c23206 100755 --- a/template/scripts/check.sh.jinja +++ b/template/scripts/check.sh.jinja @@ -3,6 +3,7 @@ set -euo pipefail cd "$(dirname "$0")/.." command -v uv >/dev/null || { echo 'uv is required: https://docs.astral.sh/uv/' >&2; exit 1; } +[ -f uv.lock ] || { echo 'uv.lock is missing: run `uv lock` and commit it' >&2; exit 1; } uv sync --frozen{% if uv_sync_args %} {{ uv_sync_args }}{% endif %} uv run --frozen pre-commit run --all-files uv run --frozen pytest