[docs]classRunwayVariablesDefinition(MutableMap):"""Runway variables definition."""default_names=["runway.variables.yml","runway.variables.yaml"]# used to track persistent state on the class to only log the message once_has_notified_missing_file:ClassVar[bool]=False
def__load_file(self)->dict[str,Any]:"""Load a variables file."""ifself._file_path:ifself._file_path.is_file():returnyaml.safe_load(self._file_path.read_text())raiseVariablesFileNotFound(self._file_path.absolute())fornameinself.default_names:test_path=self._sys_path/nameLOGGER.debug("looking for variables file: %s",test_path)iftest_path.is_file():LOGGER.verbose("found variables file: %s",test_path)returnyaml.safe_load(test_path.read_text())ifnotself._has_notified_missing_file:LOGGER.info("could not find %s in the current directory; continuing without a variables file"," or ".join(self.default_names),)self.__class__._has_notified_missing_file=True# noqa: SLF001return{}
[docs]@classmethoddefparse_obj(cls:type[Self],obj:Any)->Self:"""Parse a python object into this class. Args: obj: The object to parse. """returncls(RunwayVariablesDefinitionModel.model_validate(obj))