Skip to main content

A Django app for auditing Python code using pylint

Project description

Django Code Audit

Django Code Audit is a reusable Django app that automates Python code quality checks using Pylint, stores audit reports in the database, and provides an admin interface to view both latest and historical scores.


🚀 Features

  • Run Pylint checks on Django apps, modules, or files
  • Store audit reports and pylint scores in the database
  • View latest score and all past runs in Django Admin
  • Generate HTML reports for detailed review
  • Supports project-specific .pylintrc configuration
  • Easy integration with existing Django projects

⚡ Installation

  1. Install the package via pip:
pip install django-code-audit
  1. Add the app to INSTALLED_APPS in your Django project’s settings.py:
INSTALLED_APPS = [
    ...
    'code_audit',
    ...
]


CODE_AUDIT = {
    "DEFAULT_PYLINTRC": "/path/to/.pylintrc",
    "BASE_DIR": True,  # enable per-author level reports
}
  1. Run migrations to create necessary database tables:
python manage.py migrate code_audit

4. Usage Instructions (via Django Admin)

Follow these steps to create and run a code audit report efficiently:

Step 1: Login

🔑 Login to your Django Admin dashboard.

Step 2: Navigate to Code Audit Reports

📂 In the admin sidebar, click on Code Audit Reports.

Step 3: Add a New Report

➕ Click Add Code Audit Report.

Step 4: Fill Mandatory Fields

Fill in the following fields:

  • Module Name – The Django app or module you want to audit.
  • File Name – Python file or app to audit.
  • Report Path – Directory where the HTML report will be stored (e.g., /tmp/).

Make sure all mandatory fields are filled; otherwise, the report cannot be generated.

Step 5: Save the Report

💾 Click Save to create the audit report entry.

Step 6: Run the Audit

▶️ After saving, click Run Report to generate the code audit using Pylint.

Step 7: View the Report

👀 Once the audit is complete, click View Report to open the HTML report in your browser.

Step 8: Check Scores

📊 In the admin interface, you can:

  • View the latest pylint score for this report.
  • Browse all historical scores for each run.

4.File Author Level Reports

Django Code Audit supports generating per-author reports by filtering files that explicitly declare a maintainer or author inside the file itself.

Author Declaration Format

To be included in an author-specific audit, each file must contain a docstring with one of the following patterns (case-insensitive):

"""
current maintainer: ravi
"""

or

"""
author: ravi
"""

The system will scan all .py files in the given app/module and include only those files where the declared author matches the File Author field specified in the report.

Example

chat.py:

"""
current maintainer: ravi
"""
def send_message():
    return "ok"

utils.py:

"""
author: john
"""

If you create a Code Audit Report with:

File Author = ravi

✅ chat.py will be included in the audit.

❌ utils.py will be excluded.

5. Updated Feature: Run Audits via Django Management Command

Alongside the Django Admin interface, you can now run code audits directly from the command line with the code_audit management command.

1.🔧 Usage

python manage.py code_audit

2. Options

1.Audit the whole project (all apps):

python manage.py code_audit

2. Audit a specific file:

python manage.py code_audit --file myapp/views.py

3. Audit a specific Django app:

python manage.py code_audit --file myapp

4. Audit a specific directory:

python manage.py code_audit --file backend/utils/

5. Audit only files maintained by a specific author:

python manage.py code_audit --file_author ravi

6. Customize minimum pass score (default = 8.0):

python manage.py code_audit --file myapp/models.py --fail_under 6.5

Tip: You can customize Pylint rules by providing a .pylintrc file in your project.

## 🛠️ Configuration

You can customize the behavior of Django Code Audit by adding the following settings to your settings.py:

By default, the app uses the project’s .pylintrc if available.

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

django_code_audit-0.2.4.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

django_code_audit-0.2.4-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file django_code_audit-0.2.4.tar.gz.

File metadata

  • Download URL: django_code_audit-0.2.4.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for django_code_audit-0.2.4.tar.gz
Algorithm Hash digest
SHA256 be9660014976f26c011a7b604c3ebade4be71fa8c78fb8ad349918476867244f
MD5 4704535e39f4cea52ae9200a4c1fbc12
BLAKE2b-256 070c30c3053080b416e7bc50d9239cd8551faa7400bb8c8d7665cd3e520ba5b4

See more details on using hashes here.

File details

Details for the file django_code_audit-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_code_audit-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8d0f338e4f21b9619abe78479c0d14590431f84623ebabb1ee63641534a51cd4
MD5 b7e5f905ab9b5853bff0a9777cd7abdd
BLAKE2b-256 61320296724f1ef1c0751e25d89e6cedcab49899e33755bb4d53848392f9e4a4

See more details on using hashes here.

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