Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,19 @@ def _get_class_from_fully_qualified_class_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
if split[0] == "source_declarative_manifest":
# During testing, the modules containing the custom components are not moved to source_declarative_manifest. In order to run the test, add the source folder to your PYTHONPATH or add it runtime using sys.path.append
try:
import os

module_name_with_source_declarative_manifest = ".".join(split[1:-1])
module_ref = importlib.import_module(
module_name_with_source_declarative_manifest
)
except ModuleNotFoundError:
raise ValueError(f"Could not load module `{module_name_full}`.") from e
else:
raise ValueError(f"Could not load module `{module_name_full}`.") from e

try:
return getattr(module_ref, class_name)
Expand Down
17 changes: 11 additions & 6 deletions airbyte_cdk/sources/declarative/yaml_declarative_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ def __init__(
)

def _read_and_parse_yaml_file(self, path_to_yaml_file: str) -> ConnectionDefinition:
package = self.__class__.__module__.split(".")[0]
try:
# For testing purposes, we want to allow to just pass a file
with open(path_to_yaml_file, "r") as f:
return yaml.safe_load(f) # type: ignore # we assume the yaml represents a ConnectionDefinition
except FileNotFoundError:
# Running inside the container, the working directory during an operation is not structured the same as the static files
package = self.__class__.__module__.split(".")[0]

yaml_config = pkgutil.get_data(package, path_to_yaml_file)
if yaml_config:
decoded_yaml = yaml_config.decode()
return self._parse(decoded_yaml)
else:
yaml_config = pkgutil.get_data(package, path_to_yaml_file)
if yaml_config:
decoded_yaml = yaml_config.decode()
return self._parse(decoded_yaml)
return {}

def _emit_manifest_debug_message(self, extra_args: dict[str, Any]) -> None:
Expand Down
Loading