Skip to content

Commit 5e5f307

Browse files
committed
test: validate Ruff configuration and pre-commit integration
- Test formatting compatibility with existing codebase - Verify import sorting functionality and Django-aware organization - Validate pre-commit hooks execute correctly in containerized environment - Confirm migration files are properly excluded from formatting - Fix 31 import sorting issues and reformat 25 files during testing - All Ruff functionality working as expected with proper exclusion patterns
1 parent f86a05e commit 5e5f307

45 files changed

Lines changed: 623 additions & 740 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.kiro/specs/black-to-ruff-migration/tasks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@
3737
- Ensure consistency with Ruff usage throughout documentation
3838
- _Requirements: 3.3, 3.4, 3.5_
3939

40-
- [ ] 4. Enhance Ruff configuration for complete migration
40+
- [-] 4. Enhance Ruff configuration for complete migration
4141
- [ ] 4.1 Complete pyproject.toml Ruff configuration
4242

4343
- Add exclude patterns for migrations and other directories
4444
- Add [tool.ruff.isort] section with Django-aware import sorting (known-django, section-order, combine-as-imports)
4545
- _Requirements: 1.1, 1.2, 1.3, 1.4, 1.5_
4646

47-
- [ ] 5. Test Ruff configuration
48-
- [ ] 5.1 Validate formatting compatibility
47+
- [x] 5. Test Ruff configuration
48+
- [x] 5.1 Validate formatting compatibility
4949

5050
- Run `docker compose run --rm app uv run ruff format --check .` on existing codebase to verify minimal changes
5151
- Compare Ruff output with current formatting to ensure consistency
5252
- Verify migrations are excluded from formatting (configured in pyproject.toml)
5353
- _Requirements: 1.1, 1.3, 1.4_
5454

55-
- [ ] 5.2 Validate import sorting
55+
- [x] 5.2 Validate import sorting
5656

5757
- Run `docker compose run --rm app uv run ruff check --select I .` to test import sorting functionality
5858
- Verify Django-aware section organization is maintained
5959
- Test that import sorting follows isort-compatible behavior using `docker compose run --rm app uv run ruff check --select I --fix .`
6060
- _Requirements: 1.2, 1.5_
6161

62-
- [ ] 5.3 Test pre-commit integration
62+
- [x] 5.3 Test pre-commit integration
6363
- Run `docker compose run --rm app pre-commit run --all-files` to test pre-commit hooks in containerized environment
6464
- Test that Ruff hooks execute correctly and maintain exclusion patterns
6565
- Verify pre-commit performance improvement with Ruff using `docker compose run --rm app pre-commit run ruff-format ruff-check`

accounts/urls.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from django.conf.urls import include
22
from django.urls import path
33

4-
from .views import (
5-
AccountHomeView,
6-
LoginView,
7-
SignupView,
8-
)
4+
from .views import AccountHomeView
5+
from .views import LoginView
6+
from .views import SignupView
97

108
urlpatterns = [
119
path("", AccountHomeView.as_view(), name="account_home"),

accounts/views.py

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
from allauth.account.views import (
2-
LoginView as AllAuthLoginView,
3-
SignupView as AllAuthSignupView,
4-
)
1+
from allauth.account.views import LoginView as AllAuthLoginView
2+
from allauth.account.views import SignupView as AllAuthSignupView
53
from django.contrib import messages
64
from django.contrib.auth.decorators import login_required
7-
from django.shortcuts import (
8-
get_object_or_404,
9-
redirect,
10-
render,
11-
)
5+
from django.shortcuts import get_object_or_404
6+
from django.shortcuts import redirect
7+
from django.shortcuts import render
128
from django.urls import reverse
139
from django.utils import timezone
1410
from django.utils.decorators import method_decorator
1511
from django.views.generic import TemplateView
1612
from meta.views import MetadataMixin
1713

18-
from coderdojochi.forms import (
19-
CDCModelForm,
20-
GuardianForm,
21-
MentorForm,
22-
)
23-
from coderdojochi.models import (
24-
Guardian,
25-
MeetingOrder,
26-
Mentor,
27-
MentorOrder,
28-
Order,
29-
Student,
30-
)
14+
from coderdojochi.forms import CDCModelForm
15+
from coderdojochi.forms import GuardianForm
16+
from coderdojochi.forms import MentorForm
17+
from coderdojochi.models import Guardian
18+
from coderdojochi.models import MeetingOrder
19+
from coderdojochi.models import Mentor
20+
from coderdojochi.models import MentorOrder
21+
from coderdojochi.models import Order
22+
from coderdojochi.models import Student
3123

3224

3325
class SignupView(MetadataMixin, AllAuthSignupView):
@@ -64,13 +56,12 @@ def dispatch(self, *args, **kwargs):
6456
if not self.request.user.role:
6557
if "next" in self.request.GET:
6658
return redirect(
67-
f"{reverse('welcome')}?next={self.request.GET['next']}"
68-
)
69-
else:
70-
messages.warning(
71-
self.request,
72-
"Tell us a little about yourself before going on account.",
59+
f"{reverse('welcome')}?next={self.request.GET['next']}",
7360
)
61+
messages.warning(
62+
self.request,
63+
"Tell us a little about yourself before going on account.",
64+
)
7465
return redirect("welcome")
7566

7667
return super().dispatch(*args, **kwargs)
@@ -102,15 +93,17 @@ def get_context_data_for_mentor(self):
10293
)
10394

10495
upcoming_sessions = orders.filter(
105-
is_active=True, session__start_date__gte=timezone.now()
96+
is_active=True,
97+
session__start_date__gte=timezone.now(),
10698
).order_by("session__start_date")
10799

108100
past_sessions = orders.filter(
109-
is_active=True, session__start_date__lte=timezone.now()
101+
is_active=True,
102+
session__start_date__lte=timezone.now(),
110103
).order_by("session__start_date")
111104

112105
meeting_orders = MeetingOrder.objects.select_related().filter(
113-
mentor=mentor
106+
mentor=mentor,
114107
)
115108

116109
upcoming_meetings = meeting_orders.filter(
@@ -206,11 +199,15 @@ def post_for_mentor(self, **kwargs):
206199
mentor = context["mentor"]
207200

208201
form = MentorForm(
209-
self.request.POST, self.request.FILES, instance=mentor
202+
self.request.POST,
203+
self.request.FILES,
204+
instance=mentor,
210205
)
211206

212207
user_form = CDCModelForm(
213-
self.request.POST, self.request.FILES, instance=mentor.user
208+
self.request.POST,
209+
self.request.FILES,
210+
instance=mentor.user,
214211
)
215212

216213
if form.is_valid() and user_form.is_valid():
@@ -220,10 +217,10 @@ def post_for_mentor(self, **kwargs):
220217

221218
return redirect("account_home")
222219

223-
else:
224-
messages.error(
225-
self.request, "There was an error. Please try again."
226-
)
220+
messages.error(
221+
self.request,
222+
"There was an error. Please try again.",
223+
)
227224

228225
context["form"] = form
229226
context["user_form"] = user_form
@@ -246,10 +243,10 @@ def post_for_guardian(self, **kwargs):
246243

247244
return redirect("account_home")
248245

249-
else:
250-
messages.error(
251-
self.request, "There was an error. Please try again."
252-
)
246+
messages.error(
247+
self.request,
248+
"There was an error. Please try again.",
249+
)
253250

254251
context["form"] = form
255252
context["user_form"] = user_form

coderdojochi/admin.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,32 @@
33

44
from django.contrib import admin
55
from django.contrib.auth import get_user_model
6-
from django.db.models import (
7-
Case,
8-
Count,
9-
When,
10-
)
6+
from django.db.models import Case
7+
from django.db.models import Count
8+
from django.db.models import When
119
from django.urls import reverse
1210
from django.utils import timezone
1311
from django.utils.html import format_html
1412
from import_export import resources
15-
from import_export.admin import (
16-
ImportExportActionModelAdmin,
17-
ImportExportMixin,
18-
)
13+
from import_export.admin import ImportExportActionModelAdmin
14+
from import_export.admin import ImportExportMixin
1915
from import_export.fields import Field
2016

21-
from .models import (
22-
Course,
23-
Donation,
24-
Equipment,
25-
EquipmentType,
26-
Guardian,
27-
Location,
28-
Meeting,
29-
MeetingOrder,
30-
MeetingType,
31-
Mentor,
32-
MentorOrder,
33-
Order,
34-
RaceEthnicity,
35-
Session,
36-
Student,
37-
)
17+
from .models import Course
18+
from .models import Donation
19+
from .models import Equipment
20+
from .models import EquipmentType
21+
from .models import Guardian
22+
from .models import Location
23+
from .models import Meeting
24+
from .models import MeetingOrder
25+
from .models import MeetingType
26+
from .models import Mentor
27+
from .models import MentorOrder
28+
from .models import Order
29+
from .models import RaceEthnicity
30+
from .models import Session
31+
from .models import Student
3832

3933
User = get_user_model()
4034

@@ -94,7 +88,7 @@ def role_link(self, obj):
9488
query=obj.email,
9589
role=obj.role,
9690
)
97-
elif obj.role == "guardian":
91+
if obj.role == "guardian":
9892
return format_html(
9993
'<a href="{url}?q={query}">{role}</a>',
10094
url=reverse("admin:coderdojochi_guardian_changelist"),
@@ -173,9 +167,9 @@ def get_queryset(self, request):
173167
When(
174168
mentororder__is_active=True,
175169
then=1,
176-
)
177-
)
178-
)
170+
),
171+
),
172+
),
179173
)
180174
return qs
181175

@@ -194,7 +188,8 @@ def user_link(self, obj):
194188
return format_html(
195189
'<a href="{url}">{user}</a>',
196190
url=reverse(
197-
"admin:coderdojochi_cdcuser_change", args=(obj.user.id,)
191+
"admin:coderdojochi_cdcuser_change",
192+
args=(obj.user.id,),
198193
),
199194
user=obj.user,
200195
)
@@ -304,15 +299,16 @@ def get_queryset(self, request):
304299
qs = super(GuardianAdmin, self).get_queryset(request)
305300
qs = qs.select_related()
306301
qs = qs.annotate(student_count=Count("student")).order_by(
307-
"-student_count"
302+
"-student_count",
308303
)
309304
return qs
310305

311306
def user_link(self, obj):
312307
return format_html(
313308
'<a href="{url}">{name}</a>',
314309
url=reverse(
315-
"admin:coderdojochi_cdcuser_change", args=(obj.user.id,)
310+
"admin:coderdojochi_cdcuser_change",
311+
args=(obj.user.id,),
316312
),
317313
name=obj.user,
318314
)
@@ -386,7 +382,7 @@ def import_obj(self, obj, data, dry_run):
386382
obj.guardian = Guardian.objects.get(user__email=guardian_email)
387383
except Guardian.DoesNotExist:
388384
raise ImportError(
389-
f"guardian with email {guardian_email} not found"
385+
f"guardian with email {guardian_email} not found",
390386
)
391387

392388
if not dry_run:
@@ -466,17 +462,18 @@ def get_queryset(self, request):
466462
When(
467463
order__is_active=True,
468464
then=1,
469-
)
470-
)
471-
)
465+
),
466+
),
467+
),
472468
)
473469
return qs
474470

475471
def guardian_link(self, obj):
476472
return format_html(
477473
'<a href="{url}">{name}</a>',
478474
url=reverse(
479-
"admin:coderdojochi_guardian_change", args=(obj.guardian.id,)
475+
"admin:coderdojochi_guardian_change",
476+
args=(obj.guardian.id,),
480477
),
481478
name=obj.guardian.full_name,
482479
)
@@ -623,7 +620,7 @@ class SessionAdmin(ImportExportMixin, ImportExportActionModelAdmin):
623620
"cost",
624621
"minimum_cost",
625622
"maximum_cost",
626-
)
623+
),
627624
},
628625
),
629626
(
@@ -672,7 +669,8 @@ def mentor_count_link(self, obj):
672669
url=reverse("admin:coderdojochi_mentororder_changelist"),
673670
query=obj.id,
674671
count=MentorOrder.objects.filter(
675-
session__id=obj.id, is_active=True
672+
session__id=obj.id,
673+
is_active=True,
676674
).count(),
677675
)
678676

@@ -761,7 +759,8 @@ def get_student_link(self, obj):
761759
return format_html(
762760
'<a href="{url}">{student}</a>',
763761
url=reverse(
764-
"admin:coderdojochi_student_change", args=(obj.student.id,)
762+
"admin:coderdojochi_student_change",
763+
args=(obj.student.id,),
765764
),
766765
student=obj.student,
767766
)
@@ -772,7 +771,8 @@ def get_guardian_link(self, obj):
772771
return format_html(
773772
'<a href="{url}">{guardian}</a>',
774773
url=reverse(
775-
"admin:coderdojochi_guardian_change", args=(obj.guardian.id,)
774+
"admin:coderdojochi_guardian_change",
775+
args=(obj.guardian.id,),
776776
),
777777
guardian=obj.guardian,
778778
)

0 commit comments

Comments
 (0)