MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / load_config_file

Method load_config_file

monai/bundle/config_parser.py:592–611  ·  view source on GitHub ↗

Load a single config file with specified file path (currently support JSON and YAML files). Args: filepath: path of target file to load, supported postfixes: `.json`, `.yml`, `.yaml`. kwargs: other arguments for ``json.load`` or ```yaml.safe_load``, depends

(cls, filepath: PathLike, **kwargs: Any)

Source from the content-addressed store, hash-verified

590
591 @classmethod
592 def load_config_file(cls, filepath: PathLike, **kwargs: Any) -> dict:
593 """
594 Load a single config file with specified file path (currently support JSON and YAML files).
595
596 Args:
597 filepath: path of target file to load, supported postfixes: `.json`, `.yml`, `.yaml`.
598 kwargs: other arguments for ``json.load`` or ```yaml.safe_load``, depends on the file format.
599
600 """
601 if not filepath:
602 return {}
603 _filepath: str = str(Path(filepath))
604 if not re.compile(cls.path_match, re.IGNORECASE).findall(_filepath):
605 raise ValueError(f'unknown file input: "{filepath}"')
606 with open(_filepath) as f:
607 if _filepath.lower().endswith(cls.suffixes[0]):
608 return json.load(f, object_pairs_hook=check_key_duplicates, **kwargs) # type: ignore[no-any-return]
609 if _filepath.lower().endswith(cls.suffixes[1:]):
610 return yaml.load(f, CheckKeyDuplicatesYamlLoader, **kwargs) # type: ignore[no-any-return]
611 raise ValueError(f"only support JSON or YAML config file so far, got name {_filepath}.")
612
613 @classmethod
614 def load_config_files(cls, files: PathLike | Sequence[PathLike] | dict, **kwargs: Any) -> dict:

Callers 15

get_scoreMethod · 0.80
__init__Method · 0.80
read_cacheMethod · 0.80
set_infer_filesMethod · 0.80
__init__Method · 0.80
convert_datasetMethod · 0.80
_do_resolveMethod · 0.80
load_config_filesMethod · 0.80
update_kwargsFunction · 0.80

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected