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": True,  
    # If True, uses the default pylint configuration it's self
    # If False, you must specify a custom path in PYLINTRC_PATH

    "PYLINTRC_PATH": "",  
    # Path to a custom pylint configuration file. ex: '~/.pylintrc'
    # generate file like: pylint --generate-rcfile > ${HOME}/.pylintrc
    # Only used if DEFAULT_PYLINTRC is False

    "BASE_DIR": True,  
    # If True, generates per-author level reports relative to the project base directory
    # If False, uses full paths without truncation
}
  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. 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. Audit only files changed by a Git user

python manage.py code_audit --git-user RaviK

7.If you just want to use the currently configured Git username automatically:

python manage.py code_audit --git-user

8. 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.5.tar.gz (24.9 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.5-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_code_audit-0.2.5.tar.gz
  • Upload date:
  • Size: 24.9 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.5.tar.gz
Algorithm Hash digest
SHA256 fc5669ee34fdc601a17b4837e2ea01b066471809b355712b143f25b5b68b8d28
MD5 58f7f627fc8591dacd87e7fba0e5e7d4
BLAKE2b-256 2d9954ba58ef3b9dca6ebb56d7c6f78d68296cf561cdcf58aa2b6f6c3c90308a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_code_audit-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 83e7f365fd417c639f16f65c244d84da8a79337e4837cc1848afb74e4c8b1b04
MD5 87e57df8ba6179722412aff281129a1d
BLAKE2b-256 38f2e8b6d279a7ebc876c9de8afd8349f70bb233d9b08a08407de36def977bce

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