nvflare.fuel.utils.class_utils module

class ModuleScanner(base_pkgs: List[str], module_names: List[str], exclude_libs=True)[source]

Bases: object

Loads specified modules from base packages and then constructs a class to module name mapping.

Parameters:
  • base_pkgs – base packages to look for modules in

  • module_names – module names to load

  • exclude_libs – excludes modules containing .libs if True. Defaults to True.

create_classes_table()[source]
get_module_name(class_name) str | None[source]

Gets the name of the module that contains this class.

Parameters:

class_name – The name of the class

Returns:

The module name if found.

get_class_path_from_config(config_dict: dict, resolve_name: Callable[[str], str | None] | None = None) str[source]

Resolve a component config dict to a fully qualified class path.

Config key precedence: path → class_path → name. The first key present is used; the others are ignored. Key presence is used, not truthiness: e.g. path=”” or path=None is still “path present”, so path is validated and raises ConfigError instead of falling through to class_path or name. When only “name” is present, resolve_name(class_name) is called to get the module name.

Parameters:
  • config_dict – Config with “path”, “class_path”, or “name” (see precedence above).

  • resolve_name – Callable that takes a class name and returns module name or None. Required when config uses “name”.

Returns:

Fully qualified class path string.

Raises:

ConfigError – Invalid or missing path/class_path/name.

get_component_init_parameters(component)[source]

To retrieve the initialize parameters of an object from the class constructor.

Parameters:

component – a class instance

Returns:

instantiate_class(class_path, init_params)[source]

Method for creating an instance for the class.

Parameters:
  • class_path – full path of the class

  • init_params – A dictionary that contains the name of the transform and constructor input

  • a (arguments. The transform name will be appended to medical.common.transforms to make)

  • built. (full name of the transform to be)