diff options
-rw-r--r-- | .gitignore | 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 (renamed from protoc-gen-custom_grpc) | 0 | ||||
-rw-r--r-- | mmi2grpc/__init__.py | 4 | ||||
-rw-r--r-- | pyproject.toml | 14 | ||||
-rw-r--r-- | requirements.txt | 6 | ||||
-rwxr-xr-x | setup.py | 78 |
10 files changed, 116 insertions, 89 deletions
@@ -1,4 +1,4 @@ -build +dist __pycache__ pandora/* !pandora/__init__.py @@ -3,11 +3,15 @@ ## Install ```bash -pip3 install -r requirements.txt +git submodule update --init + +pip install -e . # With editable mode +# Or +pip install . # Without editable mode ``` -## Build grpc interfaces +## Rebuild gRPC interfaces ```bash -./setup.py build_grpc +./_build/grpc.py ``` diff --git a/_build/__init__.py b/_build/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/_build/__init__.py diff --git a/_build/backend.py b/_build/backend.py new file mode 100644 index 0000000..f25546b --- /dev/null +++ b/_build/backend.py @@ -0,0 +1,47 @@ +# 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 new file mode 100755 index 0000000..ae020a2 --- /dev/null +++ b/_build/grpc.py @@ -0,0 +1,44 @@ +#!/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/protoc-gen-custom_grpc b/_build/protoc-gen-custom_grpc index 00e47a5..00e47a5 100755 --- a/protoc-gen-custom_grpc +++ b/_build/protoc-gen-custom_grpc diff --git a/mmi2grpc/__init__.py b/mmi2grpc/__init__.py index a2b6530..2fd8603 100644 --- a/mmi2grpc/__init__.py +++ b/mmi2grpc/__init__.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Entry point to mmi2grpc.""" +"""Map Bluetooth PTS Man Machine Interface to Pandora gRPC calls.""" + +__version__ = "0.0.1" from typing import List import time diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6923987 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[project] +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"] + +[build-system] +requires = ["flit_core==3.7.1", "grpcio-tools >=1.41"] +build-backend = "_build.backend" +backend-path = ["."] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7b45d0f..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -grpcio==1.41.0 -grpcio-tools==1.41.0 -numpy==1.22.3 -protobuf==3.18.1 -scipy==1.8.0 -six==1.16.0 diff --git a/setup.py b/setup.py deleted file mode 100755 index 5a10a61..0000000 --- a/setup.py +++ /dev/null @@ -1,78 +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 setuptools commands.""" - -from setuptools import setup, Command -from setuptools.command.build_py import build_py -import pkg_resources -import os - -package_directory = os.path.dirname(os.path.realpath(__file__)) - -os.environ["PATH"] = package_directory + ':' + os.environ["PATH"] - - -class BuildGrpc(Command): - """gRPC build command.""" - description = 'build grpc files' - user_options = [] - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - from grpc_tools import protoc - - 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) - - -class BuildPyCommand(build_py): - """Custom build command.""" - - def run(self): - self.run_command('build_grpc') - build_py.run(self) - - -setup( - name='mmi2grpc', - version='0.0.1', - packages=['mmi2grpc', 'pandora'], - install_requires=[ - 'grpcio', - ], - setup_requires=[ - 'grpcio-tools' - ], - cmdclass={ - 'build_grpc': BuildGrpc, - 'build_py': BuildPyCommand, - } -) |