import os from pillar_tool.util.config import Config import tomllib def load_config(): paths: list[str] = [ "./pillar_tool.toml", "/etc/pillar_tool/config.toml", ] for path in paths: if os.path.exists(path): with open(path, 'rb') as f: # noinspection PyBroadException try: cfg_dict = tomllib.load(f) cfg = Config(**cfg_dict) globals()['_loaded_config_object'] = cfg return except Exception as e: print(e) raise ValueError(f"No valid config file could be found! (working directory: {os.getcwd()})") def config() -> Config: return globals()['_loaded_config_object']