diff --git a/.editorconfig b/.editorconfig index 8a3f2fb..041328a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,4 +16,4 @@ indent_style = space tab_width = 2 [*.py] -max_line_length = 99 +max_line_length = 79 diff --git a/.style.yapf b/.style.yapf index 33db8ef..517afe0 100644 --- a/.style.yapf +++ b/.style.yapf @@ -1,3 +1,3 @@ [style] based_on_style = facebook -COLUMN_LIMIT = 99 +COLUMN_LIMIT = 79 diff --git a/CHANGELOG b/CHANGELOG index a20bf4a..0bb2cbb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,40 @@ # This project adheres to [Semantic Versioning](http://semver.org/). # includes Added / Changed / Fixed -## [1.2.0] UNRELEASED +## [2.4.0] UNRELEASED + +## [2.3.0] 2021-09-14 +### Changed +- Upgraded grpcio +- Optimized *_pb2_grpc.py imports, `clients/intermediates` no longer need to join the runtime environment + +### Fixed +- Fixed import MAX_RECURSION_DEPTH and protobuf.__version__ +- Fixed async client feature + +## [2.2.0] 2021-08-22 +### Added +Supported async gRPC client. [#40](https://github.com/bali-framework/bali-cli/issues/40) + +## [2.1.8] 2021-07-19 +### Added +- Adjusted the Jinja2 version + +## [2.1.7] 2021-06-13 +### Added +- Supported build command find protobuf files in /protos, further simplify project structure. [https://github.com/JoshYuJump/bali/tree/main/examples/todos](https://github.com/JoshYuJump/bali/tree/main/examples/todos) +- Adjust requirement Pydantic version. + +## [2.1.6] 2021-05-12 +### Added +- Supported multi gRPC address configurations + +### Fixed +- Fixed import issues + +## [2.0.0] 2021-05-12 +### Added +- Added `refresh` argument to clear cache ## [1.1.2] 2021-04-14 ### Fixed diff --git a/cli/__init__.py b/cli/__init__.py index a351fa9..8219039 100644 --- a/cli/__init__.py +++ b/cli/__init__.py @@ -1 +1 @@ -__version__ = '2.3.0-rc.1' +__version__ = '2.3.0' diff --git a/cli/biz.py b/cli/biz.py index 9e6d549..d583b99 100644 --- a/cli/biz.py +++ b/cli/biz.py @@ -32,9 +32,24 @@ def prepare_current_repo(work_dir: Path) -> Path: def compile_proto_file(output_dir: Path, proto_file_name: str) -> None: + """Compile protobuf to pb2 & pb2_grpc files""" options = [f"-I{output_dir}", f"--python_out={output_dir}", f"--grpc_python_out={output_dir}"] os.system(f"python -m grpc_tools.protoc {' '.join(options)} {proto_file_name}") + service = proto_file_name.replace(".proto", "") + + # Modified import in *_pb2_grpc.py files + pb2_grpc_file = f'{service}_pb2_grpc.py' + pb2_grpc_path: Path = output_dir / pb2_grpc_file + with pb2_grpc_path.open(mode="r+") as f: + content = f.read() + f.seek(0) + f.truncate() + f.write(content.replace( + f'import {service}_pb2 as', + f'from . import {service}_pb2 as', + )) + def compile_client_file(proto_path: Path, service_name: str): service_pattern = re.compile(r"^service\s+(.*?)\s+{$") diff --git a/cli/templates/utils.jinja2 b/cli/templates/utils.jinja2 index 5acd4d7..cd3cc9f 100644 --- a/cli/templates/utils.jinja2 +++ b/cli/templates/utils.jinja2 @@ -13,7 +13,7 @@ from grpc import insecure_channel from google.protobuf import json_format, __version__ as protobuf__version__ from google.protobuf.empty_pb2 import Empty -from ._config import GRPC_ADDRESS, MAX_RECURSION_DEPTH +from ._config import GRPC_ADDRESS # `GRPC_ADDRESS` is Generic gRPC channel target # `GRPC_ADDRESS_EXTENDS` is gRPC channel target specified by service abbreviation @@ -28,6 +28,12 @@ try: except ImportError: CHANNEL_OPTIONS = None +# ProtobufParser max_recursion_depth +try: + from ._config import MAX_RECURSION_DEPTH +except ImportError: + MAX_RECURSION_DEPTH = 99 + # All RPC clients inherited from the `ClientMixin` class ClientMixin: diff --git a/requirements.txt b/requirements.txt index 5434d62..e4191c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ grpcio-tools>=1.32.0,<=1.48 GitPython==3.1.11 jinja2>=2.11.2 MarkupSafe==2.0.1 -protobuf>=3.15,<=3.20 +protobuf>=3.15,<=3.20.2 protobuf2pydantic==2021.11.25 pydantic~=1.7 typer>=0.3.2