Skip to content

Commit

Permalink
🎨 Reduce log verbosity
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Nov 27, 2024
1 parent 514259c commit 1131bd9
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions acapy_agent/utils/classloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,34 @@ def load_module(
)

if package:
LOGGER.debug("Preloading parent package: %s", package)
# preload parent package
if not cls.load_module(package):
LOGGER.debug("Failed to preload parent package: %s", package)
return None
# must treat as a relative import
if not mod_path.startswith("."):
mod_path = f".{mod_path}"
LOGGER.debug("Adjusted mod_path for relative import: %s", mod_path)

full_path = resolve_name(mod_path, package)
LOGGER.debug("Resolved full module path: %s", full_path)

if full_path in sys.modules:
LOGGER.debug("Module %s is already loaded", full_path)
return sys.modules[full_path]

if "." in mod_path:
parent_mod_path, mod_name = mod_path.rsplit(".", 1)
LOGGER.debug(
"Parent module path: %s, Module name: %s", parent_mod_path, mod_name
)
if parent_mod_path and parent_mod_path[-1] != ".":
parent_mod = cls.load_module(parent_mod_path, package)
if not parent_mod:
LOGGER.debug("Failed to load parent module: %s", parent_mod_path)
return None
package = parent_mod.__name__
mod_path = f".{mod_name}"
LOGGER.debug("Adjusted mod_path after loading parent: %s", mod_path)

# Load the module spec first
LOGGER.debug("Finding spec for module: %s with package: %s", mod_path, package)
spec = find_spec(mod_path, package)
if not spec:
LOGGER.debug("Module spec not found for: %s", mod_path)
return None

try:
LOGGER.debug("Importing module: %s with package: %s", mod_path, package)
LOGGER.debug("Importing package: %s, module: %s", package, mod_path)
return import_module(mod_path, package)
except ModuleNotFoundError as e:
LOGGER.warning("Module %s not found during import", full_path)
Expand Down Expand Up @@ -128,11 +116,6 @@ def load_class(
if "." in class_name:
# import module and find class
mod_path, class_name = class_name.rsplit(".", 1)
LOGGER.debug(
"Extracted module path: %s, class name: %s from full class path",
mod_path,
class_name,
)
elif default_module:
mod_path = default_module
LOGGER.debug("No module in class name, using default_module: %s", mod_path)
Expand Down Expand Up @@ -187,13 +170,6 @@ def load_subclass_of(
"""

LOGGER.debug(
"Attempting to load subclass of %s from module %s with package %s",
base_class.__name__,
mod_path,
package,
)

mod = cls.load_module(mod_path, package)
if not mod:
LOGGER.warning(
Expand All @@ -205,21 +181,11 @@ def load_subclass_of(

# Find the first declared class that inherits from the base_class
try:
LOGGER.debug(
"Inspecting classes in module %s for subclasses of %s",
mod_path,
base_class.__name__,
)
imported_class = next(
obj
for name, obj in inspect.getmembers(mod, inspect.isclass)
if issubclass(obj, base_class) and obj is not base_class
)
LOGGER.debug(
"Found subclass %s of base class %s",
imported_class.__name__,
base_class.__name__,
)
except StopIteration:
LOGGER.debug(
"No subclass of %s found in module %s",
Expand All @@ -244,7 +210,6 @@ def scan_subpackages(cls, package: str) -> Sequence[str]:

try:
package_path = resources.files(package)
LOGGER.debug("Found package path: %s", package_path)
except FileNotFoundError:
LOGGER.warning("Package %s not found during subpackage scan", package)
raise ModuleLoadError(f"Undefined package {package}")
Expand Down

0 comments on commit 1131bd9

Please sign in to comment.