From 69c08d196f8bf8fe64fc954f2f4b9f19e10e078c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 25 Nov 2023 22:22:00 +0000 Subject: Remove the need for calling dotenv manually by using pydantic --- bot/__init__.py | 7 ------- bot/constants.py | 2 ++ bot/log.py | 6 +++--- 3 files changed, 5 insertions(+), 10 deletions(-) (limited to 'bot') diff --git a/bot/__init__.py b/bot/__init__.py index 67165073..6646f2af 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,10 +1,3 @@ -try: - from dotenv import load_dotenv - print("Found .env file, loading environment variables from it.") # noqa: T201 - load_dotenv(override=True) -except ModuleNotFoundError: - pass - import asyncio import os from typing import TYPE_CHECKING diff --git a/bot/constants.py b/bot/constants.py index 894ea857..0d74fb4a 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -33,6 +33,7 @@ log = get_logger(__name__) PYTHON_PREFIX = "!" +GIT_SHA = environ.get("GIT_SHA", "development") class EnvConfig( @@ -90,6 +91,7 @@ class _Client(EnvConfig, env_prefix="client_"): github_repo: str = "https://github.com/python-discord/sir-lancebot" # Override seasonal locks: 1 (January) to 12 (December) month_override: int | None = None + sentry_dsn: str = "" Client = _Client() diff --git a/bot/log.py b/bot/log.py index b4431bc3..9ebc89a7 100644 --- a/bot/log.py +++ b/bot/log.py @@ -10,7 +10,7 @@ from pydis_core.utils import logging as core_logging from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.redis import RedisIntegration -from bot.constants import Logging +from bot.constants import Client, GIT_SHA, Logging def setup() -> None: @@ -59,12 +59,12 @@ def setup_sentry() -> None: ) sentry_sdk.init( - dsn=os.environ.get("BOT_SENTRY_DSN"), + dsn=Client.sentry_dsn, integrations=[ sentry_logging, RedisIntegration(), ], - release=f"bot@{os.environ.get('GIT_SHA')}", + release=f"bot@{GIT_SHA}", traces_sample_rate=0.5, _experiments={ "profiles_sample_rate": 0.5, -- cgit v1.2.3