-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodels.py
51 lines (45 loc) · 1.77 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from pathlib import Path
import pydantic
import yaml
from execution.consts import BENCHMARK_CONFIG_PATH
from execution.consts import EXIT_ON_ERROR
from utils import is_safe_path
import rich
import rich.padding
class RuntimeSettings(pydantic.BaseModel):
project_name: str
benchmark_mode: bool = False
ignore_cache: bool = False
def load_benchmark_file(self) -> dict:
"""Load the benchmark file for the project.
File should be located at `projects/{project_name}/benchmark.yml`
Represents all the executions that should be run, and the user inputs for each execution (external inputs).
Structure:
```yaml
executions:
- user_inputs:
x: y
...
```
"""
try:
if not is_safe_path(Path.cwd() / 'projects', Path.cwd() / 'projects' / self.project_name / BENCHMARK_CONFIG_PATH):
if EXIT_ON_ERROR:
rich.print(
rich.padding.Padding(
f"[bold red]Error: Directory traversal detected in project name[/bold red]",
(2, 4),
expand=True,
style="bold red",
)
)
os._exit(1)
else:
raise FileNotFoundError("Directory traversal detected in project name")
with open(
Path.cwd() / 'projects' / self.project_name / BENCHMARK_CONFIG_PATH, 'r'
) as file:
return yaml.safe_load(file)
except FileNotFoundError:
raise FileNotFoundError(f"Benchmark file not found for project {self.project_name}")