An extremely fast Python library to calculate the cognitive complexity of python files, written in Rust.
Project description
complexipy
An 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/complexipy
PyPI: https://pypi.org/project/complexipy/
Requirements
- Python >= 3.11
- You also need to install
git
in your computer if you want to analyze a git repository.
Installation
pip install complexipy
Usage
To run complexipy you can use the following command:
complexipy . # Use complexipy to analyze the current directory and any subdirectories
complexipy path/to/directory # Use complexipy to analyze a specific directory and any subdirectories
complexipy git_repository_url # Use complexipy to analyze a git repository
complexipy path/to/file.py # Use complexipy to analyze a specific file
complexipy path/to/file.py -m 20 # Use the -m option to set the maximum congnitive complexity, default is 15
complexipy path/to/directory -m 0 # Set the maximum cognitive complexity to 0 to disable the exit with error
complexipy path/to/directory -o # Use the -o option to output the results to a CSV file, default is False
If 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.
Example
Analyzing a file
For example, given the following file:
def a_decorator(a, b):
def inner(func):
return func
return inner
def b_decorator(a, b):
def inner(func):
if func:
return None
return func
return inner
The cognitive complexity of the file is 1, and the output of the command
complexipy path/to/file.py
will 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 seconds
Output to a CSV file
If you want to output the results to a CSV file, you can use the -o
option,
this is really useful if you want to integrate complexipy with 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 be complexipy.csv
and will be saved in the current directory.
$ complexipy path/to/file.py -o
The output will be:
Path,File Name,Cognitive Complexity
test_decorator.py,test_decorator.py,1
Analyzing a directory
You can also analyze a directory, for example:
$ complexipy .
And complexipy will analyze all the files in the current directory and any subdirectories.
Analyzing a git repository
You can also analyze a git repository, for example:
$ complexipy https://github.com/rohaquinlop/complexipy
And to generate the output to a CSV file:
$ complexipy https://github.com/rohaquinlop/complexipy -o
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks 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.
References
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for complexipy-0.2.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9dce89730ffc7bad0ed999b47af0d16fa954868eab2c422b1e659ee379158c6a |
|
MD5 | 43fbbd46be0300568f128aefe82c0388 |
|
BLAKE2b-256 | 5bf9136cfef3b7835affb10ece9ba0c7ceeb2d2ad00bd31a2f96085aabcde8a7 |
Hashes for complexipy-0.2.2-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a964917346c0cfd86c6ae1c59b0c6fda260b7c04ce1e5e628aac97e6dc49a0da |
|
MD5 | 54f75e7f99887df0115b2bb1cdf80f7d |
|
BLAKE2b-256 | 8d48db30a6d1f164a3f4caae665b4c1426f2c7c921317a67360a4c583e0df535 |
Hashes for complexipy-0.2.2-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e88d49edc1925618ee207946f1c4c0644c092cf67fdbf220c1f1f423d808ca1f |
|
MD5 | fdc467bd3a6352b9efad6cc067e202f0 |
|
BLAKE2b-256 | 524941f5b103c092bfee571c279bae71b451e1b8cabe208603926959dfcfaae1 |
Hashes for complexipy-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 626d91edbf9166b137657ed98cbe26f3a9c3fc3c68cfd04ff395f0cef2def40c |
|
MD5 | da00800a8f79abd432ffd498d274e9b8 |
|
BLAKE2b-256 | d02bafcf43ebc33eaa5e238c7e29d8153e4f1323cee6e8c0831b3a9077912a41 |
Hashes for complexipy-0.2.2-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3e67d9959a2212b93da5dc7ec116249de83a143570a7a973d28a5253c1ac8be |
|
MD5 | 2481694036d93bcc53888cf65bfc789a |
|
BLAKE2b-256 | b642a58b09fb90c16193208c063eb22b252047abb89fe03fa661fc1634739fde |
Hashes for complexipy-0.2.2-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8379fb62a74ba47c887563b6ed26bdc40f02856a78ceb9ebc5f11cb7e4e38b6d |
|
MD5 | 2e4e0012b88660df643fa8d0d9ec3f1d |
|
BLAKE2b-256 | c02cd3906c42e0e5bf8fbf02d36f8bef3092005b000ec7f39517cea8ce73c8a3 |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e23fe682e9a1dacf4fb21c5f8302252a52fe84f0566f2d2591e5b63b2ebdbfd |
|
MD5 | 992720a3db21b15ec6ee0b5165fec667 |
|
BLAKE2b-256 | eb2e8c3c809cade1cb307ed592a3895c216edd579b56a482546996357cad3019 |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d09b2c03c6af77a60354674f36a60482822c1c100b749fdf09428669390b29e |
|
MD5 | e3c8393994c0ee6c030b106d0480a886 |
|
BLAKE2b-256 | d15eb97d8ccc7950f421fced872a67e07607c369e02dc12d21252b05ca50465f |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1469ec4b03f25c19b49ca1f1838f9b3435aac83202cc4301df0b5bbc602511f |
|
MD5 | bd8ec232b7ef8f6eb7211d4dcda1f34e |
|
BLAKE2b-256 | 7a989e54053e6eb3a7ce69255d897e33f787a0b36594d1a108a9f281ccf01526 |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85aae3bb4af9e4f3ab88f1570ed2df07c171335079732b5b41ac112fc541e977 |
|
MD5 | b759e0256485252d8f9da58afefd93f9 |
|
BLAKE2b-256 | 8987f84723d7f7f258f38ded331e55e010106f1b8a680ccfe478a175162ac11d |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23ac57da8d8028eb7d73008840ae9a17f2945706aa4f20956aa4e825de956a99 |
|
MD5 | e2de15c5353d41ff4bdef4b8b9bd1177 |
|
BLAKE2b-256 | ff56617754839440c03e922406f67f9e6d55b1c3e79b2c986cb38f6f31465ba4 |
Hashes for complexipy-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff766b3e72cf177a7e350cef0be451aa9eec0999917f92c80d7e4191ff44f21 |
|
MD5 | 90849fdcd09aef56d290342969166261 |
|
BLAKE2b-256 | 330986668e6b1ee3b03b431feea9db434c2f3d3399a452434fd54214f54e1064 |
Hashes for complexipy-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53c066fc5e169eea692814bd34d1f026e014819e4fe7eb00de5725809d143900 |
|
MD5 | f8affed9d15f5b869b0d9b13cebc9bf5 |
|
BLAKE2b-256 | ff3a658ff4eab946b68a900f87d35ffbce8d456f763c3146ce34c1ddc3effe77 |
Hashes for complexipy-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56afeb0371084462079b36bba389932675ce4aadcad756fa2820834ccec0456d |
|
MD5 | bf595bb7bb43ac6a350b35f93f1bee65 |
|
BLAKE2b-256 | 2b27cb316df21783df815bdac40ce0724214ef79f5bae0b8b977e21a8c52bcb5 |
Hashes for complexipy-0.2.2-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f1445959d815ca1809a8d7709c6f1c2eaf3ec28ffd6ce50f54eda70e8fe25a8 |
|
MD5 | 013878f50d59bb65e6a6f2f2026ab539 |
|
BLAKE2b-256 | ec8d73814ac630bb0762c048799da0a8690086f817c1277553d9057ff9921619 |
Hashes for complexipy-0.2.2-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51c5afb52120b955e71fbd2ee99d80bfb03a9e84bc61acebc9b52adb9125ff2b |
|
MD5 | e0fba11948d13042bb50719fbd3b566f |
|
BLAKE2b-256 | b3783486a246f8d27bcdfda183b6dfbe2d6be6e7e997ce0509aa0aa0025de9bf |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb179b7868e943c7cbdca968974760081fc69a1be29804a5f07deeb0b38c52d4 |
|
MD5 | 0e59d81ee5615424885928447f378993 |
|
BLAKE2b-256 | 0832175191f1485c4b552716cdb86268de867f2f38fca8cd6d9ca6873ca43ea3 |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b736ed0b864b42b695c55253b47661e2fddab70d409d893aaaf0d80412624b |
|
MD5 | 732ba940c0affcd0353b83374e1bb0d4 |
|
BLAKE2b-256 | cd26ae2f644cae651fa7324459d8a8f85c990fac7b22b1cab3f58245f8b0ccb4 |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5206deae2ffd6ca9e090f0f09ace9fb6a280e1be3fd6beee36e9e905caa750f |
|
MD5 | 48f6b7d7a330e3d924d460432a2b4fc7 |
|
BLAKE2b-256 | 3029c9414b0e3354aec963d1be7f3edc06dff6a8a4b05b1c6f24e53f8971663b |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ee09cb1bcaf299b8754777dd0e3cefbe343412974eec95408e682204a874d69 |
|
MD5 | b03200b5f7213cafd1defa127b31b7c8 |
|
BLAKE2b-256 | bb5db5545fa02e0e4fbbc6d654a06405409ec42969d86369e62aeb57a8c31346 |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25fcc6cb41ce060e567cdf56b0e41870a2f7079f69e9e1c28be118ac3a63ddd2 |
|
MD5 | dfd388f645c2751beb4888d2778c1856 |
|
BLAKE2b-256 | 8ecb31f6ca27ae97bcbb7b53b5aeef5516a04cfa7385a53c6d6407666eaac329 |
Hashes for complexipy-0.2.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a884bde07d54977d0da8cfdd9b6c324592175c7c2c3dd5f1e7ed98ed7aa52cc5 |
|
MD5 | da666eeebd668cb78d96711881c19b2a |
|
BLAKE2b-256 | 2cd8261e0619199edff2988571378a1cd9b2275e0b7d2a9c38592c4a58f63b44 |
Hashes for complexipy-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5997b70dc31c5fa98784f38de411604c98769547a8f6f7f55ae0cbfe757df86 |
|
MD5 | 9f6330fb96f6ec01475e42685df5a408 |
|
BLAKE2b-256 | 0781b142f250e682fe66bbb4ba022f5635746f712e6c67ff2eefc2c5f48152a6 |
Hashes for complexipy-0.2.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac0887a277eb682798e2d0ea5dcb014b1c3e3792e14945b3c78c6e6edba81663 |
|
MD5 | 3abcecf8d555d2a4813421321958276e |
|
BLAKE2b-256 | d93646d422d86e756afe89cc45c2b28c958cec5452ab0df6bb411cd102b41c2e |