refs #701: load console profile overrides from dotenv
This commit is contained in:
@@ -61,17 +61,38 @@ def resolve_profile_path(default_path: Path) -> Path:
|
||||
return path if path.is_absolute() else default_path.parent / path
|
||||
|
||||
|
||||
def _apply_environment_overrides(profile: AppProfile) -> AppProfile:
|
||||
def _dotenv_value(name: str, path: Path | None) -> str:
|
||||
"""Read one simple KEY=value runtime setting without importing a dotenv lib."""
|
||||
|
||||
if path is None:
|
||||
return ""
|
||||
try:
|
||||
lines = path.read_text(encoding="utf-8").splitlines()
|
||||
except (OSError, UnicodeError):
|
||||
return ""
|
||||
prefix = f"{name}="
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith(prefix):
|
||||
return stripped[len(prefix) :].strip().strip('"').strip("'")
|
||||
return ""
|
||||
|
||||
|
||||
def _apply_environment_overrides(profile: AppProfile, env_file: Path | None) -> AppProfile:
|
||||
"""Apply deployment-specific presentation values without a code change."""
|
||||
|
||||
values = {
|
||||
field_name: os.environ.get(env_name, "").strip() or getattr(profile, field_name)
|
||||
field_name: (
|
||||
os.environ.get(env_name, "").strip()
|
||||
or _dotenv_value(env_name, env_file)
|
||||
or getattr(profile, field_name)
|
||||
)
|
||||
for field_name, env_name in _ENV_FIELD_NAMES.items()
|
||||
}
|
||||
return AppProfile(**values)
|
||||
|
||||
|
||||
def load_app_profile(default_path: Path) -> AppProfile:
|
||||
def load_app_profile(default_path: Path, env_file: Path | None = None) -> AppProfile:
|
||||
"""Load the selectable product skin without coupling it to a PoC name."""
|
||||
|
||||
path = resolve_profile_path(default_path)
|
||||
@@ -101,7 +122,7 @@ def load_app_profile(default_path: Path) -> AppProfile:
|
||||
text_color=_string(theme, "text_color"),
|
||||
muted_color=_string(theme, "muted_color"),
|
||||
border_color=_string(theme, "border_color"),
|
||||
))
|
||||
), env_file)
|
||||
required = (
|
||||
profile.product_name,
|
||||
profile.short_name,
|
||||
|
||||
Reference in New Issue
Block a user