Skip to content

Commit fd3a330

Browse files
authored
chore: minor improvements to working on manifest only connectors locally (#756)
1 parent e7db857 commit fd3a330

File tree

5 files changed

+247
-34
lines changed

5 files changed

+247
-34
lines changed

bin/generate-component-manifest-dagger.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77

88
set -e
99

10-
pip install dagger-io==0.13.3
1110
python bin/generate_component_manifest_files.py

debug_manifest/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ To configure the debugger in VSCode to run the `debug_manifest`, follow these st
2222
"request": "launch",
2323
"console": "integratedTerminal",
2424
"cwd": "${workspaceFolder}/debug_manifest",
25-
"python": "<PATH_TO_CDK_ENV>/bin/python",
25+
"python": "<PATH_TO_CDK_ENV>/bin/python", // REPLACE ME
2626
"module": "debug_manifest",
2727
"args": [
2828
// SPECIFY THE COMMAND: [spec, check, discover, read]
2929
"read",
30+
// SPECIFY THE MANIFEST FILE
31+
"--manifest-path",
32+
// PATH TO THE MANIFEST FILE
33+
"resources/manifest.yaml",
34+
// SPECIFY A COMPONENTS.PY FILE (OPTIONAL)
35+
"--components-path",
36+
// PATH TO THE COMPONENTS FILE
37+
"resources/components.py",
3038
// SPECIFY THE CONFIG
3139
"--config",
3240
// PATH TO THE CONFIG FILE

debug_manifest/debug_manifest.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
#
44

55
import sys
6-
from typing import Any, Mapping
76

87
from airbyte_cdk.entrypoint import AirbyteEntrypoint, launch
98
from airbyte_cdk.sources.declarative.yaml_declarative_source import (
109
YamlDeclarativeSource,
1110
)
1211

13-
configuration: Mapping[str, Any] = {
14-
"path_to_yaml": "resources/manifest.yaml",
15-
}
16-
1712

1813
def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
1914
"""
@@ -22,15 +17,56 @@ def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
2217
launch(source, args)
2318

2419

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+
2555
if __name__ == "__main__":
2656
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)
2763
catalog_path = AirbyteEntrypoint.extract_catalog(args)
2864
config_path = AirbyteEntrypoint.extract_config(args)
2965
state_path = AirbyteEntrypoint.extract_state(args)
3066

3167
debug_manifest(
3268
YamlDeclarativeSource(
33-
path_to_yaml="resources/manifest.yaml",
69+
path_to_yaml=manifest_path,
3470
catalog=YamlDeclarativeSource.read_catalog(catalog_path) if catalog_path else None,
3571
config=YamlDeclarativeSource.read_config(config_path) if config_path else None,
3672
state=YamlDeclarativeSource.read_state(state_path) if state_path else None,

0 commit comments

Comments
 (0)