diff options
author | Thomas Girardier <girardier@google.com> | 2022-05-03 12:44:13 -0700 |
---|---|---|
committer | Thomas Girardier <girardier@google.com> | 2022-06-07 23:11:52 +0000 |
commit | bad5fad11a5d6999580f129a58dfd20b9ebee2bf (patch) | |
tree | 31d10bb42dc890a1e87fbf35471e5b70eb63194e | |
parent | 72517ebefc3faf13f20be8c6cd5f3fbf0fcaa90a (diff) | |
download | mmi2grpc-bad5fad11a5d6999580f129a58dfd20b9ebee2bf.tar.gz |
mmi2grpc: use python gRPC build system from bt-test-interfaces
Remove python gRPC build system as it has been integrated in
bt-test-interfaces.
Change-Id: I38eec0f321d7d89db9c434f8eb921ac5a4b5aa0e
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | .gitmodules | 2 | ||||
-rw-r--r-- | README.md | 10 | ||||
-rw-r--r-- | _build/__init__.py | 0 | ||||
-rw-r--r-- | _build/backend.py | 47 | ||||
-rwxr-xr-x | _build/grpc.py | 44 | ||||
-rwxr-xr-x | _build/protoc-gen-custom_grpc | 110 | ||||
m--------- | bt-test-interfaces | 0 | ||||
-rw-r--r-- | mmi2grpc/__init__.py | 2 | ||||
-rw-r--r-- | pandora/__init__.py | 0 | ||||
m--------- | proto | 0 | ||||
-rw-r--r-- | pyproject.toml | 15 |
12 files changed, 15 insertions, 219 deletions
@@ -1,5 +1 @@ -dist __pycache__ -pandora/* -!pandora/__init__.py -.eggs/ diff --git a/.gitmodules b/.gitmodules index f054688..2a24692 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "bt-test-interfaces"] - path = proto + path = bt-test-interfaces url = sso://pandora/bt-test-interfaces @@ -5,13 +5,13 @@ ```bash git submodule update --init -pip install -e . # With editable mode -# Or -pip install . # Without editable mode +pip install [-e] bt-test-interfaces/python +pip install [-e] . ``` -## Rebuild gRPC interfaces +## Rebuild gRPC Bluetooth test interfaces ```bash -./_build/grpc.py +pip install grpcio-tools==1.46.3 +./bt-test-interfaces/python/_build/grpc.py ``` diff --git a/_build/__init__.py b/_build/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/_build/__init__.py +++ /dev/null diff --git a/_build/backend.py b/_build/backend.py deleted file mode 100644 index f25546b..0000000 --- a/_build/backend.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""PEP517 build backend.""" - -from .grpc import build as build_pandora_grpc - -from flit_core.wheel import WheelBuilder -# Use all build hooks from flit -from flit_core.buildapi import * - - -# Build grpc interfaces when this build backend is invoked -build_pandora_grpc() - -# flit only supports copying one module, but we need to copy two of them -# because protobuf forces the use of absolute imports. -# So Monkey patches WheelBuilder#copy_module to copy pandora folder too. -# To avoid breaking this, the version of flit_core is pinned in pyproject.toml. -old_copy_module = WheelBuilder.copy_module - - -def copy_module(self): - from flit_core.common import Module - - old_copy_module(self) - - module = self.module - - self.module = Module('pandora', self.directory) - old_copy_module(self) - - self.module = module - - -WheelBuilder.copy_module = copy_module diff --git a/_build/grpc.py b/_build/grpc.py deleted file mode 100755 index ae020a2..0000000 --- a/_build/grpc.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Build gRPC pandora interfaces.""" - -import os -import pkg_resources -from grpc_tools import protoc - -package_directory = os.path.dirname(os.path.realpath(__file__)) - - -def build(): - - os.environ['PATH'] = package_directory + ':' + os.environ['PATH'] - - proto_include = pkg_resources.resource_filename('grpc_tools', '_proto') - - files = [ - f'pandora/{f}' for f in os.listdir('proto/pandora') if f.endswith('.proto')] - protoc.main([ - 'grpc_tools.protoc', - '-Iproto', - f'-I{proto_include}', - '--python_out=.', - '--custom_grpc_out=.', - ] + files) - - -if __name__ == '__main__': - build() diff --git a/_build/protoc-gen-custom_grpc b/_build/protoc-gen-custom_grpc deleted file mode 100755 index 00e47a5..0000000 --- a/_build/protoc-gen-custom_grpc +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2022 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Custom mmi2grpc gRPC compiler.""" - -import sys - -from google.protobuf.compiler.plugin_pb2 import CodeGeneratorRequest, \ - CodeGeneratorResponse - - -def eprint(*args, **kwargs): - print(*args, file=sys.stderr, **kwargs) - - -request = CodeGeneratorRequest.FromString(sys.stdin.buffer.read()) - - -def has_type(proto_file, type_name): - return any(filter(lambda x: x.name == type_name, proto_file.message_type)) - - -def import_type(imports, type): - package = type[1:type.rindex('.')] - type_name = type[type.rindex('.')+1:] - file = next(filter( - lambda x: x.package == package and has_type(x, type_name), - request.proto_file)) - python_path = file.name.replace('.proto', '').replace('/', '.') - as_name = python_path.replace('.', '_dot_') + '__pb2' - module_path = python_path[:python_path.rindex('.')] - module_name = python_path[python_path.rindex('.')+1:] + '_pb2' - imports.add(f'from {module_path} import {module_name} as {as_name}') - return f'{as_name}.{type_name}' - - -def generate_method(imports, file, service, method): - input_mode = 'stream' if method.client_streaming else 'unary' - output_mode = 'stream' if method.server_streaming else 'unary' - - input_type = import_type(imports, method.input_type) - output_type = import_type(imports, method.output_type) - - if input_mode == 'stream': - return ( - f'def {method.name}(self, iterator, **kwargs):\n' - f' return self.channel.{input_mode}_{output_mode}(\n' - f" '/{file.package}.{service.name}/{method.name}',\n" - f' request_serializer={input_type}.SerializeToString,\n' - f' response_deserializer={output_type}.FromString\n' - f' )(iterator, **kwargs)' - ).split('\n') - else: - return ( - f'def {method.name}(self, wait_for_ready=None, **kwargs):\n' - f' return self.channel.{input_mode}_{output_mode}(\n' - f" '/{file.package}.{service.name}/{method.name}',\n" - f' request_serializer={input_type}.SerializeToString,\n' - f' response_deserializer={output_type}.FromString\n' - f' )({input_type}(**kwargs), wait_for_ready=wait_for_ready)' - ).split('\n') - - -def generate_service(imports, file, service): - methods = '\n\n '.join([ - '\n '.join( - generate_method(imports, file, service, method) - ) for method in service.method - ]) - return ( - f'class {service.name}:\n' - f' def __init__(self, channel):\n' - f' self.channel = channel\n' - f'\n' - f' {methods}\n' - ).split('\n') - - -files = [] - -for file_name in request.file_to_generate: - file = next(filter(lambda x: x.name == file_name, request.proto_file)) - - imports = set([]) - - services = '\n'.join(sum([ - generate_service(imports, file, service) for service in file.service - ], [])) - - files.append(CodeGeneratorResponse.File( - name=file_name.replace('.proto', '_grpc.py'), - content='\n'.join(imports) + '\n\n' + services - )) - -reponse = CodeGeneratorResponse(file=files) - -sys.stdout.buffer.write(reponse.SerializeToString()) diff --git a/bt-test-interfaces b/bt-test-interfaces new file mode 160000 +Subproject 469be68bd8e816707adf43d71af9b3cd22226b9 diff --git a/mmi2grpc/__init__.py b/mmi2grpc/__init__.py index 2fd8603..6385e71 100644 --- a/mmi2grpc/__init__.py +++ b/mmi2grpc/__init__.py @@ -95,7 +95,7 @@ class IUT: description: MMI description. style: MMI popup style, unused for now. """ - print(f'{profile} mmi: {description}', file=sys.stderr) + print(f'{profile} mmi: {interaction}', file=sys.stderr) # Handles A2DP and AVDTP MMIs. if profile in ('A2DP', 'AVDTP'): diff --git a/pandora/__init__.py b/pandora/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/pandora/__init__.py +++ /dev/null diff --git a/proto b/proto deleted file mode 160000 -Subproject 5c9f411d1eefac171b76051b18bd0b0435c7790 diff --git a/pyproject.toml b/pyproject.toml index 6923987..de54399 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,12 +3,13 @@ name = "mmi2grpc" authors = [{name = "Pandora", email = "pandora-core@google.com"}] readme = "README.md" dynamic = ["version", "description"] -dependencies = ["grpcio >=1.41", "numpy >=1.22", "scipy >= 1.8"] - -[tool.flit.sdist] -include = ["_build", "proto", "pandora"] +dependencies = [ + "bt-test-interfaces", + "grpcio>=1.41", + "numpy>=1.22", + "scipy>=1.8" +] [build-system] -requires = ["flit_core==3.7.1", "grpcio-tools >=1.41"] -build-backend = "_build.backend" -backend-path = ["."] +requires = ["flit_core==3.7.1"] +build-backend = "flit_core.buildapi" |