Skip to main content

A general purpose tool for validating cyclomatic complexity in Python.

Project description

PyCyclo

py-cyclo is a general-purpose command-line tool for analyzing and validating cyclomatic complexity in Python code. Designed for developers who want to maintain clean, testable, and maintainable code, py-cyclo provides detailed reports and enforcement mechanisms to ensure your codebase doesn't spiral out of control.

License Continuous Integration Release PyPI


🚀 Features

  • Measure cyclomatic complexity of Python functions and methods
  • Set complexity thresholds and enforce them via CLI
  • Supports per-file, per-function, or project-wide analysis
  • JSON, plain-text, or colorized output formats
  • Integrates easily into CI/CD pipelines

📦 Installation

You can install py-cyclo via pip:

pip install py-cyclo

Or install directly from GitHub:

pip install git+https://github.com/ocrosby/py-cyclo.git

🛠️ Usage

Usage: cyclo [OPTIONS] PATH

Example Command

# Validate the cyclomatic complexity of all Python files in the current directory
# and its subdirectories is less than or equal to 10
cyclo --max-complexity 10 .

or

Example Command

# Validate the cyclomatic complexity of all Python files in the current directory
# and its subdirectories is less than or equal to 10
cyclo -m 10 .

Example Output

Checking cyclomatic complexity in "/path/to/project"...

2 functions exceed the maximum complexity of 4:
+-------------------------------+--------------+-----------+-----------------------------------------------+
| Name                          |   Complexity |   Line No | Filename                                      |
+===============================+==============+===========+===============================================+
| example_function              |            6 |        10 | example_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| another_function              |            5 |        20 | another_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+

5 functions with a complexity < 4:
+-------------------------------+--------------+-----------+-----------------------------------------------+
| Name                          |   Complexity |   Line No | Filename                                      |
+===============================+==============+===========+===============================================+
| simple_function               |            3 |        15 | simple_module.py                              |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| helper_function               |            2 |        25 | helper_module.py                              |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| utility_function              |            2 |        30 | utility_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| another_helper_function       |            1 |        35 | another_helper_module.py                      |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| yet_another_function          |            1 |        40 | yet_another_module.py                         |
+-------------------------------+--------------+-----------+-----------------------------------------------+

Maximum complexity: 6

FAILED - Maximum complexity 4 exceeded by 2

Functions with complexity greater than the maximum allowed:
example_function: 6
another_function: 5

Options

Flag Description
--max-complexity, -m Set the maximum allowed complexity per function
--help Show CLI help

🔧 Configuration

At present there are no configuration options.


🧪 Testing

To run the test suite:

pip install --upgrade pip
pip install invoke
pip install ".[dev]"
invoke test

🤝 Contributing

Contributions are welcome! To get started:

  1. Fork this repo
  2. Create a new branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Write tests and ensure everything passes
  5. Submit a pull request

Please follow the Contributor Covenant code of conduct.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


🙌 Acknowledgments

  • Inspired by tools like radon
  • Built with ❤️ using Click and ast

🔗 Related Projects


References

📬 Contact

Feel free to reach out via GitHub Issues or submit feature requests and bugs.

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

py_cyclo-1.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

py_cyclo-1.1.1-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file py_cyclo-1.1.1.tar.gz.

File metadata

  • Download URL: py_cyclo-1.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for py_cyclo-1.1.1.tar.gz
Algorithm Hash digest
SHA256 4d606d96a75a08d2333d27548eb8229a77160a6fe0fadbe1203d5222f4447b7a
MD5 bb411a44461308c0c3f9afa08664ab43
BLAKE2b-256 2b5780904a56f8a1143649856a373a0e5661bb256ca3fe7163dbedec6571b83a

See more details on using hashes here.

File details

Details for the file py_cyclo-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: py_cyclo-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for py_cyclo-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 19f8f032d0c5366b4ecd10a46989b9bf8868203e6bbcfd7439d5c24c46eee2fa
MD5 dd92ff95f388e40cacdb6376c95a32b1
BLAKE2b-256 69d820502af6e3ad643a899e44c06a3390988fbdebbc4e7aae4481495db705ec

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