From 045391fc592678dd533c7562c5d1fa77a66cc409 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 3 Feb 2022 17:52:07 +0100 Subject: [PATCH] Code formatting --- .pylintrc | 14 --- server/.pylintrc | 87 +++++++++++++++++++ server/config/api_router.py | 3 - server/config/asgi.py | 1 + server/config/settings/base.py | 132 ++++++++++++++++------------- server/config/settings/test.py | 4 +- server/config/urls.py | 19 ++++- server/vbv_lernwelt/__init__.py | 7 -- server/vbv_lernwelt/conftest.py | 14 --- server/vbv_lernwelt/core/apps.py | 1 + server/vbv_lernwelt/core/models.py | 2 - server/vbv_lernwelt/core/tests.py | 2 - server/vbv_lernwelt/core/views.py | 2 - 13 files changed, 180 insertions(+), 108 deletions(-) delete mode 100644 .pylintrc create mode 100644 server/.pylintrc delete mode 100644 server/vbv_lernwelt/conftest.py diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 2d6bf13e..00000000 --- a/.pylintrc +++ /dev/null @@ -1,14 +0,0 @@ -[MASTER] -load-plugins=pylint_django -django-settings-module=config.settings.base -[FORMAT] -max-line-length=120 - -[MESSAGES CONTROL] -disable=missing-docstring,invalid-name - -[DESIGN] -max-parents=13 - -[TYPECHECK] -generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete diff --git a/server/.pylintrc b/server/.pylintrc new file mode 100644 index 00000000..4b032120 --- /dev/null +++ b/server/.pylintrc @@ -0,0 +1,87 @@ +[MASTER] +load-plugins=pylint_django +django-settings-module=config.settings.base +[FORMAT] +max-line-length=120 + +[MESSAGES CONTROL] +disable=missing-docstring,invalid-name + +[DESIGN] +max-parents=13 + +[TYPECHECK] +generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable= + # C0114: Missing module docstring + missing-module-docstring, + # C0116: Missing function or method docstring + missing-function-docstring, + # C0115: Missing class docstring + missing-class-docstring, + # R0201: Method could be a function + no-self-use, + # C0115: Missing class docstring + missing-class-docstring, + # C0103: Method name "test_exportHelper_returnsInvoicesOnlyOnce" doesn't conform to snake_case naming style + invalid-name, + # C0305: Trailing newlines + trailing-newlines, + # C0301: Line too long (114/100) + line-too-long, + # R0904: Too many public methods (32/20) + too-many-public-methods, + # R0903: Too few public methods (0/2) + too-few-public-methods, + # E1101: Class 'SizeChoice' has no 'objects' member + no-member, + # W0613: Unused argument 'schema_editor' + unused-argument, + # C0304: Final newline missing + missing-final-newline, + # C0303: Trailing whitespace + trailing-whitespace, + # W0511: + fixme, + # R0902: Too many instance attributes + too-many-instance-attributes, + # R0913: Too many arguments + too-many-arguments, + # R1725: Consider using Python 3 style super() without arguments + super-with-arguments, + # R0901: Too many ancestors + too-many-ancestors, + # Too many boolean expressions in if statement + too-many-boolean-expressions, + # W0212: Access to a protected member _meta of a client class + protected-access, + # W0201: Attribute defined outside __init__ + attribute-defined-outside-init, + # R1721: Unnecessary use of a comprehension + unnecessary-comprehension, + # R1705: Unnecessary "else" after "return" + no-else-return, + # R1720: Unnecessary "elif" after "raise" + no-else-raise, + # R0914: Too many local variables + too-many-locals, + # R1702: Too many nested blocks + too-many-nested-blocks, + # R0911: Too many return statements + too-many-return-statements, + # R1701: Consider merging these isinstance calls + consider-merging-isinstance, + # R0915: Too many statements + too-many-statements, + duplicate-code, + cyclic-impor diff --git a/server/config/api_router.py b/server/config/api_router.py index e932ae36..2e053e30 100644 --- a/server/config/api_router.py +++ b/server/config/api_router.py @@ -1,14 +1,11 @@ from django.conf import settings from rest_framework.routers import DefaultRouter, SimpleRouter - if settings.DEBUG: router = DefaultRouter() else: router = SimpleRouter() -# router.register("users", UserViewSet) - app_name = "api" urlpatterns = router.urls diff --git a/server/config/asgi.py b/server/config/asgi.py index 61c38a22..ea86455d 100644 --- a/server/config/asgi.py +++ b/server/config/asgi.py @@ -28,6 +28,7 @@ django_application = get_asgi_application() # application = HelloWorldApplication(application) # Import websocket application here, so apps from django_application are loaded first +# pylint: disable=wrong-import-position from config.websocket import websocket_application # noqa isort:skip diff --git a/server/config/settings/base.py b/server/config/settings/base.py index 5dabee96..12785be2 100644 --- a/server/config/settings/base.py +++ b/server/config/settings/base.py @@ -232,7 +232,9 @@ MANAGERS = ADMINS # https://docs.djangoproject.com/en/dev/ref/settings/#logging # See https://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. -VBV_DJANGO_LOGGING_CONF = env("VBV_DJANGO_LOGGING_CONF", default="VBV_DJANGO_LOGGING_CONF_JSON_FILE") +VBV_DJANGO_LOGGING_CONF = env( + "VBV_DJANGO_LOGGING_CONF", default="VBV_DJANGO_LOGGING_CONF_JSON_FILE" +) if VBV_DJANGO_LOGGING_CONF == "VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR": timestamper = structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S") @@ -241,33 +243,33 @@ if VBV_DJANGO_LOGGING_CONF == "VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR": timestamper, ] LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'formatters': { - 'colored': { - '()': structlog.stdlib.ProcessorFormatter, - 'processor': structlog.dev.ConsoleRenderer(colors=True), - 'foreign_pre_chain': pre_chain, + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "colored": { + "()": structlog.stdlib.ProcessorFormatter, + "processor": structlog.dev.ConsoleRenderer(colors=True), + "foreign_pre_chain": pre_chain, }, }, - 'handlers': { - 'default': { - 'class': 'logging.StreamHandler', - 'formatter': 'colored', + "handlers": { + "default": { + "class": "logging.StreamHandler", + "formatter": "colored", }, }, - 'loggers': { - '': { - 'handlers': ['default'], - 'level': 'INFO', - 'propagate': True, + "loggers": { + "": { + "handlers": ["default"], + "level": "INFO", + "propagate": True, }, - 'vbv_lernwelt': { - 'handlers': ['default'], - 'level': 'DEBUG', - 'propagate': False, + "vbv_lernwelt": { + "handlers": ["default"], + "level": "DEBUG", + "propagate": False, }, - } + }, } structlog.configure( @@ -287,22 +289,23 @@ if VBV_DJANGO_LOGGING_CONF == "VBV_DJANGO_LOGGING_CONF_CONSOLE_COLOR": ) else: LOGGING = { - 'version': 1, - 'disable_existing_loggers': True, - 'formatters': { - 'json': { - '()': 'pythonjsonlogger.jsonlogger.JsonFormatter', - 'format': '%(asctime)s %(msecs)03d %(process)d %(thread)d %(levelname)s %(name)s %(filename)s %(lineno)d %(funcName)s %(message)s', - 'datefmt': '%Y-%m-%dT%H:%M:%S', + "version": 1, + "disable_existing_loggers": True, + "formatters": { + "json": { + "()": "pythonjsonlogger.jsonlogger.JsonFormatter", + # noqa I004 + "format": "%(asctime)s %(msecs)03d %(process)d %(thread)d %(levelname)s %(name)s %(filename)s %(lineno)d %(funcName)s %(message)s", # noqa I004 + "datefmt": "%Y-%m-%dT%H:%M:%S", }, }, - 'handlers': { - 'file': { - 'class': 'concurrent_log_handler.ConcurrentRotatingFileHandler', - 'filename': f'{SERVER_ROOT_DIR}/myservice.log', - 'maxBytes': 1024 * 1024 * 100, - 'backupCount': 50, - 'formatter': 'json', + "handlers": { + "file": { + "class": "concurrent_log_handler.ConcurrentRotatingFileHandler", + "filename": f"{SERVER_ROOT_DIR}/myservice.log", + "maxBytes": 1024 * 1024 * 100, + "backupCount": 50, + "formatter": "json", }, "console": { "level": "DEBUG", @@ -310,23 +313,27 @@ else: "formatter": "json", }, }, - 'loggers': { - '': { - 'handlers': ['console', 'file'], - 'level': 'INFO', + "loggers": { + "": { + "handlers": ["console", "file"], + "level": "INFO", }, - 'django': { - 'handlers': ['console', 'file'], - 'level': 'WARNING', - 'propagate': False, + "django": { + "handlers": ["console", "file"], + "level": "WARNING", + "propagate": False, }, - 'vbc_lernwelt': { - 'handlers': ['console', 'file'], - 'level': 'DEBUG', - 'propagate': False, + "vbc_lernwelt": { + "handlers": ["console", "file"], + "level": "DEBUG", + "propagate": False, }, - "sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False}, - } + "sentry_sdk": { + "level": "ERROR", + "handlers": ["console"], + "propagate": False, + }, + }, } structlog.configure( @@ -381,22 +388,30 @@ SECRET_KEY = env( default="J9FiYN31FuY7lHrmx9Mpai3GGpTVCxakEclOfCLretDe7bTf2DtTsgazJ0aIMtbq", ) # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = env.list("VBV_DJANGO_ALLOWED_HOSTS", default=["localhost", "0.0.0.0", "127.0.0.1"]) +ALLOWED_HOSTS = env.list( + "VBV_DJANGO_ALLOWED_HOSTS", default=["localhost", "0.0.0.0", "127.0.0.1"] +) # CACHES CACHES = { - 'default': { - 'BACKEND': env("VBV_DJANGO_CACHE_BACKEND", default='django.core.cache.backends.db.DatabaseCache'), - 'LOCATION': env("VBV_DJANGO_CACHE_LOCATION", default='django_cache_table'), + "default": { + "BACKEND": env( + "VBV_DJANGO_CACHE_BACKEND", + default="django.core.cache.backends.db.DatabaseCache", + ), + "LOCATION": env("VBV_DJANGO_CACHE_LOCATION", default="django_cache_table"), } } -if 'django_redis.cache.RedisCache' in env("VBV_DJANGO_CACHE_BACKEND", default=''): +if "django_redis.cache.RedisCache" in env("VBV_DJANGO_CACHE_BACKEND", default=""): CACHES = { - 'default': { - 'BACKEND': env("VBV_DJANGO_CACHE_BACKEND", default='django.core.cache.backends.db.DatabaseCache'), - 'LOCATION': env("VBV_DJANGO_CACHE_LOCATION", default='django_cache_table'), + "default": { + "BACKEND": env( + "VBV_DJANGO_CACHE_BACKEND", + default="django.core.cache.backends.db.DatabaseCache", + ), + "LOCATION": env("VBV_DJANGO_CACHE_LOCATION", default="django_cache_table"), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", # Mimicing memcache behavior. @@ -517,6 +532,7 @@ if DJANGO_DEV_MODE == "production": event_level=logging.ERROR, # Send errors as events ) integrations = [sentry_logging, DjangoIntegration(), RedisIntegration()] + # pylint: disable=abstract-class-instantiated sentry_sdk.init( dsn=SENTRY_DSN, integrations=integrations, diff --git a/server/config/settings/test.py b/server/config/settings/test.py index b26e1a05..8e6e83cb 100644 --- a/server/config/settings/test.py +++ b/server/config/settings/test.py @@ -1,6 +1,4 @@ -""" -With these settings, tests run faster. -""" +# pylint: disable=unused-wildcard-import,wildcard-import,wrong-import-position from .base import * # noqa from .base import env diff --git a/server/config/urls.py b/server/config/urls.py index b389857e..a353b863 100644 --- a/server/config/urls.py +++ b/server/config/urls.py @@ -12,12 +12,25 @@ from rest_framework.authtoken.views import obtain_auth_token from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt urlpatterns = [ - path("", django_view_authentication_exempt(TemplateView.as_view(template_name="pages/home.html")), name="home"), - path("about/", TemplateView.as_view(template_name="pages/about.html"), name="about"), + path( + "", + django_view_authentication_exempt( + TemplateView.as_view(template_name="pages/home.html") + ), + name="home", + ), + path( + "about/", TemplateView.as_view(template_name="pages/about.html"), name="about" + ), # Django Admin, use {% url 'admin:index' %} path(settings.ADMIN_URL, admin.site.urls), # Your stuff: custom urls includes go here - path('login/', django_view_authentication_exempt(auth_views.LoginView.as_view(template_name='core/login.html'))), + path( + "login/", + django_view_authentication_exempt( + auth_views.LoginView.as_view(template_name="core/login.html") + ), + ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG: # Static file serving when using Gunicorn + Uvicorn for local web socket development diff --git a/server/vbv_lernwelt/__init__.py b/server/vbv_lernwelt/__init__.py index e1d86152..e69de29b 100644 --- a/server/vbv_lernwelt/__init__.py +++ b/server/vbv_lernwelt/__init__.py @@ -1,7 +0,0 @@ -__version__ = "0.1.0" -__version_info__ = tuple( - [ - int(num) if num.isdigit() else num - for num in __version__.replace("-", ".", 1).split(".") - ] -) diff --git a/server/vbv_lernwelt/conftest.py b/server/vbv_lernwelt/conftest.py deleted file mode 100644 index ccca8b05..00000000 --- a/server/vbv_lernwelt/conftest.py +++ /dev/null @@ -1,14 +0,0 @@ -import pytest - -from vbv_lernwelt.users.models import User -from vbv_lernwelt.users.tests.factories import UserFactory - - -@pytest.fixture(autouse=True) -def media_storage(settings, tmpdir): - settings.MEDIA_ROOT = tmpdir.strpath - - -@pytest.fixture -def user() -> User: - return UserFactory() diff --git a/server/vbv_lernwelt/core/apps.py b/server/vbv_lernwelt/core/apps.py index d7837ded..eceb1b3d 100644 --- a/server/vbv_lernwelt/core/apps.py +++ b/server/vbv_lernwelt/core/apps.py @@ -7,6 +7,7 @@ class CoreConfig(AppConfig): def ready(self): try: + # pylint: disable=unused-import,import-outside-toplevel import vbv_lernwelt.core.signals # noqa F401 except ImportError: pass diff --git a/server/vbv_lernwelt/core/models.py b/server/vbv_lernwelt/core/models.py index a2f71471..abc64ab9 100644 --- a/server/vbv_lernwelt/core/models.py +++ b/server/vbv_lernwelt/core/models.py @@ -9,8 +9,6 @@ class User(AbstractUser): If adding fields that need to be filled at user signup, """ - pass - class SecurityRequestResponseLog(models.Model): label = models.CharField(max_length=255, blank=True, default="") diff --git a/server/vbv_lernwelt/core/tests.py b/server/vbv_lernwelt/core/tests.py index 7ce503c2..a39b155a 100644 --- a/server/vbv_lernwelt/core/tests.py +++ b/server/vbv_lernwelt/core/tests.py @@ -1,3 +1 @@ -from django.test import TestCase - # Create your tests here. diff --git a/server/vbv_lernwelt/core/views.py b/server/vbv_lernwelt/core/views.py index 91ea44a2..60f00ef0 100644 --- a/server/vbv_lernwelt/core/views.py +++ b/server/vbv_lernwelt/core/views.py @@ -1,3 +1 @@ -from django.shortcuts import render - # Create your views here.