"""General utilities for apps.""" import enum import os class AreaError(Exception): """Error raised when area configuration is invalid or missing.""" class Area(enum.Enum): """The area we are running.""" Test = "Test" Live = "Live" def from_env() -> Area: """Load AREA from environment variable. Raises: AreaError: if AREA is not defined """ var = os.getenv("AREA", "Test") if var == "Test": return Area.Test if var == "Live": return Area.Live msg = "AREA not defined" raise AreaError(msg)