diff --git a/src/dvsim/job/deploy.py b/src/dvsim/job/deploy.py index 71247b85..11779688 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,22 @@ 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", {}) + + # 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__, @@ -115,9 +135,9 @@ def get_job_spec(self) -> "JobSpec": qual_name=self.qual_name, block=IPMeta( name=self.sim_cfg.name, - variant=self.sim_cfg.variant, - commit=self.sim_cfg.commit, - commit_short=self.sim_cfg.commit_short, + variant=self._variant, + commit=commit, + commit_short=commit_short, branch=self.sim_cfg.branch, url="", revision_info=self.sim_cfg.revision, @@ -143,7 +163,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,