Package: complexipy
complexipyAn extremely fast Python library to calculate the cognitive complexity of python files, written in Rust.Documentation:https://rohaquinlop.github.io/complexipy/Source Code:https://github.com/rohaquinlop/complexipyPyPI:https://pypi.org/project/complexipy/RequirementsPython >= 3.11You also need to installgitin your computer if you want to analyze a git repository.InstallationpipinstallcomplexipyUsageTo runcomplexipyyou can use the following command:complexipy.# Use complexipy to analyze the current directory and any subdirectoriescomplexipypath/to/directory# Use complexipy to analyze a specific directory and any subdirectoriescomplexipygit_repository_url# Use complexipy to analyze a git repositorycomplexipypath/to/file.py# Use complexipy to analyze a specific filecomplexipypath/to/file.py-m20# Use the -m option to set the maximum congnitive complexity, default is 15complexipypath/to/directory-m0# Set the maximum cognitive complexity to 0 to disable the exit with errorcomplexipypath/to/directory-o# Use the -o option to output the results to a CSV file, default is FalseIf the cognitive complexity of a file is greater than the maximum cognitive, then
the return code will be 1 and exit with error, otherwise it will be 0.ExampleAnalyzing a fileFor example, given the following file:defa_decorator(a,b):definner(func):returnfuncreturninnerdefb_decorator(a,b):definner(func):iffunc:returnNonereturnfuncreturninnerThe cognitive complexity of the file is 1, and the output of the commandcomplexipy path/to/file.pywill be:─────────────────────── complexipy 0.2.2 🐙 ───────────────────────
- Finished analysis in test_decorator.py
──────────────────── 🎉 Analysis completed!🎉 ─────────────────────
                       Summary
┏━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Path              ┃ File              ┃ Complexity ┃
┡━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ test_decorator.py │ test_decorator.py │ 1          │
└───────────────────┴───────────────────┴────────────┘
🧠 Total Cognitive Complexity in ./tests/test_decorator.py: 1
1 files analyzed in 0.0005 secondsOutput to a CSV fileIf you want to output the results to a CSV file, you can use the-ooption,
this is really useful if you want to integratecomplexipywith other tools,
for example, a CI/CD pipeline. You will get the output in the console and will
create a CSV file with the results of the analysis.The filename will becomplexipy.csvand will be saved in the current directory.$complexipypath/to/file.py-oThe output will be:Path,File Name,Cognitive Complexity
test_decorator.py,test_decorator.py,1Analyzing a directoryYou can also analyze a directory, for example:$complexipy.Andcomplexipywill analyze all the files in the current directory and any
subdirectories.Analyzing a git repositoryYou can also analyze a git repository, for example:$complexipyhttps://github.com/rohaquinlop/complexipyAnd to generate the output to a CSV file:$complexipyhttps://github.com/rohaquinlop/complexipy-oLicenseThis project is licensed under the MIT License - see theLICENSEfile
for details.AcknowledgmentsThanks to G. Ann Campbell for publishing the paper "Cognitive Complexity a new
way to measure understandability".This project is inspired by the Sonar way to calculate the cognitive
complexity.ReferencesCognitive Complexity