1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import tomllib
class Config: _profile = None
@classmethod def __load(cls): if cls._profile is None: import os root_dir = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(root_dir, "config.toml"), "rb") as fp: config_data = tomllib.load(fp) profiles = config_data.get("profiles") active = profiles.get("active") cls._profile = profiles.get(active) return cls._profile
@classmethod def get(cls, key: str): if cls._profile is None: cls.__load() return cls._profile.get(key)
|