import os from pillar_tool.util.config import Config import tomllib def load_config(): paths: list[str] = [ "/etc/pillar_tool/config.toml", "./pillar_tool.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 except: pass raise ValueError("No valid config file could be found!") def config() -> Config: return globals()['_loaded_config_object']