Skip to main content

Python-native GazeCRAP analysis engine

Project description

gaze-py

gaze-py is a Python-native port of gaze, the GazeCRAP analysis engine. It detects observable side effects in Python functions using AST-only static analysis (no code execution, no imports of analysed modules), classifies each effect as contractual or incidental using a five-signal confidence engine, and computes CRAP and GazeCRAP scores to surface functions that are both complex and under-tested. The output is schema-compatible with the Go gaze implementation.

Requirements

  • Python 3.11+

Installation

# Run without installing (recommended for one-off use)
uvx --from gaze-py gazepy --help

# Permanent install
uv tool install gaze-py

# Or with pip
pip install gaze-py

Basic usage

# Analyse a source directory (CRAP will be null — no coverage provided)
gazepy analyze src/

# JSON output (default)
gazepy analyze src/ --format=json

# Human-readable text output (one line per function)
gazepy analyze src/ --format=text

# CRAP scoring — auto-runs pytest for coverage
gazepy crap src/

# CRAP scoring with a pre-generated coverage report
gazepy crap src/ --coverprofile coverage.json

# Scaffold OpenCode agent and command files into .opencode/
gazepy init

CRAP scoring with gazepy crap

CRAP scoring requires line coverage data. The crap command can collect coverage automatically by running pytest, or accept a pre-generated coverage.py JSON report:

# Auto-run pytest and collect coverage (requires pytest-cov)
gazepy crap src/

# Use a pre-generated coverage report (recommended in CI to avoid a double test run)
pytest --cov=your_package --cov-report=json:coverage.json
gazepy crap src/ --coverprofile coverage.json

When coverage is provided, the line_coverage and crap fields are populated in the output. When omitted, those fields are null (not 0.0) — null means "not measured", not "zero coverage". GazeCRAP and quadrant fields remain null until O1 ships.

The analyze command detects side effects only — it does not compute CRAP scores. Use gazepy crap for CRAP scoring.

Understanding the output

Each function in the output includes:

Field Description
side_effects List of detected observable side effects with type, tier, and classification
complexity McCabe cyclomatic complexity
line_coverage Fraction of lines covered (0.0–1.0), or null if not provided
crap CRAP score (complexity² × (1 − coverage)³ + complexity), or null
gaze_crap GazeCRAP score using contract coverage, or null (O1 deferred)
quadrant Q1–Q4 classification based on CRAP and GazeCRAP, or null
fix_strategy Recommended action: add_tests, decompose_and_test, or decompose
contract_coverage Fraction of contractual effects covered by tests, or null

The summary section includes recommended_actions — up to 20 functions sorted by priority (add_tests → decompose_and_test → decompose) that exceed the CRAP threshold.

Current limitations

  • GazeCRAP scoring deferred: The O1 quality/assertion mapping engine (which computes contract_coverage from test assertions) is not yet implemented. As a result, gaze_crap, contract_coverage, and quadrant are always null in this release. The fix_strategy field uses CRAP-only rules (Q3/add_assertions is unreachable without O1).
  • Effect confidence range deferred: The effect_confidence_range field is present in the output schema (as null) but not yet computed.

Releasing

Releases are published to PyPI via GitHub Actions using trusted publishing (OIDC — no stored secrets).

One-time setup (already done)

  1. PyPI trusted publisher: pypi.org → gaze-py project → Settings → Publishing → publisher configured for mpeter/gaze-py, workflow release.yml, environment pypi.
  2. GitHub environment: repo Settings → Environments → pypi (optional approval gate).

Releasing a new version

  1. Bump version in pyproject.toml and __version__ in src/gaze_py/__init__.py in a PR. Merge to main.
  2. Go to GitHub Actions → Release → Run workflow.
  3. Enter the tag matching the version (e.g. v0.3.0).
  4. Approve the pypi environment gate if configured.
  5. The workflow validates, tags, builds, and publishes automatically.

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

gaze_py-0.2.0.tar.gz (405.8 kB view details)

Uploaded Source

Built Distribution

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

gaze_py-0.2.0-py3-none-any.whl (58.2 kB view details)

Uploaded Python 3

File details

Details for the file gaze_py-0.2.0.tar.gz.

File metadata

  • Download URL: gaze_py-0.2.0.tar.gz
  • Upload date:
  • Size: 405.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for gaze_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 60a09ec818279da38c2919c07e90bc320283146fa95f626f19e9a22ae2d20522
MD5 ef7a4770d19c212c19edb40fc444079a
BLAKE2b-256 ed546a507e335d4d5df95f7d9e7fecb96f6cfcc7f6be1cac6ff4ffbd476b6877

See more details on using hashes here.

Provenance

The following attestation bundles were made for gaze_py-0.2.0.tar.gz:

Publisher: release.yml on mpeter/gaze-py

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

File details

Details for the file gaze_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gaze_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 58.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for gaze_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bb6bfb1f0848a754aa188d1bd08a4faaddafee98772c01c846cca5fb552b506
MD5 d98117c22e3f1eac52e1e66e56223a84
BLAKE2b-256 580ed9be39295d32f51e842a09381a0deaca2e26e38da39793d6271e03480e2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gaze_py-0.2.0-py3-none-any.whl:

Publisher: release.yml on mpeter/gaze-py

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