Skip to content

Commit a33e393

Browse files
committed
Missing secrets is not fatal.
1 parent b154343 commit a33e393

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/modelgauge/config.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
import tomli
88

99
from modelgauge import config_templates
10+
from modelgauge.log_config import get_logger
1011
from modelgauge.secret_values import MissingSecretValues, RawSecrets, SecretDescription
1112

1213
DEFAULT_CONFIG_DIR = "config"
1314
DEFAULT_SECRETS = "secrets.toml"
1415
SECRETS_PATH = os.path.join(DEFAULT_CONFIG_DIR, DEFAULT_SECRETS)
1516
CONFIG_TEMPLATES = [DEFAULT_SECRETS]
1617

18+
logger = get_logger(__name__)
19+
1720

1821
def find_config_dir(path: str = ".") -> str:
1922
"""Search up the tree for the config directory."""
@@ -47,9 +50,13 @@ def write_default_config(parent_dir: str = "."):
4750

4851
def load_secrets_from_config(path: str = ".") -> RawSecrets:
4952
"""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 = {}
5360
for values in data.values():
5461
# Verify the config is shaped as expected.
5562
assert isinstance(values, Mapping), "All keys should be in a [scope]."

tests/modelgauge_tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def test_load_secrets_from_config_no_file(tmpdir):
8686
config_dir = tmpdir.join("config")
8787
os.makedirs(config_dir)
8888

89-
with pytest.raises(FileNotFoundError):
90-
load_secrets_from_config(tmpdir)
89+
secrets = load_secrets_from_config(tmpdir)
90+
assert secrets == {}
9191

9292

9393
def test_load_secrets_from_config_bad_format(tmpdir):

0 commit comments

Comments
 (0)