feat: creatives and external channels
This commit is contained in:
@@ -9,18 +9,19 @@ RESET = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
|
||||
|
||||
def load_settings(settings_class: type[BaseSettings]) -> BaseSettings:
|
||||
def load_settings[T: BaseSettings](settings_class: type[T]) -> T:
|
||||
try:
|
||||
return settings_class()
|
||||
except ValidationError as e:
|
||||
print(f'{RED}{BOLD}Missing environment variables:{RESET}')
|
||||
|
||||
missing = set()
|
||||
missing: set[str] = set()
|
||||
for err in e.errors():
|
||||
if err['type'] == 'missing' and len(err['loc']) == 1:
|
||||
field = settings_class.model_fields.get(str(err['loc'][0]))
|
||||
if field and hasattr(field.annotation, 'model_fields'):
|
||||
for name, info in field.annotation.model_fields.items():
|
||||
field_info = settings_class.model_fields.get(str(err['loc'][0]))
|
||||
if field_info and field_info.annotation is not None and hasattr(field_info.annotation, 'model_fields'):
|
||||
annotation_fields = getattr(field_info.annotation, 'model_fields', {})
|
||||
for name, info in annotation_fields.items():
|
||||
if info.is_required():
|
||||
missing.add(f'{err["loc"][0]}__{name}'.upper())
|
||||
else:
|
||||
@@ -28,8 +29,8 @@ def load_settings(settings_class: type[BaseSettings]) -> BaseSettings:
|
||||
else:
|
||||
missing.add('__'.join(str(loc).upper() for loc in err['loc']))
|
||||
|
||||
for field in sorted(missing):
|
||||
print(f' {YELLOW}{field}{RESET}')
|
||||
for field_name in sorted(missing):
|
||||
print(f' {YELLOW}{field_name}{RESET}')
|
||||
|
||||
print(f'\n{RED}Check .env file or set required variables{RESET}')
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user