Skip to content

Commit

Permalink
fix(grpc): readthedocs build (#2866)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Aug 5, 2022
1 parent 8f2a36e commit 8b5fe25
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
11 changes: 10 additions & 1 deletion .readthedocs.yml
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions bentoml/_internal/bento/build_dev_bentoml_whl.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions bentoml/_internal/io_descriptors/text.py
Expand Up @@ -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"
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions 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
Expand Down

0 comments on commit 8b5fe25

Please sign in to comment.