Skip to content

Commit

Permalink
updates ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Dec 23, 2024
1 parent fd17566 commit e37dd0d
Show file tree
Hide file tree
Showing 60 changed files with 208 additions and 118 deletions.
5 changes: 2 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ select = [
"E4", "E7", "E9",
"ERA", # eradicate
"F", # pyflakes
# "FBT", # flake8-boolean-trap
"FLY", # flynt
"FURB", # refurb
"I", # isort
Expand All @@ -32,12 +31,12 @@ select = [
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"R", # PyLint Refactor
# "RET", # flake8-return
"RET", # flake8-return
"S", # bandit,
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
# "TC", # flake8-type-checking
"TC", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8 2020
Expand Down
6 changes: 5 additions & 1 deletion src/country_workspace/admin/household.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING

from django.contrib import admin, messages
from django.http import HttpRequest, HttpResponse
from django.urls import reverse
from django.utils.translation import gettext as _

Expand All @@ -11,6 +12,9 @@
from .base import BaseModelAdmin
from .filters import IsValidFilter

if TYPE_CHECKING:
from django.http import HttpRequest, HttpResponse


@admin.register(Household)
class HouseholdAdmin(BaseModelAdmin):
Expand Down
6 changes: 5 additions & 1 deletion src/country_workspace/admin/individual.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from typing import TYPE_CHECKING

from django.contrib import admin
from django.urls import reverse

from admin_extra_buttons.buttons import LinkButton
from admin_extra_buttons.decorators import link
from adminfilters.autocomplete import LinkedAutoCompleteFilter

from ..models import Individual
from .base import BaseModelAdmin
from .filters import IsValidFilter

if TYPE_CHECKING:
from admin_extra_buttons.buttons import LinkButton


@admin.register(Individual)
class IndividualAdmin(BaseModelAdmin):
Expand Down
6 changes: 4 additions & 2 deletions src/country_workspace/admin/job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Sequence
from typing import TYPE_CHECKING, Sequence

from django.contrib import admin
from django.http import HttpRequest

from adminfilters.autocomplete import AutoCompleteFilter, LinkedAutoCompleteFilter
from django_celery_boost.admin import CeleryTaskModelAdmin
Expand All @@ -10,6 +9,9 @@
from .base import BaseModelAdmin
from .filters import FailedFilter

if TYPE_CHECKING:
from django.http import HttpRequest


@admin.register(AsyncJob)
class AsyncJobAdmin(CeleryTaskModelAdmin, BaseModelAdmin):
Expand Down
4 changes: 2 additions & 2 deletions src/country_workspace/cache/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def process_response(self, request: HttpRequest, response: HttpResponse) -> Http
timeout = self.page_timeout
patch_response_headers(response, timeout)
if response.status_code == 200:
cache_key = self.manager.build_key_from_request(request)
cache_key = self.manager.build_key_from_request(request, "view", getattr(request.user, "pk", ""))
response.headers["Etag"] = cache_key
if hasattr(response, "render") and callable(response.render):
response.add_post_render_callback(lambda r: self.manager.store(cache_key, r))
Expand All @@ -56,7 +56,7 @@ def process_request(self, request: HttpRequest) -> HttpResponse:
return None # Don't bother checking the cache.

# try and get the cached GET response
cache_key = self.manager.build_key_from_request(request)
cache_key = self.manager.build_key_from_request(request, "view", getattr(request.user, "pk", ""))
if cache_key is None:
request._cache_update_cache = True
return None # No cache information available, need to rebuild.
Expand Down
5 changes: 4 additions & 1 deletion src/country_workspace/config/fragments/debug_toolbar.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.http import HttpRequest
from typing import TYPE_CHECKING

from django_regex.utils import RegexList

if TYPE_CHECKING:
from django.http import HttpRequest


def show_ddt(request: "HttpRequest") -> bool: # pragma: no-cover
from flags.state import flag_enabled
Expand Down
6 changes: 5 additions & 1 deletion src/country_workspace/contrib/hope/validators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import TYPE_CHECKING

from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist

from country_workspace.models import Household
from country_workspace.validators.base import BeneficiaryGroupValidator

if TYPE_CHECKING:
from country_workspace.models import Household


class FullHouseholdValidator(BeneficiaryGroupValidator):
def validate(self, hh: "Household") -> list:
Expand Down
5 changes: 4 additions & 1 deletion src/country_workspace/middleware/exception.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from typing import TYPE_CHECKING

from django.core.exceptions import PermissionDenied
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.utils.deprecation import MiddlewareMixin

if TYPE_CHECKING:
from django.http import HttpRequest, HttpResponse

logger = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions src/country_workspace/middleware/state.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
from typing import TYPE_CHECKING

from django.http import HttpRequest, HttpResponse

import sentry_sdk

from country_workspace.workspaces.utils import RequestHandler

if TYPE_CHECKING:
from collections.abc import Callable

from django.http import HttpRequest, HttpResponse


logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/models/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import TYPE_CHECKING, Any

from django.db import models
from django.db.models import QuerySet
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext as _
Expand All @@ -15,6 +14,8 @@
from country_workspace.utils.flex_fields import get_obj_checksum

if TYPE_CHECKING:
from django.db.models import QuerySet

from hope_flex_fields.models import DataChecker

from country_workspace.models import Office, Program
Expand Down
6 changes: 5 additions & 1 deletion src/country_workspace/models/individual.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from typing import TYPE_CHECKING

from django.db import models
from django.utils.functional import cached_property

import reversion
from hope_flex_fields.models import DataChecker

from .base import BaseModel, Validable
from .household import Household

if TYPE_CHECKING:
from hope_flex_fields.models import DataChecker


@reversion.register()
class Individual(Validable, BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/models/program.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import TYPE_CHECKING

from django.db import models
from django.db.models import QuerySet
from django.utils.translation import gettext as _

from hope_flex_fields.models import DataChecker
Expand All @@ -13,6 +12,8 @@
from .office import Office

if TYPE_CHECKING:
from django.db.models import QuerySet

from .household import Household
from .individual import Individual

Expand Down
6 changes: 5 additions & 1 deletion src/country_workspace/models/sync.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from typing import TYPE_CHECKING

from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Model
from django.utils import timezone

from country_workspace.models.base import BaseManager, BaseModel

if TYPE_CHECKING:
from django.db.models import Model


class SyncManager(BaseManager):
def refresh(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from typing import TYPE_CHECKING

from django.core.signing import get_cookie_signer
from django.http import HttpRequest, HttpResponse

if TYPE_CHECKING:
from collections.abc import Iterator
from typing import Any

from django.http import HttpRequest, HttpResponse

from .models import Office, Program

not_set = object()
Expand Down
7 changes: 5 additions & 2 deletions src/country_workspace/utils/flags.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import logging
import os
import re
from typing import Any
from typing import TYPE_CHECKING, Any

from django.conf import settings
from django.core.exceptions import ValidationError
from django.http import HttpRequest

from adminfilters.utils import parse_bool
from flags.conditions import conditions

from country_workspace.state import state

if TYPE_CHECKING:
from django.http import HttpRequest


logger = logging.getLogger(__name__)


Expand Down
5 changes: 2 additions & 3 deletions src/country_workspace/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
from urllib.parse import urljoin

from django.conf import settings
from django.http import HttpRequest
from django.http.request import split_domain_port
from django.urls import reverse

from ..state import state

if TYPE_CHECKING:
from ..types.http import AnyRequest
from django.http import HttpRequest


def get_server_host(request: "AnyRequest | None" = None) -> str:
def get_server_host(request: "HttpRequest | None" = None) -> str:
req: HttpRequest | None = request or state.request
host = req.get_host()
domain, port = split_domain_port(host)
Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/workspaces/admin/cleaners/actions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import TYPE_CHECKING

from django.contrib import admin, messages
from django.db.models import QuerySet
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.utils.translation import gettext as _
Expand All @@ -18,6 +17,8 @@
from .validate import validate_queryset

if TYPE_CHECKING:
from django.db.models import QuerySet

from country_workspace.types import Beneficiary
from country_workspace.workspaces.admin.hh_ind import BeneficiaryBaseAdmin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.apps import apps
from django.core.exceptions import ObjectDoesNotExist
from django.core.files.storage import default_storage
from django.db.models import QuerySet

from hope_flex_fields.models import DataChecker, FlexField
from hope_flex_fields.xlsx import get_format_for_field
Expand All @@ -17,6 +16,8 @@
from country_workspace.workspaces.admin.cleaners.base import BaseActionForm

if TYPE_CHECKING:
from django.db.models import QuerySet

from country_workspace.types import Beneficiary


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django import forms
from django.db import transaction
from django.db.models import QuerySet
from django.forms import MultiValueField, widgets
from django.utils.text import slugify

Expand All @@ -12,6 +11,8 @@
from .base import BaseActionForm

if TYPE_CHECKING:
from django.db.models import QuerySet

from hope_flex_fields.models import DataChecker

from country_workspace.types import Beneficiary
Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/workspaces/admin/cleaners/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

from django import forms
from django.db import transaction
from django.db.models import QuerySet

from country_workspace.utils.flex_fields import get_checker_fields

from .base import BaseActionForm

if TYPE_CHECKING:
from django.db.models import QuerySet

from hope_flex_fields.models import DataChecker

from country_workspace.types import Beneficiary
Expand Down
2 changes: 1 addition & 1 deletion src/country_workspace/workspaces/admin/hh_ind.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from admin_extra_buttons.decorators import button
from adminfilters.mixin import AdminAutoCompleteSearchMixin
from concurrency.utils import fqn
from hope_flex_fields.models import DataChecker

from ...models import AsyncJob
from ...state import state
Expand All @@ -24,6 +23,7 @@

if TYPE_CHECKING:
from hope_flex_fields.forms import FlexForm
from hope_flex_fields.models import DataChecker

from ...models.base import Validable
from ...types import Beneficiary
Expand Down
11 changes: 5 additions & 6 deletions src/country_workspace/workspaces/admin/household.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import TYPE_CHECKING

from django.db.models import QuerySet
from django.contrib.admin import register
from django.http import HttpRequest
from django.urls import reverse
from django.utils.translation import gettext as _
Expand All @@ -9,16 +9,15 @@
from admin_extra_buttons.decorators import link

from ...state import state
from ..models import CountryHousehold
from ..sites import workspace
from .filters import CWLinkedAutoCompleteFilter, WIsValidFilter
from .hh_ind import BeneficiaryBaseAdmin

if TYPE_CHECKING:
from ..models import CountryProgram
from django.db.models import QuerySet

from django.contrib.admin import register

from ..models import CountryHousehold
from ..sites import workspace
from ..models import CountryProgram


@register(CountryHousehold, site=workspace)
Expand Down
Loading

0 comments on commit e37dd0d

Please sign in to comment.