Skip to content

Code metrics

code_metrics

Best-effort code metrics for a package: LOC + module/function/class counts.

LOC is counted from src/**/*.py (filesystem only). Structural counts come from axm-ast's ContextTool (already a dependency). Designed to feed a kind="code" quality-history line; every failure is swallowed so it can never break an audit.

collect_code_metrics(path)

Return {lines, modules, functions, classes, commits} (absent if unknown).

Source code in packages/axm-audit/src/axm_audit/code_metrics.py
Python
def collect_code_metrics(path: str) -> dict[str, object]:
    """Return ``{lines, modules, functions, classes, commits}`` (absent if unknown)."""
    root = Path(path).resolve()
    metrics: dict[str, object] = {}
    loc = _count_loc(root)
    if loc is not None:
        metrics["lines"] = loc
    commits = _count_commits(root)
    if commits is not None:
        metrics["commits"] = commits
    metrics.update(_structural_counts(path))
    return metrics