Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
2 changes: 2 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 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

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.
8 changes: 5 additions & 3 deletions docs/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ 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.

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
pip install -e ".[dev]"
uv lock
bash scripts/check.sh
pre-commit install
pre-commit run --all-files
```

## 3. Add project-specific overrides
Expand Down
7 changes: 7 additions & 0 deletions scripts/tests/agent-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ 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" ]]
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" ]]
python3 "$1" "$tmp/enabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions template/scripts/check.sh.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/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; }
[ -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
2 changes: 1 addition & 1 deletion template/{% if agent_guidance %}AGENTS.md{% endif %}
Original file line number Diff line number Diff line change
@@ -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.
Loading