nvflare.fuel.utils.config_service module¶
- class ConfigService[source]¶
Bases:
object
The ConfigService provides a global configuration service that can be used by any component at any layer. The ConfigService manages config information and makes it available to any component, in two ways: 1. Config info is preloaded into predefined sections. Callers can get the config data by a section name. 2. Manages config path (a list of directories) and loads file from the path.
Only JSON file loading is supported.
- classmethod add_section(section_name: str, data: dict, overwrite_existing: bool = True)[source]¶
Add a section to the config data.
- Parameters:
section_name – name of the section to be added
data – data of the section
overwrite_existing – if section already exists, whether to overwrite
Returns:
- classmethod find_file(file_basename: str) None | str [source]¶
Find specified file from the config path. Caller is responsible for loading/processing the file. This is useful for non-JSON files.
- Parameters:
file_basename – base name of the file to be found
Returns: full name of the file if found; None if not.
- classmethod initialize(section_files: Dict[str, str], config_path: List[str], parsed_args=None, var_dict=None)[source]¶
Initialize the ConfigService. Configuration is divided into sections, and each section must have a JSON config file. Only specify the base name of the config file. Config path is provided to locate config files. Files are searched in the order of provided config_dirs. If multiple directories contain the same file name, then the first one is used.
- Parameters:
section_files – dict: section name => config file
config_path – list of config directories
process_start_cmd_args – command args for starting the program
var_dict – dict for additional vars
Returns:
- find_file_in_dir(file_basename, path) None | str [source]¶
Find a file from a directory and return the full path of the file, if found
- Parameters:
file_basename – base name of the file to be found
path – the directory from where the file is to be found
Returns: the full path of the file, if found; None if not found
- search_file(file_basename: str, dirs: List[str]) None | str [source]¶
Find a file by searching a list of dirs and return the one in the last dir.
- Parameters:
file_basename – base name of the file to be found
dirs – list of directories to search
Returns: the full path of the file, if found; None if not found