Skip to content

Commit

Permalink
chore: enable more ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Feb 5, 2025
1 parent 4455abb commit 14b7f85
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 96 deletions.
57 changes: 23 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ target-version = "py311"

[tool.ruff.lint]
ignore = [
"S113", # TODO
"PERF401", # TODO
"D10", # TODO: we are missing many docstrings
"D203", # CONFIG: incompatible with D211
"D212", # CONFIG: incompatible with D213
Expand All @@ -149,43 +151,30 @@ ignore = [
"PLR2004", # TODO: Magic value used in comparison, consider replacing 201 with a constant variable
"PLW2901", # TODO: overwriting variables inside loop
"N818", # TODO: exception naming
"COM", # CONFIG: No trailing commas
"PTH", # TODO: Not using pathlib
"FBT", # TODO: Boolean in function definition
"TD002", # CONFIG: no detailed TODO documentation is required
"TD003", # CONFIG: no detailed TODO documentation is required
"PT", # CONFIG: Not using pytest
"EM101", # TODO: Exception must not use a string literal, assign to variable first
"EM102", # TODO: Exception must not use an f-string literal, assign to variable first
"ARG001", # TODO: Unused function argument (mostly for API compatibility)
"ARG002", # TODO: Unused method argument (mostly for API compatibility)
"ARG003", # TODO: Unused class method argument (mostly for API compatibility)
"FIX002", # CONFIG: we use TODO
"RUF012", # TODO: Mutable class attributes should be annotated with `typing.ClassVar`
"ANN001", # TODO: Missing type annotation for function argument
"ANN002", # TODO: Missing type annotation for `*args`
"ANN003", # TODO: Missing type annotation for `**kwargs`
"ANN201", # TODO: Missing return type annotation for public function
"ANN202", # TODO: Missing return type annotation for private function
"ANN204", # TODO: Missing return type annotation for special method
"ANN205", # TODO: Missing return type annotation for staticmethod
"ANN206", # TODO: Missing return type annotation for classmethod
"SLF001" # TODO: Private member accessed (might need noqa tags)
]
select = [
"E",
"F",
"B",
"T10",
"A",
"C4",
"C90",
"YTT",
"DJ",
"UP",
"D",
"PD",
"PGH",
"PL",
"TRY",
"RUF",
"ERA",
"ICN",
"ISC",
"EXE",
"INP",
"PIE",
"G",
"PYI",
"Q",
"SIM",
"TID",
"RSE",
"T20",
"RET",
"SLF",
"N"
]
select = ["ALL"]

[tool.ruff.lint.mccabe]
max-complexity = 16
Expand Down
2 changes: 1 addition & 1 deletion wlhosted/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def can_install(cls, component, user):
# Only instalable on the sandbox project
return component.project.slug == "sandbox"

def daily(self, component):
def daily(self, component) -> None:
component.do_reset()
4 changes: 2 additions & 2 deletions wlhosted/dbrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class HostedRouter:
block running migrations on that.
"""

def db_for_read(self, model, **hints):
def db_for_read(self, model, **hints) -> str | None:
"""Attempts to read payments models go to payments_db."""
if model._meta.app_label == "payments":
return "payments_db"
if model._meta.app_label == "memory":
return "memory_db"
return None

def db_for_write(self, model, **hints):
def db_for_write(self, model, **hints) -> str | None:
"""Attempts to write payments models go to payments_db."""
if model._meta.app_label == "payments":
return "payments_db"
Expand Down
7 changes: 4 additions & 3 deletions wlhosted/integrations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
#

from __future__ import annotations
from django.utils import timezone

import datetime

from django import forms
from django.core.exceptions import ValidationError
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from weblate.billing.models import Billing, Plan

from wlhosted.integrations.utils import get_origin
from wlhosted.payments.models import Customer, Payment, get_period_delta, date_format
from wlhosted.payments.models import Customer, Payment, date_format, get_period_delta


class ChooseBillingForm(forms.Form):
Expand Down Expand Up @@ -60,7 +61,7 @@ def __init__(self, user, *args, **kwargs):
super().__init__(user, *args, **kwargs)
self.fields["plan"].queryset = Plan.objects.public(user)

def clean(self):
def clean(self) -> None:
plan = self.cleaned_data.get("plan")
period = self.cleaned_data.get("period")
if not plan or not period:
Expand Down
4 changes: 2 additions & 2 deletions wlhosted/integrations/management/commands/list_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#

from django.core.management.base import BaseCommand
from weblate.billing.models import Billing
from weblate.auth.models import User
from weblate.billing.models import Billing


class Command(BaseCommand):
help = "lists payments using obsolete payment method"

def handle(self, *args, **options):
def handle(self, *args, **options) -> None:
emails = set()
for billing in (
Billing.objects.filter(state=Billing.STATE_ACTIVE)
Expand Down
2 changes: 1 addition & 1 deletion wlhosted/integrations/management/commands/list_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class Command(BaseCommand):
help = "lists payments using obsolete payment method"

def handle(self, *args, **options):
def handle(self, *args, **options) -> None:
for billing in Billing.objects.filter(state=Billing.STATE_ACTIVE):
if "recurring" not in billing.payment:
continue
Expand Down
8 changes: 4 additions & 4 deletions wlhosted/integrations/management/commands/migrate_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_country(text):
class Command(BaseCommand):
help = "migrates payments to include all needed metadata"

def update_payment(self, invoice):
def update_payment(self, invoice) -> None:
payment = Payment.objects.get(pk=invoice.payment["pk"])
if payment.start:
return
Expand All @@ -60,7 +60,7 @@ def update_payment(self, invoice):
payment.end = invoice.end
payment.save(update_fields=["start", "end"])

def handle_missing_payment(self, invoice, storage):
def handle_missing_payment(self, invoice, storage) -> bool:
if not invoice.ref:
self.stderr.write(
f"Missing reference in {invoice.pk} [{invoice.billing.pk}]: {invoice}"
Expand Down Expand Up @@ -116,14 +116,14 @@ def handle_missing_payment(self, invoice, storage):
invoice.save(update_fields=["payment"])
return True

def include_billing_id(self, invoice):
def include_billing_id(self, invoice) -> None:
payment = Payment.objects.get(pk=invoice.payment["pk"])
if "billing" not in payment.extra:
self.stdout.write(f"Linking payment: {payment}")
payment.extra["billing"] = invoice.billing_id
payment.save(update_fields=["extra"])

def handle(self, *args, **options):
def handle(self, *args, **options) -> None:
storage = InvoiceStorage(settings.PAYMENT_FAKTURACE)
for invoice in Invoice.objects.all():
if isinstance(invoice.payment, dict) and "pk" in invoice.payment:
Expand Down
2 changes: 1 addition & 1 deletion wlhosted/integrations/management/commands/push_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
class Command(BaseCommand):
help = "pushes user data to weblate.org"

def handle(self, *args, **options):
def handle(self, *args, **options) -> None:
for user in User.objects.filter(is_active=True).iterator():
propagate_user_changes(None, user)
2 changes: 1 addition & 1 deletion wlhosted/integrations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Meta:

@receiver(pre_save, sender=User)
@disable_for_loaddata
def propagate_user_changes(sender, instance, **kwargs):
def propagate_user_changes(sender, instance, **kwargs) -> None:
from wlhosted.integrations.tasks import notify_user_change

if instance.is_anonymous:
Expand Down
13 changes: 6 additions & 7 deletions wlhosted/integrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@

from wlhosted.integrations.models import handle_received_payment
from wlhosted.integrations.utils import get_origin
from wlhosted.payments.models import Payment
from wlhosted.payments.models import get_period_delta, date_format
from wlhosted.payments.models import Payment, date_format, get_period_delta


@app.task
def pending_payments():
def pending_payments() -> None:
with transaction.atomic(using="payments_db"):
payments = Payment.objects.filter(
customer__origin=get_origin(), state=Payment.ACCEPTED
Expand All @@ -46,7 +45,7 @@ def pending_payments():


@app.task
def notify_paid_removal(billing_id):
def notify_paid_removal(billing_id) -> None:
billing = Billing.objects.get(pk=billing_id)
for user in billing.get_notify_users():
send_notification_email(
Expand All @@ -59,7 +58,7 @@ def notify_paid_removal(billing_id):


@app.task
def recurring_payments():
def recurring_payments() -> None:
cutoff = timezone.now().date() + timedelta(days=1)
for billing in Billing.objects.filter(state=Billing.STATE_ACTIVE).prefetch():
if "recurring" not in billing.payment:
Expand Down Expand Up @@ -100,7 +99,7 @@ def recurring_payments():


@app.task
def notify_user_change(username, changes, create):
def notify_user_change(username, changes, create) -> None:
if not settings.PAYMENT_SECRET:
return
response = requests.post(
Expand All @@ -117,7 +116,7 @@ def notify_user_change(username, changes, create):


@app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
def setup_periodic_tasks(sender, **kwargs) -> None:
sender.add_periodic_task(300, pending_payments.s(), name="pending-payments")
sender.add_periodic_task(
crontab(hour=8, minute=0), recurring_payments.s(), name="recurring-payments"
Expand Down
Loading

0 comments on commit 14b7f85

Please sign in to comment.