From be5df5515a2e26f80f7f5a3daa4ff59259ee4981 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Fri, 5 Aug 2022 04:39:14 -0700 Subject: [PATCH] fix(grpc): readthedocs build (#2866) --- .readthedocs.yml | 11 +++++++++- .../_internal/bento/build_dev_bentoml_whl.py | 18 +++++++++-------- bentoml/_internal/io_descriptors/text.py | 20 ++++++++++++++----- pyproject.toml | 3 ++- requirements/docs-requirements.txt | 1 + 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 4781c26b71c..94e742e486d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -5,13 +5,22 @@ # Required version: 2 +build: + os: "ubuntu-20.04" + tools: + python: "3.9" + jobs: + post_checkout: + - git fetch --unshallow + pre_install: + - git update-index --assume-unchanged docs/source/conf.py + # Build documentation in the docs/ directory with Sphinx sphinx: configuration: docs/source/conf.py # Optionally set the version of Python and requirements required to build your docs python: - version: 3.8 install: - requirements: requirements/docs-requirements.txt - method: setuptools diff --git a/bentoml/_internal/bento/build_dev_bentoml_whl.py b/bentoml/_internal/bento/build_dev_bentoml_whl.py index d65b12e767e..8170372ead3 100644 --- a/bentoml/_internal/bento/build_dev_bentoml_whl.py +++ b/bentoml/_internal/bento/build_dev_bentoml_whl.py @@ -26,14 +26,6 @@ def build_bentoml_editable_wheel(target_path: str) -> None: # skip this entirely if BentoML is installed from PyPI return - try: - from build import ProjectBuilder - from build.env import IsolatedEnvBuilder - except ModuleNotFoundError: - raise BentoMLException( - f"`{BENTOML_DEV_BUILD}=True`, which requires the `pypa/build` package. Install development dependencies with `pip install -r requirements/dev-requirements.txt` and try again." - ) - # Find bentoml module path module_location = source_locations("bentoml") if not module_location: @@ -48,6 +40,16 @@ def build_bentoml_editable_wheel(target_path: str) -> None: logger.info( "BentoML is installed in `editable` mode; building BentoML distribution with the local BentoML code base. The built wheel file will be included in the target bento." ) + + try: + from build.env import IsolatedEnvBuilder + + from build import ProjectBuilder + except ModuleNotFoundError: + raise BentoMLException( + f"'{BENTOML_DEV_BUILD}=True', which requires the 'pypa/build' package. Install development dependencies with 'pip install -r requirements/dev-requirements.txt' and try again." + ) + with IsolatedEnvBuilder() as env: builder = ProjectBuilder(os.path.dirname(pyproject)) builder.python_executable = env.executable diff --git a/bentoml/_internal/io_descriptors/text.py b/bentoml/_internal/io_descriptors/text.py index 268563f1752..41ebbcaf979 100644 --- a/bentoml/_internal/io_descriptors/text.py +++ b/bentoml/_internal/io_descriptors/text.py @@ -6,13 +6,17 @@ from starlette.requests import Request from starlette.responses import Response -from bentoml.grpc.v1 import service_pb2 - from .base import IODescriptor from ..utils.http import set_cookies +from ..utils.lazy_loader import LazyLoader if TYPE_CHECKING: + from bentoml.grpc.v1 import service_pb2 as _service_pb2 + from ..context import InferenceApiContext as Context + from ...server.grpc.types import BentoServicerContext +else: + _service_pb2 = LazyLoader("_service_pb2", globals(), "bentoml.grpc.v1.service_pb2") MIME_TYPE = "text/plain" @@ -113,11 +117,17 @@ async def to_http_response(self, obj: str, ctx: Context | None = None) -> Respon else: return Response(obj, media_type=MIME_TYPE) - async def from_grpc_request(self, request: service_pb2.Request, context) -> str: + async def from_grpc_request( + self, + request: _service_pb2.Request, + context: BentoServicerContext, # pylint: disable=unused-argument + ) -> str: return str(request.input.string_value) - async def to_grpc_response(self, obj: str, context) -> service_pb2.Response: - return service_pb2.Response(output=service_pb2.Value(string_value=obj)) + async def to_grpc_response( + self, obj: str, context: BentoServicerContext # pylint: disable=unused-argument + ) -> _service_pb2.Response: + return _service_pb2.Response(output=_service_pb2.Value(string_value=obj)) def generate_protobuf(self): pass diff --git a/pyproject.toml b/pyproject.toml index e74ebac8842..df87afcbd3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,11 +116,12 @@ min-public-methods=2 [tool.isort] profile = "black" +line_length = 88 length_sort = true force_single_line = true order_by_type = true force_alphabetical_sort_within_sections = true -skip_glob = ["typings/*", "docs/*", "bentoml/grpc/*"] +skip_glob = ["typings/*","test/*", "**/*_pb2.py", "**/*_pb2_grpc.py"] [tool.pyright] pythonVersion = "3.10" diff --git a/requirements/docs-requirements.txt b/requirements/docs-requirements.txt index 98065d15e83..c6a7d734ac9 100644 --- a/requirements/docs-requirements.txt +++ b/requirements/docs-requirements.txt @@ -1,5 +1,6 @@ # Docs dependencies -r tests-requirements.txt +mypy-protobuf setuptools>=62.0.0 sphinx==4.5.0 myst-parser