Package: python-abc
Python ABCA python implementation ofthe ABC Software metric:The ABC software metric was introduced by Jerry Fitzpatrick in 1997 to overcome the drawbacks of the LOC. The metric defines an ABC score as a triplet of values that represent the size of a set of source code statements. An ABC score is calculated by counting the number of assignments (A), number of branches (B), and number of conditionals (C) in a program. ABC score can be applied to individual methods, functions, classes, modules or files within a program.Fitzpatrick's original paper is, at the time of writing, onlyavailable via the Wayback
Machine, soa copy of it is included in this repoas well.The paper lists the counting rules for C, C++ and Java, so here are the rules this repo uses for
Python:Add one to the assignment count when:Occurrence of an assignment operator (excluding default parameter assignments).Add one to the branch count when:Occurrence of a function call/await or a class method call/await.Occurrence of a class instantiation.Add one to the condition count when:Occurrence of a conditional operator.Occurrence of the following keywords:else,elif,except.Occurrence of anassertstatement without a conditional operator.UsageInstall the requirements in your virtual environment of choice, then you can see the command line
arguments that are available:$python-mpython_abc--help
usage:python_abc[-h][--debugDEBUG][--sortSORT][--verboseVERBOSE]path

ApythonimplementationoftheABCSoftwaremetric:https://en.wikipedia.org/wiki/ABC_Software_Metric

positionalarguments:pathpathtodirectoryorfile

optionalarguments:-h,--helpshowthishelpmessageandexit--debugDEBUGdisplayASToutputforeachelementintheparsedtree--sortSORTsortfilesfromhighesttolowestmagnitude--verboseVERBOSEdisplaymarked-upfileGivenfile.pythat contains the following text:ifaandb:print(a)else:print(b)a=sum(iforiinrange(1000)ifi%3==0andi%5==0)deff(n):definner(n):returnn**2ifn==0:return1elifn==1:returnnelifn<5:return(n-1)**2returnn*pow(inner(n),f(n-1),n-3)You can get the barebones output as follows:$python-mpython_abc/path/to/file.py
/path/to/file.py<1,7,10>(12.2)Passing theverboseflag will give more detail:$python-mpython_abcfile.py--verbose=truecc|ifaandb:
b|print(a)c|else:
b|print(b)|abbcc|a=sum(iforiinrange(1000)ifi%3==0andi%5==0)||deff(n):|definner(n):|returnn**2c|ifn==0:|return1cc|elifn==1:|returnn
cc|elifn<5:|return(n-1)**2bbb|returnn*pow(inner(n),f(n-1),n-3)file.py<1,7,10>(12.2)If you want to inspect the abstract syntax tree for the file you can pass thedebugflag, which
will print out each node from the tree and the vector that resulted from it.Thepathargument can also be a path to a directory, in which case all Python files in that
directory (and its sub-directories) will be scanned, at which point it can be useful to pass thesortflag to rank the files by ABC magnitude:$python-mpython_abc.--sort
./calculate.py<18,56,23>(63.2)./vector.py<12,23,11>(28.2)./main.py<10,23,8>(26.3)./tests/test_vector.py<4,19,10>(21.8)./tests/__init__.py<4,12,1>(12.7)./tests/test_radon_test_cases.py<1,2,1>(2.4)./tests/test_calculate_condition.py<1,2,1>(2.4)./tests/test_calculate_empty.py<1,2,1>(2.4)./tests/test_calculate_assignment.py<1,2,1>(2.4)./tests/test_calculate_branch.py<1,2,1>(2.4)Finally you can pass acoresargument to tell the library how many CPU cores to use. By
default the library will try to use all the cores that are available on your machine.