improve typing for config

This commit is contained in:
ducklet 2023-03-18 22:09:03 +01:00
parent a020d972f8
commit c9c95ba2fa

View file

@ -2,20 +2,20 @@ import os
import tomllib import tomllib
from pathlib import Path from pathlib import Path
datadir = Path(os.getenv("UNWIND_DATA") or "./data") datadir: Path = Path(os.getenv("UNWIND_DATA") or "./data")
cachedir = ( cachedir: Path = Path(p) if (p := os.getenv("UNWIND_CACHEDIR")) else datadir / ".cache"
Path(cachedir) debug: bool = os.getenv("DEBUG") == "1"
if (cachedir := os.getenv("UNWIND_CACHEDIR", datadir / ".cache")) loglevel: str = os.getenv("UNWIND_LOGLEVEL") or ("DEBUG" if debug else "INFO")
else None storage_path: Path = (
Path(p) if (p := os.getenv("UNWIND_STORAGE")) else datadir / "db.sqlite"
)
config_path: Path = (
Path(p) if (p := os.getenv("UNWIND_CONFIG")) else datadir / "config.toml"
) )
debug = os.getenv("DEBUG") == "1"
loglevel = os.getenv("UNWIND_LOGLEVEL") or ("DEBUG" if debug else "INFO")
storage_path = os.getenv("UNWIND_STORAGE", datadir / "db.sqlite")
config_path = os.getenv("UNWIND_CONFIG", datadir / "config.toml")
with open(config_path, "rb") as fd: with open(config_path, "rb") as fd:
_config = tomllib.load(fd) _config = tomllib.load(fd)
api_base = _config["api"].get("base", "/api/") api_base: str = _config["api"].get("base", "/api/")
api_cors = _config["api"].get("cors", "*") api_cors: str = _config["api"].get("cors", "*")
api_credentials = _config["api"].get("credentials", {}) api_credentials: dict[str, str] = _config["api"].get("credentials", {})