CRAP score per function for Python source files
Project description
crap4py
Python port of Uncle Bob's crap4go and crap4clj — CRAP score per function for Python source files.
CRAP (Change Risk Anti-Pattern) = CC² × (1 − coverage)³ + CC — a per-function metric combining cyclomatic complexity and branch coverage. Higher means riskier to change. Conventional threshold: 30.
Install
# Run without installing
uvx crap4py
# Persistent install
uv tool install crap4py
Usage
crap4py src/ --lcov lcov.info
Generate lcov.info with coverage.py:
pytest --cov --cov-branch --cov-report=lcov:lcov.info
Output
CRAP Report
Function | Module | CC | Cov% | CRAP
----------------------------+-------------------------------+----+-------+-----
_sort_key | src/crap4py/_crap.py | 3 | 33.3 | 9.9
main | src/crap4py/__main__.py | 2 | 100.0 | 2.0
Options
| Flag | Description |
|---|---|
--lcov PATH |
LCOV branch-coverage file (required) |
--max-crap N |
Exit non-zero if any function exceeds N (CI gate) |
--max-workers N |
Parallel workers for large codebases |
--fragment TEXT |
Only analyse files whose path contains TEXT |
CI gate
crap4py src/ --lcov lcov.info --max-crap 30
Exits non-zero if any function's CRAP score exceeds the threshold. N/A functions (no coverage data) never trip the gate.
How it works
- Complexity — cyclomatic complexity from Python's
astperdef/async def - Coverage — branch coverage from LCOV
BRDArecords intersected with each function's line range - Skips —
.gitignore-ignored paths and test files (test_*.py,*_test.py) are excluded automatically
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crap4py-0.1.1.tar.gz.
File metadata
- Download URL: crap4py-0.1.1.tar.gz
- Upload date:
- Size: 216.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd5f4ecc1613490515fd229f6958fad06cf448497e6c99a612712fce965272cc
|
|
| MD5 |
61942fc910278c138c9cf8600adaf3bb
|
|
| BLAKE2b-256 |
48a8dc6cc095b29eeba5c37ab04605819782f5f5e080cde38c97063bbeff1780
|
Provenance
The following attestation bundles were made for crap4py-0.1.1.tar.gz:
Publisher:
release.yml on gabadi/crap4py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crap4py-0.1.1.tar.gz -
Subject digest:
bd5f4ecc1613490515fd229f6958fad06cf448497e6c99a612712fce965272cc - Sigstore transparency entry: 1934517876
- Sigstore integration time:
-
Permalink:
gabadi/crap4py@42b8960a8b349f79cad42dc27bf98ffcfe53e096 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gabadi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@42b8960a8b349f79cad42dc27bf98ffcfe53e096 -
Trigger Event:
push
-
Statement type:
File details
Details for the file crap4py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: crap4py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cdaf28dccfc88313c95f1bacdf99fe19a39efbe9855d981352bb02a7a17a90c
|
|
| MD5 |
5ca94de8e3aa1fc6f1abc21c630a0d69
|
|
| BLAKE2b-256 |
03c6eda37aa64d84a3e22a5c9242e5696a83750c7737dc99d43bce97dfc53e53
|
Provenance
The following attestation bundles were made for crap4py-0.1.1-py3-none-any.whl:
Publisher:
release.yml on gabadi/crap4py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crap4py-0.1.1-py3-none-any.whl -
Subject digest:
2cdaf28dccfc88313c95f1bacdf99fe19a39efbe9855d981352bb02a7a17a90c - Sigstore transparency entry: 1934517899
- Sigstore integration time:
-
Permalink:
gabadi/crap4py@42b8960a8b349f79cad42dc27bf98ffcfe53e096 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gabadi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@42b8960a8b349f79cad42dc27bf98ffcfe53e096 -
Trigger Event:
push
-
Statement type: