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 config_not_found_msg(file_basename, search_dirs)[source]
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 get_bool_var(name: str, conf=None, default=None)[source]
classmethod get_float_var(name: str, conf=None, default=None)[source]
classmethod get_int_var(name: str, conf=None, default=None)[source]
classmethod get_section(name: str)[source]
classmethod get_str_var(name: str, conf=None, default=None)[source]
classmethod get_var_values()[source]
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

  • parsed_args – command args for starting the program

  • var_dict – dict for additional vars

Returns:

classmethod load_config_dict(file_basename: str, search_dirs: List | None = None, raise_exception: bool = True) Dict | None[source]

Load a specified config file ( ignore extension) :param raise_exception: if True raise exception when error occurs :param file_basename: base name of the config file to be loaded. :param for example: file_basename = config_fed_server.json :param what the function does is to search for config file that matches: :param config_fed_server.[json|json.default|conf|conf.default|yml|yml.default]: :param in given search directories: cls._config_path :param if json or json.default is not found;: :param then switch to Pyhoncon [.conf] or corresponding default file; if still not found; then we switch: :param to YAML files. We use OmegaConf to load YAML: :param search_dirs: which directories to search.

Returns: Dictionary from the configuration

if not found, exception will be raised.

classmethod load_configuration(file_basename: str) Config | None[source]
logger = <Logger nvflare.fuel.utils.config_service (WARNING)>
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