Skip to content

Commit ab9d7ac

Browse files
authored
Merge pull request #44 from satyam-seth-learnings/setup-black
Setup black
2 parents 04b1fbd + b267838 commit ab9d7ac

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

.vscode/setting.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll": "explicit"
5+
},
6+
"editor.rulers": [
7+
100
8+
],
9+
"[python]": {
10+
"editor.defaultFormatter": "ms-python.black-formatter"
11+
}
12+
}

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,30 @@
202202
```sh
203203
mypy .
204204
```
205+
206+
10. Setup black
207+
208+
- Install black package
209+
210+
```sh
211+
pip install black
212+
```
213+
214+
- Add installed black package to requirements file
215+
216+
```sh
217+
pip freeze | grep black >> requirements.txt
218+
```
219+
220+
- Add black config in `puproject.toml` file
221+
222+
```toml
223+
[tool.black]
224+
force-exclude = "/migrations/"
225+
```
226+
227+
- Fix formatting using black
228+
229+
```sh
230+
black .
231+
```

backend/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"django.contrib.sessions",
3838
"django.contrib.messages",
3939
"django.contrib.staticfiles",
40-
'rest_framework',
41-
'core',
40+
"rest_framework",
41+
"core",
4242
]
4343

4444
MIDDLEWARE = [

core/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Create your models here.
44

5+
56
class Student(models.Model):
67
"""Student Model"""
78

@@ -10,5 +11,5 @@ class Student(models.Model):
1011

1112
def __str__(self):
1213
"""Student string representation"""
13-
14-
return f"{self.first_name} {self.last_name}"
14+
15+
return f"{self.first_name} {self.last_name}"

core/tests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# Create your tests here.
66

7+
78
class StudentModelTest(TestCase):
89
def setUp(self):
910
self.student = Student.objects.create(
@@ -16,8 +17,8 @@ def test_student_creation(self):
1617

1718
self.assertEqual(self.student.first_name, "John")
1819
self.assertEqual(self.student.last_name, "Doe")
19-
20+
2021
def test_str_method(self):
2122
"""Test the __str__ method of the Student model."""
22-
23-
self.assertEqual(str(self.student), "John Doe")
23+
24+
self.assertEqual(str(self.student), "John Doe")

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
force-exclude = "/migrations/"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ coverage==7.9.2
44
mypy==1.17.0
55
django-stubs==5.2.2
66
djangorestframework-stubs==3.16.1
7+
black==25.1.0

0 commit comments

Comments
 (0)