nvflare.fuel.utils.config_factory module¶
- class ConfigFactory[source]¶
Bases:
object
- class OmegaConfLoader¶
Bases:
ConfigLoader
- load_config(file_path: str) Config ¶
Load configuration from config file.
- Parameters:
file_path (str) – file path for configuration to be loaded
- Returns:
A Config
- load_config_from_dict(config_dict: dict) Config ¶
Load Configuration based on a given config dict.
- Parameters:
config_dict (dict) – dict for configuration to be loaded
- Returns:
A Config
- load_config_from_str(config_str: str) Config ¶
Load Configuration based on the string representation of the underline configuration.
For example, Json String for Jsonformat. python conf string or yaml string presentation
- Parameters:
config_str (str) – string for configuration to be loaded
- Returns:
A Config
- class PyhoconLoader¶
Bases:
ConfigLoader
- load_config(file_path: str) Config ¶
Load configuration from config file.
- Parameters:
file_path (str) – file path for configuration to be loaded
- Returns:
A Config
- load_config_from_dict(config_dict: dict) Config ¶
Load Configuration based on a given config dict.
- Parameters:
config_dict (dict) – dict for configuration to be loaded
- Returns:
A Config
- load_config_from_str(config_str: str) Config ¶
Load Configuration based on the string representation of the underline configuration.
For example, Json String for Jsonformat. python conf string or yaml string presentation
- Parameters:
config_str (str) – string for configuration to be loaded
- Returns:
A Config
- static get_config_loader(config_format: ConfigFormat) ConfigLoader | None [source]¶
return ConfigLoader for given config_format
- Parameters:
config_format – ConfigFormat
- Returns:
the matching ConfigLoader for the given format
- static load_config(file_path: str, search_dirs: List[str] | None = None, target_fmt: ConfigFormat | None = None) Config | None [source]¶
- Find the configuration for given initial init_file_path and search directories.
for example, the initial config file path given is config_client.json the search function will ignore the .json extension and search “config_client.xxx” in the given directory in specified extension search order. The first found file_path will be used as configuration. the “.xxx” is one of the extensions defined in the configuration format.
- Parameters:
file_path – initial file path
search_dirs – search directory. If none, the parent directory of init_file_path will be used as search dir
target_fmt – (ConfigFormat) if specified, only this format searched, ignore all other formats.
- Returns:
None if not found, or Config
- logger = <Logger ConfigFactory (WARNING)>¶
- omega_import_ok = True¶
- pyhocon_import_ok = True¶
- static search_config_format(init_file_path: str, search_dirs: List[str] | None = None, target_fmt: ConfigFormat | None = None) Tuple[ConfigFormat | None, str | None] [source]¶
- find the configuration format and the location (file_path) for given initial init_file_path and search directories.
for example, the initial config file path given is config_client.json the search function will ignore the .json extension and search “config_client.xxx” in the given directory in specified extension search order. The first found file_path will be used as configuration. the “.xxx” is one of the extensions defined in the configuration format.
- Parameters:
init_file_path – initial file_path for the configuration
search_dirs – search directory. If none, the parent directory of init_file_path will be used as search dir
target_fmt – (ConfigFormat) if specified, only this format searched, ignore all other formats.
- Returns:
Tuple of None,None or ConfigFormat and real configuration file path