For a map of all org Python standards docs, start with development.md.
Use this guide to adopt the baseline in an existing repository.
- What the template manages
- 1. Adopt the template
- 2. Install and validate
- 3. Add project-specific overrides
- 4. Update to a new release
- 5. Migrating from v5 to v6 (single CI contract)
- 6. Migrating from v4 (copied templates) to v5 (Copier)
- Optional agent guidance
template/ and copier.yml form a Copier template: .pre-commit-config.yaml, baselines/ruff.toml, scripts/check.sh, .github/workflows/ci.yml and a starter pyproject.toml. copier update merges new releases into the repo while keeping local edits (3-way merge against the previously adopted release). CI runs through reusable workflows of github-workflows; see reusable-workflows.md.
Install Copier with an exact pin (for example uv tool install copier==9.18.2), then from the repository root:
copier copy --trust --vcs-ref v6.0.1 gh:BehindTheMusicTree/python-project-standards . --overwrite # x-release-please-version
git add -p # keep repo-specific hooks and settings the template overwroteQuestions (copier.yml):
package_name—[project] namein the starterpyproject.toml.agent_guidance— see Optional agent guidance.uv_sync_args— extrauv syncarguments forscripts/check.shandci.yml(for example--extra processing).
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 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.
A repo that already has its own scripts/check.sh or .github/workflows/ci.yml gets a Copier conflict on adoption: reconcile it with the template version.
For a repo without .copier-answers.yml, scripts/check.sh only passes once the repo satisfies this contract:
pre-commit,ruff,mypy,pytestandpytest-covare in[dependency-groups] dev.check.shruns them withpython -minside the uv environment, so a globally installed binary never satisfies it, and it stops with a hint whenpre-commitis missing.pyproject.tomlhas[tool.ruff] extend = "baselines/ruff.toml"without its ownline-lengthorselect, and the[tool.mypy],[tool.coverage.run],[tool.coverage.report]and[tool.pytest.ini_options]sections oftemplate/pyproject.toml.jinja, includingfiles, the coveragesource(a single root, see the comment there) and the coverageaddopts.- Existing lint and test workflows are removed, or reduced to jobs
ci.ymldoes not cover.
uv lock
bash scripts/check.sh
pre-commit install- Follow shared Python style notes in this repo’s
docs/where applicable (e.g. string enumerations (StrEnum)). - Ruff: keep
[tool.ruff] extend = "baselines/ruff.toml"inpyproject.tomland put onlyexclude,extend-exclude, and[tool.ruff.lint]per-file-ignores/extend-per-file-ignoreson top. Do not setlint.select,lint.ignore,line-length, or[tool.ruff.format]there—Ruff would override the shared baseline. Shared rule changes arrive throughcopier updateonbaselines/ruff.toml. - Mypy: keep the strict keys from the template
[tool.mypy]; add[[tool.mypy.overrides]]only when needed (for example tests). - Add local pre-commit hooks for custom checks only when needed;
copier updatekeeps them.
copier update # latest tag; or --vcs-ref vX.Y.Z
bash scripts/check.shResolve any conflicts like a git merge and commit the result together with the updated .copier-answers.yml.
v6 replaces lint.yml, test.yml and this repository's reusable-pre-commit.yml with one managed ci.yml; the reusable_lint and test_workflow questions are gone.
- Note what
.github/workflows/lint.ymlandtest.ymldo locally.copier updatedeletes both, including local edits, without a conflict. - Run
copier update, then port those local needs intoci.yml(see Repo-specific needs). Replaceservices:containers with testcontainers. - Delete any other workflow calling
reusable-pre-commit.ymlor duplicating the lint and test jobs. pyproject.tomlis not updated by Copier: add[tool.mypy] files = ["."](or your paths), the coverageaddopts(--cov --cov-branch --cov-report=xml:coverage.xml),[tool.coverage.run] sourceset to a single root holding your packages (src, or.withomit = [".venv/*", "tests/*"]plus any tooling directory; without it, files no test imports are not measured),[tool.coverage.report] include_namespace_packages = trueandpytest-covin the dev group. Do not list several roots:coverage.ymlmerges same-named files across them.- In
.pre-commit-config.yaml, keep the local ruff and mypy hooks; their versions now come fromuv.lock. - Check that
uv.lockis current, then runbash scripts/check.sh. Tests now run withpython -P, which keeps the repository root offsys.path: if imports fail withModuleNotFoundError, install the package (asrc/layout with[build-system]), or declare the needed directories in[tool.pytest.ini_options] pythonpath(the simpler fix for a flat layout). - Update the required status checks:
lint / checkreplaces the former lint context andTests successthe test contexts (see Required status checks).
Coverage now applies the organization standard of coverage.yml to the pull request.
v5 removes the copy-and-verify machinery. In each consumer:
- Run the adoption steps in §1.
- Delete
STANDARDS_VERSION(replaced by_commitin.copier-answers.yml),scripts/verify-standards.sh,scripts/check_lint_baseline.py,baselines/DIGESTSandbaselines/expected-mypy.json. - Remove the
verify-python-project-standardshook from.pre-commit-config.yaml. - Agent/editor rules are no longer distributed (
templates/cursor-rules/is gone); rules each repo already copied are now owned by that repo.
Set Copier answer agent_guidance to true to create project-owned starter guidance and a pinned drift-check workflow. Existing AGENTS.md, CLAUDE.md, and agent drift workflow files are preserved; reconcile their contents with the agent-config contract before enabling the check. The default is false for existing and new consumers.