From 853d2f34a6191712ea2c5672d03038d91621247e Mon Sep 17 00:00:00 2001 From: Jeff Triplett Date: Wed, 25 Oct 2023 14:05:26 -0500 Subject: [PATCH] :tractor: Migrate to environs[django] (#68) * :tractor: Migrate to environs[django] * :gear: Adds just bootstrap --- Justfile | 3 +++ pyproject.toml | 2 +- src/service/__init__.py | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Justfile b/Justfile index d15d176..ed01e28 100644 --- a/Justfile +++ b/Justfile @@ -7,6 +7,9 @@ set dotenv-load := true # DEPENDENCIES # ################## +@bootstrap: + python -m pip install --editable '.[dev,hc,relay]' + install: python -m pip install --editable '.[dev]' diff --git a/pyproject.toml b/pyproject.toml index 54a123f..d6d51f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ hc = ["requests"] lint = ["pre-commit"] psycopg = ["psycopg[binary]"] psycopg2 = ["psycopg2-binary"] -relay = ["dj-database-url"] +relay = ["environs[django]"] [project.urls] Documentation = "https://github.com/westerveltco/django-email-relay#readme" diff --git a/src/service/__init__.py b/src/service/__init__.py index b629c12..335fa12 100644 --- a/src/service/__init__.py +++ b/src/service/__init__.py @@ -4,11 +4,11 @@ import os from typing import Any -import dj_database_url import django from django.conf import global_settings from django.conf import settings from django.core.management import call_command +from environs import Env from email_relay.conf import EMAIL_RELAY_SETTINGS_NAME @@ -133,9 +133,11 @@ def merge_with_defaults( return return_dict +env = Env() + default_settings = { "DATABASES": { - "default": dj_database_url.parse(os.getenv("DATABASE_URL", "sqlite://:memory:")) + "default": env.dj_db_url("DATABASE_URL", default="sqlite://:memory:") }, "LOGGING": { "version": 1, @@ -147,7 +149,7 @@ def merge_with_defaults( }, "root": { "handlers": ["console"], - "level": os.getenv("LOG_LEVEL", "INFO"), + "level": env("LOG_LEVEL", "INFO"), }, }, "INSTALLED_APPS": [