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
2 changes: 1 addition & 1 deletion .agents/generated-rules.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"copier-template": "d4711ceadf0cf1bb10d81a3a65b892b6bf0a0a20f40496fcb32407024152d15e",
"copier-template": "60f7fea420e20a336163bd3abe79207db5753e8875ac9b7b5cca420d134f1c53",
"documentation-toc": "52734c4c63f46babf96aeae1260407add66dbec2d997f90a25ef01b7e1479127",
"github-actions": "c7bc81aede69023b0715ce8c0712f8e147cf5c2b6d90acf6a47a912ba99a182f",
"markdown-documentation": "027f47636d9d510e6cbd5505f9339c1aeee6f41dd823c0b478d409dde1ae4538",
Expand Down
2 changes: 1 addition & 1 deletion .agents/rules/copier-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These files are **rendered into consumer repositories** by `copier copy` and mer

## `copier.yml`

- `_skip_if_exists` lists **bootstrap-only** files (`pyproject.toml`, agent guidance); everything else under `template/` is updated on `copier update`. `_skip_if_exists` only protects files that exist: a file a consumer deletes is re-created on update, so optional files use a question-gated filename (`agent_guidance`). A file removed from the template is deleted from consumers, local edits included.
- `_skip_if_exists` lists **bootstrap-only** files (`pyproject.toml`, agent guidance); everything else under `template/` is updated on `copier update`. `_skip_if_exists` only protects files that exist: a file a consumer deletes is re-created on update, so optional files use a question-gated filename (`agent_guidance`). The starter `src/` package and `tests/` are created by a `_tasks` entry gated on `_copier_operation == 'copy'`, never as template files, so `copier update` cannot add them to existing consumers; the task skips a repo that already has a Python package. A file removed from the template is deleted from consumers, local edits included.
- Renaming or removing a question is **breaking** for existing `.copier-answers.yml` files; document it in **`CHANGELOG.md`** and **`docs/migration-guide.md`**.

## `template/baselines/ruff.toml`
Expand Down
2 changes: 1 addition & 1 deletion .claude/rules/copier-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ These files are **rendered into consumer repositories** by `copier copy` and mer

## `copier.yml`

- `_skip_if_exists` lists **bootstrap-only** files (`pyproject.toml`, agent guidance); everything else under `template/` is updated on `copier update`. `_skip_if_exists` only protects files that exist: a file a consumer deletes is re-created on update, so optional files use a question-gated filename (`agent_guidance`). A file removed from the template is deleted from consumers, local edits included.
- `_skip_if_exists` lists **bootstrap-only** files (`pyproject.toml`, agent guidance); everything else under `template/` is updated on `copier update`. `_skip_if_exists` only protects files that exist: a file a consumer deletes is re-created on update, so optional files use a question-gated filename (`agent_guidance`). The starter `src/` package and `tests/` are created by a `_tasks` entry gated on `_copier_operation == 'copy'`, never as template files, so `copier update` cannot add them to existing consumers; the task skips a repo that already has a Python package. A file removed from the template is deleted from consumers, local edits included.
- Renaming or removing a question is **breaking** for existing `.copier-answers.yml` files; document it in **`CHANGELOG.md`** and **`docs/migration-guide.md`**.

## `template/baselines/ruff.toml`
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ This repository is an organization-wide standards and template bundle, not an in
- Pinning: workflow `uses:` lines and documented examples use release tags (`@vX.Y.Z`) or commit SHAs, never long-lived `@main`.
- Consumer guidance: changes to `template/` stay consistent with `docs/development.md`, `docs/reusable-workflows.md` and `README.md`.
- CI contract: `scripts/check.sh` targets and the job ids of the template `ci.yml` are public API; changing them is breaking and documented in `docs/migration-guide.md`.
- Validate: `copier copy --vcs-ref HEAD . "$TMPDIR/demo" --defaults --data package_name=demo && cd "$TMPDIR/demo" && git init -q && uv lock && git add -A && bash scripts/check.sh lint`.
- Validate: `copier copy --vcs-ref HEAD . "$TMPDIR/demo" --defaults --trust --data package_name=demo && cd "$TMPDIR/demo" && git init -q && uv lock && git add -A && bash scripts/check.sh lint`.
- Python policy follows `docs/string-enums.md` (`StrEnum`, not `(str, Enum)`), `template/baselines/ruff.toml` (`UP` selected) and strict mypy plus pytest-cov in `template/pyproject.toml.jinja`; tools and remote pre-commit `rev:` stay pinned.
- `README.md` and `docs/development.md` are the source of truth.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Portable agent guidance is an optional Copier bootstrap; see [development guidan

## Repository Layout

- `copier.yml` + `template/`: **[Copier](https://copier.readthedocs.io/)** template rendered into consumer repos — `.pre-commit-config.yaml`, `baselines/ruff.toml`, `scripts/check.sh`, `.github/workflows/ci.yml` (updated by `copier update`), plus a bootstrap-only `pyproject.toml`.
- `copier.yml` + `template/`: **[Copier](https://copier.readthedocs.io/)** template rendered into consumer repos — `.pre-commit-config.yaml`, `baselines/ruff.toml`, `scripts/check.sh`, `.github/workflows/ci.yml` (updated by `copier update`), plus a bootstrap-only `pyproject.toml`; `copier copy` (with `--trust`) also creates missing `src/<package>/` and `tests/` starters.
- `docs/`: **[development.md](docs/development.md)** (hub), migration guide, versioning, CI contract, and style notes (e.g. [`string-enums.md`](docs/string-enums.md)).
- `scripts/tests/`: repository checks, including the read-only sync between **`STANDARDS_VERSION`** and every pin carrying the Release Please version marker (see [docs/versioning.md](docs/versioning.md)).

Expand All @@ -63,7 +63,7 @@ Portable agent guidance is an optional Copier bootstrap; see [development guidan

```bash
uv tool install copier==9.18.2
copier copy gh:BehindTheMusicTree/python-project-standards /path/to/repo # new repo
copier copy --trust 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
```
Expand Down
23 changes: 23 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
_subdirectory: template
# Starter package and smoke test: created on `copier copy` only, and only in a repo with no
# Python package yet (an `--overwrite` adoption keeps its own layout). Template files would be
# added by `copier update`, which must not touch a consumer's layout.
_tasks:
- when: "{{ _copier_operation == 'copy' }}"
command: |
if find . \( -name .git -o -name .venv -o -name node_modules \) -prune -o -name __init__.py -not -path './tests/*' -print -quit | grep -q .; then exit 0; fi
mkdir -p "src/{{ package_module }}" tests
[ -e "src/{{ package_module }}/__init__.py" ] || printf '"""%s."""\n' '{{ package_name }}' > "src/{{ package_module }}/__init__.py"
[ -e "src/{{ package_module }}/py.typed" ] || : > "src/{{ package_module }}/py.typed"
[ -e tests/test_import.py ] || printf 'import {{ package_module }}\n\n\ndef test_package_is_importable() -> None:\n assert {{ package_module }}.__doc__\n' > tests/test_import.py

_skip_if_exists:
- pyproject.toml
- AGENTS.md
Expand All @@ -8,6 +20,17 @@ _skip_if_exists:
package_name:
type: str
help: Distribution name for pyproject.toml
validator: >-
{% if not package_name | regex_search('^[A-Za-z_][A-Za-z0-9._-]*$') %}
Must start with a letter or underscore and contain only letters, digits, ".", "-" and "_"
{% elif (package_name | lower | replace('-', '_') | replace('.', '_')) in ['false', 'none', 'true', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] %}
Must not be a Python keyword once lowercased
{% endif %}

package_module:
type: str
when: false
default: "{{ package_name | lower | replace('-', '_') | replace('.', '_') }}"

agent_guidance:
type: bool
Expand Down
4 changes: 2 additions & 2 deletions docs/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Use this guide to adopt the baseline in an existing repository.
Install Copier with an exact pin (for example `uv tool install copier==9.18.2`), then from the repository root:

```bash
copier copy --vcs-ref v6.0.0 gh:BehindTheMusicTree/python-project-standards . --overwrite # x-release-please-version
copier copy --trust --vcs-ref v6.0.0 gh:BehindTheMusicTree/python-project-standards . --overwrite # x-release-please-version
git add -p # keep repo-specific hooks and settings the template overwrote
```

Expand All @@ -34,7 +34,7 @@ Questions (`copier.yml`):
- **`agent_guidance`** — see [Optional agent guidance](#optional-agent-guidance).
- **`uv_sync_args`** — extra `uv sync` arguments for `scripts/check.sh` and `ci.yml` (for example `--extra processing`).

`pyproject.toml` is **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).
`pyproject.toml` is **bootstrap-only** (`_skip_if_exists`): rendered for new repos, never touched in existing ones. `copier copy` also runs a copy-only task (so it needs `--trust`; `copier update` never runs it) that creates a `src/<package>/` placeholder with `py.typed` and `tests/test_import.py` when the repo has no Python package yet (an `--overwrite` adoption of an existing project is left alone), so `check.sh` passes on a fresh render. The module name is `package_name` lowercased with hyphens and dots turned into `_`; `package_name` must start with a letter or underscore. `pyproject.toml` declares `[tool.setuptools.packages.find] where = ["src"]` so the package builds. 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).

Commit **`.copier-answers.yml`**: it records the adopted release (`_commit`) and answers so later updates know what to merge.

Expand Down
9 changes: 5 additions & 4 deletions scripts/tests/agent-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ trap 'rm -rf "$tmp"' EXIT
mkdir "$tmp/source"
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
copier copy --defaults --trust --data package_name=demo "$tmp/source" "$tmp/default" >/dev/null
[[ ! -e "$tmp/default/AGENTS.md" ]]
[[ -x "$tmp/default/scripts/check.sh" ]]
[[ -f "$tmp/default/src/demo/__init__.py" && -f "$tmp/default/tests/test_import.py" ]]
grep -qx 'uv sync --frozen' "$tmp/default/scripts/check.sh"
actionlint "$tmp/default/.github/workflows/ci.yml"
# A stub uv records the calls; it fails the pre-commit import only when asked to.
Expand Down Expand Up @@ -41,20 +42,20 @@ for args in other '' 'lint test'; do
done
# A global pre-commit binary must not stand in for the missing venv module.
if NO_PRE_COMMIT=1 check lint; then exit 1; fi
copier copy --defaults --data package_name=demo --data 'uv_sync_args=--extra processing' "$tmp/source" "$tmp/extra" >/dev/null
copier copy --defaults --trust --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/ci.yml"
[[ "$(grep -c 'uv-sync-args: "--extra processing"' "$tmp/extra/.github/workflows/ci.yml")" == 2 ]]
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
copier copy --defaults --trust --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"
actionlint "$tmp/enabled/.github/workflows/agent-drift.yml"
mkdir -p "$tmp/existing/.github/workflows"
printf 'existing agents\n' > "$tmp/existing/AGENTS.md"
printf 'existing claude\n' > "$tmp/existing/CLAUDE.md"
printf 'existing workflow\n' > "$tmp/existing/.github/workflows/agent-drift.yml"
copier copy --defaults --overwrite --data package_name=demo --data agent_guidance=true "$tmp/source" "$tmp/existing" >/dev/null
copier copy --defaults --trust --overwrite --data package_name=demo --data agent_guidance=true "$tmp/source" "$tmp/existing" >/dev/null
[[ "$(cat "$tmp/existing/AGENTS.md")" == 'existing agents' ]]
[[ "$(cat "$tmp/existing/CLAUDE.md")" == 'existing claude' ]]
[[ "$(cat "$tmp/existing/.github/workflows/agent-drift.yml")" == 'existing workflow' ]]
3 changes: 3 additions & 0 deletions template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ version = "0.1.0"
requires-python = ">=3.12"
dependencies = []

[tool.setuptools.packages.find]
where = ["src"]

[dependency-groups]
dev = [
"pre-commit==4.5.1",
Expand Down
Loading