fix: switch to dev settings for Docker services and improve env config
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 10m27s
CI/CD Pipeline / Run Tests (push) Failing after 10m43s
CI/CD Pipeline / Build & Push Images (push) Successful in 7m28s
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Successful in 44s
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 10m27s
CI/CD Pipeline / Run Tests (push) Failing after 10m43s
CI/CD Pipeline / Build & Push Images (push) Successful in 7m28s
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Successful in 44s
This commit is contained in:
53
src/config/settings/env.py
Normal file
53
src/config/settings/env.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from decouple import AutoConfig, Config, RepositoryEnv
|
||||
|
||||
|
||||
def build_config(base_dir: Path):
|
||||
env_file = base_dir / ".env"
|
||||
if env_file.exists():
|
||||
return Config(RepositoryEnv(str(env_file)))
|
||||
return AutoConfig(search_path=base_dir)
|
||||
|
||||
|
||||
def env_bool(value: Any, default: bool = False) -> bool:
|
||||
if value is None:
|
||||
return default
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, (int, float)):
|
||||
return bool(value)
|
||||
s = str(value).strip().lower()
|
||||
if s in {"1", "true", "yes", "y", "on"}:
|
||||
return True
|
||||
if s in {"0", "false", "no", "n", "off"}:
|
||||
return False
|
||||
return default
|
||||
|
||||
|
||||
def env_int(value: Any, default: int = 0) -> int:
|
||||
try:
|
||||
return int(str(value).strip())
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def env_list(value: Any, default: Iterable[str] = ()) -> list[str]:
|
||||
"""
|
||||
Поддерживает:
|
||||
- "a,b,c"
|
||||
- "a, b, c"
|
||||
- пустые значения
|
||||
"""
|
||||
if value is None:
|
||||
return list(default)
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return [str(x).strip() for x in value if str(x).strip()]
|
||||
s = str(value).strip()
|
||||
if not s:
|
||||
return list(default)
|
||||
return [p.strip() for p in s.split(",") if p.strip()]
|
||||
Reference in New Issue
Block a user