Skip to content

Commit

Permalink
Allow overriding app settings with environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
caarmen committed Dec 8, 2024
1 parent 781da7d commit 43ebd98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rm -rf reports
SQL_LOG_LEVEL=DEBUG python -m pytest \
APP__LOGGING__SQL_LOG_LEVEL=DEBUG python -m pytest \
--numprocesses=auto \
--cov=slackhealthbot \
--cov-report=xml \
Expand Down
10 changes: 7 additions & 3 deletions slackhealthbot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ class AppSettings(BaseSettings):
app: App
withings: Withings
fitbit: Fitbit
model_config = SettingsConfigDict(yaml_file="config/app-merged.yaml")
model_config = SettingsConfigDict(
env_nested_delimiter="__",
yaml_file="config/app-merged.yaml",
)

@classmethod
def _load_yaml_file(
Expand All @@ -101,14 +104,15 @@ def _load_merged_config(cls) -> dict:
def settings_customise_sources(
cls,
settings_cls: BaseSettings,
*args,
*,
env_settings: PydanticBaseSettingsSource,
**kwargs,
) -> tuple[PydanticBaseSettingsSource, ...]:
merged_config = cls._load_merged_config()
with open("config/app-merged.yaml", "w", encoding="utf-8") as file:
yaml.safe_dump(merged_config, file)
yaml_settings_source = YamlConfigSettingsSource(settings_cls)
return (yaml_settings_source,)
return (env_settings, yaml_settings_source)


class SecretSettings(BaseSettings):
Expand Down

0 comments on commit 43ebd98

Please sign in to comment.