headroomlabs-ai/headroom · error · ValueError

could not find a rev for {RUFF_PRE_COMMIT_REPO}

Error message

could not find a rev for {RUFF_PRE_COMMIT_REPO}

What it means

verify-ruff-version.py scans `.pre-commit-config.yaml` for the Ruff hook repo (`- repo: <RUFF_PRE_COMMIT_REPO>`) and reads the next `rev:` line before the following `- repo:` entry. The error means either the repo entry is missing entirely, or it exists with no `rev:` key — so the pre-commit Ruff version cannot be compared against pyproject.toml.

Source

Thrown at scripts/verify-ruff-version.py:63

    versions = [str(package["version"]) for package in packages if package["name"] == "ruff"]
    if len(versions) != 1:
        raise ValueError(f"expected one locked Ruff package, found {versions!r}")
    return versions[0]


def _pre_commit_version() -> str:
    lines = (ROOT / ".pre-commit-config.yaml").read_text(encoding="utf-8").splitlines()
    for index, line in enumerate(lines):
        if line.strip() != f"- repo: {RUFF_PRE_COMMIT_REPO}":
            continue
        for candidate in lines[index + 1 :]:
            stripped = candidate.strip()
            if stripped.startswith("- repo:"):
                break
            if stripped.startswith("rev:"):
                return stripped.removeprefix("rev:").strip().removeprefix("v")
        break
    raise ValueError(f"could not find a rev for {RUFF_PRE_COMMIT_REPO}")


def _workflow_errors() -> list[str]:
    workflow = (ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8")
    errors = []
    if WORKFLOW_VERSION_COMMAND not in workflow:
        errors.append(f"ci.yml does not run {WORKFLOW_VERSION_COMMAND!r}")
    if WORKFLOW_INSTALL_REFERENCE not in workflow:
        errors.append(f"ci.yml does not install Ruff from {WORKFLOW_INSTALL_REFERENCE!r}")
    return errors


def _parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--print-version",
        action="store_true",
        help="print the authoritative version after validating every execution path",

View on GitHub (pinned to 322425c43b)

Solutions

  1. Open `.pre-commit-config.yaml` and confirm the exact repo line matches RUFF_PRE_COMMIT_REPO (same URL, same `- repo: ` prefix).
  2. Add/restore `rev: v<X.Y.Z>` directly under that repo entry, matching the pinned Ruff version.
  3. Keep `rev:` between the `- repo:` line and the next `- repo:` line — the parser stops scanning at the next repo entry.

Example fix

# .pre-commit-config.yaml - before
repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    hooks:
      - id: ruff

# after
repos:
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.5.0
    hooks:
      - id: ruff
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

RUFF_REPO = "https://github.com/astral-sh/ruff-pre-commit"

def pre_commit_ruff_rev(config: Path) -> str | None:
    lines = config.read_text().splitlines()
    for i, line in enumerate(lines):
        if line.strip() == f"- repo: {RUFF_REPO}":
            for cand in lines[i + 1:]:
                s = cand.strip()
                if s.startswith("- repo:"):
                    break
                if s.startswith("rev:"):
                    return s.removeprefix("rev:").strip().removeprefix("v")
    return None
# assert pre_commit_ruff_rev(...) == pinned_version in CI

Prevention

When it happens

Trigger: Removing the Ruff pre-commit hook; renaming the repo URL so the exact `- repo: https://github.com/astral-sh/ruff-pre-commit` line no longer matches; adding the hook without a `rev:`; `rev:` appearing after a nested `- repo:` list item.

Common situations: Pre-commit config refactors that switch to a local hook wrapper or a mirror URL; pre-commit autoupdate rewriting the entry into a shape the parser skips; indentation changes making the `rev:` line not match the scan window.

Related errors


AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15). Data as JSON: /api/errors/fd1d61e1f6e4002e. Report an issue: GitHub.