File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed
Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -168,15 +168,16 @@ def config_file_exists(cls, config_file):
168168
169169 @model_validator (mode = "after" )
170170 def setup_config (cls , values ) -> Any :
171- with open (file = values .config_file , mode = "r" ) as f :
172- file_content = f .read ()
173- f .close ()
171+ with open (file = values .config_file , mode = "r" ) as file :
172+ file_content = file .read ()
173+ file .close ()
174174
175175 # replace environment variables (pattern: ${VARIABLE_NAME})
176176 for match in set (re .findall (pattern = r"\${[A-Z_]+}" , string = file_content )):
177177 variable = match .replace ("${" , "" ).replace ("}" , "" )
178- assert os .getenv (variable ), f"Environment variable { variable } not found or empty to replace { match } ."
179- file_content = file_content .replace (match , os .environ [variable ])
178+ if not os .getenv (variable ):
179+ logging .warning (f"Environment variable { variable } not found or empty to replace { match } ." )
180+ file_content = file_content .replace (match , os .getenv (variable , match ))
180181
181182 config = Config (** yaml .safe_load (file_content ))
182183
Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ services:
4444 postgres :
4545 condition : service_healthy
4646
47-
4847 postgres :
4948 extends :
5049 file : compose.yml
Original file line number Diff line number Diff line change 11from functools import lru_cache
2+ import logging
23import os
34import re
45from typing import Any , Optional
@@ -43,15 +44,16 @@ def config_file_exists(cls, config_file):
4344
4445 @model_validator (mode = "after" )
4546 def setup_config (cls , values ) -> Any :
46- with open (file = values .config_file , mode = "r" ) as f :
47- file_content = f .read ()
48- f .close ()
47+ with open (file = values .config_file , mode = "r" ) as file :
48+ file_content = file .read ()
49+ file .close ()
4950
5051 # replace environment variables (pattern: ${VARIABLE_NAME})
5152 for match in set (re .findall (pattern = r"\${[A-Z_]+}" , string = file_content )):
5253 variable = match .replace ("${" , "" ).replace ("}" , "" )
53- assert os .getenv (variable ), f"Environment variable { variable } not found or empty to replace { match } ."
54- file_content = file_content .replace (match , os .environ [variable ])
54+ if not os .getenv (variable ):
55+ logging .warning (f"Environment variable { variable } not found or empty to replace { match } ." )
56+ file_content = file_content .replace (match , os .getenv (variable , match ))
5557
5658 config = Config (** yaml .safe_load (file_content ))
5759
You can’t perform that action at this time.
0 commit comments