forked from petercable/grpc_requests
-
Notifications
You must be signed in to change notification settings - Fork 5
/
complexity.sh
37 lines (30 loc) · 1.3 KB
/
complexity.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# This script generated a simplified complexity report for a given series of
# Python files, or for non-__init__.py files in the src/grpc_requests directory
# if no arguments are provided.
# Radon is used to generate the average Cyclomatic Complexity, Maintainability
# Index, and Halstead difficulty and effort metrics for the given files.
# This report is meant as a quick guide to possible weaknesses in the codebase
# and not meant as a make or break test for work being undertaken.
# Cyclomatic Complexity - Lower is better
# Maintainability Index - Higher is better
# Halstead difficulty - Lower is better
# Halstead effort - Lower is better
if ! command -v radon &> /dev/null; then
echo "radon is not installed. Please make sure you have installed the requirements-dev.txt."
exit 1
fi
if [ "$#" -eq 0 ]; then
TARGETS=$(find src/grpc_requests/ -name "*.py" ! -name "__init__.py")
else
TARGETS="${*}"
fi
for TARGET in $TARGETS; do
echo "Report for $TARGET"
echo "===================="
radon cc "$TARGET" -n F -s --total-average | grep "Average" | sed "s|Average complexity|Cyclomatic Complexity|"
radon mi "$TARGET" -s | sed "s|$TARGET|Maintainability Index|"
radon hal "$TARGET" | grep -E "difficulty|effort" | sed "s/^[ \t]*//"
echo "===================="
echo
done