Skip to content

Commit

Permalink
✨ support grpcio with xDS support
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangTianLi committed Mar 20, 2021
1 parent 066c6a6 commit 044259b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ grpcio-reflection = "*"
grpcio-health-checking = "*"

[requires]
python_version = "3.7"
python_version = "3.8"

[scripts]
init-pre-commit = "pre-commit install"
Expand Down
3 changes: 2 additions & 1 deletion grpcalchemy/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
)

from google.protobuf.message import Message as GeneratedProtocolMessageType
from grpc._server import _Context as Context
from grpc import ServicerContext
from grpc._server import _Context as Context

from .meta import ServiceMeta, __meta__
from .orm import Message

Expand Down
5 changes: 4 additions & 1 deletion grpcalchemy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ class DefaultConfig(BaseConfig):
#: Server Reflection
GRPC_SEVER_REFLECTION_ENABLE = False

#gRPC Service Third-Part Package Support
#: gRPC Service Third-Part Package Support
GRPC_THIRD_PART_PACKAGES: List[str] = []
#: If set to true, retrieves server configuration via xDS. This is an
#: EXPERIMENTAL option. Only for grpcio >= 1.36.0
GRPC_XDS_SUPPORT = False
10 changes: 7 additions & 3 deletions grpcalchemy/server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import logging
import multiprocessing
import os.path
import socket
import sys
import time
from concurrent import futures
from importlib import import_module
from threading import Event
from typing import Callable, Dict, Optional, Tuple, Type, ContextManager, List

import grpc
from grpc import GenericRpcHandler
from grpc import __version__ as GRPC_VERSION
from grpc._cython import cygrpc
from grpc._server import (
_add_generic_handlers,
Expand Down Expand Up @@ -73,7 +72,12 @@ def __init__(self, config: DefaultConfig):
)
completion_queue = cygrpc.CompletionQueue()
self.logger.info(f"server options: {self.config.GRPC_SERVER_OPTIONS}")
server = cygrpc.Server(tuple(self.config.GRPC_SERVER_OPTIONS))
if tuple(map(int, GRPC_VERSION.split("."))) >= (1, 36, 0):
server = cygrpc.Server(
tuple(self.config.GRPC_SERVER_OPTIONS), self.config.GRPC_XDS_SUPPORT
)
else:
server = cygrpc.Server(tuple(self.config.GRPC_SERVER_OPTIONS))
server.register_completion_queue(completion_queue)

#: gRPC Server State
Expand Down
4 changes: 3 additions & 1 deletion grpcalchemy/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import socket
import sys
from importlib import import_module, reload
from os import walk, path, mkdir
from os.path import abspath, dirname, exists, join
from typing import Union, Optional, TYPE_CHECKING, Tuple
import sys

import grpc_tools.protoc
import pkg_resources
from jinja2 import Environment, FileSystemLoader

from grpcalchemy.config import DefaultConfig

if TYPE_CHECKING:
Expand Down

0 comments on commit 044259b

Please sign in to comment.