@@ -16,11 +16,39 @@ def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
1616 """
1717 launch (source , args )
1818
19+ def _register_components_from_file (filepath : str ) -> None :
20+ """Load and register components from a Python file specified in the args."""
21+ import importlib .util
22+ import sys
23+ from pathlib import Path
24+
25+ components_path = Path (filepath )
26+
27+ module_name = "components"
28+ sdm_module_name = "source_declarative_manifest.components"
29+
30+ # Create module spec
31+ spec = importlib .util .spec_from_file_location (module_name , components_path )
32+ if spec is None or spec .loader is None :
33+ raise ImportError (f"Could not load module from { components_path } " )
34+
35+ # Create module and execute code, registering the module before executing its code
36+ # To avoid issues with dataclasses that look up the module
37+ module = importlib .util .module_from_spec (spec )
38+ sys .modules [module_name ] = module
39+ sys .modules [sdm_module_name ] = module
40+
41+ spec .loader .exec_module (module )
42+
1943
2044if __name__ == "__main__" :
2145 args = sys .argv [1 :]
2246 parsed_args = AirbyteEntrypoint .parse_args (args )
47+
2348 manifest_path = getattr (parsed_args , "manifest_path" , None ) or "resources/manifest.yaml"
49+ components_path = getattr (parsed_args , "components_path" , None )
50+ if components_path :
51+ _register_components_from_file (components_path )
2452 catalog_path = AirbyteEntrypoint .extract_catalog (args )
2553 config_path = AirbyteEntrypoint .extract_config (args )
2654 state_path = AirbyteEntrypoint .extract_state (args )
0 commit comments