|  | 
| 7 | 7 | import tomli | 
| 8 | 8 | 
 | 
| 9 | 9 | from modelgauge import config_templates | 
|  | 10 | +from modelgauge.log_config import get_logger | 
| 10 | 11 | from modelgauge.secret_values import MissingSecretValues, RawSecrets, SecretDescription | 
| 11 | 12 | 
 | 
| 12 | 13 | DEFAULT_CONFIG_DIR = "config" | 
| 13 | 14 | DEFAULT_SECRETS = "secrets.toml" | 
| 14 | 15 | SECRETS_PATH = os.path.join(DEFAULT_CONFIG_DIR, DEFAULT_SECRETS) | 
| 15 | 16 | CONFIG_TEMPLATES = [DEFAULT_SECRETS] | 
| 16 | 17 | 
 | 
|  | 18 | +logger = get_logger(__name__) | 
|  | 19 | + | 
| 17 | 20 | 
 | 
| 18 | 21 | def find_config_dir(path: str = ".") -> str: | 
| 19 | 22 |     """Search up the tree for the config directory.""" | 
| @@ -47,9 +50,13 @@ def write_default_config(parent_dir: str = "."): | 
| 47 | 50 | 
 | 
| 48 | 51 | def load_secrets_from_config(path: str = ".") -> RawSecrets: | 
| 49 | 52 |     """Load the toml file and verify it is shaped as expected.""" | 
| 50 |  | -    secrets_path = os.path.join(find_config_dir(path), DEFAULT_SECRETS) | 
| 51 |  | -    with open(secrets_path, "rb") as f: | 
| 52 |  | -        data = tomli.load(f) | 
|  | 53 | +    try: | 
|  | 54 | +        secrets_path = os.path.join(find_config_dir(path), DEFAULT_SECRETS) | 
|  | 55 | +        with open(secrets_path, "rb") as f: | 
|  | 56 | +            data = tomli.load(f) | 
|  | 57 | +    except FileNotFoundError as exc: | 
|  | 58 | +        logger.warning("Could not find secrets file", exc_info=exc) | 
|  | 59 | +        data = {} | 
| 53 | 60 |     for values in data.values(): | 
| 54 | 61 |         # Verify the config is shaped as expected. | 
| 55 | 62 |         assert isinstance(values, Mapping), "All keys should be in a [scope]." | 
|  | 
0 commit comments