Skip to content

furoxr/cyclomatic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feature:

python 3.10.0 is required

  1. calculate cyclomatic complexity of a program (python)
  2. generate ast from source code with the help of tree-sitter
  3. support the calculation in parallel when the target is a directory

Installation

pip install git+https://github.com/furoxr/cyclomatic.git

Examples:

import pathlib
import cyclomatic
from cyclomatic import (
    cyclomatic_singly,
    cyclomatic_in_batch,
    cyclomatic_in_parallel
)

package_path = pathlib.Path(cyclomatic.__file__).parent

# get the cyclomatic complexity of the whole file
result = cyclomatic_singly(str(package_path / 'cyclomatic.py'))
score_of_the_module = result.score

# get the cyclomatic complexity under the target directory
result = cyclomatic_in_batch(str(package_path))
file_names = list(result.keys())
corresponding_complexity_score = [i.score for i in list(result.values())]

# calculating in parallel would be much more efficient if there are many files
result = cyclomatic_in_parallel(str(package_path))

Introduction:

  • The cyclomatic complexity is equal to the num of decision point plus one. This package use two steps to calculate it:

    1. generates ast from the source code with the help of tree-sitter
    2. walks the ast and counts the num of decesion points
  • package structure:

    1. cyclomatic.ast is responsable for ast generation.
    2. cyclomatic.calculator is responsable for calculation of the cyclomatic complexity. every module under this package is a calculator for the target program language. Though it only supports python for now.

Concepts:

Cyclomatic complexity - Wikiwand

Control-flow graph - Wikiwand

Resources:

tree-sitter python binding: py-tree-sitter

tree-sitter python grammer: tree-sitter-python

About

A tool to calculate cyclomatic complexity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages