|
2 | 2 | import os |
3 | 3 | import sys |
4 | 4 | from dataclasses import dataclass, field, fields |
| 5 | +from functools import lru_cache |
5 | 6 | from pathlib import Path |
6 | 7 | from typing import Any, Literal, Mapping, TypeAlias |
7 | 8 |
|
@@ -79,6 +80,7 @@ def get_default_engine() -> SUPPORTED_ENGINES | None: |
79 | 80 | return "docker" if available("docker") else None |
80 | 81 |
|
81 | 82 |
|
| 83 | +@lru_cache(maxsize=1) |
82 | 84 | def get_default_store() -> str: |
83 | 85 | # Check if running as root (Unix only) |
84 | 86 | if hasattr(os, 'geteuid') and os.geteuid() == 0: |
@@ -136,24 +138,21 @@ def coerce_to_bool(value: Any) -> bool: |
136 | 138 | raise ValueError(f"Cannot coerce {value!r} to bool") |
137 | 139 |
|
138 | 140 |
|
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() |
145 | 144 |
|
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") |
150 | 146 |
|
151 | 147 |
|
152 | 148 | @dataclass |
153 | 149 | class Benchmarks: |
154 | | - storage_folder: Path = field(default_factory=get_default_benchmarks_storage_folder) |
| 150 | + storage_folder: str = field(default_factory=get_storage_folder) |
155 | 151 | disable: bool = False |
156 | 152 |
|
| 153 | + def __post_init__(self): |
| 154 | + os.makedirs(self.storage_folder, exist_ok=True) |
| 155 | + |
157 | 156 |
|
158 | 157 | @dataclass |
159 | 158 | class UserConfig: |
|
0 commit comments