https://github.com/soda480/pybuilder-radon
A pybuilder plugin that checks the cyclomatic complexity of a project using radon.
https://github.com/soda480/pybuilder-radon
cyclomatic-complexity plugin pybuilder pybuilder-plugin python radon
Last synced: 3 months ago
JSON representation
A pybuilder plugin that checks the cyclomatic complexity of a project using radon.
- Host: GitHub
- URL: https://github.com/soda480/pybuilder-radon
- Owner: soda480
- License: apache-2.0
- Created: 2021-03-06T03:47:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-22T21:51:10.000Z (about 1 year ago)
- Last Synced: 2024-09-27T09:14:51.892Z (9 months ago)
- Topics: cyclomatic-complexity, plugin, pybuilder, pybuilder-plugin, python, radon
- Language: Python
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pybuilder-radon
[](https://github.com/soda480/pybuilder-radon/actions)
[](https://pybuilder.io/)
[](https://pypi.org/project/bandit/)
[](https://badge.fury.io/py/pybuilder-radon)
[](https://www.python.org/downloads/)A pybuilder plugin that checks the cyclomatic complexity of your project using `radon`. For more information about radon refer to the [radon pypi page](https://pypi.org/project/radon/).
To add this plugin into your pybuilder project, add the following line near the top of your build.py:
```python
use_plugin('pypi:pybuilder_radon')
```**NOTE** if you are using Pybuilder version `v0.11.x`, then specify the following version of the plugin:
```python
use_plugin('pypi:pybuilder_radon', '~=0.1.2')
```### cyclomatic complexity
Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. Cyclomatic complexity can be used to measure code complexity. The higher the complexity score the more complex the code, which typically translates to the code being more difficult to understand, maintain and to test. The number of the Cyclomatic complexity depends on how many different execution paths or control flow of your code can execute depending on various inputs. The metrics for Cyclomatic Complexity are:
Score | Complexity | Risk Type
-- | -- | --
1 to 10 | simple | not much risk
11 to 20 | complex | low risk
21 to 50 | too complex | medium risk, attention
more than 50 | very complex | unable to test, high riskRefer to [cyclomatic complexity](https://www.c-sharpcorner.com/article/code-metrics-cyclomatic-complexity/) for more information.
### Pybuilder radon properties
The pybuilder task `pyb radon` will use radon to to analyze your project and display the average cyclomatic complexity, verbose mode will display complexity of all classes, functions and methods analyzed. The following plugin properties are available to further configure the plugin's execution.
Name | Type | Default Value | Description
-- | -- | -- | --
radon_break_build_average_complexity_threshold | float | None | Fail build if overall average complexity is greater than the specified threshold
radon_break_build_complexity_threshold | float | None | Fail build if complexity of any class, function or method exceeds the specified thresholdThe plugin properties are set using `project.set_property`, for example setting the following properties, `pyb complexity` will fail if the average overall complexity score of the project exceeds `4` or if the complexity score of **any** class, method or function exceeds `10`:
```Python
project.set_property('radon_break_build_average_complexity_threshold', 4)
project.set_property('radon_break_build_complexity_threshold', 10)
```### Development
Clone the repository and ensure the latest version of Docker is installed on your development server.
Build the Docker image:
```sh
docker image build \
-t pybradon:latest .
```Run the Docker container:
```sh
docker container run \
--rm \
-it \
-v $PWD:/code \
pybradon:latest \
bash
```Execute the build:
```sh
pyb -X
```