Skip to content

Commit

Permalink
Revert "Remove the module class scan (#2790)" (#2819)
Browse files Browse the repository at this point in the history
This reverts commit b96dc32.
  • Loading branch information
yhwen authored Aug 21, 2024
1 parent d7d97fd commit ad8aaea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 72 deletions.
16 changes: 7 additions & 9 deletions nvflare/fuel/utils/class_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import Dict, List, Optional

from nvflare.security.logging import secure_format_exception
from nvflare.utils.components_utils import create_classes_table_static

DEPRECATED_PACKAGES = ["nvflare.app_common.pt", "nvflare.app_common.homomorphic_encryption"]

Expand Down Expand Up @@ -86,10 +85,10 @@ def __init__(self, base_pkgs: List[str], module_names: List[str], exclude_libs=T
self.exclude_libs = exclude_libs

self._logger = logging.getLogger(self.__class__.__name__)
self._class_table = create_classes_table_static()
self._class_table: Dict[str, str] = {}
self._create_classes_table()

def _create_classes_table(self):
class_table: Dict[str, str] = {}
scan_result_table = {}
for base in self.base_pkgs:
package = importlib.import_module(base)
Expand All @@ -112,21 +111,20 @@ def _create_classes_table(self):
# same class name exists in multiple modules
if name in scan_result_table:
scan_result = scan_result_table[name]
if name in class_table:
class_table.pop(name)
class_table[f"{scan_result.module_name}.{name}"] = module_name
class_table[f"{module_name}.{name}"] = module_name
if name in self._class_table:
self._class_table.pop(name)
self._class_table[f"{scan_result.module_name}.{name}"] = module_name
self._class_table[f"{module_name}.{name}"] = module_name
else:
scan_result = _ModuleScanResult(class_name=name, module_name=module_name)
scan_result_table[name] = scan_result
class_table[name] = module_name
self._class_table[name] = module_name
except (ModuleNotFoundError, RuntimeError) as e:
self._logger.debug(
f"Try to import module {module_name}, but failed: {secure_format_exception(e)}. "
f"Can't use name in config to refer to classes in module: {module_name}."
)
pass
return class_table

def get_module_name(self, class_name) -> Optional[str]:
"""Gets the name of the module that contains this class.
Expand Down
63 changes: 0 additions & 63 deletions nvflare/utils/components_utils.py

This file was deleted.

0 comments on commit ad8aaea

Please sign in to comment.