Skip to content

Commit 741a2a0

Browse files
bazarnovCopilot
andauthored
fix: (CDK) (manifest-only) - add ability to debug manifest-only sources / destinations (#407)
Co-authored-by: Copilot <[email protected]>
1 parent 5d82e14 commit 741a2a0

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

debug_manifest/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore all resource files
2+
resources/*
3+
4+
# But do not ignore .gitkeep files, to keep an empty `resources` directory
5+
!resources/.gitkeep

debug_manifest/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Configuring the Debugger
2+
3+
## For VSCode
4+
5+
### Set Up the debugger configuration (one-time setup step)
6+
To configure the debugger in VSCode to run the `debug_manifest`, follow these steps:
7+
8+
1. Clone or Open the existing `airbyte-python-cdk` project in VSCode.
9+
2. Click on the Run and Debug icon in the Activity Bar on the side of the window.
10+
3. Click on the `create a launch.json file` link to create a new configuration file.
11+
4. Select `Python` from the list of environments.
12+
5. Replace the contents of the generated `launch.json` file with the following configuration:
13+
14+
```json
15+
{
16+
"version": "0.2.0",
17+
"configurations": [
18+
{
19+
"name": "Python: Debug Manifest",
20+
"type": "debugpy",
21+
"request": "launch",
22+
"console": "integratedTerminal",
23+
"cwd": "${workspaceFolder}/debug_manifest",
24+
"python": "<PATH_TO_CDK_ENV>/bin/python",
25+
"module": "debug_manifest",
26+
"args": [
27+
// SPECIFY THE COMMAND: [spec, check, discover, read]
28+
"read",
29+
// SPECIFY THE CONFIG
30+
"--config",
31+
// PATH TO THE CONFIG FILE
32+
"resources/config.json",
33+
// SPECIFY THE CATALOG
34+
"--catalog",
35+
// PATH TO THE CATALOG FILE
36+
"resources/catalog.json",
37+
// SPECIFY THE STATE (optional)
38+
// "--state",
39+
// PATH TO THE STATE FILE
40+
// "resources/state.json",
41+
// ADDITIONAL FLAGS, like `--debug` (optional)
42+
"--debug"
43+
],
44+
}
45+
]
46+
}
47+
```
48+
49+
6. Save the `launch.json` file.
50+
7. Install `CDK dependencies` by running `poetry install --all-extras`
51+
8. Replace the `"python": "<PATH_TO_CDK_ENV>/bin/python"` with the correct interpreter `PATH` pointing to the `CDK env` installed from Step `7` (use `which python` to have the complete python path), to wire the CDK env to the debugger. Alternatively you can switch the default interpreter you use in your IDE.
52+
### Set up the necessary resources to use within the manifest-only connector
53+
* These resources are ignored by `git`, in the `.gitignore`, thus should not be committed
54+
1. Put the `config.json` inside the `/airbyte_cdk/debug_manifest/resources` (this will hold the `source input configuration`).
55+
2. Put the `catalog.json` inside the `/airbyte_cdk/debug_manifest/resources` (this will hold the `configured catalog` for the target source).
56+
3. Put the `manifest.yaml` inside the `/airbyte_cdk/debug_manifest/resources`
57+
4. (Optional) Put the `state.json` inside the `/airbyte_cdk/debug_manifest/resources`
58+
59+
## Debugging Steps
60+
1. Set any necessary breakpoints in your code, or `CDK` components code.
61+
2. Press `F5` / `Shift + CMD + D` / click the green play button in the `Run and Debug` view to start debugging.
62+
3. Iterate over the `2` and `3`, to debug your `manifest-only` source.
63+
64+
Basically, you're now able to run the `manifest-only` sources like the regular python source, with `spec`, `check`, `discover` and `read` commands, as well as having the `--debug` alongside.

debug_manifest/debug_manifest.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
import sys
6+
from typing import Any, Mapping
7+
8+
from airbyte_cdk.entrypoint import launch
9+
from airbyte_cdk.sources.declarative.yaml_declarative_source import (
10+
YamlDeclarativeSource,
11+
)
12+
13+
configuration: Mapping[str, Any] = {
14+
"path_to_yaml": "resources/manifest.yaml",
15+
}
16+
17+
18+
def debug_manifest(source: YamlDeclarativeSource, args: list[str]) -> None:
19+
"""
20+
Run the debug manifest with the given source and arguments.
21+
"""
22+
launch(source, args)
23+
24+
25+
if __name__ == "__main__":
26+
debug_manifest(
27+
YamlDeclarativeSource(**configuration),
28+
sys.argv[1:],
29+
)

debug_manifest/resources/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)