From b3d3de537404825a4ba8da136b84c2420f212818 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Sat, 18 Mar 2023 15:23:51 -0400 Subject: [PATCH] Use typecasting env functions Many of these environment variables were probably not actually usable, since they would be strings if set in the env file. Using the typecasting functions fixes this, and generally shows the intention of the code more clearly. --- bookwyrm/settings.py | 18 +++++++++--------- celerywyrm/settings.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 3f14daf1b..a04ed8cc7 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -18,7 +18,7 @@ RELEASE_API = env( "https://api.github.com/repos/bookwyrm-social/bookwyrm/releases/latest", ) -PAGE_LENGTH = env("PAGE_LENGTH", 15) +PAGE_LENGTH = env.int("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") JS_CACHE = "a7d4e720" @@ -26,7 +26,7 @@ JS_CACHE = "a7d4e720" # email EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend") EMAIL_HOST = env("EMAIL_HOST") -EMAIL_PORT = env("EMAIL_PORT", 587) +EMAIL_PORT = env.int("EMAIL_PORT", 587) EMAIL_HOST_USER = env("EMAIL_HOST_USER") EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD") EMAIL_USE_TLS = env.bool("EMAIL_USE_TLS", True) @@ -205,14 +205,14 @@ WSGI_APPLICATION = "bookwyrm.wsgi.application" # redis/activity streams settings REDIS_ACTIVITY_HOST = env("REDIS_ACTIVITY_HOST", "localhost") -REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379) +REDIS_ACTIVITY_PORT = env.int("REDIS_ACTIVITY_PORT", 6379) REDIS_ACTIVITY_PASSWORD = requests.utils.quote(env("REDIS_ACTIVITY_PASSWORD", "")) -REDIS_ACTIVITY_DB_INDEX = env("REDIS_ACTIVITY_DB_INDEX", 0) +REDIS_ACTIVITY_DB_INDEX = env.int("REDIS_ACTIVITY_DB_INDEX", 0) REDIS_ACTIVITY_URL = env( "REDIS_ACTIVITY_URL", f"redis://:{REDIS_ACTIVITY_PASSWORD}@{REDIS_ACTIVITY_HOST}:{REDIS_ACTIVITY_PORT}/{REDIS_ACTIVITY_DB_INDEX}", ) -MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200)) +MAX_STREAM_LENGTH = env.int("MAX_STREAM_LENGTH", 200) STREAMS = [ {"key": "home", "name": _("Home Timeline"), "shortname": _("Home")}, @@ -221,12 +221,12 @@ STREAMS = [ # Search configuration # total time in seconds that the instance will spend searching connectors -SEARCH_TIMEOUT = int(env("SEARCH_TIMEOUT", 8)) +SEARCH_TIMEOUT = env.int("SEARCH_TIMEOUT", 8) # timeout for a query to an individual connector -QUERY_TIMEOUT = int(env("QUERY_TIMEOUT", 5)) +QUERY_TIMEOUT = env.int("QUERY_TIMEOUT", 5) # Redis cache backend -if env("USE_DUMMY_CACHE", False): +if env.bool("USE_DUMMY_CACHE", False): CACHES = { "default": { "BACKEND": "django.core.cache.backends.dummy.DummyCache", @@ -256,7 +256,7 @@ DATABASES = { "USER": env("POSTGRES_USER", "bookwyrm"), "PASSWORD": env("POSTGRES_PASSWORD", "bookwyrm"), "HOST": env("POSTGRES_HOST", ""), - "PORT": env("PGPORT", 5432), + "PORT": env.int("PGPORT", 5432), }, } diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index 052f48843..e06b256f5 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -6,8 +6,8 @@ from bookwyrm.settings import * # pylint: disable=line-too-long REDIS_BROKER_PASSWORD = requests.utils.quote(env("REDIS_BROKER_PASSWORD", "")) REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker") -REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379) -REDIS_BROKER_DB_INDEX = env("REDIS_BROKER_DB_INDEX", 0) +REDIS_BROKER_PORT = env.int("REDIS_BROKER_PORT", 6379) +REDIS_BROKER_DB_INDEX = env.int("REDIS_BROKER_DB_INDEX", 0) REDIS_BROKER_URL = env( "REDIS_BROKER_URL", f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/{REDIS_BROKER_DB_INDEX}",