Skip to content

A tutorial showcasing python code quality tools: Radon and Xenon.

Notifications You must be signed in to change notification settings

aboyalejandro/code-quality-check

Repository files navigation

👨🏻‍💻 Code Quality Checker with Radon and Xenon

This repository uses Radon and Xenon to analyze code complexity and maintainability. These tools help ensure your code is readable, maintainable, and within specified complexity limits.

✅ Features

  • Radon for cyclomatic complexity (CC) and maintainability index (MI).
  • Xenon for enforcing complexity thresholds.
  • Runs checks both locally and in CI/CD pipelines with GitHub Actions.

👇 For context on how these metrics work, you can read this blog post:

👀 How to fix your Python code with Radon & Xenon before it's too late

Setup Instructions

1. 👨🏻‍💻 Running Locally

Requirements: python >= 3.9 & pip

  • Install Dependencies:
pip install radon xenon
  • Cyclomatic Complexity (CC) Check:
radon cc ./ -s
  • Maintainability Index (MI) Check:
radon mi ./
  • Xenon Complexity Enforcement:
xenon --max-absolute B ./

This is how the result should look like:

check_result

2. 📦 Using Docker

Requirements: Docker Desktop

docker build -t code-quality-checker .
docker run -t code-quality-checker

3. 🔂 GitHub Actions Integration

Requirements: Github repo

This repository includes a GitHub Actions workflow that automatically checks the code quality when a pull request is opened or updated on the main branch.

GitHub Actions Workflow .github/workflows/code-quality.yml

Once the checks are completed, you'll see the results directly in the GitHub pull request under the "Checks" tab.

There's a sample pull request to check the outcome.

🔥 Fixing the code with CursorAI

Cursor is an AI-powered code editor that can help you fix your code by adding comments, suggestions, and even whole functions and classes.

You can paste the code into Cursor and it will give you a summary of the code and suggestions on how to improve it. There are some screenshots on this repo for you to check how it works.

  • Get tips, learnings and tricks for your Data career!
  • Join the Substack newsletter to get similar content to this one and more to improve your Data career!

About

A tutorial showcasing python code quality tools: Radon and Xenon.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published