Skip to content

Commit c93cd82

Browse files
committed
fix: [config] add explicit relative path field to the config loading
The rel_path is a calculated field that is critical to determining where files are placed and found in the scratch dir and also the reports dir. At the moment the field is not created until the flow objects are created. Which means that the saved config doesn't have the information unless it's overridden in the config itself. This commit moves the calculated field out of the flow base class init into the config loading stage where it is saved the filesystem in the scratch dir along with the rest of the loaded config. Which means it can be used to navigate the scratch dir after a run. Signed-off-by: James McCorrie <[email protected]>
1 parent ad977a9 commit c93cd82

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/dvsim/project.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class FlowConfig(BaseModel):
3232
flow: str
3333
name: str
3434

35+
self_dir: Path
36+
rel_path: Path
37+
3538

3639
class TopFlowConfig(BaseModel):
3740
"""Flow configuration data."""
@@ -42,6 +45,9 @@ class TopFlowConfig(BaseModel):
4245
project: str
4346
revision: str
4447

48+
self_dir: Path
49+
rel_path: Path
50+
4551
cfgs: Mapping[Path, FlowConfig]
4652

4753

@@ -209,6 +215,13 @@ def _load_flow_config(
209215
cfg["tool"] = args.tool
210216

211217
if "cfgs" in cfg:
218+
# add any missing rel_path fields
219+
for child_cfg in cfg["cfgs"].values():
220+
if "rel_path" not in child_cfg:
221+
child_cfg["rel_path"] = child_cfg["self_dir"].relative_to(
222+
root_path,
223+
)
224+
212225
return TopFlowConfig.model_validate(cfg)
213226

214227
return FlowConfig.model_validate(cfg)

tests/test_project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"config": {
3030
"flow": "flow",
3131
"name": "name",
32+
"self_dir": Path("self_dir"),
33+
"rel_path": Path("rel_path"),
3234
},
3335
},
3436
FlowConfig,

0 commit comments

Comments
 (0)