Skip to content

Commit e61ac6d

Browse files
committed
add flake8-plugins to CI and fix linter warnings
1 parent 7fd0ef4 commit e61ac6d

47 files changed

Lines changed: 440 additions & 221 deletions

Some content is hidden

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

.flake8

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
[flake8]
22
max-line-length = 120
33

4-
ignore =
5-
VNE002
6-
VNE003
7-
W503
8-
94
exclude =
105
./.cache,
116
./.git,
@@ -20,4 +15,4 @@ exclude =
2015
./.vscode,
2116
*migrations*,
2217

23-
enable-extensions = print, VNE
18+
enable-extensions = print, VNE, B, A, C4, BLK

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ repos:
66
exclude: ^.*\b(migrations)\b.*$
77
language_version: python3
88
- repo: https://github.com/pycqa/flake8
9-
rev: 5.0.4
9+
rev: 6.1.0
1010
hooks:
1111
- id: flake8
12+
additional_dependencies:
13+
- flake8-print
14+
- flake8-variables-names
15+
- flake8-bugbear
16+
- flake8-builtins
17+
- flake8-comprehensions
18+
- flake8-broken-line
19+
- flake8-mutable

chats/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ProjectChat(BaseChat):
8585
created_at: A DateTimeField indicating date of creation.
8686
"""
8787

88-
id = models.PositiveIntegerField(primary_key=True, unique=True)
88+
id = models.PositiveIntegerField(primary_key=True, unique=True) # noqa A003 VNE003
8989
project = models.ForeignKey(
9090
Project, on_delete=models.CASCADE, related_name="project_chats"
9191
)
@@ -126,7 +126,7 @@ class DirectChat(BaseChat):
126126
get_users: returns list of users, who are in chat
127127
"""
128128

129-
id = models.CharField(primary_key=True, max_length=64)
129+
id = models.CharField(primary_key=True, max_length=64) # noqa A003 VNE003
130130
users = models.ManyToManyField(User, related_name="direct_chats")
131131

132132
def get_users(self):
@@ -287,7 +287,7 @@ class Meta:
287287

288288

289289
class FileToMessage(models.Model):
290-
file = models.OneToOneField(
290+
file = models.OneToOneField( # noqa VNE002
291291
UserFile,
292292
on_delete=models.CASCADE,
293293
related_name="file_to_message",

chats/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ async def create_file_to_message(
108108

109109
async def match_files_and_messages(file_urls, messages):
110110
for url in file_urls:
111-
file = await sync_to_async(UserFile.objects.get)(pk=url)
111+
user_file = await sync_to_async(UserFile.objects.get)(pk=url)
112112
# implicitly matches a file and a message
113113
await create_file_to_message(
114114
direct_message=messages["direct_message"],
115115
project_message=messages["project_message"],
116-
file=file,
116+
file=user_file,
117117
)
118118

119119

chats/websockets_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ class EventGroupType(str, Enum):
2727

2828
@dataclass(frozen=True)
2929
class Event:
30-
type: EventType
30+
type: EventType # noqa: A003, VNE003
3131
content: dict

core/management/commands/migrate_education.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Command(BaseCommand):
1212
"""
1313
Use: python manage.py migrate_education.
1414
"""
15+
1516
def handle(self, *args, **kwargs):
1617
self.stdout.write("Start manual migration ...")
1718
try:
@@ -22,9 +23,7 @@ def handle(self, *args, **kwargs):
2223
)
2324
)
2425
except Exception as e:
25-
self.stderr.write(
26-
self.style.ERROR(f"Migration failed: {str(e)}")
27-
)
26+
self.stderr.write(self.style.ERROR(f"Migration failed: {str(e)}"))
2827

2928

3029
@transaction.atomic
@@ -33,12 +32,16 @@ def migrate_organization_to_education() -> int:
3332
Migrate old field `organization` to new model `Education`.
3433
Returns count migrated users.
3534
"""
36-
users_with_irganization = CustomUser.objects.exclude(organization=None).exclude(organization="")
37-
UserEducation.objects.bulk_create([
38-
UserEducation(
39-
user=user,
40-
organization_name=user.organization,
41-
)
42-
for user in users_with_irganization
43-
])
35+
users_with_irganization = CustomUser.objects.exclude(organization=None).exclude(
36+
organization=""
37+
)
38+
UserEducation.objects.bulk_create(
39+
[
40+
UserEducation(
41+
user=user,
42+
organization_name=user.organization,
43+
)
44+
for user in users_with_irganization
45+
]
46+
)
4447
return users_with_irganization.count()

core/management/commands/migrate_old_to_new_fields_trigram.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ class Command(BaseCommand):
2121
$CREATE EXTENSION pg_trgm;
2222
Migrate old fields to new.
2323
"""
24+
2425
def handle(self, *args, **kwargs):
2526
self.stdout.write("Starting manual migrations...")
2627
try:
2728
start = time()
2829
migrate_old_to_new_fields_trigram()
2930
end = time()
30-
self.stdout.write(self.style.SUCCESS(
31-
f"Manual trigram migrations completed successfully, timing: {end - start}")
31+
self.stdout.write(
32+
self.style.SUCCESS(
33+
f"Manual trigram migrations completed successfully, timing: {end - start}"
34+
)
3235
)
3336
except Exception as e:
34-
self.stderr.write(self.style.ERROR(f"Manual trigram migrations failed: {str(e)}"))
37+
self.stderr.write(
38+
self.style.ERROR(f"Manual trigram migrations failed: {str(e)}")
39+
)
3540

3641

3742
@transaction.atomic
@@ -64,7 +69,10 @@ def migrate_old_to_new_fields_trigram() -> None:
6469

6570
# Migration `key_skills` -> `skills`.
6671
# (Only users who have not filled `skills`, but have filled in `key_skills`).
67-
if user.key_skills and not SkillToObject.objects.filter(object_id=user.id).exists():
72+
if (
73+
user.key_skills
74+
and not SkillToObject.objects.filter(object_id=user.id).exists()
75+
):
6876
for skill_name in user.key_skills.lower().split(","):
6977
if not skill_name:
7078
continue # Skipping empty lines
@@ -85,7 +93,10 @@ def migrate_old_to_new_fields_trigram() -> None:
8593

8694
# Boolean field is responsible for transferring data if both fields
8795
# were already there or were transferred = `True` (default value = `False`).
88-
if user.v2_speciality and SkillToObject.objects.filter(object_id=user.id).exists():
96+
if (
97+
user.v2_speciality
98+
and SkillToObject.objects.filter(object_id=user.id).exists()
99+
):
89100
user.dataset_migration_applied = True
90101

91102
user.save()

core/management/commands/reverse_migrate_education.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ def add_arguments(self, parser: CommandParser) -> None:
1717
parser.add_argument(
1818
"--confirm",
1919
action="store_true",
20-
help="Confirm delete Users educations from UserEducation model"
20+
help="Confirm delete Users educations from UserEducation model",
2121
)
2222

2323
def handle(self, *args, **kwargs):
2424
confirm = kwargs["confirm"]
25-
self.stdout.write(self.style.WARNING(
26-
"You are about to DELETE ALL INSTANCES in the UserEducation model."))
25+
self.stdout.write(
26+
self.style.WARNING(
27+
"You are about to DELETE ALL INSTANCES in the UserEducation model."
28+
)
29+
)
2730

2831
if not confirm:
2932
answer = input("Type 'yes' to continue, or 'no' to cancel: ").lower()
@@ -35,7 +38,9 @@ def handle(self, *args, **kwargs):
3538

3639
try:
3740
deleted_instances = delete_all_instances_usereducation()
38-
self.stdout.write(self.style.SUCCESS("Manual migrations completed successfully."))
41+
self.stdout.write(
42+
self.style.SUCCESS("Manual migrations completed successfully.")
43+
)
3944
self.stdout.write(self.style.SUCCESS(f"Deleted: {deleted_instances}"))
4045
except Exception as e:
4146
self.stderr.write(self.style.ERROR(f"Manual migrations failed: {str(e)}"))

core/management/commands/reverse_old_to_new_fields.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Command(BaseCommand):
1212
"""
1313
DO NOT USE IN PROD, ONLY DEBUG.
1414
"""
15+
1516
def add_arguments(self, parser):
1617
parser.add_argument(
1718
"--confirm",
@@ -38,7 +39,9 @@ def handle(self, *args, **options):
3839
self.stdout.write("Starting manual migrations...")
3940
try:
4041
reverse()
41-
self.stdout.write(self.style.SUCCESS("Manual migrations completed successfully."))
42+
self.stdout.write(
43+
self.style.SUCCESS("Manual migrations completed successfully.")
44+
)
4245
except Exception as e:
4346
self.stderr.write(self.style.ERROR(f"Manual migrations failed: {str(e)}"))
4447

@@ -50,4 +53,6 @@ def reverse():
5053
user.dataset_migration_applied = False
5154
user.v2_speciality = None
5255
user.save()
53-
SkillToObject.objects.filter(content_type=ContentType.objects.get_for_model(CustomUser)).delete()
56+
SkillToObject.objects.filter(
57+
content_type=ContentType.objects.get_for_model(CustomUser)
58+
).delete()

core/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Meta:
2929

3030

3131
class SkillToObjectSerializer(serializers.ModelSerializer):
32-
id = serializers.IntegerField(source="skill.id")
32+
id = serializers.IntegerField(source="skill.id") # noqa A003 VNE003
3333
name = serializers.CharField(source="skill.name")
3434
category = SkillCategorySerializer(source="skill.category")
3535

0 commit comments

Comments
 (0)