Skip to content

Commit

Permalink
chore(grpc): vcs generated stubs (#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Sep 20, 2022
1 parent ead83cd commit 2e38f35
Show file tree
Hide file tree
Showing 15 changed files with 1,936 additions and 31 deletions.
10 changes: 1 addition & 9 deletions .devcontainer/lifecycle/post-start
Expand Up @@ -7,15 +7,7 @@ git config --global pull.ff only
git fetch upstream --tags && git pull

# install editable wheels & tools for bentoml
pip install -e ".[tracing,grpc]" --verbose
pip install -r requirements/dev-requirements.txt
pip install -U "grpcio-tools>=1.41.0" "mypy-protobuf>=3.3.0"
# generate stubs
OPTS=(-I. --grpc_python_out=. --python_out=. --mypy_out=. --mypy_grpc_out=.)
python -m grpc_tools.protoc "${OPTS[@]}" bentoml/grpc/v1alpha1/service.proto
python -m grpc_tools.protoc "${OPTS[@]}" bentoml/grpc/v1alpha1/service_test.proto
# uninstall broken protobuf typestubs
pip uninstall -y types-protobuf
pip install -e ".[tracing,grpc]" -r requirements/dev-requirements.txt

# setup docker buildx
docker buildx install
Expand Down
2 changes: 2 additions & 0 deletions .gitattributes
@@ -1,2 +1,4 @@
typings/**/*.pyi linguist-generated=true
*_pb2*.py linguist-generated=true
*_pb2*.pyi linguist-generated=true
* text=auto eol=lf
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Expand Up @@ -257,12 +257,6 @@ jobs:
path: ${{ steps.cache-dir.outputs.dir }}
key: ${{ runner.os }}-tests-${{ hashFiles('requirements/tests-requirements.txt') }}

# Simulate ./scripts/generate_grpc_stubs.sh
- name: Generate gRPC stubs
run: |
pip install protobuf==3.19.4 "grpcio-tools==1.41"
find bentoml/grpc/v1alpha1 -type f -name "*.proto" -exec python -m grpc_tools.protoc -I. --grpc_python_out=. --python_out=. "{}" \;
- name: Install dependencies
run: |
pip install -e ".[grpc]"
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Expand Up @@ -117,7 +117,3 @@ catboost_info

# ignore pyvenv
pyvenv.cfg

# generated stub that is included in distribution
*_pb2*.py
*_pb2*.pyi
12 changes: 2 additions & 10 deletions bentoml/grpc/utils/_import_hook.py
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from pathlib import Path

if TYPE_CHECKING:
import types
Expand Down Expand Up @@ -33,9 +32,7 @@ def import_generated_stubs(
# generate git root from this file's path
from bentoml._internal.utils import LazyLoader

GIT_ROOT = Path(__file__).parent.parent.parent.parent

exception_message = f"Generated stubs for '{version}/{file}' are missing. To generate stubs, run '{GIT_ROOT}/scripts/generate_grpc_stubs.sh'"
exception_message = f"Generated stubs for '{version}/{file}' are missing (broken installation). Please reinstall bentoml: 'pip install bentoml[grpc].'"
file = file.split(".")[0]

service_pb2 = LazyLoader(
Expand All @@ -57,11 +54,6 @@ def import_grpc() -> tuple[types.ModuleType, types.ModuleType]:
from bentoml._internal.utils import LazyLoader

exception_message = "'grpcio' is required for gRPC support. Install with 'pip install bentoml[grpc]'."
grpc = LazyLoader(
"grpc",
globals(),
"grpc",
exc_msg=exception_message,
)
grpc = LazyLoader("grpc", globals(), "grpc", exc_msg=exception_message)
aio = LazyLoader("aio", globals(), "grpc.aio", exc_msg=exception_message)
return grpc, aio
963 changes: 963 additions & 0 deletions bentoml/grpc/v1alpha1/service_pb2.py

Large diffs are not rendered by default.

0 comments on commit 2e38f35

Please sign in to comment.