Skip to content

Commit 69bd71d

Browse files
feat: Add package command (#84)
Co-authored-by: erezrokah <[email protected]>
1 parent 2ffd88b commit 69bd71d

File tree

12 files changed

+524
-12
lines changed

12 files changed

+524
-12
lines changed

.github/workflows/unittests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
16+
- # Required for the package command tests to work
17+
name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
1619
- name: Set up Python
1720
uses: actions/setup-python@v5
1821
with:

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
.idea/
161+
162+
.DS_Store

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Copy the code and install dependencies
6+
COPY requirements.txt .
7+
COPY setup.cfg .
8+
COPY setup.py .
9+
COPY cloudquery cloudquery
10+
COPY main.py .
11+
RUN pip3 install --no-cache-dir -r requirements.txt
12+
13+
EXPOSE 7777
14+
15+
ENTRYPOINT ["python3", "main.py"]
16+
17+
CMD ["serve", "--address", "[::]:7777", "--log-format", "json", "--log-level", "info"]

cloudquery/sdk/internal/memdb/memdb.py

+61-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,75 @@
33
from cloudquery.sdk import schema
44
from typing import List, Generator, Dict
55
import pyarrow as pa
6+
from cloudquery.sdk.types import JSONType
67

78
NAME = "memdb"
89
VERSION = "development"
910

1011

1112
class MemDB(plugin.Plugin):
1213
def __init__(self) -> None:
13-
super().__init__(NAME, VERSION)
14+
super().__init__(
15+
NAME, VERSION, opts=plugin.plugin.Options(team="cloudquery", kind="source")
16+
)
1417
self._db: Dict[str, pa.RecordBatch] = {}
15-
self._tables: Dict[str, schema.Table] = {}
18+
self._tables: Dict[str, schema.Table] = {
19+
"table_1": schema.Table(
20+
name="table_1",
21+
columns=[
22+
schema.Column(
23+
name="name",
24+
type=pa.string(),
25+
primary_key=True,
26+
not_null=True,
27+
unique=True,
28+
),
29+
schema.Column(
30+
name="id",
31+
type=pa.string(),
32+
primary_key=True,
33+
not_null=True,
34+
unique=True,
35+
incremental_key=True,
36+
),
37+
],
38+
title="Table 1",
39+
description="Test Table 1",
40+
is_incremental=True,
41+
relations=[
42+
schema.Table(
43+
name="table_1_relation_1",
44+
columns=[
45+
schema.Column(
46+
name="name",
47+
type=pa.string(),
48+
primary_key=True,
49+
not_null=True,
50+
unique=True,
51+
),
52+
schema.Column(name="data", type=JSONType()),
53+
],
54+
title="Table 1 Relation 1",
55+
description="Test Table 1 Relation 1",
56+
)
57+
],
58+
),
59+
"table_2": schema.Table(
60+
name="table_2",
61+
columns=[
62+
schema.Column(
63+
name="name",
64+
type=pa.string(),
65+
primary_key=True,
66+
not_null=True,
67+
unique=True,
68+
),
69+
schema.Column(name="id", type=pa.string()),
70+
],
71+
title="Table 2",
72+
description="Test Table 2",
73+
),
74+
}
1675

1776
def get_tables(self, options: plugin.TableOptions = None) -> List[plugin.Table]:
1877
tables = list(self._tables.values())

cloudquery/sdk/plugin/plugin.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,32 @@ class SyncOptions:
2929
backend_options: BackendOptions = None
3030

3131

32+
@dataclass
33+
class BuildTarget:
34+
os: str = None
35+
arch: str = None
36+
37+
38+
@dataclass
39+
class Options:
40+
dockerfile: str = None
41+
build_targets: List[BuildTarget] = None
42+
team: str = None
43+
kind: str = None
44+
45+
3246
class Plugin:
33-
def __init__(self, name: str, version: str) -> None:
47+
def __init__(self, name: str, version: str, opts: Options = None) -> None:
3448
self._name = name
3549
self._version = version
50+
self._opts = Options() if opts is None else opts
51+
if self._opts.dockerfile is None:
52+
self._opts.dockerfile = "Dockerfile"
53+
if self._opts.build_targets is None:
54+
self._opts.build_targets = [
55+
BuildTarget("linux", "amd64"),
56+
BuildTarget("linux", "arm64"),
57+
]
3658

3759
def init(self, spec: bytes, no_connection: bool = False) -> None:
3860
pass
@@ -46,6 +68,18 @@ def name(self) -> str:
4668
def version(self) -> str:
4769
return self._version
4870

71+
def team(self) -> str:
72+
return self._opts.team
73+
74+
def kind(self) -> str:
75+
return self._opts.kind
76+
77+
def dockerfile(self) -> str:
78+
return self._opts.dockerfile
79+
80+
def build_targets(self) -> List[BuildTarget]:
81+
return self._opts.build_targets
82+
4983
def get_tables(self, options: TableOptions) -> List[Table]:
5084
raise NotImplementedError()
5185

cloudquery/sdk/schema/table.py

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def filter_dfs_func(tt: List[Table], include, exclude, skip_dependent_tables: bo
151151
filtered_tables = []
152152
for t in tt:
153153
filtered_table = copy.deepcopy(t)
154+
for r in filtered_table.relations:
155+
r.parent = filtered_table
154156
filtered_table = _filter_dfs_impl(
155157
filtered_table, False, include, exclude, skip_dependent_tables
156158
)

0 commit comments

Comments
 (0)