Skip to content

Commit d78815b

Browse files
committed
refactor: [config] move overrides from flow base to config loading stage
This is to ensure that the saved project config is already resolved otherwise the overrides mechanism would need to be implemented in any code that loads the project config. Without this change, the report generation code can't see the correct rel_path field as it is overridden in the flow object after being saved as part of the project config. Signed-off-by: James McCorrie <[email protected]>
1 parent c93cd82 commit d78815b

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/dvsim/config/load.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@ def _merge_use_cfgs(
421421
return {k: v for k, v in cfg.items() if k != "use_cfgs"}
422422

423423

424+
def _apply_overrides(cfg: Mapping[str, object]) -> Mapping[str, object]:
425+
"""Apply overrides that are found in the config."""
426+
if "overrides" not in cfg:
427+
return cfg
428+
429+
overrides = cfg["overrides"]
430+
log.debug("applying overrides: %s", overrides)
431+
432+
# copy and filter out the overrides field
433+
new_cfg = {k: v for k, v in cfg.items() if k != "overrides"}
434+
435+
# apply the overrides
436+
new_cfg.update({o["name"]: o["value"] for o in overrides})
437+
438+
return new_cfg
439+
440+
424441
def load_cfg(
425442
path: Path,
426443
*,
@@ -502,6 +519,9 @@ def load_cfg(
502519
wildcard_values=path_resolution_wildcards,
503520
)
504521

522+
# Apply overrides
523+
cfg_data = _apply_overrides(cfg=cfg_data)
524+
505525
# Import any use_cfgs child config files
506526
return _merge_use_cfgs(
507527
top_cfg=cfg_data,

src/dvsim/flow/base.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ def __init__(
8181
# process' environment.
8282
self.exports = []
8383

84-
# Add overrides using the overrides keyword - existing attributes
85-
# are overridden with the override values.
86-
self.overrides = []
87-
8884
# Add a notion of "primary" cfg - this is indicated using
8985
# a special key 'use_cfgs' within the hjson cfg.
9086
self.is_primary_cfg = child_configs is not None
@@ -127,15 +123,14 @@ def __init__(
127123
# Merge in the values from the loaded config file.
128124
self.__dict__.update(self._config_data)
129125

130-
# Is this a primary config? If so, we need to load up all the child
131-
# configurations at this point. If not, we place ourselves into
132-
# self.cfgs and consider ourselves a sort of "degenerate primary
133-
# configuration".
126+
# Expand wildcards. If subclasses need to mess around with parameters
127+
# after merging the hjson but before expansion, they can override
128+
# _expand and add the code at the start.
129+
self._expand()
134130

135-
if self.rel_path == "":
136-
self.rel_path = self.flow_cfg_file.parent.relative_to(
137-
self._project_cfg.root_path,
138-
)
131+
# Construct the path variables after variable expansion.
132+
self.results_dir = Path(self.scratch_base_path) / "reports" / self.rel_path
133+
self.results_page = self.results_dir / self.results_html_name
139134

140135
def _expand(self) -> None:
141136
"""Expand wildcards after merging hjson.

0 commit comments

Comments
 (0)