Skip to content

Commit

Permalink
Refactor settings file env var settings
Browse files Browse the repository at this point in the history
This code is pretty ugly still but I got rid of a few lines.
  • Loading branch information
pcraig3 committed Nov 9, 2024
1 parent 0fd7f84 commit ecb67b3
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions bloom_nofos/bloom_nofos/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# Initialise environment variables
env_file = ".env"

is_docker = cast_to_boolean(os.environ.get("IS_DOCKER", False))
if is_docker:
if cast_to_boolean(os.environ.get("IS_DOCKER", False)):
env_file = ".env.docker"

is_prod = cast_to_boolean(os.environ.get("IS_PROD", False))
Expand All @@ -35,12 +34,20 @@
env = environ.Env()
env_path = os.path.join(BASE_DIR, "bloom_nofos", env_file)

# Check if the env_path exists before reading
if os.path.exists(env_path):
env_exists = os.path.exists(env_path)
if env_exists:
environ.Env.read_env(env_path)
else:

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = cast_to_boolean(env.get_value("DEBUG", default=True))
print("=====")
print("DEBUG: {}".format(DEBUG))
if DEBUG:
print("=====")
print("Environment file not found at {}".format(env_path))
if env_exists:
print(".env file: {}".format(env_file))
else:
print("No .env file found at {}".format(env_path))

# Project version

Expand All @@ -54,14 +61,6 @@

GITHUB_SHA = os.getenv("GITHUB_SHA", None)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = cast_to_boolean(env.get_value("DEBUG", default=True))
print("=====")
print("DEBUG: {}".format(DEBUG))
if DEBUG:
print("=====")
print("Using env vars from: {}".format(env_file))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

Expand Down

0 comments on commit ecb67b3

Please sign in to comment.