Skip to content

Commit

Permalink
Fix(sdm): module ref issue in python components import (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers authored Jan 22, 2025
1 parent 3a9ab87 commit ce1074b
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import annotations

import datetime
import importlib
import inspect
import re
import sys
Expand Down Expand Up @@ -1180,14 +1181,17 @@ def _get_class_from_fully_qualified_class_name(
module_name_full = ".".join(split[:-1])
class_name = split[-1]

if module_name_full == COMPONENTS_MODULE_NAME:
# Assume "components" on its own means "source_declarative_manifest.components"
module_name_full = SDM_COMPONENTS_MODULE_NAME
try:
module_ref = importlib.import_module(module_name_full)
except ModuleNotFoundError as e:
raise ValueError(f"Could not load module `{module_name_full}`.") from e

try:
return getattr(sys.modules[module_name_full], class_name)
except (AttributeError, ModuleNotFoundError) as e:
raise ValueError(f"Could not load class {full_qualified_class_name}.") from e
return getattr(module_ref, class_name)
except AttributeError as e:
raise ValueError(
f"Could not load class `{class_name}` from module `{module_name_full}`.",
) from e

@staticmethod
def _derive_component_type_from_type_hints(field_type: Any) -> Optional[str]:
Expand Down

0 comments on commit ce1074b

Please sign in to comment.