Skip to main content

oo-ratchet

Quality gates for Python code that fail when a change makes it worse.

License CI PyPI Python

oo-ratchet is a command line tool that runs five checks over a Python package. Most of them are ratchets: a ratchet compares the code with a baseline recorded earlier and fails if quality got worse. A baseline is a JSON file, committed to the repository, that holds the scores of each file. The tool is the shared copy of gates that vox, quarry, lux and z-spec each used to keep in their own tools/ directory.

Quick Start

The tool needs Python 3.13 or newer.

uv add --dev punt-oo-ratchet

Record today's scores for a package as the first baseline:

uv run oo-ratchet oo src/pkg/ --update

Commit .punt-labs/oo-ratchet/oo-baseline.json and merge it to main. The check compares your branch with the merge base of origin/main and HEAD, so it needs that baseline on origin/main and a fetched origin/main. Without them it exits 1 with cannot resolve merge-base. On a branch, check a change:

uv run oo-ratchet oo src/pkg/ --check
Other ways to install

With pip:

pip install punt-oo-ratchet

Without installing, with uvx:

uvx --from punt-oo-ratchet oo-ratchet --help
Verify the install
uv run oo-ratchet doctor

It checks Python, git, uv, Claude Code, whether the install is editable, this repository's configuration and the advisor key. It exits 1 on a required failure.

Features

  • OO metrics --- scores each file on encapsulation, parameter counts, complexity, module size and a few conventions, and fails when any score gets worse on a touched file or when no score improves anywhere in the change (a change that only adds files meeting the targets passes, and so does a change whose touched files already meet every target, since there is almost nothing left to improve)
  • Coupling and cohesion --- counts imports between modules, import cycles and how little the methods of a class share their fields, and fails on any regression
  • Suppression count --- counts noqa, type: ignore, pylint: disable and pyright: ignore comments and fails when the total rises
  • Layer rules --- checks that modules import only from their own layer or one nearer the core, with a baseline of known violations that can only shrink
  • Design check --- reports design smells such as classes that are only a bag of functions; opt in to fail on a small set of reliable rules
  • Audited exceptions --- loosening a baseline needs a named command and leaves a row in an audit log
  • Fails closed --- an unreadable baseline, a git error or an unresolvable base commit fails the run

What It Looks Like

A branch adds a class with an explicit __init__ and one noqa comment. The oo gate reports the regressions and exits 1. Rows for metrics that passed are left out here:

$ oo-ratchet oo src/shop/ --check --base-ref origin/main --require-base
File                                     Metric                       Baseline    Current    Delta     Status
------------------------------------------------------------------------------------------------------------
src/shop/application/checkout.py         encapsulation_ratio             1.000      0.000   -1.000  REGRESSED
src/shop/application/checkout.py         init_violations                 0.000      1.000   +1.000  REGRESSED
src/shop/application/checkout.py         public_attr_violations          0.000      1.000   +1.000  REGRESSED
FAIL: baseline out of date -- run make update-oo: src/shop/application/checkout.py
FAIL: regression detected
FAIL: no metric improved on any touched file

The suppressions gate fails on the same branch:

$ oo-ratchet suppressions src/shop/ --check --base-ref origin/main --require-base
Baseline total: 0
Current total:  1

FAIL: suppression count increased by 1 (after waivers)

Files with new or increased, unwaived suppressions:
  src/shop/application/checkout.py: +1 unwaived (0 -> 1)

Commands

Run oo-ratchet <gate> <package-dir> [flags]. The package directory is the folder that holds __init__.py.

Gate What it does Main flags
oo Must-improve: no metric regresses on a touched file and at least one improves, unless every touched file already meets all eight targets --check, --update, --relax FILE --justify, --rebaseline-files --reason, --rebaseline --reason, --json
coupling Regression-only: import counts, cycles and cohesion must not get worse --check, --update, --rebaseline-files --reason, --rebaseline --reason, --json
suppressions Regression-only: the total of lint and type-ignore comments must not rise --check, --update, --rebaseline --reason, --relax FILE --justify
layers A baseline of imports that break the layer rules; it may only shrink --check, --update, --suggest, --json, --allow-config-change
design Advisory report of design smells; exits 1 only with --enforce --base-ref REF, --enforce, --layers FILE, --json
goal How far the package is from the target in [tool.oo-ratchet.goal], and how it moved over a session show [--base-ref REF], summary --since SHA, guide, --json

Flags that apply to most gates:

  • --check compares the code with the baseline and exits 1 on failure.
  • --update records the current scores and never loosens them.
  • --base-ref REF --require-base compares against a git commit and fails if it cannot be found. In a pull request, pass the merge-base commit.
  • --tripwire is for the run after a merge to main. The one adoption merge, which adds the first baseline, passes.
  • --namespace NAME scans several directories as one package.

A gate runs in enforce mode unless its table says otherwise. With mode = "advise" in [tool.oo-ratchet.oo], coupling, suppressions or layers, --check exits 0 on a measured failure and still exits 1 when it could not decide (an unresolvable base, a corrupt baseline). The mode on the base commit binds, so a change cannot turn its own gate off. Any other value exits 2.

Goal: Summary and Guide

oo-ratchet goal summary SRC --since SHA reports how the code moved since the commit SHA. It checks out SHA, and each later commit on the path from SHA to HEAD (first parents only), in a throwaway directory, and measures every target declared in [tool.oo-ratchet.goal] there. It prints the gap count of each check, by level, after each commit; the cause each commit worked, when the counts show one; any trade (a commit that cleared a cause and added other gaps); and the net change from SHA to the last commit. It writes no file and leaves your work tree and the repository's refs unchanged. --json prints one JSON object instead.

Exit Meaning
0 The table was printed
1 An enforce-mode target is not met at the last commit
2 SHA does not resolve or is not on the first-parent path to HEAD, HEAD has no goal table, a source directory or pyproject.toml is missing at a commit, --since was not given, or a checkout failed; the message names the commit

Goal: the goalpost guard

oo-ratchet goal show SRC --base-ref REF compares the goal tables at the merge base of REF and HEAD with the work tree and prints WARNING: target changed since <sha>: allow rose: suppressions 0 -> 3 when an allow rose, a target was removed, enforce became advise, a design target stopped counting a rule, or trade-cap rose. --json adds target_changed. It is a warning: exit codes do not change, and an unresolvable REF exits 2. Details: Goal Guard.

Goal: the advisor

oo-ratchet goal propose SRC asks a language model what to do next. It sees every finding, even those within an allowance, and chooses the next step or few steps, large structure first, then plans them with the source open; not a full plan, with a guessed (never checked) score impact. --cause ID plans one cause. It writes no file; it sends source only with OPENAI_API_KEY set. Goal Advisor.

Claude Code plugin

Install the CLI and the plugin with curl -fsSL https://raw.githubusercontent.com/punt-labs/python-oo-ratchet/82e8401/install.sh | sh. The plugin adds eight slash commands, from /oo-ratchet:setup to the /oo-ratchet:improve loop (oo-ratchet goal guide prints its instructions); see the plugin guide.

A ring is a named layer of the package: entry, adapters, application or domain. design --base-ref REF scans the code at the merge base and again at the working tree, then reports which findings were added or removed. oo-ratchet <gate> --help lists every flag.

Setup

/oo-ratchet:setup does a repository's first run. By hand, follow Configuring a Repo: gates and their order, [tool.oo-ratchet] settings, layer rules, Makefile targets, CI, files to commit.

Documentation

Configuring a Repo | Reference | Layers Gate | Design Check | Formal Model | Policy | Contributing | Changelog

License

MIT

Metadata

Release files for punt-oo-ratchet 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for punt-oo-ratchet 0.9.0
File Size Uploaded Provenance Actions
punt_oo_ratchet-0.9.0.tar.gz 265.4 kB With provenance Details for punt_oo_ratchet-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for punt-oo-ratchet 0.9.0
File Interpreter ABI Platform Actions
punt_oo_ratchet-0.9.0-py3-none-any.whl Python 3 none any Details for punt_oo_ratchet-0.9.0-py3-none-any.whl

Total release size: 641.1 kB

Release files / punt_oo_ratchet-0.9.0.tar.gz

Download URL punt_oo_ratchet-0.9.0.tar.gz
Size 265.4 kB
Tags Source
SHA-256 checksum
How to use checksums
736c6083da17dd76c6a35c9d1d542e6a033d017bc00771824223ebf5e3d81985
BLAKE2b-256 checksum
How to use checksums
0fb6a2f196a4f4b91f3d1ffdbf5059c3854c4d87075ab16cabe80e8432026354
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / punt_oo_ratchet-0.9.0-py3-none-any.whl

Download URL punt_oo_ratchet-0.9.0-py3-none-any.whl
Size 375.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f9f7426eefe81ab4952f9b1f425b800f18bc21ee7ef2cf74a3f0946a684b6eb
BLAKE2b-256 checksum
How to use checksums
1dedc49c2636b8fc51852ba74bb54da9298a47afa247e2743cf5d939e726a708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for punt-oo-ratchet 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for punt_oo_ratchet-0.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page