Skip to content

Commit

Permalink
generate grpc code
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 20, 2024
1 parent cf87011 commit 45eeef7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 70 deletions.
13 changes: 11 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tasks:
- ./api/**/*.py
sources:
- ./proto/**/*.proto
- poetry.lock
cmds:
- >-
poetry run python -m grpc_tools.protoc
Expand All @@ -34,10 +35,18 @@ tasks:
--noviews
'mysql+pymysql://{{.MYSQL_USER}}:{{.MYSQL_PASS}}@{{.MYSQL_HOST}}:{{.MYSQL_PORT}}/{{.MYSQL_DB}}'
dev:
dotenv:
- .env
sources:
- chii/**/*.py
- rpc/**/*.py
generates:
- a-file-not-exists-so-it-always-rerun
cmd: python start_grpc_server.py

dev: poetry run watchgod start_grpc_server.main
mypy: mypy --show-column-numbers chii rpc

lint:
- poetry run mypy chii rpc
- poetry run ruff check .
- poetry run mypy chii rpc
Empty file removed api/__init__.py
Empty file.
Empty file removed api/v1/__init__.py
Empty file.
12 changes: 11 additions & 1 deletion api/v1/timeline_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions api/v1/timeline_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

from api.v1 import timeline_pb2 as api_dot_v1_dot_timeline__pb2

GRPC_GENERATED_VERSION = '1.63.0'
GRPC_GENERATED_VERSION = '1.66.1'
GRPC_VERSION = grpc.__version__
EXPECTED_ERROR_RELEASE = '1.65.0'
SCHEDULED_RELEASE_DATE = 'June 25, 2024'
_version_not_supported = False

try:
Expand All @@ -18,15 +16,12 @@
_version_not_supported = True

if _version_not_supported:
warnings.warn(
raise RuntimeError(
f'The grpc package installed is at version {GRPC_VERSION},'
+ f' but the generated code in api/v1/timeline_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
+ f' This warning will become an error in {EXPECTED_ERROR_RELEASE},'
+ f' scheduled for release on {SCHEDULED_RELEASE_DATE}.',
RuntimeWarning
)


Expand Down Expand Up @@ -116,6 +111,7 @@ def add_TimeLineServiceServicer_to_server(servicer, server):
generic_handler = grpc.method_handlers_generic_handler(
'api.v1.TimeLineService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('api.v1.TimeLineService', rpc_method_handlers)


# This class is part of an EXPERIMENTAL API.
Expand Down
59 changes: 1 addition & 58 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ aiohttp = "3.10.5"
pydantic-settings = "2.5.2"
typing-extensions = '4.12.2'
sslog = "0.0.0a45"
protobuf = "^5.28.2"

[tool.poetry.group.dev.dependencies]
sqlacodegen = "3.0.0rc5"
Expand All @@ -33,8 +34,6 @@ pytest-env = "==1.1.5"
# linter and formatter
pre-commit = "==3.8.0"
mypy = "==1.11.2"
watchgod = "0.8.2"
types-protobuf = "^4.21.0.2"

[tool.poetry-plugin-bump]
commit_msg = 'bump: v{version}'
Expand Down
3 changes: 3 additions & 0 deletions start_grpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from concurrent import futures

import etcd3
import google.protobuf
import grpc
from etcd3 import Lease
from etcd3.utils import retry
Expand All @@ -15,6 +16,8 @@
from chii.config import config
from rpc.timeline_service import TimeLineService

print(google.protobuf.__version__)


class Register(threading.Thread):
"""
Expand Down

0 comments on commit 45eeef7

Please sign in to comment.