Skip to content

Commit

Permalink
Merge pull request #1095 from metno/pydantic-setupclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisblake authored Apr 7, 2024
2 parents 3452413 + fe7756a commit ae9bc27
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pyaerocom/aeroval/setupclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,20 @@ class EvalSetup(BaseModel):
@computed_field
@cached_property
def proj_info(self) -> ProjectInfo:
return ProjectInfo(proj_id=self.proj_id)
return ProjectInfo(
proj_id=self.proj_id
) # special case because ProjectInfo only has one attrbibute proj_id which is required by EvalSetup

@computed_field
@cached_property
def exp_info(self) -> ExperimentInfo:
return ExperimentInfo(exp_id=self.exp_id)
if not hasattr(self, "model_extra"):
return ExperimentInfo(exp_id=self.exp_id)
model_args = {
key: val for key, val in self.model_extra.items() if key in ExperimentInfo.model_fields
}
model_args["exp_id"] = self.exp_id
return ExperimentInfo(**model_args)

@cached_property
def json_filename(self) -> str:
Expand All @@ -330,9 +338,9 @@ def path_manager(self) -> OutputPaths:
}
return OutputPaths(proj_id=self.proj_id, exp_id=self.exp_id, **model_args)

# This is a hack to get keys from a general CFG into their appropriate respective classes
# Many computed_fields here have this hack to get keys from a general CFG into their appropriate respective classes
# TODO: all these computed fields could be more easily defined if the config were
# rigid enough to have they explicitly defined (e.g., in a TOML file), rather than dumping everything
# rigid enough to have them explicitly defined (e.g., in a TOML file), rather than dumping everything
# into one large config dict and then dishing out the relevant parts to each class.
@computed_field
@cached_property
Expand Down

0 comments on commit ae9bc27

Please sign in to comment.