Skip to content

Commit 355242b

Browse files
committed
updated default benchmarks path logic
Signed-off-by: Ian Eaves <ian.k.eaves@gmail.com>
1 parent 2c83c8d commit 355242b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

docs/ramalama.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@
214214
#
215215

216216
[ramalama.benchmarks]
217-
#storage_folder = <conf dir>/benchmarks
217+
#storage_folder = <default store>/benchmarks
218218
#
219219
# Manually specify where to save benchmark results.
220-
# By default, this will be stored in the default configuration
221-
# directory for your platform as benchmarks.jsonl.
220+
# By default, results are stored under the default model store directory
221+
# in benchmarks/benchmarks.jsonl.
222+
# Changing `ramalama.store` does not update this; set storage_folder explicitly.
222223

223224

224225
[ramalama.user]

docs/ramalama.conf.5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ The ramalama.benchmarks table contains benchmark related settings.
258258

259259
`[[ramalama.benchmarks]]`
260260

261-
**storage_folder**="<conf dir>/benchmarks"
261+
**storage_folder**="<default store>/benchmarks"
262262

263263
Manually specify where to save benchmark results.
264-
By default, this will be stored in the default configuration
265-
directory for your platform as `benchmarks.jsonl`.
264+
By default, this will be stored in the default model store directory under `benchmarks/`.
265+
Changing `ramalama.store` does not update this; set `ramalama.benchmarks.storage_folder` explicitly if needed.
266266

267267
## RAMALAMA.USER TABLE
268268
The ramalama.user table contains user preference settings.

ramalama/config.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
from dataclasses import dataclass, field, fields
5+
from functools import lru_cache
56
from pathlib import Path
67
from typing import Any, Literal, Mapping, TypeAlias
78

@@ -79,6 +80,7 @@ def get_default_engine() -> SUPPORTED_ENGINES | None:
7980
return "docker" if available("docker") else None
8081

8182

83+
@lru_cache(maxsize=1)
8284
def get_default_store() -> str:
8385
# Check if running as root (Unix only)
8486
if hasattr(os, 'geteuid') and os.geteuid() == 0:
@@ -136,24 +138,21 @@ def coerce_to_bool(value: Any) -> bool:
136138
raise ValueError(f"Cannot coerce {value!r} to bool")
137139

138140

139-
def get_default_benchmarks_storage_folder() -> Path:
140-
conf_dir = None
141-
for dir in DEFAULT_CONFIG_DIRS:
142-
if os.path.exists(dir):
143-
conf_dir = dir
144-
break
141+
def get_storage_folder(base_path: str | None = None):
142+
if base_path is None:
143+
base_path = get_default_store()
145144

146-
if conf_dir is not None:
147-
return conf_dir / "benchmarks"
148-
149-
return DEFAULT_CONFIG_DIRS[0]
145+
return os.path.join(base_path, "benchmarks")
150146

151147

152148
@dataclass
153149
class Benchmarks:
154-
storage_folder: Path = field(default_factory=get_default_benchmarks_storage_folder)
150+
storage_folder: str = field(default_factory=get_storage_folder)
155151
disable: bool = False
156152

153+
def __post_init__(self):
154+
os.makedirs(self.storage_folder, exist_ok=True)
155+
157156

158157
@dataclass
159158
class UserConfig:

ramalama/transports/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import platform
44
import random
5-
import shlex
65
import socket
76
import subprocess
87
import sys

test/unit/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_env_overrides_file_and_default():
143143
],
144144
)
145145
def test_get_default_store(uid, is_root, expected):
146+
get_default_store.cache_clear()
146147
with patch("os.geteuid", return_value=uid):
147148
assert get_default_store() == expected
148149

0 commit comments

Comments
 (0)