|
56 | 56 |
|
57 | 57 | 4. Setup Django app |
58 | 58 |
|
59 | | -- Start Django app |
| 59 | +- Start Django app |
60 | 60 |
|
61 | 61 | ```sh |
62 | 62 | python3 manage.py startapp <app-name> |
|
87 | 87 |
|
88 | 88 | 6. Run unit tests |
89 | 89 |
|
90 | | - ```sh |
91 | | - python3 manage.py test |
92 | | - ``` |
| 90 | +```sh |
| 91 | +python3 manage.py test |
| 92 | +``` |
93 | 93 |
|
94 | 94 | 7. Setup DRF(Django Rest Framework) |
95 | 95 |
|
|
102 | 102 | - Add installed DRF package to requirements file |
103 | 103 |
|
104 | 104 | ```sh |
105 | | - pip freeze | grep djangorestframework >> requirements.txt |
| 105 | + pip freeze | grep djangorestframework >> requirements.txt |
106 | 106 | ``` |
107 | 107 |
|
108 | 108 | - Install DRF app in project setting |
|
125 | 125 | - Add installed Coverage package to requirements file |
126 | 126 |
|
127 | 127 | ```sh |
128 | | - pip freeze | grep coverage >> requirements.txt |
| 128 | + pip freeze | grep coverage >> requirements.txt |
129 | 129 | ``` |
130 | 130 |
|
131 | 131 | - Run tests with coverage |
|
157 | 157 | - Add installed mypy package to requirements file |
158 | 158 |
|
159 | 159 | ```sh |
160 | | - pip freeze | grep mypy== >> requirements.txt |
| 160 | + pip freeze | grep mypy== >> requirements.txt |
161 | 161 | ``` |
162 | 162 |
|
163 | 163 | - Install django stubs package |
|
169 | 169 | - Add installed django stubs package to requirements file |
170 | 170 |
|
171 | 171 | ```sh |
172 | | - pip freeze | grep django-stubs== >> requirements.txt |
| 172 | + pip freeze | grep django-stubs== >> requirements.txt |
173 | 173 | ``` |
174 | 174 |
|
175 | 175 | - Install drf stubs package |
|
181 | 181 | - Add installed drf stubs package to requirements file |
182 | 182 |
|
183 | 183 | ```sh |
184 | | - pip freeze | grep djangorestframework-stubs >> requirements.txt |
| 184 | + pip freeze | grep djangorestframework-stubs >> requirements.txt |
185 | 185 | ``` |
186 | 186 |
|
187 | 187 | - Add MyPy config file `mypy.init` |
|
214 | 214 | - Add installed black package to requirements file |
215 | 215 |
|
216 | 216 | ```sh |
217 | | - pip freeze | grep black >> requirements.txt |
| 217 | + pip freeze | grep black >> requirements.txt |
218 | 218 | ``` |
219 | 219 |
|
220 | 220 | - Add black config in `puproject.toml` file |
|
226 | 226 |
|
227 | 227 | - Note:- black official [doc](https://black.readthedocs.io/en/stable/getting_started.html) |
228 | 228 |
|
| 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 | + |
229 | 241 | - Fix formatting using black |
230 | 242 |
|
231 | 243 | ```sh |
232 | 244 | black . |
233 | 245 | ``` |
| 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 | + ``` |
0 commit comments