From 12b44385c36e8384422a52dd17117f3b14fefca7 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Thu, 2 Apr 2026 19:27:39 +0100 Subject: [PATCH 1/2] Tweak how we set up Deploy._variant_suffix Note: we can't do this by checking if self.sim_cfg is of type SimCfg, because that would give a circular dependency between job.deploy and sim.flow. Signed-off-by: Rupert Swarbrick --- src/dvsim/job/deploy.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/dvsim/job/deploy.py b/src/dvsim/job/deploy.py index 71247b85..01d00dab 100644 --- a/src/dvsim/job/deploy.py +++ b/src/dvsim/job/deploy.py @@ -73,10 +73,14 @@ def __init__(self, sim_cfg: "SimCfg") -> None: self.sim_cfg = sim_cfg self.flow = sim_cfg.name - if not hasattr(self.sim_cfg, "variant"): - self.sim_cfg.variant = "" + # The sim_cfg argument might be a SimCfg, in which case it might define + # a variant. We don't depend on this, though: if sim_cfg is an instance + # of some other subclass of FlowCfg, just take an empty "variant". + self._variant: str | None = getattr(self.sim_cfg, "variant", None) + if not (isinstance(self._variant, str) or self._variant is None): + raise TypeError("Unexpected type for variant") - self._variant_suffix = f"_{self.sim_cfg.variant}" if self.sim_cfg.variant else "" + self._variant_suffix = f"_{self._variant}" if self._variant is not None else "" # A list of jobs on which this job depends. self.dependencies = [] @@ -106,6 +110,9 @@ def __init__(self, sim_cfg: "SimCfg") -> None: def get_job_spec(self) -> "JobSpec": """Get the job spec for this deployment.""" + # If the FlowCfg object in self.sim_cfg doesn't have a links dictionary, default to {}. + links = getattr(self.sim_cfg, "links", {}) + return JobSpec( name=self.name, job_type=self.__class__.__name__, @@ -115,7 +122,7 @@ def get_job_spec(self) -> "JobSpec": qual_name=self.qual_name, block=IPMeta( name=self.sim_cfg.name, - variant=self.sim_cfg.variant, + variant=self._variant, commit=self.sim_cfg.commit, commit_short=self.sim_cfg.commit_short, branch=self.sim_cfg.branch, @@ -143,7 +150,7 @@ def get_job_spec(self) -> "JobSpec": odir=self.odir, renew_odir=self.renew_odir, log_path=Path(f"{self.odir}/{self.target}.log"), - links=self.sim_cfg.links, + links=links, pre_launch=self.pre_launch(), post_finish=self.post_finish(), pass_patterns=self.pass_patterns, From 1d6b34f710a520c9a642f67867b66e975949fdb6 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Thu, 2 Apr 2026 19:34:21 +0100 Subject: [PATCH 2/2] Allow the type of self.sim_cfg not to have commit/commit_short This wouldn't work at runtime, but postponing the check until then is a reasonable stop-gap that allows us to postpone working out which subclasses of FlowCfg define commit/commit_short until we have tidied up the types in more of those classes. Signed-off-by: Rupert Swarbrick --- src/dvsim/job/deploy.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/dvsim/job/deploy.py b/src/dvsim/job/deploy.py index 01d00dab..11779688 100644 --- a/src/dvsim/job/deploy.py +++ b/src/dvsim/job/deploy.py @@ -113,6 +113,19 @@ def get_job_spec(self) -> "JobSpec": # If the FlowCfg object in self.sim_cfg doesn't have a links dictionary, default to {}. links = getattr(self.sim_cfg, "links", {}) + # Get commit and commit_short arguments to pass to JobSpec. We don't + # necessarily know that self.sim_cfg is actually a SimCfg object, so it + # might not have them defined. If it doesn't, we can't generate a + # meaningful job spec. + commit: str = self.sim_cfg.commit + commit_short: str = self.sim_cfg.commit_short + if not (commit and commit_short): + msg = ( + "Cannot generate job spec. FlowCfg object " + "commit/commit_short is {commit}/{commit_short}." + ) + raise TypeError(msg) + return JobSpec( name=self.name, job_type=self.__class__.__name__, @@ -123,8 +136,8 @@ def get_job_spec(self) -> "JobSpec": block=IPMeta( name=self.sim_cfg.name, variant=self._variant, - commit=self.sim_cfg.commit, - commit_short=self.sim_cfg.commit_short, + commit=commit, + commit_short=commit_short, branch=self.sim_cfg.branch, url="", revision_info=self.sim_cfg.revision,