Skip to main content

Python Code Quality Analysis Tool - feed the results from 11 CQ CQ straight into an LLM.

Project description

CQ - Python Code Quality Analysis Tool

Python Code Quality Analysis Tool - feed the results from 11 CQ tools straight into an LLM. The primary workflow is:

cq check -o llm   # get the single most critical defect as markdown

Feed that output to an LLM, apply the fix, repeat until the score is clean.

Install

uv tool install python-code-quality

# or
git pull https://github.com/rhiza-fr/py-cq.git
cd py-cq
uv tool install .

Tools

CQ runs these tools in parallel:

Priority Tool Measures
1 compileall Syntax errors
2 bandit Security vulnerabilities
3 ruff Lint / style
4 ty Type errors
5 pytest Test pass rate
6 coverage Test coverage
7 radon cc Cyclomatic complexity
8 radon mi Maintainability index
9 radon hal Halstead volume / bug estimate
10 vulture Dead code
11 interrogate Docstring coverage

Usage

# LLM workflow: get the top defect as markdown (primary use case)
cq check -o llm

# Rich table with all metrics (default, also saves .cq.json)
cq check

# Numeric score only — useful in CI or scripts
cq check -o score

# Full JSON output
cq check -o json

# Explicit path (defaults to current directory)
cq check path/to/project/
cq check path/to/file.py

# Run sequentially (1 worker) instead of in parallel
cq check --workers 1

# Clear cached results before running
cq check --clear-cache

# Save table output to a custom file
cq check --out-file custom_results.json

# Show effective tool configuration (thresholds, enabled/disabled status)
cq config
cq config path/to/project/

Output

> cq check .
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┓
 Tool                  Time                     Metric  Score    Status   
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━┩
 compile              0.42s                    compile  1.000    OK       
 bandit               0.56s                   security  1.000    OK       
 ruff                 0.17s                       lint  1.000    OK       
 ty                   0.33s                 type_check  1.000    OK       
 pytest               0.91s                      tests  1.000    OK       
 coverage             1.26s                   coverage  0.910    OK       
 radon cc             0.32s                 simplicity  0.982    OK       
 radon mi             0.38s            maintainability  0.869    OK       
 radon hal            0.30s              file_bug_free  0.928    OK       
 radon hal                              file_smallness  0.851    OK       
 radon hal                          functions_bug_free  0.913    OK       
 radon hal                         functions_smallness  0.724    OK       
 vulture              0.32s                  dead_code  1.000    OK       
 interrogate          0.36s               doc_coverage  1.000    OK       
                                                 Score  0.965             
└──────────────────┴──────────┴───────────────────────────┴─────────┴──────────┘
> cq check . -o score
0.9662730667181059 # this is designed to approach but not reach 1.0
> cq check . -o llm
`data/problems/travelling_salesman/ts_bad.py:21`**F841**: Local variable `unused_variable` is assigned to but never used

18:     min_dist = float("inf")
19:     nearest_city = None
20:     for city in cities:
21:         unused_variable = 67
22:         dist = calc_dist(current_city, city)
23:         if dist < min_dist:
24:             min_dist = dist
25:             nearest_city = city

Please fix only this issue. After fixing, run `cq check . -o llm` to verify.

Configuration

Add a [tool.cq] section to your project's pyproject.toml:

[tool.cq]
# Skip tools that are slow or not relevant to your project
disable = ["coverage", "interrogate"]

# Override warning/error thresholds per tool
[tool.cq.thresholds.coverage]
warning = 0.9
error = 0.7

Tool IDs match the keys in config/tools.yaml: compilation, bandit, ruff, ty, pytest, coverage, complexity, maintainability, halstead, vulture, interrogate.

LLM workflow

-o llm selects the single worst-scoring tool and formats its top defect as concise markdown. The LLM fixes it, you re-run cq check -o llm, and repeat until all tools are green. Priority order ensures the most critical category (security, type errors, failing tests) is fixed before cosmetic ones.

Tools

Many thanks to all the wonderful maintainers of :

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_code_quality-0.1.6.tar.gz (61.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_code_quality-0.1.6-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

Details for the file python_code_quality-0.1.6.tar.gz.

File metadata

  • Download URL: python_code_quality-0.1.6.tar.gz
  • Upload date:
  • Size: 61.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_code_quality-0.1.6.tar.gz
Algorithm Hash digest
SHA256 21621b378fd8711b2a8a51e513d14cfc1779e8730c5d8f6a88152f7d2e47f890
MD5 f6b0e98d705b09f6387d5acd10218369
BLAKE2b-256 3fe19977a08f92f440b55e55f3fb51ac5eff9718f72488d34a4141012d3f8c6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_code_quality-0.1.6.tar.gz:

Publisher: python-publish.yml on rhiza-fr/py-cq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_code_quality-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for python_code_quality-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e586d93d4cedbfe58b0a37a4b95893879f5a9ce6b0efa2a8a9392798c24e80ee
MD5 2a8158e7fcd1799064fe4d4603312c3a
BLAKE2b-256 67dcfca902303823e3bcedd81c168d3a494bf80916b65e97c426a5210d6f5c44

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_code_quality-0.1.6-py3-none-any.whl:

Publisher: python-publish.yml on rhiza-fr/py-cq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page