Merged in feature/DAIP2-2112-implement-pre-commit-hooks--- (pull request #924)

Feature/DAIP2-2112 implement pre commit hooks

* Add pre-commit hooks for local code quality checks

Adds .pre-commit-config.yaml with file hygiene hooks (trailing-whitespace,
end-of-file-fixer, check-yaml/json, check-merge-conflict, check-added-large-files)
plus local hooks for black and mypy on pre-commit and pytest on pre-push.
Includes setup documentation and adds pre-commit to dev dependencies.
Auto-fixed trailing whitespace and missing newlines caught by the new hooks.

* Add sample pre-commit hook for testing purposes

* Add test file for pre-commit hook validation

* Remove test file for pre-commit hook validation

* Merged DEV into feature/DAIP2-2112-implement-pre-commit-hooks---

* Merged DEV into feature/DAIP2-2112-implement-pre-commit-hooks---

* Move to documentation


Approved-by: Katon Minhas
This commit is contained in:
Sujit Deokar
2026-03-25 14:49:14 +00:00
committed by Katon Minhas
parent 2be11faafc
commit 829682d07c
12 changed files with 117 additions and 22 deletions
+39
View File
@@ -0,0 +1,39 @@
default_language_version:
python: python3.12
default_install_hook_types: [pre-commit, pre-push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: check-added-large-files
args: ['--maxkb=500']
- repo: local
hooks:
- id: black
name: black (formatter)
entry: uv run black src/
language: system
pass_filenames: false
types: [python]
- id: mypy
name: mypy (type check)
entry: uv run mypy src/
language: system
pass_filenames: false
types: [python]
- id: pytest
name: pytest (unit tests)
entry: uv run pytest src/tests/
language: system
pass_filenames: false
stages: [pre-push]
+62
View File
@@ -0,0 +1,62 @@
# Pre-commit Local Setup (uv)
## What is pre-commit?
`pre-commit` runs checks before each commit (for example: formatting and file sanity checks).
This repository uses pre-commit locally only. Bitbucket Pipelines does not run pre-commit.
## Install and set up locally (with uv)
1. Install `uv` (if not installed):
```bash
# Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
```
2. Install all dependencies (including pre-commit):
```bash
uv sync --group dev
```
3. Install git hooks in this repo:
```bash
uv run pre-commit install
```
## How it works
When you run `git commit`, pre-commit automatically runs these checks on your staged files:
| Hook | What it does | Auto-fix? |
|---|---|---|
| `trailing-whitespace` | Removes spaces at end of lines | Yes |
| `end-of-file-fixer` | Ensures files end with a newline | Yes |
| `check-yaml` | Validates YAML syntax | Manual fix |
| `check-json` | Validates JSON syntax | Manual fix |
| `check-merge-conflict` | Detects `<<<<<<<` conflict markers | Manual fix |
| `check-added-large-files` | Blocks files larger than 500KB | Manual fix |
- **Pass** -> commit goes through
- **Fail (auto-fix)** -> commit blocked, files fixed, re-stage and commit again
- **Fail (manual fix)** -> commit blocked, fix the error, re-stage and commit again
## Common commands
Run on all files:
```bash
uv run pre-commit run --all-files
```
Run on staged files (happens automatically on commit):
```bash
uv run pre-commit run
```
@@ -1 +0,0 @@
@@ -1 +0,0 @@
-1
View File
@@ -1 +0,0 @@
@@ -1 +0,0 @@
@@ -1 +0,0 @@
@@ -1 +0,0 @@