Skip to content

gbvkUtilities/complexity-analyzer-cli

Complexity Analyzer CLI

License: MIT Python 3.6+

A lightweight Python tool to calculate the Cyclomatic Complexity of functions in your Python source code. It uses the ast module to parse code and identify decision points, helping you identify complex functions that may need refactoring.

Features

  • AST-based Analysis: Doesn't run your code; safely parses the Abstract Syntax Tree.
  • Function-level Metrics: Provides complexity scores for every function and method.
  • Configurable Thresholds: Flag functions that exceed a specific complexity limit.
  • CI Friendly: Simple CLI interface and exit-code behavior (can be extended).

Installation

No dependencies outside the Python standard library are required.

git clone https://github.com/gbvk312/complexity-analyzer-cli.git
cd complexity-analyzer-cli

Usage

Analyze a single file:

python complexity_analyzer.py your_file.py

Analyze multiple files with a custom threshold:

python complexity_analyzer.py file1.py file2.py --threshold 15

Example Output

Analyzing: example.py
Function Name                  Line   Complexity
--------------------------------------------------
get_user_data                  10     3         
process_payments               25     12         [!] High Complexity

What is Cyclomatic Complexity?

Cyclomatic complexity is a quantitative measure of the number of linearly independent paths through a program's source code.

  • 1-10: Simple, easy to test.
  • 11-20: More complex, moderate risk.
  • 21-50: Complex, high risk.
  • >50: Untestable, very high risk.

Roadmap

  • Support for directory-wide recursive analysis.
  • Export results to JSON/CSV.
  • Integration with pre-commit hooks.
  • Support for JavaScript/TypeScript (requires additional parser).

License

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

About

Calculate cyclomatic complexity of Python functions.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages