3
3
#
4
4
5
5
import sys
6
- from typing import Any , Mapping
7
6
8
7
from airbyte_cdk .entrypoint import AirbyteEntrypoint , launch
9
8
from airbyte_cdk .sources .declarative .yaml_declarative_source import (
10
9
YamlDeclarativeSource ,
11
10
)
12
11
13
- configuration : Mapping [str , Any ] = {
14
- "path_to_yaml" : "resources/manifest.yaml" ,
15
- }
16
-
17
12
18
13
def debug_manifest (source : YamlDeclarativeSource , args : list [str ]) -> None :
19
14
"""
@@ -22,15 +17,56 @@ def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
22
17
launch (source , args )
23
18
24
19
20
+ def _register_components_from_file (filepath : str ) -> None :
21
+ """
22
+ Dynamically load a Python file containing custom component definitions and register it
23
+ under specific module names in sys.modules to ensure that these classes can be properly
24
+ resolved during hydration of the manifest yaml file.
25
+
26
+ This is a somewhat hacky replacement for the file structure manipulation we do when building
27
+ connector images to ensure the custom components can be imported.
28
+ """
29
+ import importlib .util
30
+ import sys
31
+ from pathlib import Path
32
+
33
+ components_path = Path (filepath )
34
+ if not components_path .exists ():
35
+ raise FileNotFoundError (f"Components file not found: { components_path } " )
36
+
37
+ module_name = "components"
38
+ sdm_module_name = "source_declarative_manifest.components"
39
+
40
+ spec = importlib .util .spec_from_file_location (module_name , components_path )
41
+ if spec is None or spec .loader is None :
42
+ raise ImportError (f"Could not load module from { components_path } " )
43
+
44
+ # Create module and execute code
45
+ module = importlib .util .module_from_spec (spec )
46
+
47
+ # Register then execute the module
48
+ # we dual-register the module to mirror what is done elsewhere in the CDK
49
+ sys .modules [module_name ] = module
50
+ sys .modules [sdm_module_name ] = module
51
+
52
+ spec .loader .exec_module (module )
53
+
54
+
25
55
if __name__ == "__main__" :
26
56
args = sys .argv [1 :]
57
+ parsed_args = AirbyteEntrypoint .parse_args (args )
58
+
59
+ manifest_path = getattr (parsed_args , "manifest_path" , None ) or "resources/manifest.yaml"
60
+ components_path = getattr (parsed_args , "components_path" , None )
61
+ if components_path :
62
+ _register_components_from_file (components_path )
27
63
catalog_path = AirbyteEntrypoint .extract_catalog (args )
28
64
config_path = AirbyteEntrypoint .extract_config (args )
29
65
state_path = AirbyteEntrypoint .extract_state (args )
30
66
31
67
debug_manifest (
32
68
YamlDeclarativeSource (
33
- path_to_yaml = "resources/manifest.yaml" ,
69
+ path_to_yaml = manifest_path ,
34
70
catalog = YamlDeclarativeSource .read_catalog (catalog_path ) if catalog_path else None ,
35
71
config = YamlDeclarativeSource .read_config (config_path ) if config_path else None ,
36
72
state = YamlDeclarativeSource .read_state (state_path ) if state_path else None ,
0 commit comments