Skip to content

Add pre-commit package for django app#867

Open
VadimKovalenkoSNF wants to merge 28 commits intomainfrom
pre-commit-package-for-django-app
Open

Add pre-commit package for django app#867
VadimKovalenkoSNF wants to merge 28 commits intomainfrom
pre-commit-package-for-django-app

Conversation

@VadimKovalenkoSNF
Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF commented Jan 19, 2026

Add Dockerized pre-commit hooks for Python lint/format

  • Add ruff, isort, black to Django image and align flake8 config (88 chars, E203/W503).
  • Switch pre-commit hooks to run via docker compose run django with repo mount and proper config paths.
  • Document Docker build requirement for hooks and updated lint workflow.

Add .vscode/example-settings.json for VSCode / Cursor.


Ruff, Black, and isort play different roles:

  • Black: single, opinionated formatter for consistent layout (spacing/line breaks/quotes), no lint logic.
  • Ruff: fast linter with many flake8-style rules and auto-fixes (unused imports/vars, style cleanups); acts as a lightweight guard before CI.
  • isort: deterministic import ordering. Ruff can sort imports, but we keep isort to match our CI chain and avoid config drift.

We keep all three so formatting, linting, and import ordering stay consistent locally and in CI; flake8 remains as a final parity check.

@VadimKovalenkoSNF VadimKovalenkoSNF self-assigned this Jan 19, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Docker-backed pre-commit hooks for Ruff, isort, Black, and Flake8 limited to src/django, plus local lint/tool configs, dev tooling requirements, VS Code example settings, .gitignore tweak, and README documentation for setup. (49 words)

Changes

Cohort / File(s) Summary
Pre-commit config
\.pre-commit-config.yaml
Adds four Docker-run hooks (ruff-docker, isort-docker, black-docker, flake8-docker) that mount the repo at /workspace, use --entrypoint and --no-deps, and target files matching ^src/django/.*\.py$.
Tool configuration
pyproject.toml, src/django/.flake8
Adds Black/isort/Ruff settings in pyproject.toml (line-length 88, py38 target, src/excludes, Ruff ignore rules) and a Flake8 config at src/django/.flake8 (excludes, max-line-length 88, extend-ignore E203,W503).
Dev dependencies
src/django/requirements.txt
Adds pinned dev tooling: black==26.1.0, isort==7.0.0, ruff==0.14.14.
Editor settings & ignore
.vscode/example-settings.json, .gitignore
Adds example VS Code workspace settings for Ruff/Black (formatter, format-on-save, Python path) and adjusts .gitignore to ignore .vscode/* while allowing .vscode/example-settings.json.
Documentation
README.md
Adds "Linting & git hooks for Django app" documentation, hot-reload anchor normalization, new sections for running e2e/Playwright tests, and nav/anchor updates to include the new sections.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant PC as Pre-commit
    participant Dock as Docker
    participant Repo as Repository (/workspace)
    participant Tool as Formatter/Linter

    Dev->>PC: git commit (triggers hooks)
    PC->>Dock: start container (mount Repo at /workspace)
    Dock->>Repo: read changed files matching ^src/django/.*\.py$
    Dock->>Tool: invoke tool via --entrypoint (use /workspace configs)
    Tool-->>Dock: apply fixes / return status
    Dock-->>PC: return results
    PC-->>Dev: allow or block commit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add pre-commit package for django app' directly and accurately reflects the main objective of adding pre-commit hooks for the Django application, which is the primary focus of the changeset.
Description check ✅ Passed The description provides comprehensive context about the Dockerized pre-commit hooks implementation, explains the rationale for each tool (Black, Ruff, isort, flake8), documents configuration changes, and covers all major changes in the PR including VSCode settings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pre-commit-package-for-django-app

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@README.md`:
- Line 249: Clarify the pre-commit installation context around the existing `pip
install pre-commit` and `pre-commit install` instructions and the note that
hooks run in Docker: explicitly state whether developers should install
pre-commit locally (system/virtualenv) for local pre-commit execution, or
whether the repository relies on Docker to run hooks (or both), and update the
README around the `pip install pre-commit` and `pre-commit install` lines and
the "hooks run in Docker" sentence to one concise statement that explains the
recommended developer workflow (e.g., install pre-commit locally for immediate
checks and note that CI/Docker also runs the hooks), plus an optional command
for running hooks inside the Docker image if applicable.
- Around line 247-258: Add a prerequisite step to the README stating that the
Docker image must be built before running pre-commit hooks that execute inside
the django container; specifically, before describing the "Local first wall" /
editor setup, add a short note telling developers to run the project Docker
build (e.g., docker compose build or the repository's docker build command) so
that the pre-commit invocation (pre-commit run --all-files) and hooks defined in
.pre-commit-config.yaml that run inside the django container will not fail.
- Line 250: Update the README to clarify the .venv virtual environment: state
whether .venv is created automatically by the project setup or must be created
manually, add explicit steps to create it (e.g., python -m venv .venv) and how
to activate it, and explain how editor settings should point to .venv's Python
interpreter and formatter (Black/Ruff) when using local venv vs Docker; also
mention interaction with the existing ./scripts/start_local_dev flow (that it
uses Docker and does not create .venv) so contributors know when to create .venv
locally.
🧹 Nitpick comments (1)
README.md (1)

255-255: Fix extra leading space.

There's an extra space before "Example settings file" in the bullet point.

Minor formatting fix
--  Example settings file: `.vscode/example-settings.json`. Copy to `.vscode/settings.json` to apply.
+- Example settings file: `.vscode/example-settings.json`. Copy to `.vscode/settings.json` to apply.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@README.md`:
- Around line 12-24: The TOC entries contain fragment identifiers that don't
match the rendered heading IDs (causing markdownlint MD051); update the link
fragments to exactly match the generated anchors for the headings (for example
"Local Development" and "Running e2e (Playwright) and integration tests") or add
explicit HTML anchors directly above those headings so the fragments resolve;
ensure any special characters/emojis in headings (e.g., "Hot Reloading 🔥",
"Scripts 🧰", "Tools ⚒️") are either removed or encoded in the TOC links to
match the renderer's ID generation and then verify the updated refs in the
README TOC (the visible heading texts are the unique identifiers to match).

vlad-shapik
vlad-shapik previously approved these changes Feb 2, 2026
Copy link
Contributor

@vlad-shapik vlad-shapik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@README.md`:
- Around line 267-268: Update the README so the referenced settings file is
consistent: change the reference to `.vscode/settings.json` in the sentence
about enabling format on save and Ruff fixes to point to the example file
`.vscode/example-settings.json` (or explicitly state "see
`.vscode/example-settings.json` and copy it to `.vscode/settings.json`") so it
matches the following line that instructs copying the example file; update the
mention in the same paragraph that lists Black, `source.fixAll`,
`source.fixAll.ruff`, and virtualenv binary paths to reference the example file
name `.vscode/example-settings.json`.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants