generated from dopt-python/py311
fix loading of .env files
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
|
||||
@@ -9,4 +10,8 @@ if sys.stdout is None:
|
||||
if sys.stderr is None:
|
||||
sys.stderr = open(os.devnull, "w", encoding="utf-8")
|
||||
|
||||
deploy_env_pth = Path(sys.executable).parent / ".env"
|
||||
if deploy_env_pth.exists():
|
||||
dotenv.load_dotenv(dotenv_path=deploy_env_pth)
|
||||
else:
|
||||
dotenv.load_dotenv()
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import enum
|
||||
import os
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
@@ -15,7 +16,10 @@ LIB_PATH: Final[Path] = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
BASE_PATH = io_.search_folder_path(
|
||||
LIB_PATH, stop_folder_name=os.getenv("DOPT_STOP_FOLDER_NAME", "python")
|
||||
LIB_PATH,
|
||||
stop_folder_name=os.getenv(
|
||||
"DOPT_STOP_FOLDER_NAME", str(uuid.uuid4())
|
||||
), # random default to provoke early failures
|
||||
)
|
||||
assert BASE_PATH, "base path not found"
|
||||
|
||||
@@ -28,6 +32,7 @@ class Config:
|
||||
PTH_USER_CFG: Path = BASE_PATH / os.getenv("DOPT_PATH_CONFIG", "config/wattana.toml")
|
||||
|
||||
|
||||
assert Config.PTH_USER_CFG.exists(), "user config not found"
|
||||
user_cfg = configs.load_toml(Config.PTH_USER_CFG)
|
||||
USER_CFG: t.UserConfig = t.UserConfig(
|
||||
Datenbank=t.UserConfig_Datenbank(**user_cfg["Datenbank"]),
|
||||
|
||||
Reference in New Issue
Block a user