utils/devstats/excludes.py
Krzysztof kuhy Rudnicki 2f7e87c10e
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
devstats: local refs only, keep source in data dirs
Count only the local default branch, as the spec's stale-ref answer
asks (origin/ only names the branch and drives the "behind" warning).
Source files under data/, assets/ and fixtures/ (lib/data/*.dart) now
count as code; vendored and build dirs still drop everything.
Regenerated DOCS-comparison.md.

Bug-class-check: devstats/tests/test_excludes.py (code-under-data-dir cases)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:23:38 +01:00

93 lines
3.9 KiB
Python

"""THE exclude list: which changed paths count as code, docs or dropped churn.
One ordered constant, first match wins. A pattern ending in "/" matches any
directory component of the path; any other pattern is a glob on the file name.
Vendored/build directories come first so nothing inside node_modules/ or
addons/ is rescued by a later rule; source files (by extension) are kept
before the data/, assets/ and fixtures/ directory rules, so lib/data/*.dart
and a fixtures/ fake binary in Python stay code; the code keeps come before the file excludes so
package.json survives `*.json`; translation dirs come before `*.json` so
locales/en.json counts as docs, like the article's "+800k translations and docs".
Judgment calls, calibrated on the 30-day top-40 churn list (2026-11-27):
- `*.txt` is data (one word list was ~10% of all churn) except requirements/CMake.
- `*.json` is data (eval dumps, fixtures, baselines) except a few config names.
- Godot `addons/` is vendored (GUT, copies of dev_tools) except the source of
kuhy's own addon under `godot_dev_tools/`; `*.tres` is data; `*.import`/`*.uid` are
generated; `*.tscn` scenes stay code (authored structure).
- `fixtures/` is test data; test code (source extensions) inside it stays.
"""
from __future__ import annotations
from fnmatch import fnmatchcase
from typing import Literal
Bucket = Literal["code", "docs", "excluded"]
RULES: tuple[tuple[Bucket, str], ...] = (
# kuhy's own Godot addon source (utils/godot_dev_tools); games carry vendored copies
("code", "godot_dev_tools/"),
# vendored and build-output directories (any depth): everything inside goes
*(
("excluded", d)
for d in (
"node_modules/", "vendor/", "third_party/", "addons/", ".venv/", ".dart_tool/",
"dist/", "build/", "generated/", "htmlcov/", "coverage/", "__snapshots__/",
)
),
# config files that would otherwise fall under a data glob below
*(
("code", f)
for f in ("package.json", "tsconfig*.json", "jsconfig.json", "deno.json",
"requirements*.txt", "CMakeLists.txt")
),
# translations and docs directories
*(("docs", d) for d in ("docs/", "doc/", "l10n/", "locales/", "i18n/", "translations/")),
# lockfiles
*(
("excluded", f)
for f in ("*.lock", "*.lockb", "package-lock.json", "npm-shrinkwrap.json",
"pnpm-lock.yaml", "go.sum")
),
# generated files
*(
("excluded", f)
for f in ("*.g.dart", "*.freezed.dart", "*.mocks.dart", "*.gr.dart", "*.pb.go",
"*_pb2.py", "*.min.js", "*.min.css", "*.map", "coverage.xml", "lcov.info",
"*.lcov", "*.import", "*.uid", "*.snap")
),
# source files stay code even inside the data dirs below (lib/data/*.dart)
*(
("code", f)
for f in ("*.py", "*.dart", "*.ts", "*.tsx", "*.js", "*.jsx", "*.mjs", "*.gd", "*.go",
"*.kt", "*.kts", "*.java", "*.sh", "*.c", "*.h", "*.cpp", "*.rs", "*.lua")
),
# data and asset directories: whatever is not source in them is data
*(("excluded", d) for d in ("data/", "assets/", "fixtures/")),
# data and assets
*(
("excluded", f)
for f in ("*.json", "*.jsonl", "*.ndjson", "*.geojson", "*.csv", "*.tsv", "*.txt",
"*.tcx", "*.gpx", "*.tres", "*.svg", "*.log")
),
# docs and translations
*(
("docs", f)
for f in ("*.md", "*.mdx", "*.rst", "*.adoc", "*.arb", "*.po", "*.pot",
"LICENSE*", "COPYING*")
),
)
def classify(path: str) -> Bucket:
"""Bucket for one repo-relative path (binaries are handled by the caller)."""
*dirs, name = path.split("/")
for bucket, pattern in RULES:
if pattern.endswith("/"):
if any(fnmatchcase(d, pattern[:-1]) for d in dirs):
return bucket
elif fnmatchcase(name, pattern):
return bucket
return "code"