Skip to content

Commit 3743ec3

Browse files
authored
Merge pull request #47 from satyam-seth-learnings/setup-isort
Setup isort
2 parents 33cc1e1 + ea2a074 commit 3743ec3

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

.vscode/setting.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"editor.formatOnSave": true,
33
"editor.codeActionsOnSave": {
4-
"source.fixAll": "explicit"
4+
"source.fixAll": "explicit",
5+
"source.organizeImports": "explicit"
56
},
67
"editor.rulers": [
78
100
89
],
910
"[python]": {
1011
"editor.defaultFormatter": "ms-python.black-formatter"
11-
}
12+
},
13+
"isort.args":[
14+
"--profile",
15+
"black",
16+
"--skip-glob",
17+
"*/migrations/*"
18+
]
1219
}

README.md

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
4. Setup Django app
5858

59-
- Start Django app
59+
- Start Django app
6060

6161
```sh
6262
python3 manage.py startapp <app-name>
@@ -87,9 +87,9 @@
8787

8888
6. Run unit tests
8989

90-
```sh
91-
python3 manage.py test
92-
```
90+
```sh
91+
python3 manage.py test
92+
```
9393

9494
7. Setup DRF(Django Rest Framework)
9595

@@ -102,7 +102,7 @@
102102
- Add installed DRF package to requirements file
103103

104104
```sh
105-
pip freeze | grep djangorestframework >> requirements.txt
105+
pip freeze | grep djangorestframework >> requirements.txt
106106
```
107107

108108
- Install DRF app in project setting
@@ -125,7 +125,7 @@
125125
- Add installed Coverage package to requirements file
126126

127127
```sh
128-
pip freeze | grep coverage >> requirements.txt
128+
pip freeze | grep coverage >> requirements.txt
129129
```
130130

131131
- Run tests with coverage
@@ -157,7 +157,7 @@
157157
- Add installed mypy package to requirements file
158158

159159
```sh
160-
pip freeze | grep mypy== >> requirements.txt
160+
pip freeze | grep mypy== >> requirements.txt
161161
```
162162

163163
- Install django stubs package
@@ -169,7 +169,7 @@
169169
- Add installed django stubs package to requirements file
170170

171171
```sh
172-
pip freeze | grep django-stubs== >> requirements.txt
172+
pip freeze | grep django-stubs== >> requirements.txt
173173
```
174174

175175
- Install drf stubs package
@@ -181,7 +181,7 @@
181181
- Add installed drf stubs package to requirements file
182182

183183
```sh
184-
pip freeze | grep djangorestframework-stubs >> requirements.txt
184+
pip freeze | grep djangorestframework-stubs >> requirements.txt
185185
```
186186

187187
- Add MyPy config file `mypy.init`
@@ -214,7 +214,7 @@
214214
- Add installed black package to requirements file
215215

216216
```sh
217-
pip freeze | grep black >> requirements.txt
217+
pip freeze | grep black >> requirements.txt
218218
```
219219

220220
- Add black config in `puproject.toml` file
@@ -226,8 +226,62 @@
226226

227227
- Note:- black official [doc](https://black.readthedocs.io/en/stable/getting_started.html)
228228

229+
- Install VS Code Black extension [`ms-python.black-formatter`](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter)
230+
231+
- Configure VS Code python default formatter to black in `.vscode/settings.json` file
232+
233+
```json
234+
{
235+
"[python]": {
236+
"editor.defaultFormatter": "ms-python.black-formatter"
237+
}
238+
}
239+
```
240+
229241
- Fix formatting using black
230242

231243
```sh
232244
black .
233245
```
246+
247+
11. Setup isort
248+
249+
- Install isort package
250+
251+
```sh
252+
pip install isort
253+
```
254+
255+
- Add installed isort package to requirements file
256+
257+
```sh
258+
pip freeze | grep isort >> requirements.txt
259+
```
260+
261+
- Add MyPy config file `isort.cfg`
262+
263+
```cfg
264+
[settings]
265+
profile = black
266+
verbose = true
267+
skip_glob = **/migrations/*.py
268+
```
269+
270+
- Install VS Code Black extension [`ms-python.isort`](https://marketplace.visualstudio.com/items?itemName=ms-python.isort)
271+
272+
- Configure VS Code to organize python imports using isort in `.vscode/settings.json`
273+
274+
```json
275+
{
276+
"editor.codeActionsOnSave": {
277+
"source.organizeImports": "explicit"
278+
},
279+
"isort.args": ["--profile", "black", "--skip-glob", "*/migrations/*"]
280+
}
281+
```
282+
283+
- Sort imports using isort
284+
285+
```sh
286+
isort .
287+
```

core/tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from datetime import date
2+
13
from django.test import TestCase
4+
25
from .models import Student
3-
from datetime import date
46

57
# Create your tests here.
68

isort.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[settings]
2+
profile = black
3+
verbose = true
4+
skip_glob = **/migrations/*.py

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ mypy==1.17.0
55
django-stubs==5.2.2
66
djangorestframework-stubs==3.16.1
77
black==25.1.0
8+
isort==6.0.1

0 commit comments

Comments
 (0)