From e5118107fc869d1170c49966b29677e0e2248e31 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Thu, 2 Apr 2026 19:10:47 +0100 Subject: [PATCH] Tidy up the last few Ruff problems in one_shot.py Signed-off-by: Rupert Swarbrick --- src/dvsim/flow/one_shot.py | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/dvsim/flow/one_shot.py b/src/dvsim/flow/one_shot.py index c717eea2..d055b31d 100644 --- a/src/dvsim/flow/one_shot.py +++ b/src/dvsim/flow/one_shot.py @@ -6,8 +6,9 @@ from abc import abstractmethod from collections import OrderedDict -from collections.abc import Sequence +from collections.abc import Callable, Mapping, Sequence from pathlib import Path +from typing import ClassVar from dvsim.flow.base import FlowCfg from dvsim.job.data import CompletedJobStatus @@ -21,9 +22,25 @@ class OneShotCfg(FlowCfg): """Simple one-shot build flow for non-simulation targets like linting, synthesis and FPV.""" - ignored_wildcards = [*FlowCfg.ignored_wildcards, "build_mode", "index", "test"] + ignored_wildcards: ClassVar[list[str]] = [ + *FlowCfg.ignored_wildcards, + "build_mode", + "index", + "test", + ] - def __init__(self, flow_cfg_file, hjson_data, args, mk_config) -> None: + def __init__( + self, flow_cfg_file: str, hjson_data: Mapping, args: object, mk_config: Callable + ) -> None: + """Initialise OneShotCfg object. + + Args: + flow_cfg_file: Path to hjson cfg that was loaded. + hjson_data: The parsed hjson from flow_cfg_file. + args: Arguments passed to dvsim + mk_config: A factory method to allow multi-layer builds. + + """ # Options set from command line self.tool = args.tool self.verbose = args.verbose @@ -76,7 +93,7 @@ def __init__(self, flow_cfg_file, hjson_data, args, mk_config) -> None: super().__init__(flow_cfg_file, hjson_data, args, mk_config) - def _merge_hjson(self, hjson_data) -> None: + def _merge_hjson(self, hjson_data: Mapping) -> None: # If build_unique is set, then add current timestamp to uniquify it if self.build_unique: self.build_dir += "_" + self.timestamp @@ -108,7 +125,9 @@ def _expand(self) -> None: # Purge the output directories. This operates on self. def _purge(self) -> None: - assert self.scratch_path + if not self.scratch_path: + raise RuntimeError("Scratch path is '', so cannot purge.") + log.info("Purging scratch path %s", self.scratch_path) rm_path(self.scratch_path) @@ -158,7 +177,7 @@ def _gen_results(self, results: Sequence[CompletedJobStatus]) -> None: """Generate results for this config.""" @abstractmethod - def gen_results_summary(self): + def gen_results_summary(self) -> str: """Gathers the aggregated results from all sub configs.""" def gen_results(self, results: Sequence[CompletedJobStatus]) -> None: @@ -183,18 +202,16 @@ def gen_results(self, results: Sequence[CompletedJobStatus]) -> None: log.info("[scratch_path]: [%s] [%s]", project, item.scratch_path) # TODO: Implement HTML report using templates + # + # This was previously implemented by rendering the markdown results for the item. results_dir = Path(self.results_dir) results_dir.mkdir(exist_ok=True, parents=True) - # (results_dir / self.results_html_name).write_text( - # md_results_to_html(self.results_title, self.css_file, item.results_md) - # ) - log.verbose("[report]: [%s] [%s/report.html]", project, item.results_dir) self.errors_seen |= item.errors_seen if self.is_primary_cfg: self.gen_results_summary() - # self.write_results(self.results_html_name, self.results_summary_md) + # TODO: Write a combined HTML report to self.results_html_name