pw_rpc: Merge pw_rpc protos into the pw_rpc package
This merges the pw_rpc_protos pw_proto_library Python package into
pw_rpc.
Requires: pigweed-internal:10840
Change-Id: Ib510571d75281d29d2a6719950b33ec09d0a5b9d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36505
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Joe Ethier <jethier@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_hdlc/rpc_example/example_script.py b/pw_hdlc/rpc_example/example_script.py
index eb5f26b..c979240 100755
--- a/pw_hdlc/rpc_example/example_script.py
+++ b/pw_hdlc/rpc_example/example_script.py
@@ -23,7 +23,7 @@
from pw_hdlc.rpc import HdlcRpcClient, default_channels
# Point the script to the .proto file with our RPC services.
-PROTO = Path(os.environ['PW_ROOT'], 'pw_rpc/pw_rpc_protos/echo.proto')
+PROTO = Path(os.environ['PW_ROOT'], 'pw_rpc/echo.proto')
def script(device: str, baud: int) -> None:
diff --git a/pw_rpc/BUILD.gn b/pw_rpc/BUILD.gn
index 0424f1e..3a5a79f 100644
--- a/pw_rpc/BUILD.gn
+++ b/pw_rpc/BUILD.gn
@@ -138,7 +138,8 @@
"internal/packet.proto",
]
inputs = [ "echo.options" ]
- prefix = "pw_rpc_protos"
+ python_package = "py"
+ prefix = "pw_rpc"
}
pw_doc_group("docs") {
@@ -217,7 +218,8 @@
pw_python_action("generate_ids_test") {
outputs = [ "$target_gen_dir/generated_ids_test.cc" ]
- script = "py/ids_test.py"
+
+ script = "py/tests/ids_test.py"
args = [ "--generate-cc-test" ] + rebase_path(outputs)
python_deps = [
"$dir_pw_build/py",
diff --git a/pw_rpc/CMakeLists.txt b/pw_rpc/CMakeLists.txt
index a832b07..b929d5a 100644
--- a/pw_rpc/CMakeLists.txt
+++ b/pw_rpc/CMakeLists.txt
@@ -74,7 +74,7 @@
INPUTS
echo.options
PREFIX
- pw_rpc_protos
+ pw_rpc
)
pw_proto_library(pw_rpc.test_protos
diff --git a/pw_rpc/docs.rst b/pw_rpc/docs.rst
index 9ec4c77..8bd39b3 100644
--- a/pw_rpc/docs.rst
+++ b/pw_rpc/docs.rst
@@ -280,7 +280,7 @@
-------------
Pigweed RPC packets consist of a type and a set of fields. The packets are
encoded as protocol buffers. The full packet format is described in
-``pw_rpc/pw_rpc_protos/internal/packet.proto``.
+``pw_rpc/pw_rpc/internal/packet.proto``.
.. literalinclude:: internal/packet.proto
:language: protobuf
diff --git a/pw_rpc/nanopb/public/pw_rpc/echo_service_nanopb.h b/pw_rpc/nanopb/public/pw_rpc/echo_service_nanopb.h
index 7e64895..54f8e7f 100644
--- a/pw_rpc/nanopb/public/pw_rpc/echo_service_nanopb.h
+++ b/pw_rpc/nanopb/public/pw_rpc/echo_service_nanopb.h
@@ -15,7 +15,7 @@
#include <cstring>
-#include "pw_rpc_protos/echo.rpc.pb.h"
+#include "pw_rpc/echo.rpc.pb.h"
namespace pw::rpc {
diff --git a/pw_rpc/public/pw_rpc/internal/packet.h b/pw_rpc/public/pw_rpc/internal/packet.h
index 9ea3d7c..2004d70 100644
--- a/pw_rpc/public/pw_rpc/internal/packet.h
+++ b/pw_rpc/public/pw_rpc/internal/packet.h
@@ -18,7 +18,7 @@
#include <span>
#include "pw_bytes/span.h"
-#include "pw_rpc_protos/internal/packet.pwpb.h"
+#include "pw_rpc/internal/packet.pwpb.h"
#include "pw_status/status_with_size.h"
namespace pw::rpc::internal {
diff --git a/pw_rpc/py/BUILD.gn b/pw_rpc/py/BUILD.gn
index 2c627e5..4c49985 100644
--- a/pw_rpc/py/BUILD.gn
+++ b/pw_rpc/py/BUILD.gn
@@ -18,7 +18,11 @@
import("$dir_pw_docgen/docs.gni")
pw_python_package("py") {
- setup = [ "setup.py" ]
+ generate_setup = {
+ name = "pw_rpc"
+ version = "0.0.1"
+ }
+
sources = [
"pw_rpc/__init__.py",
"pw_rpc/callback_client.py",
@@ -35,22 +39,22 @@
"pw_rpc/plugin_raw.py",
]
tests = [
- "callback_client_test.py",
- "client_test.py",
- "console_tools_test.py",
- "descriptors_test.py",
- "ids_test.py",
- "packets_test.py",
+ "tests/callback_client_test.py",
+ "tests/client_test.py",
+ "tests/console_tools_test.py",
+ "tests/descriptors_test.py",
+ "tests/ids_test.py",
+ "tests/packets_test.py",
]
python_deps = [
"$dir_pw_build/py",
"$dir_pw_protobuf/py",
"$dir_pw_protobuf_compiler/py",
"$dir_pw_status/py",
- "..:protos.python",
]
python_test_deps = [ "$dir_pw_build/py" ]
pylintrc = "$dir_pigweed/.pylintrc"
+ proto_library = "..:protos"
}
pw_doc_group("docs") {
diff --git a/pw_rpc/py/pw_rpc/client.py b/pw_rpc/py/pw_rpc/client.py
index 32689e6..11d8192 100644
--- a/pw_rpc/py/pw_rpc/client.py
+++ b/pw_rpc/py/pw_rpc/client.py
@@ -20,11 +20,11 @@
NamedTuple, Optional)
from google.protobuf.message import DecodeError
-from pw_rpc_protos.internal.packet_pb2 import PacketType, RpcPacket
from pw_status import Status
from pw_rpc import descriptors, packets
from pw_rpc.descriptors import Channel, Service, Method
+from pw_rpc.internal.packet_pb2 import PacketType, RpcPacket
_LOG = logging.getLogger(__name__)
diff --git a/pw_rpc/py/pw_rpc/packets.py b/pw_rpc/py/pw_rpc/packets.py
index dd0917c..3f15468 100644
--- a/pw_rpc/py/pw_rpc/packets.py
+++ b/pw_rpc/py/pw_rpc/packets.py
@@ -14,9 +14,10 @@
"""Functions for working with pw_rpc packets."""
from google.protobuf import message
-from pw_rpc_protos.internal import packet_pb2
from pw_status import Status
+from pw_rpc.internal import packet_pb2
+
def decode(data: bytes):
packet = packet_pb2.RpcPacket()
diff --git a/pw_rpc/py/setup.py b/pw_rpc/py/setup.py
deleted file mode 100644
index 12a943e..0000000
--- a/pw_rpc/py/setup.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2020 The Pigweed Authors
-#
-# 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.
-"""pw_rpc"""
-
-import setuptools # type: ignore
-
-setuptools.setup(
- name='pw_rpc',
- version='0.0.1',
- author='Pigweed Authors',
- author_email='pigweed-developers@googlegroups.com',
- description='On-device remote procedure calls',
- packages=setuptools.find_packages(),
- package_data={'pw_rpc': ['py.typed']},
- zip_safe=False,
- entry_points={
- 'console_scripts': [
- 'pw_rpc_codegen_nanopb = pw_rpc.plugin_nanopb:main',
- 'pw_rpc_codegen_raw = pw_rpc.plugin_raw:main'
- ]
- },
- install_requires=[
- 'protobuf',
- 'pw_protobuf_compiler',
- 'pw_rpc_protos',
- 'pw_status',
- ],
- tests_require=['pw_build'],
-)
diff --git a/pw_rpc/py/callback_client_test.py b/pw_rpc/py/tests/callback_client_test.py
similarity index 99%
rename from pw_rpc/py/callback_client_test.py
rename to pw_rpc/py/tests/callback_client_test.py
index ed41b3e..9f9d3e6 100755
--- a/pw_rpc/py/callback_client_test.py
+++ b/pw_rpc/py/tests/callback_client_test.py
@@ -19,10 +19,10 @@
from typing import List, Tuple
from pw_protobuf_compiler import python_protos
-from pw_rpc_protos.internal import packet_pb2
from pw_status import Status
from pw_rpc import callback_client, client, packets
+from pw_rpc.internal import packet_pb2
TEST_PROTO_1 = """\
syntax = "proto3";
diff --git a/pw_rpc/py/client_test.py b/pw_rpc/py/tests/client_test.py
similarity index 98%
rename from pw_rpc/py/client_test.py
rename to pw_rpc/py/tests/client_test.py
index 9a610f4..b3c9c06 100755
--- a/pw_rpc/py/client_test.py
+++ b/pw_rpc/py/tests/client_test.py
@@ -16,12 +16,12 @@
import unittest
-from pw_rpc_protos.internal.packet_pb2 import PacketType, RpcPacket
from pw_protobuf_compiler import python_protos
from pw_status import Status
from pw_rpc import callback_client, client, packets
import pw_rpc.ids
+from pw_rpc.internal.packet_pb2 import PacketType, RpcPacket
TEST_PROTO_1 = """\
syntax = "proto3";
diff --git a/pw_rpc/py/console_tools_test.py b/pw_rpc/py/tests/console_tools_test.py
similarity index 100%
rename from pw_rpc/py/console_tools_test.py
rename to pw_rpc/py/tests/console_tools_test.py
diff --git a/pw_rpc/py/descriptors_test.py b/pw_rpc/py/tests/descriptors_test.py
similarity index 100%
rename from pw_rpc/py/descriptors_test.py
rename to pw_rpc/py/tests/descriptors_test.py
diff --git a/pw_rpc/py/ids_test.py b/pw_rpc/py/tests/ids_test.py
similarity index 100%
rename from pw_rpc/py/ids_test.py
rename to pw_rpc/py/tests/ids_test.py
diff --git a/pw_rpc/py/packets_test.py b/pw_rpc/py/tests/packets_test.py
similarity index 97%
rename from pw_rpc/py/packets_test.py
rename to pw_rpc/py/tests/packets_test.py
index b10b831..4bf4dc1 100755
--- a/pw_rpc/py/packets_test.py
+++ b/pw_rpc/py/tests/packets_test.py
@@ -17,8 +17,8 @@
import unittest
from pw_status import Status
-from pw_rpc_protos.internal.packet_pb2 import PacketType, RpcPacket
+from pw_rpc.internal.packet_pb2 import PacketType, RpcPacket
from pw_rpc import packets
_TEST_REQUEST = RpcPacket(type=PacketType.REQUEST,