Skip to content

Commit d6d29aa

Browse files
authored
Merge pull request #51 from satyam-seth-learnings/setup-pre-commit
Setup pre commit
2 parents 3941390 + 163ab1c commit d6d29aa

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed

.pre-commit-config.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
9+
- repo: https://github.com/psf/black
10+
rev: 25.1.0
11+
hooks:
12+
- id: black
13+
name: black to format python code
14+
15+
- repo: https://github.com/pycqa/isort
16+
rev: 6.0.1
17+
hooks:
18+
- id: isort
19+
name: isort to sort imports
20+
args:
21+
- --profile
22+
- black
23+
- --verbose
24+
- --skip-glob
25+
- "**/migrations/*.py"
26+
27+
- repo: https://github.com/pre-commit/mirrors-mypy
28+
rev: v1.17.0
29+
hooks:
30+
- id: mypy
31+
name: mypy to check types
32+
additional_dependencies:
33+
- django-jazzmin==3.0.1
34+
- django-stubs==5.2.2
35+
- djangorestframework==3.16.0
36+
- djangorestframework-stubs==3.16.1
37+
args: ["--config-file=mypy.ini"]
38+
39+
- repo: https://github.com/pycqa/pylint
40+
rev: v3.3.7
41+
hooks:
42+
- id: pylint
43+
name: pylint to check code quality
44+
entry: pylint
45+
language: python
46+
types: [python]
47+
args: ["--rcfile=.pylintrc"]
48+
additional_dependencies:
49+
- django-jazzmin==3.0.1
50+
- Django==5.2.4
51+
- pylint-django==2.6.1
52+
- djangorestframework==3.16.0

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fail-under=10
4646
#from-stdin=
4747

4848
# Files or directories to be skipped. They should be base names, not paths.
49-
ignore=CVS
49+
ignore=CVS
5050

5151
# Add files or directories matching the regular expressions patterns to the
5252
# ignore-list. The regex matches against paths and can be in Posix or Windows

.vscode/setting.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
"--skip-glob",
1717
"*/migrations/*"
1818
]
19-
}
19+
}

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,108 @@ python3 manage.py test
968968
```
969969

970970
- Install VS Code pylint extension [`ms-python.pylint`](https://marketplace.visualstudio.com/items?itemName=ms-python.pylint)
971+
972+
13. Setup pre commit
973+
974+
- Install pre commit package
975+
976+
```sh
977+
pip install pre_commit
978+
```
979+
980+
- Add installed pre commit package to requirements file
981+
982+
```sh
983+
pip freeze | grep pre_commit >> requirements.txt
984+
```
985+
986+
- Add pre commit config file `.pre-commit-config.yaml`
987+
988+
```yaml
989+
repos:
990+
- repo: https://github.com/pre-commit/pre-commit-hooks
991+
rev: v2.3.0
992+
hooks:
993+
- id: check-yaml
994+
- id: end-of-file-fixer
995+
- id: trailing-whitespace
996+
```
997+
998+
- Add pre commit config for black in `.pre-commit-config.yaml`
999+
1000+
```yaml
1001+
repos:
1002+
- repo: https://github.com/psf/black
1003+
rev: 25.1.0
1004+
hooks:
1005+
- id: black
1006+
name: black to format python code
1007+
```
1008+
1009+
- Add pre commit config for isort in `.pre-commit-config.yaml`
1010+
1011+
```yaml
1012+
repos:
1013+
- repo: https://github.com/pycqa/isort
1014+
rev: 6.0.1
1015+
hooks:
1016+
- id: isort
1017+
name: isort to sort imports
1018+
args:
1019+
- --profile
1020+
- black
1021+
- --verbose
1022+
- --skip-glob
1023+
- "**/migrations/*.py"
1024+
```
1025+
1026+
- Add pre commit config for mypy in `.pre-commit-config.yaml`
1027+
1028+
```yaml
1029+
repos:
1030+
- repo: https://github.com/pre-commit/mirrors-mypy
1031+
rev: v1.17.0
1032+
hooks:
1033+
- id: mypy
1034+
name: mypy to check types
1035+
additional_dependencies:
1036+
- django-jazzmin==3.0.1
1037+
- django-stubs==5.2.2
1038+
- djangorestframework==3.16.0
1039+
- djangorestframework-stubs==3.16.1
1040+
args: ["--config-file=mypy.ini"]
1041+
```
1042+
1043+
- Add pre commit config for pylint in `.pre-commit-config.yaml`
1044+
1045+
```yaml
1046+
repos:
1047+
- repo: https://github.com/pycqa/pylint
1048+
rev: v3.3.7
1049+
hooks:
1050+
- id: pylint
1051+
name: pylint to check code quality
1052+
entry: pylint
1053+
language: python
1054+
types: [python]
1055+
args: ["--rcfile=.pylintrc"]
1056+
additional_dependencies:
1057+
- django-jazzmin==3.0.1
1058+
- Django==5.2.4
1059+
- pylint-django==2.6.1
1060+
- djangorestframework==3.16.0
1061+
```
1062+
1063+
- Install pre commit dependencies
1064+
1065+
```sh
1066+
pre-commit install
1067+
```
1068+
1069+
- Run pre-commit hooks manually
1070+
1071+
```sh
1072+
pre-commit run --all-files
1073+
```
1074+
1075+
- Note:- pre commit official [doc](https://pre-commit.com/)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ black==25.1.0
88
isort==6.0.1
99
pylint==3.3.7
1010
pylint-django==2.6.1
11+
pre_commit==4.2.0

0 commit comments

Comments
 (0)