Skip to content

Commit 7fcc814

Browse files
authored
chore(ci): Add lint, test, regen workflows (#4)
1 parent 021deb8 commit 7fcc814

File tree

11 files changed

+136
-27
lines changed

11 files changed

+136
-27
lines changed

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint with Black
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.x"
18+
- name: Install dependencies
19+
run: pip install -r requirements.txt
20+
- name: Check formatting
21+
run: make fmt-check

.github/workflows/publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
python-version: '3.x'
2121
- name: Install dependencies
2222
run: |
23-
python -m pip install --upgrade pip
2423
pip install -r requirements.txt
2524
pip install build
2625
- name: Build package

.github/workflows/regen.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Generate Python Code from plugin-pb
2+
on:
3+
schedule:
4+
- cron: "0 8 * * *"
5+
workflow_dispatch:
6+
7+
jobs:
8+
regen:
9+
timeout-minutes: 30
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.x"
18+
- name: Install dependencies
19+
run: |
20+
pip install -r requirements.txt
21+
- name: Generate code
22+
run: |
23+
make clone-proto
24+
make gen-proto
25+
- name: Create Pull Request
26+
uses: peter-evans/create-pull-request@v4
27+
with:
28+
# required so the PR triggers workflow runs
29+
token: ${{ secrets.GH_CQ_BOT }}
30+
branch: fix/gen_proto
31+
base: main
32+
title: "fix: Generate Python Code from `plugin-pb`"
33+
commit-message: "fix: Generate Python Code from `plugin-pb`"
34+
body: This PR was created by a scheduled workflow to regenerate the Python code from `plugin-pb`.
35+
author: cq-bot <cq-bot@users.noreply.github.com>
36+
labels: automerge

.github/workflows/unittest.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
timeout-minutes: 30
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.x'
20+
- name: Install dependencies
21+
run: pip install -r requirements.txt
22+
- name: Run tests
23+
run: make test

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
test:
2+
pytest .
3+
4+
fmt:
5+
black . --exclude=cloudquery
6+
7+
fmt-check:
8+
black --check . --exclude=cloudquery
19

210
clone-proto:
311
git clone https://github.com/cloudquery/plugin-pb
412

5-
gen:
13+
gen-proto:
614
cd plugin-pb && git pull && cd ..
715

816
mkdir -p ./protos/cloudquery/plugin_v3

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
grpcio==1.56.0
1+
black==23.7.0
22
grpcio-tools==1.56.0
3+
grpcio==1.56.0
34
protobuf==4.23.4
5+
pyarrow==12.0.1
6+
pytest==7.4.0

samples/plugin_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
import grpc
33
from cloudquery.plugin_v3 import plugin_pb2, plugin_pb2_grpc
44

5+
56
def run():
67
# NOTE(gRPC Python Team): .close() is possible on a channel and should be
78
# used in circumstances in which the with statement does not fit the needs
89
# of the code.
9-
with grpc.insecure_channel('localhost:50051') as channel:
10+
with grpc.insecure_channel("localhost:50051") as channel:
1011
stub = plugin_pb2_grpc.PluginStub(channel)
1112
response = stub.GetName(plugin_pb2.GetName.Request())
1213
print(response.name)
1314

14-
if __name__ == '__main__':
15+
16+
if __name__ == "__main__":
1517
logging.basicConfig()
1618
run()

samples/plugin_server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ def Close(self, request, context):
3939

4040
def serve():
4141
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
42-
plugin_pb2_grpc.add_PluginServicer_to_server(
43-
PluginServicer(), server)
44-
server.add_insecure_port('[::]:50051')
42+
plugin_pb2_grpc.add_PluginServicer_to_server(PluginServicer(), server)
43+
server.add_insecure_port("[::]:50051")
4544
print("Starting server. Listening on port 50051")
4645
server.start()
4746
server.wait_for_termination()
4847

4948

50-
if __name__ == '__main__':
49+
if __name__ == "__main__":
5150
logging.basicConfig()
5251
serve()

setup.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"grpcio >= 1.56.0",
1515
"grpcio-tools >= 1.56.0",
1616
"protobuf >= 4.23.4",
17-
"pyarrow >= 12.0.1"
17+
"pyarrow >= 12.0.1",
1818
]
1919
url = "https://github.com/cloudquery/plugin-pb-python"
2020

@@ -65,6 +65,13 @@
6565
# namespace_packages=namespaces,
6666
install_requires=dependencies,
6767
include_package_data=True,
68-
package_data={"cloudquery": ["plugin_v3/py.typed", "plugin_v3/*.pyi", "discovery_v1/py.typed", "discovery_v1/*.pyi"]},
68+
package_data={
69+
"cloudquery": [
70+
"plugin_v3/py.typed",
71+
"plugin_v3/*.pyi",
72+
"discovery_v1/py.typed",
73+
"discovery_v1/*.pyi",
74+
]
75+
},
6976
zip_safe=False,
7077
)

tests/plugin_v3/arrow.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/plugin_v3/arrow_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pyarrow as pa
2+
from cloudquery.plugin_v3.arrow import (
3+
schemas_to_bytes,
4+
new_schemas_from_bytes,
5+
record_to_bytes,
6+
new_record_from_bytes,
7+
)
8+
9+
10+
def test_schema_round_trip():
11+
sc = pa.schema(
12+
fields=[pa.field("a", pa.int64())], metadata={"foo": "bar", "baz": "quux"}
13+
)
14+
b = schemas_to_bytes([sc])
15+
schemas = new_schemas_from_bytes(b)
16+
assert len(schemas) == 1
17+
assert schemas[0].equals(sc)
18+
19+
20+
def test_record_round_trip():
21+
sc = pa.schema(
22+
fields=[pa.field("a", pa.int64())], metadata={"foo": "bar", "baz": "quux"}
23+
)
24+
rec = pa.RecordBatch.from_arrays([pa.array([1, 2, 3])], schema=sc)
25+
b = record_to_bytes(rec)
26+
rec2 = new_record_from_bytes(b)
27+
assert rec.equals(rec2)

0 commit comments

Comments
 (0)