40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""List the production functions over the lawbook 301 limits, longest first (STRA-338 helper for the size work).
|
|
|
|
Usage: scripts/limits-offenders.py [--top N] [--min-lines 31] PATH_PREFIX...
|
|
Each line: lines complexity nesting wide-lines file:start function-key
|
|
"""
|
|
import argparse
|
|
import pathlib
|
|
import sys
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
|
|
|
from limits import files, policy # noqa: E402
|
|
|
|
|
|
def main(argv):
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("prefixes", nargs="+")
|
|
parser.add_argument("--top", type=int, default=0)
|
|
parser.add_argument("--min-lines", type=int, default=31)
|
|
args = parser.parse_args(argv)
|
|
root = pathlib.Path(__file__).resolve().parent.parent
|
|
pol = policy.load(root)
|
|
rows = []
|
|
for prefix in args.prefixes:
|
|
for path in sorted((root / prefix).rglob("*.rs")):
|
|
rel = path.relative_to(root).as_posix()
|
|
if "/target/" in rel or policy.is_test_path(rel):
|
|
continue
|
|
fns, _ = files.scan_file(root, pol, rel)
|
|
rows += [(fn, rel) for fn in fns if not fn.test and fn.fn_lines >= args.min_lines]
|
|
rows.sort(key=lambda row: -row[0].fn_lines)
|
|
for fn, rel in rows[: args.top or None]:
|
|
print(f"{fn.fn_lines:5} {fn.complexity:4} {fn.nesting:3} {fn.width:4} {rel}:{fn.start} {fn.key}")
|
|
print(f"# {len(rows)} functions", file=sys.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main(sys.argv[1:])
|