Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ruff to ci #2051

Merged
merged 61 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9262be2
Initial attempt at ruff
richardebeling Oct 2, 2023
94a5a62
Progress
richardebeling Oct 9, 2023
8a56e8b
prohibit FIXME, TODO and XXX
Kakadus Oct 23, 2023
ab8b453
add zip strict parameter
Kakadus Oct 23, 2023
c911e90
import Callable from collections.abc
Kakadus Oct 23, 2023
5b46b3d
add ignores in settings
Kakadus Oct 23, 2023
ee949d0
add __all__
Kakadus Oct 23, 2023
d47105b
add stacklevel to warning, when top level code is executed twice
Kakadus Oct 23, 2023
6db57f3
add ruff ignores to pylint ignores
Kakadus Oct 23, 2023
39662a3
add some more rules
Kakadus Oct 30, 2023
dee96bf
add DJ checks
Kakadus Oct 30, 2023
c747b28
improve comments (fixup!)
Kakadus Nov 13, 2023
fdcbe48
ruff formatter
Kakadus Nov 13, 2023
aa6d58e
enable "free" tests
Kakadus Nov 13, 2023
5dd6441
replace pylint disables with ruff
Kakadus Nov 13, 2023
037041c
enable and (auto) fix set|list|map literal
Kakadus Nov 13, 2023
fbfa113
enable and (auto) fix implicit string concat
Kakadus Nov 13, 2023
587e99e
enable and (auto) fix unnecessary start in range
Kakadus Nov 13, 2023
61b5a78
enable and (auto) fix exception parentheses
Kakadus Nov 13, 2023
8446461
enable and (auto) fix unnecessary assignment
Kakadus Nov 13, 2023
c0a8502
enable COMpatible COM
Kakadus Nov 13, 2023
5830d4b
enable and fix unspecific ignore
Kakadus Nov 13, 2023
333889e
enable and fix string join
Kakadus Nov 13, 2023
22d4a79
enable and fix list comprehensions
Kakadus Nov 13, 2023
3173077
enable some pylint rules
Kakadus Nov 20, 2023
07770ca
rerun ci
Kakadus Nov 20, 2023
002736a
attr defined mypy ignore
Kakadus Nov 20, 2023
6aecca3
Fix spelling and grammar
Kakadus Dec 24, 2023
afaf098
enable PL, but keep invalid-name
Kakadus Dec 29, 2023
3c06cf8
enable PERF203 and BLE instead of broad-exception-caught
Kakadus Dec 29, 2023
9e88552
add pylint disable (why?!)
Kakadus Dec 29, 2023
b1b969e
change warning stacklevel to 3
Kakadus Dec 29, 2023
f6eb6ab
Merge remote-tracking branch 'upstream/main' into ruff
Kakadus Dec 29, 2023
d73931c
don't break github
Kakadus Jan 29, 2024
b6bf08b
don't break github 2
Kakadus Jan 29, 2024
feda4b1
don't break github 3
Kakadus Jan 29, 2024
6e978e1
don't break github 4
Kakadus Jan 29, 2024
b819c0e
Revert "don't break github 4"
Kakadus Jan 29, 2024
6596072
Revert "don't break github 3"
Kakadus Jan 29, 2024
1d8763c
Revert "don't break github 2"
Kakadus Jan 29, 2024
84a0712
bump ruff
Kakadus Jan 29, 2024
6203ce7
Merge branch 'main' into ruff
Kakadus Jan 29, 2024
22507ee
fix strict last unstrict zip (oops)
Kakadus Jan 29, 2024
c787d4b
add comment and don't break github?
Kakadus Feb 12, 2024
8037532
add comment and don't break github? again!
Kakadus Feb 12, 2024
b292520
Update pyproject.toml
Kakadus Feb 26, 2024
49290e4
Use correct weekday range
Kakadus Feb 26, 2024
f9f74c8
change unaddressed rule comment
Kakadus Feb 26, 2024
ea5e4d2
Merge remote-tracking branch 'upstream' into ruff
Kakadus Feb 26, 2024
ea14cce
fix errors introduced in latest changes
Kakadus Feb 26, 2024
5baa043
run ruff first and then pylint. Also do this with manage.py
Kakadus Feb 26, 2024
9a8e1ce
adapt test accordingly
Kakadus Feb 26, 2024
a4edc17
update ruff to latest and migrate settings
Kakadus Feb 26, 2024
cb34395
Merge remote-tracking branch 'upstream/main' into ruff
Kakadus Feb 26, 2024
2e9518c
do not print in commands, use stdout instead!
Kakadus Mar 4, 2024
0a8a056
Merge remote-tracking branch 'upstream/main' into ruff
Kakadus Apr 8, 2024
2a9ccf1
update ruff
Kakadus Apr 8, 2024
8656a54
Merge remote-tracking branch 'upstream/main' into ruff
Kakadus Apr 8, 2024
84a9b1d
Merge remote-tracking branch 'upstream/main' into ruff
Kakadus Apr 8, 2024
cceca4c
lint enrollment_preprocessor
Kakadus Apr 8, 2024
aa4da6b
sort imports
Kakadus Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ jobs:
- name: Setup python
uses: ./.github/setup_python

- name: Run linter
- name: Run pylint
run: pylint evap -j 0

- name: Run ruff
run: ruff .


formatter:
runs-on: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions evap/contributor/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_managers_only(self):
)
formset = InlineContributionFormset(instance=evaluation, form_kwargs={"evaluation": evaluation})

expected = set([questionnaire])
expected = {questionnaire}
self.assertEqual(expected, set(formset.forms[0].fields["questionnaires"].queryset))
self.assertEqual(expected, set(formset.forms[1].fields["questionnaires"].queryset))

Expand All @@ -79,7 +79,7 @@ def test_managers_only(self):
)
formset = InlineContributionFormset(instance=evaluation, form_kwargs={"evaluation": evaluation})

expected = set([questionnaire, questionnaire_managers_only])
expected = {questionnaire, questionnaire_managers_only}
self.assertEqual(expected, set(formset.forms[0].fields["questionnaires"].queryset))
self.assertEqual(expected, set(formset.forms[1].fields["questionnaires"].queryset))

Expand Down
8 changes: 3 additions & 5 deletions evap/evaluation/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from collections.abc import Callable
from functools import wraps
from typing import Callable

from django.contrib.auth.backends import ModelBackend
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -28,8 +28,7 @@
return None

try:
user = UserProfile.objects.get(login_key=key)
return user
return UserProfile.objects.get(login_key=key)
except UserProfile.DoesNotExist:
return None

Expand Down Expand Up @@ -144,12 +143,11 @@
return []

def create_user(self, claims):
user = self.UserModel.objects.create(
return self.UserModel.objects.create(

Check warning on line 146 in evap/evaluation/auth.py

View check run for this annotation

Codecov / codecov/patch

evap/evaluation/auth.py#L146

Added line #L146 was not covered by tests
email=claims.get("email"),
first_name_given=claims.get("given_name", ""),
last_name=claims.get("family_name", ""),
)
return user

def update_user(self, user, claims):
if not user.first_name_given:
Expand Down
14 changes: 7 additions & 7 deletions evap/evaluation/management/commands/anonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def anonymize_users(self, first_names, last_names):
if len(first_names) * len(last_names) < len(user_profiles) * 1.5:
self.stdout.write(
"Warning: There are few example names compared to all that real data to be anonymized. "
+ "Consider adding more data to the first_names.txt and last_names.txt files in the anonymize_data "
+ "folder."
"Consider adding more data to the first_names.txt and last_names.txt files in the anonymize_data "
"folder."
)

while len(fake_usernames) < len(user_profiles):
Expand All @@ -111,7 +111,7 @@ def anonymize_users(self, first_names, last_names):

# Actually replace all the real user data
self.stdout.write("Replacing email addresses and login keys with fake ones...")
for user, name in zip(user_profiles, fake_usernames):
for user, name in zip(user_profiles, fake_usernames, strict=True):
if user.email and user.email.split("@")[0] in Command.ignore_email_usernames:
continue
user.first_name_given = name[0]
Expand Down Expand Up @@ -161,7 +161,7 @@ def anonymize_courses(self):
# Shuffle public courses' names in order to decouple them from the results.
# Also, assign public courses' names to private ones as their names may be confidential.
self.stdout.write("Shuffling course names...")
public_names = list(set(map(lambda c: (c.name_de, c.name_en), public_courses)))
public_names = list({(c.name_de, c.name_en) for c in public_courses})
random.shuffle(public_names)

for i, course in enumerate(courses):
Expand All @@ -188,7 +188,7 @@ def anonymize_evaluations(self):

self.stdout.write("Shuffling evaluation names...")
named_evaluations = (evaluation for evaluation in evaluations if evaluation.name_de and evaluation.name_en)
names = list(set(map(lambda c: (c.name_de, c.name_en), named_evaluations)))
names = list({(c.name_de, c.name_en) for c in named_evaluations})
random.shuffle(names)

for i, evaluation in enumerate(evaluations):
Expand Down Expand Up @@ -244,7 +244,7 @@ def anonymize_answers(self, lorem_ipsum):
for question, counters in counters_per_question.items():
original_sum = sum(counter.count for counter in counters)

missing_values = set(CHOICES[question.type].values).difference(set(c.answer for c in counters))
missing_values = set(CHOICES[question.type].values).difference({c.answer for c in counters})
missing_values.discard(NO_ANSWER) # don't add NO_ANSWER counter if it didn't exist before
for value in missing_values:
counters.append(
Expand All @@ -259,7 +259,7 @@ def anonymize_answers(self, lorem_ipsum):
index = random.randint(0, len(generated_counts) - 1) # nosec
generated_counts[index] += to_add

for counter, generated_count in zip(counters, generated_counts):
for counter, generated_count in zip(counters, generated_counts, strict=True):
assert generated_count >= 0
counter.count = generated_count

Expand Down
14 changes: 5 additions & 9 deletions evap/evaluation/management/commands/send_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ def get_sorted_evaluation_url_tuples_with_urgent_review() -> list[tuple[Evaluati
for evaluation in Evaluation.objects.filter(state=Evaluation.State.EVALUATED)
if evaluation.textanswer_review_state == Evaluation.TextAnswerReviewState.REVIEW_URGENT
]
evaluation_url_tuples = sorted(
evaluation_url_tuples, key=lambda evaluation_url_tuple: evaluation_url_tuple[0].full_name
)
return evaluation_url_tuples
return sorted(evaluation_url_tuples, key=lambda evaluation_url_tuple: evaluation_url_tuple[0].full_name)


@log_exceptions
Expand All @@ -43,11 +40,10 @@ def handle(self, *args, **options):

@staticmethod
def send_student_reminders():
check_dates = []

# Collect end-dates of evaluations whose participants need to be reminded today.
for number_of_days in settings.REMIND_X_DAYS_AHEAD_OF_END_DATE:
check_dates.append(datetime.date.today() + datetime.timedelta(days=number_of_days))
check_dates = [
datetime.date.today() + datetime.timedelta(days=number_of_days)
for number_of_days in settings.REMIND_X_DAYS_AHEAD_OF_END_DATE
]

recipients = set()
for evaluation in Evaluation.objects.filter(
Expand Down
4 changes: 2 additions & 2 deletions evap/evaluation/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='course',
unique_together=set([('semester', 'degree', 'name_de'), ('semester', 'degree', 'name_en')]),
unique_together={('semester', 'degree', 'name_de'), ('semester', 'degree', 'name_en')},
),
migrations.AddField(
model_name='contribution',
Expand All @@ -273,6 +273,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='contribution',
unique_together=set([('course', 'contributor')]),
unique_together={('course', 'contributor')},
),
]
2 changes: 1 addition & 1 deletion evap/evaluation/migrations/0017_delete_old_degrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='course',
unique_together=set([('semester', 'name_en'), ('semester', 'name_de')]),
unique_together={('semester', 'name_en'), ('semester', 'name_de')},
),
migrations.RemoveField(
model_name='course',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='gradeanswercounter',
unique_together=set([('question', 'contribution', 'answer')]),
unique_together={('question', 'contribution', 'answer')},
),
migrations.AlterUniqueTogether(
name='likertanswercounter',
unique_together=set([('question', 'contribution', 'answer')]),
unique_together={('question', 'contribution', 'answer')},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='ratinganswercounter',
unique_together=set([('question', 'contribution', 'answer')]),
unique_together={('question', 'contribution', 'answer')},
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterUniqueTogether(
name='gradeanswercounter',
unique_together=set([]),
unique_together=set(),
),
migrations.RemoveField(
model_name='gradeanswercounter',
Expand All @@ -22,7 +22,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='likertanswercounter',
unique_together=set([]),
unique_together=set(),
),
migrations.RemoveField(
model_name='likertanswercounter',
Expand Down
2 changes: 1 addition & 1 deletion evap/evaluation/migrations/0100_clear_evaluation_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def name_evaluations(apps, _schema_editor):
evaluation.name_en = course.name_en
evaluation.save()
else:
for i in range(0, course.evaluations.count()):
for i in range(course.evaluations.count()):
evaluation = Evaluation.objects.get(pk=course.evaluations.all()[i].pk)
Kakadus marked this conversation as resolved.
Show resolved Hide resolved
evaluation.name_de = f"{course.name_de} ({i})"
evaluation.name_en = f"{course.name_en} ({i})"
Expand Down
Loading
Loading