McCabe complexity for just changed files in a commit?
rosuav at gmail.com
Sun Oct 3 00:18:53 EDT 2021
On Sun, Oct 3, 2021 at 3:07 PM Dan Stromberg <drsalists at gmail.com> wrote:
> Hi folks.
> Is there a way of getting the McCabe Complexity of just the functions and
> methods (in Python) changed in a git commit?
> I found radon, and it looks good. But I think it wants to do entire files,
No idea about the complexity calculation, but perhaps the easiest way
is to ask git to list all files that changed in a particular commit,
then look at those files before and after, and compare the
git diff-tree 1af743
:100644 100644 b5908b5a36a4749e0bef2a16a2733a7461a818dc
e00ba8738dbf3421288d31c60de9ee42a085c148 M auto-volume.py
The first line is the commit hash, and then each subsequent line names
a file that changed. The two hashes given are the old version and the
new version. Then you can:
git cat-file -p b5908b5a36a4749e0bef2a16a2733a7461a818dc
git cat-file -p e00ba8738dbf3421288d31c60de9ee42a085c148
to see the files - hopefully you can pipe that into radon and get the
complexities, and calculate the increase or decrease from that.
If the file was newly created in that commit, you'll see an initial
hash of all zeroes, and instead of "M" before the file name, it'll be
"A". Similarly, if a file gets deleted, there'll be "D" and the new
hash will be all zeroes.
Would that work?
More information about the Python-list