Skip to content

Commit

Permalink
🎨 refactor composite message type
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangTianLi committed Apr 22, 2021
1 parent 46ae53a commit f6b4cdf
Show file tree
Hide file tree
Showing 24 changed files with 547 additions and 374 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[run]
source = grpcalchemy
omit =
grpcalchemy/types.py
2 changes: 1 addition & 1 deletion .github/workflows/python-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ History
0.7.*(2021-03-20)
--------------------

* Remove Default Feature in Message
* Refactor Composite Message Type
* Support gRPC with xDS
* Add `PROTO_AUTO_GENERATED` setting to make runtime proto generation optional

Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#

import datetime
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
Expand Down Expand Up @@ -44,8 +44,8 @@

# General information about the project.
project = "gRPCAlchemy"
copyright = "2018, GuangTian Li"
author = "GuangTian Li"
copyright = f"{datetime.datetime.now().year}, GuangTianLi"
author = "GuangTianLi"

# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
Expand Down
12 changes: 6 additions & 6 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ within the post. Let's take a look at the code of our modified :class:`Post` cla
.. code-block:: python
from typing import List
from grpcalchemy.orm import Message
from grpcalchemy.orm import Message, Repeated
class Post(Message):
title: str
author: User
tags: List[str]
tags: Repeated[str]
The :class:`~grpcalchemy.orm.ListField` object that is used to define a Post's tags
takes a field object as its first argument --- this means that you can have
Expand All @@ -130,12 +130,12 @@ We can then define a list of comment documents in our post message:
.. code-block:: python
from typing import List
from grpcalchemy.orm import Message
from grpcalchemy.orm import Message, Repeated
class Post(Message):
title: str
author: User
tags: List[str]
comments: List[Comment]
tags: Repeated[str]
comments: Repeated[Comment]
Defining our gRPC Method
===================================
Expand Down Expand Up @@ -167,7 +167,7 @@ Using Iterator to define Stream gRPC Method:
pass
return HelloMessage(text=f'Hello {r.text}')
@StreamStream
@grpcmethod
def StreamStream(self, request: Iterator[HelloMessage], context: Context) -> Iterator[HelloMessage]:
for r in request:
yield HelloMessage(text=f'Hello {r.text}')
Expand Down
4 changes: 2 additions & 2 deletions grpcalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
__email__ = "guangtian_li@qq.com"
__version__ = "0.7.2"

__all__ = ["Blueprint", "Context", "grpcmethod", "DefaultConfig", "Server"]
__all__ = ["Blueprint", "Context", "grpcmethod", "DefaultConfig", "Server", "Streaming"]

from .blueprint import Blueprint, Context, grpcmethod
from .blueprint import Blueprint, Context, grpcmethod, Streaming
from .config import DefaultConfig
from .server import Server
5 changes: 3 additions & 2 deletions grpcalchemy/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

if TYPE_CHECKING: # pragma: no cover
from .server import Server
Expand Down Expand Up @@ -280,13 +281,13 @@ def _validate_rpc_method(

request_origin = getattr(request_type, "__origin__", None)
if request_origin:
if issubclass(request_origin, Iterable):
if issubclass(request_origin, Streaming):
request_type = request_type.__args__[0]
request_streaming = True

response_origin = getattr(response_type, "__origin__", None)
if response_origin:
if issubclass(response_origin, Iterable):
if issubclass(response_origin, Streaming):
response_type = response_type.__args__[0]
response_streaming = True
if all(
Expand Down
4 changes: 0 additions & 4 deletions grpcalchemy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,3 @@ class DefaultConfig(BaseConfig):
#: If set to true, retrieves server configuration via xDS. This is an
#: EXPERIMENTAL option. Only for grpcio >= 1.36.0
GRPC_XDS_SUPPORT = False

#: If set to true, retrieves server configuration via xDS. This is an
#: EXPERIMENTAL option. Only for grpcio >= 1.36.0
GRPC_XDS_SUPPORT = False
Loading

0 comments on commit f6b4cdf

Please sign in to comment.