Skip to main content

An extremely fast Python library to calculate the cognitive complexity of python files, written in Rust.

Project description

complexipy

complexipy

An extremely fast Python library to calculate the cognitive complexity of python files, written in Rust.

Quality Gate Package version


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.1 🐙 ───────────────────────
- 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

complexipy-0.2.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

complexipy-0.2.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ s390x

complexipy-0.2.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ppc64le

complexipy-0.2.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARMv7l

complexipy-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

complexipy-0.2.1-cp312-none-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12Windows x86-64

complexipy-0.2.1-cp312-none-win32.whl (1.8 MB view details)

Uploaded CPython 3.12Windows x86

complexipy-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

complexipy-0.2.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ s390x

complexipy-0.2.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ppc64le

complexipy-0.2.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686

complexipy-0.2.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARMv7l

complexipy-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

complexipy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

complexipy-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

complexipy-0.2.1-cp311-none-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

complexipy-0.2.1-cp311-none-win32.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86

complexipy-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

complexipy-0.2.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ s390x

complexipy-0.2.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ppc64le

complexipy-0.2.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686

complexipy-0.2.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARMv7l

complexipy-0.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

complexipy-0.2.1-cp311-cp311-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

complexipy-0.2.1-cp311-cp311-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file complexipy-0.2.1.tar.gz.

File metadata

  • Download URL: complexipy-0.2.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for complexipy-0.2.1.tar.gz
Algorithm Hash digest
SHA256 85c27e1056ae4067919360e9956ed1f33dc7f1f4a761626a13f72f97eec38213
MD5 10978e2e9d008311814dccbbbd9cb434
BLAKE2b-256 8fda80e1c69087e9993cbf030fcfd7f4dd07df22ba482c3d83195cfed3db22a0

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 f571a7722ea5bb5b61f7d9a2f5b5c418894b0ac162bc3b27b40eafe92542385b
MD5 39f292ec16772c79ee1e2351cfa0b6b0
BLAKE2b-256 b439e55853a6ceb7140185c257f29567db3e5b8a1472a4be0da004e78e8fdf98

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 4477964a116d5692f1c35952aedb7163301e76d2ec976d73dc4e5bc9897c1461
MD5 50db81b80ce8c29dce74bb8a06f04547
BLAKE2b-256 4b13bed391880fc5f46897fefb3f7d1074bfdafe8612aea251a5ad2e999b2022

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 9a76c1abf405f5cec529ec804c80e97156198e1a651c44bfda43eee10bd08f96
MD5 49a1afb4ea97207b05aa5044e9213360
BLAKE2b-256 f49b16dd4dea69909da64d7725ea93eae78dd7dae41e0965036ff8c476ca0093

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b0560e7f8584834e183d1b0e6bf2b74b364bc4ca49ca98a0909b59e4331fef31
MD5 ce003ec02969f9f45474f6ae687f5085
BLAKE2b-256 4f52a7816187f778835352f80afa8c028062bb6d4ea3817d6a406d290b21c83c

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 ff00c0455bec385f3ad9a0ea32065ac0e76ec5752da768af6d81307c008b30dc
MD5 4325baa6414ff744e140a5fac077f9fb
BLAKE2b-256 68239f70292cc4d8e43da4d0d077c71369794a90ff2696c9644599a1136f091a

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-none-win32.whl.

File metadata

  • Download URL: complexipy-0.2.1-cp312-none-win32.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for complexipy-0.2.1-cp312-none-win32.whl
Algorithm Hash digest
SHA256 7eb7729c7ea7b3154bbda514cad15ae8e85fcfa938434b02b43fb13d6850b9f1
MD5 f35fdc7cf12bf18099f215c8ea888876
BLAKE2b-256 b98d72d96399181c6b457d20121f79e9b87d70dbcb47b3f5ce303bafb9cdd34f

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae1213b90090a08f7b3c16d915d403de6c52da306c3e2885e100bfa47fa0e78a
MD5 59357126e270389857b51fd223597da6
BLAKE2b-256 b4704136061d5cef7294a391d357d0b6fb6bf9a2d78dff6bab2963a8251996a2

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 dac720186193bedb1114c56010a0a148bed1ddf2d68a62736350b0060f0ec3e8
MD5 b67dae47c4324b0602a5d12b4ed2659b
BLAKE2b-256 dcfbb209a4bc065f06656419851cac8ff52f29bf3c96cde5d4161f8fee3f33a5

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 0147421b4cecc1a5b5c54806d8108e9836ddf0a3d70104f42a6214bec48cd306
MD5 8d972de4dffbb3c32326b67529adc05d
BLAKE2b-256 f3ffed4e4e877dfcd04c202945fe2d74343be2753c4a99f74039e4413c1d0081

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2b270ce813a1b2cc40948c7f4ebcc63abeb95d454de06e7eb3ea321e39b6b314
MD5 121af72fc1d015b52779b4b1770fcf09
BLAKE2b-256 ec15e4dbc4a7bebcc256bfe879eec41cf31d8f0a947a61edf5bed90c7c05b8e9

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 c614570a52ad043f7ca8692c26c71eca55383c0797ca93a8ec0fe84ed0ce3546
MD5 52da39a24a899ae735ca9ed1e398474a
BLAKE2b-256 58e0621edadd2c3253f826844f19bd31d3d825cca56430b09c2c002a2dad8720

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 68b002f507722b11e31260307696fd1c494716c62201320a1084779df2671c3f
MD5 747867d7367f5bca4928f8827ac9d5f1
BLAKE2b-256 e00ef0690c6c0901187fa32a18c8bcface1a313371ff8ed56eead9aae5ac5f04

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c6349e684668fc19070821f249bd8a45509bd605b5ac4f0692e24f27dd8e081
MD5 41cc02523c441ea24d217dffa77a2037
BLAKE2b-256 335e1295aa11d04636cce0548861616d51cdda1c465844e21a95a96a16786234

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 920a8434a36d3be99ef578b6682c22cbd157b30d23247ef1769b3c98adfe49b1
MD5 c33d3b6380c6a57145a02f8bf7d3d66b
BLAKE2b-256 c9700b7d6abc06ac502238e920c6412d5b6e38e92341cc287025120271808ded

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 d5b919d0c76e2e3200f672cdf4bcbed64b2cb9d7bdf08914c132954fac1819d1
MD5 ca71775878f66f929b237c0f830ab6d3
BLAKE2b-256 e32bac0e7ed28a62a40a8a5bc729a16acedc58f8cc95fd31380132750848278d

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-none-win32.whl.

File metadata

  • Download URL: complexipy-0.2.1-cp311-none-win32.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.4.0

File hashes

Hashes for complexipy-0.2.1-cp311-none-win32.whl
Algorithm Hash digest
SHA256 7bf930e54802370b89578e2de4c11312d8098ebe78265c47d9931756e881bfa8
MD5 73c9ac8f2cee7fabea74e80715485dcc
BLAKE2b-256 02b2df0545d0dc9efb264efe6aa9f4fe808204545767b5a7939b3a5b46de84ae

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9176dff001a4db8d6125fc496e7d7334a85ca16a078110e184e98babc93baf7f
MD5 9654656752d466b33adfb7712fc4157d
BLAKE2b-256 09fb26b3cda0b013c603e75fc6722a336defd57efba664ca28c0a0feb4107e23

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 18d7bf897cf992fde401d09686df2b0f91bbdc7fa68122e0f93b98613ea65971
MD5 37743d15fa31052c4f44f15e078b0997
BLAKE2b-256 83b0b5522a5bafafd842f4ae494eac34aa993b2e74e15e59ffa462d847fbde29

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 afbacb7f7b3f400e1d5a1722a3d90e0714876f451f4a05697a7f0367a66b3ce2
MD5 0406df945088a27d241b6932b0fea0c2
BLAKE2b-256 3059df3b508a205335cbed9140f31f76f714b3bc84975147c2560a6ab964a6b0

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 65f198969ba2f5aee863e2a519786ca77d763ee3d81347db0514339b3a80ac72
MD5 6f6cb857ce1bb7139ecbae2535a1548d
BLAKE2b-256 ba01e669bd676eb8191e5322f838dc2c26676bfe24e042396bdc95fbc2f180b7

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 cb80a1f53915430d999dd670f234b65eb414e6d7a0fe1b6ebecaf6725a46369f
MD5 5cc001d611af7408101ca343dc4727c3
BLAKE2b-256 5386010dca253ccb26076a20c625be273e8c1c89a7dbe016e6f5344025474f05

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 96d834e5cc73887856d818a3b421ea01c92e761f2f48a388d378f5d589997cd6
MD5 c3deba398052ebfb32310f5aefa76f19
BLAKE2b-256 b546fcea2506313622f7965ad90066cb9d8250e81ba1326df22094b2dc804e8b

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3353bff3644d740396bc37ea600b5ba9a8d2b077349e9cfe56f7d66bdc5a6af6
MD5 9f1db3464bdb6291b5aa36be0eba64ec
BLAKE2b-256 2096b18e3d1252eae46bd8e68d30eddf6f535613db087f4fde51d1c6dc902a8f

See more details on using hashes here.

File details

Details for the file complexipy-0.2.1-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for complexipy-0.2.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2dd985a2e086dfd791f588ff8164a65b406691bbd3bcfc0cc1a170f42812e730
MD5 048e646b7729e0b8ca6896325ea5e3c2
BLAKE2b-256 9826c0ef757d606345e9bdc56f7bd0aee25227a7a2829a6eb333bd9fd3e90fd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page