Version 2.4.0
Command line tool
One module, no dependencies, three commands. It reads a working tree and a Git log and prints a table; everything else is formatting.
Install
Download metrica-cli-2.4.0.zip and
verify it against CHECKSUMS.txt. The module
runs directly, so putting it on your PATH is enough:
$ sha256sum -c CHECKSUMS.txt
metrica-cli-2.4.0.zip: OK
$ unzip -q metrica-cli-2.4.0.zip
$ install -m 755 metrica-cli-2.4.0/metrica.py /usr/local/bin/metrica
$ metrica --version
metrica 2.4.0
The archive is also a valid package if you prefer an entry point managed by
your environment — pip install ./metrica-cli-2.4.0 installs the
same metrica command. Python 3.9 or newer; git
must be on the PATH for churn and
report.
Commands
| Command | Reads | Answers |
|---|---|---|
scan |
the working tree | How big and how complicated is each file right now? |
churn |
the Git log | Which files keep being changed, and by how many people? |
report |
both | Which files are complicated and keep being changed? |
scan works on any directory. churn and
report need a Git repository and exit with status 3 if they do
not find one.
Options
| Option | Default | Effect |
|---|---|---|
--format | table | table, json or csv. |
--top N | all files | Only the N highest ranked rows. |
--sort FIELD | per command | Any output field: complexity, commits, lines, code, hotspot, authors, path. All but path sort descending. |
--exclude DIR | see below | Directory name to skip, at any depth. Repeatable. |
--since DATE | whole history | Limit the log window. Anything git log --since accepts, such as '18 months ago' or 2025-01-01. churn and report only. |
Default sort is complexity for scan,
commits for churn and hotspot for
report. These directories are always skipped:
.git, node_modules, vendor,
dist, build, target,
__pycache__, .venv, venv,
.tox, and the usual tool caches.
Examples
The largest files, regardless of history:
$ metrica scan . --sort lines --top 4
FILE LANG LINES CODE DOC% CPLX CHG AUTH HOT
----------------- ------ ----- ---- ---- ---- --- ---- ---
core/scheduler.py Python 467 378 11 93 0 0 0.0
core/pipeline.py Python 341 273 12 61 0 0 0.0
api/handlers.py Python 307 246 12 53 0 0 0.0
store/postgres.py Python 259 205 12 37 0 0 0.0
CHG, AUTH and HOT are zero here
because scan never opens the log. Use report if
you want them filled in.
Churn over a window, as CSV for a spreadsheet:
$ metrica churn . --since '18 months ago' --top 3 --format csv
path,language,lines,code,comment_ratio,complexity,commits,authors,hotspot
web/render.js,JavaScript,239,165,0.122,45,9,1,48.4
core/registry.py,Python,168,126,0.149,19,5,1,11.4
web/table.js,JavaScript,154,111,0.126,23,2,1,5.5
JSON carries a little more than the table does — the raw comment count,
lines added and removed, and max_function, the worst single
function in the file for Python sources:
$ metrica report . --top 1 --format json
{
"version": "2.4.0",
"files": [
{
"path": "web/render.js",
"language": "JavaScript",
"lines": 239,
"code": 165,
"comment": 23,
"blank": 51,
"comment_ratio": 0.122,
"complexity": 45,
"max_function": 0,
"commits": 9,
"added": 261,
"removed": 44,
"authors": 1,
"hotspot": 48.4
}
],
"totals": {
"files": 1,
"lines": 239,
"code": 165,
"comment": 23,
"complexity": 45
}
}
totals covers the rows that were printed, not the whole
repository. With --top in play that is a subset, which is
usually what you want when piping into something else — but it is worth
knowing before you quote the number.
Exit codes
| Code | Meaning |
|---|---|
0 | Success. |
1 | No recognised source files under the path. |
2 | Path is not a directory. |
3 | Not a Git repository, or git is not installed. |
Tests
The archive ships its test suite; it needs nothing but the standard library.
$ cd metrica-cli-2.4.0 && python -m unittest discover -s tests
...............
----------------------------------------------------------------------
Ran 15 tests in 0.044s
OK