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.6.tar.gz (25.0 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.6-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_code_audit-0.2.6.tar.gz
  • Upload date:
  • Size: 25.0 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.6.tar.gz
Algorithm Hash digest
SHA256 71903168b6cb6eecd899bc7a4cdcff96b50137bf1848f542a5d84c7ab110f972
MD5 c22fa024888a38958508bc78866154ff
BLAKE2b-256 96a2d14ecf33513a18acd652f2047fc42cebc02edb64b3e0bd9bed6a9b3419c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_code_audit-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ebf3b34c36d454c5fee92948681faae0d1b0a4e2b3f1f91ee179c777421056ab
MD5 1042a00628a113416d56a61519493859
BLAKE2b-256 d6aec2ee817fd76ef7cbc0504887451ad80aa4a142379eaf8cbf8c50cefdb354

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