Load a cfg. Args: cfg_file_obj_or_str (str or file): Supports loading from: - A file object backed by a YAML file - A file object backed by a Python source file that exports an attribute "cfg" that is eith
(cls, cfg_file_obj_or_str)
| 341 | |
| 342 | @classmethod |
| 343 | def load_cfg(cls, cfg_file_obj_or_str): |
| 344 | """ |
| 345 | Load a cfg. |
| 346 | Args: |
| 347 | cfg_file_obj_or_str (str or file): |
| 348 | Supports loading from: |
| 349 | - A file object backed by a YAML file |
| 350 | - A file object backed by a Python source file that exports an attribute |
| 351 | "cfg" that is either a dict or a CfgNode |
| 352 | - A string that can be parsed as valid YAML |
| 353 | """ |
| 354 | _assert_with_logging( |
| 355 | isinstance(cfg_file_obj_or_str, _FILE_TYPES + (str,)), |
| 356 | "Expected first argument to be of type {} or {}, but it was {}".format( |
| 357 | _FILE_TYPES, str, type(cfg_file_obj_or_str) |
| 358 | ), |
| 359 | ) |
| 360 | if isinstance(cfg_file_obj_or_str, str): |
| 361 | return cls._load_cfg_from_yaml_str(cfg_file_obj_or_str) |
| 362 | elif isinstance(cfg_file_obj_or_str, _FILE_TYPES): |
| 363 | return cls._load_cfg_from_file(cfg_file_obj_or_str) |
| 364 | else: |
| 365 | raise NotImplementedError("Impossible to reach here (unless there's a bug)") |
| 366 | |
| 367 | @classmethod |
| 368 | def _load_cfg_from_file(cls, file_obj): |
no test coverage detected