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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ AI coding agents ship code fast — but fast doesn't mean safe. Every `eval()` a

## How it works

In a [benchmark on five large Python repositories](benchmarks/results/large-repo-study.md), 18 of 50 source-reviewed findings suggested a concrete change. The report shows where the checks helped, where they gave misleading advice, and how to reproduce the results.

PyCodeGate detects your project's context: framework (Django, FastAPI, Flask), Python version, package manager (uv, poetry, pip), and test framework. That context drives which rules are active — Django projects get SQL injection checks, FastAPI projects get async-correctness checks, and so on.

It then runs analysis passes **in parallel**: a lint pass across 9 categories (Security, Correctness, Complexity, Architecture, Performance, Structure, Imports, Dependencies, Dead Code), a dead-code pass powered by [Vulture](https://github.com/jendrikseipp/vulture) that finds unused functions, classes, imports, and variables, and an optional dependency-vulnerability pass via [pip-audit](https://github.com/pypa/pip-audit).
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Precision benchmark

[Large-repository usefulness study](results/large-repo-study.md) compares five tagged Git projects and reviews 50 findings against their source. It includes per-project counts, the individual review decisions and commands to reproduce the sample.

A quality gate is only useful if it stays quiet on good code. This benchmark runs
PyCodeGate against the source of widely used, idiomatic PyPI packages and reports
the findings per rule. A rule that fires heavily here is a false-positive suspect.
Expand Down
56 changes: 56 additions & 0 deletions benchmarks/check_large_repo_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Verify the source-reviewed sample against local scan output."""

from __future__ import annotations

import argparse
import hashlib
import json
from collections import Counter
from pathlib import Path

BENCHMARKS = Path(__file__).resolve().parent
PER_SEVERITY = 5
SEVERITIES = ("error", "warning")
VERDICTS = {"actionable", "context-dependent", "false-positive"}


def digest(diagnostic: dict) -> str:
canonical = json.dumps(diagnostic, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()


def select_sample(diagnostics: list[dict]) -> list[tuple[str, str]]:
selected = []
for severity in SEVERITIES:
hashes = sorted(digest(item) for item in diagnostics if item["severity"] == severity)
selected.extend((severity, value) for value in hashes[:PER_SEVERITY])
return selected


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("scans", type=Path, help="Directory containing the five local scan reports")
parser.add_argument(
"--review", type=Path, default=BENCHMARKS / "results" / "large-repo-review.json"
)
args = parser.parse_args()
pins = json.loads((BENCHMARKS / "large_repo_pins.json").read_text())
review = json.loads(args.review.read_text())
expected = Counter()
for name, pin in pins.items():
scan = json.loads((args.scans / f"{name}.json").read_text())
for severity, key in select_sample(scan["diagnostics"]):
expected[pin["repository"], severity, key] += 1
actual = Counter((row["repo"], row["severity"], row["sha256"]) for row in review)
if actual != expected:
raise SystemExit("The reviewed diagnostics differ from the deterministic sample")
if any(digest(row["diagnostic"]) != row["sha256"] for row in review):
raise SystemExit("A published diagnostic differs from the reviewed scan output")
classifications = Counter(row["classification"] for row in review)
if classifications.keys() - VERDICTS:
raise SystemExit("Unknown classification in the review")
print(json.dumps(classifications, indent=2, sort_keys=True))


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions benchmarks/large_repo_pins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"django": {"repository": "django/django", "tag": "6.1.3", "commit": "f16e25dcb9fe55734ba4ea2b00ac34405b7df74a"},
"pandas": {"repository": "pandas-dev/pandas", "tag": "v3.1.1", "commit": "3dcc6fbbbebc5e85dd3e83fe49b382ca7735cae1"},
"numpy": {"repository": "numpy/numpy", "tag": "v2.5.5", "commit": "afcbc6d21a88a7b59c5bfe115198e24ed51b3dae"},
"scikit-learn": {"repository": "scikit-learn/scikit-learn", "tag": "1.9.1", "commit": "866c0f51e7560ef0303cbcc5f159df5382ea9e3f"},
"transformers": {"repository": "huggingface/transformers", "tag": "v5.23.0", "commit": "52b080b6416a7897e2af90febeb4dfad22b84d19"}
}
Loading
Loading