From 104b6724031a1390ffa53519d5677c61f02a527e Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 18:31:09 +0100 Subject: [PATCH 1/3] fix(template): run check.sh tools through the uv venv with python -m check.sh ran `uv run pre-commit`, which resolves through PATH and accepts a global binary. Run pre-commit and pytest with `python -m` so only the project venv counts, guard on pre-commit missing from dev dependencies, and document a first-adoption checklist. Co-Authored-By: Claude Sonnet 5.5 --- docs/development.md | 2 +- docs/migration-guide.md | 10 ++++++++++ scripts/tests/agent-template.sh | 3 +++ template/scripts/check.sh.jinja | 5 +++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/development.md b/docs/development.md index 323a7de..e655328 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. 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`. +**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`. A repo adopting the template for the first time follows the [first-adoption checklist](migration-guide.md#first-adoption-checklist). ## Portable agent guidance diff --git a/docs/migration-guide.md b/docs/migration-guide.md index 0eb1696..03bee18 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -44,6 +44,16 @@ Commit **`.copier-answers.yml`**: it records the adopted release (`_commit`) and A repo that already has its own `scripts/check.sh` gets a Copier conflict on the first update: reconcile it with the template version. +### First-adoption checklist + +For a repo without `.copier-answers.yml`, `scripts/check.sh` only passes once the repo satisfies this contract: + +- `pre-commit`, `ruff`, `mypy` and `pytest` are in `[dependency-groups] dev`. `check.sh` runs them with `python -m` inside the uv environment, so a globally installed binary never satisfies it, and it stops with a hint when `pre-commit` is missing. +- `pyproject.toml` has `[tool.ruff] extend = "baselines/ruff.toml"` without its own `line-length` or `select`, and a `[tool.mypy]` section copied from [`template/pyproject.toml.jinja`](../template/pyproject.toml.jinja). +- The ruff and mypy versions in `.pre-commit-config.yaml` match the ones in `uv.lock`. +- `reusable_lint: false` when CI already runs `bash scripts/check.sh`, so the template does not add a second lint job. +- `test_workflow: false` when tests run in another workflow. Do not rerun pytest in a separate job without a reason, because `check.sh` already runs it. + ## 2. Install and validate ```bash diff --git a/scripts/tests/agent-template.sh b/scripts/tests/agent-template.sh index b1ea541..a85aa49 100644 --- a/scripts/tests/agent-template.sh +++ b/scripts/tests/agent-template.sh @@ -10,6 +10,9 @@ copier copy --defaults --data package_name=demo "$tmp/source" "$tmp/default" >/d [[ ! -e "$tmp/default/AGENTS.md" ]] [[ -x "$tmp/default/scripts/check.sh" ]] grep -qx 'uv sync --frozen' "$tmp/default/scripts/check.sh" +grep -qx "uv run --frozen python -m pre_commit run --all-files" "$tmp/default/scripts/check.sh" +grep -qx "uv run --frozen python -m pytest" "$tmp/default/scripts/check.sh" +grep -q "import pre_commit" "$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" diff --git a/template/scripts/check.sh.jinja b/template/scripts/check.sh.jinja index 9c23206..57007cb 100755 --- a/template/scripts/check.sh.jinja +++ b/template/scripts/check.sh.jinja @@ -5,5 +5,6 @@ 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 +uv run --frozen python -c 'import pre_commit' 2>/dev/null || { echo 'pre-commit is not a project dependency: add it to [dependency-groups] dev' >&2; exit 1; } +uv run --frozen python -m pre_commit run --all-files +uv run --frozen python -m pytest From c366bf329d99482ff9d0288a5b88de796db9e64a Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 18:32:05 +0100 Subject: [PATCH 2/3] fix(template): keep uv errors visible and use python -m in lint.yml Co-Authored-By: Claude Sonnet 5.5 --- .../workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja | 2 +- template/scripts/check.sh.jinja | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 7c8e188..a3a8e2a 100644 --- a/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja +++ b/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja @@ -14,4 +14,4 @@ jobs: 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 + pre-commit-command: uv run --frozen python -m pre_commit run --all-files diff --git a/template/scripts/check.sh.jinja b/template/scripts/check.sh.jinja index 57007cb..b31d253 100755 --- a/template/scripts/check.sh.jinja +++ b/template/scripts/check.sh.jinja @@ -5,6 +5,6 @@ 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 python -c 'import pre_commit' 2>/dev/null || { echo 'pre-commit is not a project dependency: add it to [dependency-groups] dev' >&2; exit 1; } +uv run --frozen python -c 'import pre_commit' || { echo 'check failed: if the error above is ModuleNotFoundError, add pre-commit to [dependency-groups] dev' >&2; exit 1; } uv run --frozen python -m pre_commit run --all-files uv run --frozen python -m pytest From 7b851b42a34e295bfff63b3ebec4e45aa77dcdcb Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 18:44:05 +0100 Subject: [PATCH 3/3] ci: retrigger pull_request workflows Co-Authored-By: Claude Sonnet 5.5