Skip to content

Commit fd85d96

Browse files
committed
add support for components.py
1 parent a22b03f commit fd85d96

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

debug_manifest/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ To configure the debugger in VSCode to run the `debug_manifest`, follow these st
3131
"--manifest-path",
3232
// PATH TO THE MANIFEST FILE
3333
"resources/manifest.yaml",
34+
// SPECIFY A COMPONENTS.PY FILE (OPTIONAL)
35+
"--components-path",
36+
// PATH TO THE COMPONENTS FILE
37+
"resources/components.py",
3438
// SPECIFY THE CONFIG
3539
"--config",
3640
// PATH TO THE CONFIG FILE

debug_manifest/debug_manifest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2044
if __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

Comments
 (0)