| name | pr-loc-breakdown |
| description | Break down pure-Python lines-of-code changes per file for a PR (or two git refs), excluding non-.py files, blank lines, comments, and docstrings. Uses an AST/tokenize-based programmatic counter โ never hand-counted. Input format: "<PR_NUMBER>" (e.g. "277") or "<BASE_REF> <HEAD_REF>". |
PR Pure-Python LOC Breakdown
Produce an accurate per-file breakdown of pure Python code added/removed in a
PR. "Pure" means only executable Python: it excludes markdown/docs/other
non-.py files, blank lines, whole-line comments, inline comments, and
docstrings (module / class / function string-literal statements).
Why a script (not eyeballing the diff)
git diff --stat counts every changed line including blanks, comments, and
docstrings, so it overstates code churn. Counting by reading the diff by hand is
error-prone and not reproducible. This skill ships count_py_loc.py, which:
- Resolves the base & head SHAs (via
gh for a PR number, or git merge-base
for two refs โ so churn that arrived from main moving forward is excluded).
- Lists changed
.py files with git diff --name-only <base> <head> -- '*.py'.
- Reconstructs each file's base and head content (
git show <ref>:<path>).
- Strips comments + docstrings + blank lines from each version using Python's
ast (docstring line ranges) and tokenize (whole-line comments).
- Diffs the two cleaned versions with
difflib.unified_diff(n=0) and counts
+/- lines โ real added/removed pure-code lines per file.
Because it diffs cleaned files, multi-line docstrings, reformatting, and
comment churn never inflate the numbers.