Skip to content

Commit

Permalink
Improve ConfigParser documentation (#7058)
Browse files Browse the repository at this point in the history
Fixes #7057

### Description
Improve the usage of `ConfigParser` methods `read_config`,
`load_config_file`, `load_config_files`.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: KumoLiu <yunl@nvidia.com>
  • Loading branch information
KumoLiu authored Sep 28, 2023
1 parent 84566d1 commit 14fcf72
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions monai/bundle/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def read_meta(self, f: PathLike | Sequence[PathLike] | dict, **kwargs: Any) -> N

def read_config(self, f: PathLike | Sequence[PathLike] | dict, **kwargs: Any) -> None:
"""
Read the config from specified JSON or YAML file.
The config content in the `self.config` dictionary.
Read the config from specified JSON/YAML file or a dictionary and
override the config content in the `self.config` dictionary.
Args:
f: filepath of the config file, the content must be a dictionary,
Expand Down Expand Up @@ -383,7 +383,7 @@ def _do_parse(self, config: Any, id: str = "") -> None:
@classmethod
def load_config_file(cls, filepath: PathLike, **kwargs: Any) -> dict:
"""
Load config file with specified file path (currently support JSON and YAML files).
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`.
Expand All @@ -405,13 +405,15 @@ def load_config_file(cls, filepath: PathLike, **kwargs: Any) -> dict:
@classmethod
def load_config_files(cls, files: PathLike | Sequence[PathLike] | dict, **kwargs: Any) -> dict:
"""
Load config files into a single config dict.
Load multiple config files into a single config dict.
The latter config file in the list will override or add the former config file.
``"::"`` (or ``"#"``) in the config keys are interpreted as special characters to go one level
further into the nested structures.
Args:
files: path of target files to load, supported postfixes: `.json`, `.yml`, `.yaml`.
if providing a list of files, wil merge the content of them.
if providing a dictionary, return it directly.
kwargs: other arguments for ``json.load`` or ```yaml.safe_load``, depends on the file format.
"""
if isinstance(files, dict): # already a config dict
Expand Down

0 comments on commit 14fcf72

Please sign in to comment.