From 0cdab193087a5f82459f0c9008b9f1d04b378eba Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 8 Jun 2024 17:56:36 -0400 Subject: [PATCH] Fix rust complaints. --- etebase_server/django/__init__.py | 2 ++ etebase_server/django/app_settings_inner.py | 16 ++++++++-------- etebase_server/django/models.py | 4 ++-- etebase_server/fastapi/main.py | 6 +++--- etebase_server/fastapi/routers/collection.py | 2 +- etebase_server/myauth/models.py | 12 ++---------- etebase_server/settings.py | 2 +- pyproject.toml | 2 +- 8 files changed, 20 insertions(+), 26 deletions(-) diff --git a/etebase_server/django/__init__.py b/etebase_server/django/__init__.py index 99ee8b6..d321c95 100644 --- a/etebase_server/django/__init__.py +++ b/etebase_server/django/__init__.py @@ -1 +1,3 @@ from .app_settings_inner import app_settings + +__all__ = ["app_settings"] diff --git a/etebase_server/django/app_settings_inner.py b/etebase_server/django/app_settings_inner.py index 41fd910..9adf120 100644 --- a/etebase_server/django/app_settings_inner.py +++ b/etebase_server/django/app_settings_inner.py @@ -34,11 +34,11 @@ class AppSettings: return getattr(settings, self.prefix + name, dflt) @cached_property - def REDIS_URI(self) -> t.Optional[str]: # pylint: disable=invalid-name + def REDIS_URI(self) -> t.Optional[str]: # noqa: N802 return self._setting("REDIS_URI", None) @cached_property - def API_PERMISSIONS_READ(self): # pylint: disable=invalid-name + def API_PERMISSIONS_READ(self): # noqa: N802 perms = self._setting("API_PERMISSIONS_READ", tuple()) ret = [] for perm in perms: @@ -46,7 +46,7 @@ class AppSettings: return ret @cached_property - def API_PERMISSIONS_WRITE(self): # pylint: disable=invalid-name + def API_PERMISSIONS_WRITE(self): # noqa: N802 perms = self._setting("API_PERMISSIONS_WRITE", tuple()) ret = [] for perm in perms: @@ -54,35 +54,35 @@ class AppSettings: return ret @cached_property - def GET_USER_QUERYSET_FUNC(self): # pylint: disable=invalid-name + def GET_USER_QUERYSET_FUNC(self): # noqa: N802 get_user_queryset = self._setting("GET_USER_QUERYSET_FUNC", None) if get_user_queryset is not None: return self.import_from_str(get_user_queryset) return None @cached_property - def CREATE_USER_FUNC(self): # pylint: disable=invalid-name + def CREATE_USER_FUNC(self): # noqa: N802 func = self._setting("CREATE_USER_FUNC", None) if func is not None: return self.import_from_str(func) return None @cached_property - def DASHBOARD_URL_FUNC(self): # pylint: disable=invalid-name + def DASHBOARD_URL_FUNC(self): # noqa: N802 func = self._setting("DASHBOARD_URL_FUNC", None) if func is not None: return self.import_from_str(func) return None @cached_property - def CHUNK_PATH_FUNC(self): # pylint: disable=invalid-name + def CHUNK_PATH_FUNC(self): # noqa: N802 func = self._setting("CHUNK_PATH_FUNC", None) if func is not None: return self.import_from_str(func) return None @cached_property - def CHALLENGE_VALID_SECONDS(self): # pylint: disable=invalid-name + def CHALLENGE_VALID_SECONDS(self): # noqa: N802 return self._setting("CHALLENGE_VALID_SECONDS", 60) diff --git a/etebase_server/django/models.py b/etebase_server/django/models.py index 0faf708..4e6e5bd 100644 --- a/etebase_server/django/models.py +++ b/etebase_server/django/models.py @@ -18,7 +18,7 @@ from pathlib import Path from django.conf import settings from django.core.validators import RegexValidator from django.db import models, transaction -from django.db.models import Max, Value as V +from django.db.models import Max, Value as Val from django.db.models.functions import Coalesce, Greatest from django.utils.crypto import get_random_string from django.utils.functional import cached_property @@ -29,7 +29,7 @@ UidValidator = RegexValidator(regex=r"^[a-zA-Z0-9\-_]{20,}$", message="Not a val def stoken_annotation_builder(stoken_id_fields: t.List[str]): - aggr_fields = [Coalesce(Max(field), V(0)) for field in stoken_id_fields] + aggr_fields = [Coalesce(Max(field), Val(0)) for field in stoken_id_fields] return Greatest(*aggr_fields) if len(aggr_fields) > 1 else aggr_fields[0] diff --git a/etebase_server/fastapi/main.py b/etebase_server/fastapi/main.py index 335ca1b..9e80dba 100644 --- a/etebase_server/fastapi/main.py +++ b/etebase_server/fastapi/main.py @@ -25,9 +25,9 @@ def create_application(prefix="", middlewares=[]): }, # FIXME: version="2.5.0", ) - VERSION = "v1" - BASE_PATH = f"{prefix}/api/{VERSION}" - COLLECTION_UID_MARKER = "{collection_uid}" + VERSION = "v1" # noqa: N806 + BASE_PATH = f"{prefix}/api/{VERSION}" # noqa: N806 + COLLECTION_UID_MARKER = "{collection_uid}" # noqa: N806 app.include_router(authentication_router, prefix=f"{BASE_PATH}/authentication", tags=["authentication"]) app.include_router(collection_router, prefix=f"{BASE_PATH}/collection", tags=["collection"]) app.include_router(item_router, prefix=f"{BASE_PATH}/collection/{COLLECTION_UID_MARKER}", tags=["item"]) diff --git a/etebase_server/fastapi/routers/collection.py b/etebase_server/fastapi/routers/collection.py index 3356a6a..b293f03 100644 --- a/etebase_server/fastapi/routers/collection.py +++ b/etebase_server/fastapi/routers/collection.py @@ -374,7 +374,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val revision_data = item_model.content uid = item_model.uid - Model = models.CollectionItem + Model = models.CollectionItem # noqa: N806 with transaction.atomic(): instance, created = Model.objects.get_or_create( diff --git a/etebase_server/myauth/models.py b/etebase_server/myauth/models.py index 89b94b4..c862a46 100644 --- a/etebase_server/myauth/models.py +++ b/etebase_server/myauth/models.py @@ -1,21 +1,13 @@ import typing as t from django.contrib.auth.models import AbstractUser, UserManager as DjangoUserManager -from django.core import validators +from django.contrib.auth.validators import UnicodeUsernameValidator from django.db import models -from django.utils.deconstruct import deconstructible from django.utils.translation import gettext_lazy as _ -@deconstructible -class UnicodeUsernameValidator(validators.RegexValidator): - regex = r"^[\w.-]+\Z" - message = _("Enter a valid username. This value may contain only letters, " "numbers, and ./-/_ characters.") - flags = 0 - - class UserManager(DjangoUserManager): - def get_by_natural_key(self, username: str): + def get_by_natural_key(self, username: t.Optional[str]): return self.get(**{self.model.USERNAME_FIELD + "__iexact": username}) diff --git a/etebase_server/settings.py b/etebase_server/settings.py index 03c0338..fc486fe 100644 --- a/etebase_server/settings.py +++ b/etebase_server/settings.py @@ -201,7 +201,7 @@ if "DJANGO_MEDIA_ROOT" in os.environ: # Make an `etebase_server_settings` module available to override settings. try: - from etebase_server_settings import * + from etebase_server_settings import * # noqa: F403 except ImportError: pass diff --git a/pyproject.toml b/pyproject.toml index 02fad2c..22072d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ exclude = [ [tool.ruff.lint] select = ["E", "F", "I", "N", "T20", "W"] -ignore = ["E203", "E501", "E711", "E712", "N803", "N818", "T201"] +ignore = ["E203", "E501", "E711", "E712", "N803", "N815", "N818", "T201"] [tool.ruff.lint.isort] combine-as-imports = true