From 0d94dbafb56f93b7bf70cc80bdc1b3091c155388 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 4 Sep 2024 21:42:45 +0000 Subject: [PATCH 01/26] Changes to reproduce --- test/distrib/bazel/python/BUILD | 300 +++++++++--------- .../test/bazel_distribtests.bzl | 6 +- 2 files changed, 153 insertions(+), 153 deletions(-) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 83b477e44574e..3334aca80fbba 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -27,96 +27,96 @@ package( default_testonly = 1, ) -proto_library( - name = "helloworld_proto", - srcs = ["helloworld.proto"], - deps = [ - ":hello_dep_proto", - "@com_google_protobuf//:duration_proto", - "@com_google_protobuf//:timestamp_proto", - ], -) - -# Test that .proto files can be located in strict subdiretories of the package. -proto_library( - name = "hello_dep_proto", - srcs = ["subdir/hello_dep.proto"], -) - -py_proto_library( - name = "helloworld_py_pb2", - deps = [":helloworld_proto"], -) - -py_grpc_library( - name = "helloworld_py_pb2_grpc", - srcs = [":helloworld_proto"], - deps = [":helloworld_py_pb2"], -) - -py_proto_library( - name = "duration_py_pb2", - deps = ["@com_google_protobuf//:duration_proto"], -) - -py_proto_library( - name = "timestamp_py_pb2", - deps = ["@com_google_protobuf//:timestamp_proto"], -) - -py_test( - name = "import_test", - srcs = ["helloworld.py"], - main = "helloworld.py", - python_version = "PY3", - deps = [ - ":duration_py_pb2", - ":helloworld_py_pb2", - ":helloworld_py_pb2_grpc", - ":timestamp_py_pb2", - ], -) - -# Test compatibility of py_proto_library and py_grpc_library rules with -# proto_library targets as deps when the latter use import_prefix and/or -# strip_import_prefix arguments -# -# See namespaced/upper/example for more encompassing tests. -proto_library( - name = "helloworld_moved_proto", - srcs = ["helloworld.proto"], - import_prefix = "google/cloud", - strip_import_prefix = "", - deps = [ - ":hello_dep_proto", - "@com_google_protobuf//:duration_proto", - "@com_google_protobuf//:timestamp_proto", - ], -) - -py_proto_library( - name = "helloworld_moved_py_pb2", - deps = [":helloworld_moved_proto"], -) - -py_grpc_library( - name = "helloworld_moved_py_pb2_grpc", - srcs = [":helloworld_moved_proto"], - deps = [":helloworld_moved_py_pb2"], -) - -py_test( - name = "import_moved_test", - srcs = ["helloworld_moved.py"], - main = "helloworld_moved.py", - python_version = "PY3", - deps = [ - ":duration_py_pb2", - ":helloworld_moved_py_pb2", - ":helloworld_moved_py_pb2_grpc", - ":timestamp_py_pb2", - ], -) +# proto_library( +# name = "helloworld_proto", +# srcs = ["helloworld.proto"], +# deps = [ +# ":hello_dep_proto", +# "@com_google_protobuf//:duration_proto", +# "@com_google_protobuf//:timestamp_proto", +# ], +# ) + +# # Test that .proto files can be located in strict subdiretories of the package. +# proto_library( +# name = "hello_dep_proto", +# srcs = ["subdir/hello_dep.proto"], +# ) + +# py_proto_library( +# name = "helloworld_py_pb2", +# deps = [":helloworld_proto"], +# ) + +# py_grpc_library( +# name = "helloworld_py_pb2_grpc", +# srcs = [":helloworld_proto"], +# deps = [":helloworld_py_pb2"], +# ) + +# py_proto_library( +# name = "duration_py_pb2", +# deps = ["@com_google_protobuf//:duration_proto"], +# ) + +# py_proto_library( +# name = "timestamp_py_pb2", +# deps = ["@com_google_protobuf//:timestamp_proto"], +# ) + +# py_test( +# name = "import_test", +# srcs = ["helloworld.py"], +# main = "helloworld.py", +# python_version = "PY3", +# deps = [ +# ":duration_py_pb2", +# ":helloworld_py_pb2", +# ":helloworld_py_pb2_grpc", +# ":timestamp_py_pb2", +# ], +# ) + +# # Test compatibility of py_proto_library and py_grpc_library rules with +# # proto_library targets as deps when the latter use import_prefix and/or +# # strip_import_prefix arguments +# # +# # See namespaced/upper/example for more encompassing tests. +# proto_library( +# name = "helloworld_moved_proto", +# srcs = ["helloworld.proto"], +# import_prefix = "google/cloud", +# strip_import_prefix = "", +# deps = [ +# ":hello_dep_proto", +# "@com_google_protobuf//:duration_proto", +# "@com_google_protobuf//:timestamp_proto", +# ], +# ) + +# py_proto_library( +# name = "helloworld_moved_py_pb2", +# deps = [":helloworld_moved_proto"], +# ) + +# py_grpc_library( +# name = "helloworld_moved_py_pb2_grpc", +# srcs = [":helloworld_moved_proto"], +# deps = [":helloworld_moved_py_pb2"], +# ) + +# py_test( +# name = "import_moved_test", +# srcs = ["helloworld_moved.py"], +# main = "helloworld_moved.py", +# python_version = "PY3", +# deps = [ +# ":duration_py_pb2", +# ":helloworld_moved_py_pb2", +# ":helloworld_moved_py_pb2_grpc", +# ":timestamp_py_pb2", +# ], +# ) # Test that a py_proto_library wrapping a proto_library in another package can # be imported from the package that contains the py_proto_library *AND* from @@ -136,63 +136,63 @@ py_test( ], ) -py_test( - name = "import_from_proto_library_package_test", - srcs = ["import_from_proto_library_package.py"], - main = "import_from_proto_library_package.py", - python_version = "PY3", - deps = [ - ":subpackage_py_pb2", - ], -) - -py_test( - name = "import_from_grpcio_reflection_test", - srcs = ["import_from_grpcio_reflection.py"], - main = "import_from_grpcio_reflection.py", - python_version = "PY3", - deps = [ - "@com_github_grpc_grpc//src/python/grpcio_reflection/grpc_reflection/v1alpha:grpc_reflection", - ], -) - -# Test that a py_proto_library can be successfully imported without requiring -# explicit dependencies on unused dependencies of the generated code. -py_test( - name = "transitive_proto_dep_test", - srcs = ["transitive_proto_dep.py"], - main = "transitive_proto_dep.py", - python_version = "PY3", - deps = [ - ":helloworld_py_pb2", - ], -) - -python_rules_test_suite( - name = "python_rules_test", -) - -# Test that grpc_library attribute replaces grpcio dependency on -# py_grpc_library targets - -py_library( - name = "grpc_library_replacement", - srcs = ["grpc_library_replacement.py"], -) - -py_grpc_library( - name = "helloworld_py_pb2_grpc_library_changed", - srcs = [":helloworld_proto"], - grpc_library = ":grpc_library_replacement", - deps = [":helloworld_py_pb2"], -) - -py_test( - name = "grpc_library_replacement_test", - srcs = ["grpc_library_replacement_test.py"], - main = "grpc_library_replacement_test.py", - python_version = "PY3", - deps = [ - ":helloworld_py_pb2_grpc_library_changed", - ], -) +# py_test( +# name = "import_from_proto_library_package_test", +# srcs = ["import_from_proto_library_package.py"], +# main = "import_from_proto_library_package.py", +# python_version = "PY3", +# deps = [ +# ":subpackage_py_pb2", +# ], +# ) + +# py_test( +# name = "import_from_grpcio_reflection_test", +# srcs = ["import_from_grpcio_reflection.py"], +# main = "import_from_grpcio_reflection.py", +# python_version = "PY3", +# deps = [ +# "@com_github_grpc_grpc//src/python/grpcio_reflection/grpc_reflection/v1alpha:grpc_reflection", +# ], +# ) + +# # Test that a py_proto_library can be successfully imported without requiring +# # explicit dependencies on unused dependencies of the generated code. +# py_test( +# name = "transitive_proto_dep_test", +# srcs = ["transitive_proto_dep.py"], +# main = "transitive_proto_dep.py", +# python_version = "PY3", +# deps = [ +# ":helloworld_py_pb2", +# ], +# ) + +# python_rules_test_suite( +# name = "python_rules_test", +# ) + +# # Test that grpc_library attribute replaces grpcio dependency on +# # py_grpc_library targets + +# py_library( +# name = "grpc_library_replacement", +# srcs = ["grpc_library_replacement.py"], +# ) + +# py_grpc_library( +# name = "helloworld_py_pb2_grpc_library_changed", +# srcs = [":helloworld_proto"], +# grpc_library = ":grpc_library_replacement", +# deps = [":helloworld_py_pb2"], +# ) + +# py_test( +# name = "grpc_library_replacement_test", +# srcs = ["grpc_library_replacement_test.py"], +# main = "grpc_library_replacement_test.py", +# python_version = "PY3", +# deps = [ +# ":helloworld_py_pb2_grpc_library_changed", +# ], +# ) diff --git a/tools/bazelify_tests/test/bazel_distribtests.bzl b/tools/bazelify_tests/test/bazel_distribtests.bzl index 9f35a57b3cb60..70c750041d4cf 100644 --- a/tools/bazelify_tests/test/bazel_distribtests.bzl +++ b/tools/bazelify_tests/test/bazel_distribtests.bzl @@ -35,9 +35,9 @@ def generate_bazel_distribtests(name): for bazel_version in SUPPORTED_BAZEL_VERSIONS: for shard_name in _TEST_SHARDS: - # TODO(https://github.com/grpc/grpc/issues/35391): Fix bazel 7 or later + distribtest_python test - if shard_name == "distribtest_python": - continue + # TODO(https://github.com/grpc/grpc/issues/35391): Fix bazel 7 + distribtest_python test + # if bazel_version.startswith("7") and shard_name == "distribtest_python": + # continue test_name = "bazel_distribtest_%s_%s" % (bazel_version, shard_name) grpc_run_bazel_distribtest_test( name = test_name, From aaebd2d77d85cbafae2d550e7b4f8a35af2b8cac Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 8 Oct 2024 00:00:11 +0000 Subject: [PATCH 02/26] Test Protobuf py_proto_library --- bazel/python_rules.bzl | 49 +++--- test/distrib/bazel/python/BUILD | 159 +----------------- test/distrib/bazel/python/in_subpackage/BUILD | 3 +- 3 files changed, 35 insertions(+), 176 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index f5fa1a0550916..e9f38d103436f 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -15,6 +15,8 @@ load("@rules_proto//proto:defs.bzl", "ProtoInfo") load("@rules_python//python:py_info.bzl", "PyInfo") +load("@com_google_protobuf//bazel:py_proto_library.bzl", protobuf_py_proto_library = "py_proto_library") + load( "//bazel:protobuf.bzl", "declare_out_files", @@ -158,28 +160,31 @@ def _generate_py_impl(context): out_pyinfo, ] -py_proto_library = rule( - attrs = { - "deps": attr.label_list( - mandatory = True, - allow_empty = False, - providers = [ProtoInfo], - aspects = [_gen_py_aspect], - ), - "_protoc": attr.label( - default = Label("@com_google_protobuf//:protoc"), - providers = ["files_to_run"], - executable = True, - cfg = "exec", - ), - "_protobuf_library": attr.label( - default = Label("@com_google_protobuf//:protobuf_python"), - providers = [PyInfo], - ), - "imports": attr.string_list(), - }, - implementation = _generate_py_impl, -) +# py_proto_library = rule( +# attrs = { +# "deps": attr.label_list( +# mandatory = True, +# allow_empty = False, +# providers = [ProtoInfo], +# aspects = [_gen_py_aspect], +# ), +# "_protoc": attr.label( +# default = Label("@com_google_protobuf//:protoc"), +# providers = ["files_to_run"], +# executable = True, +# cfg = "exec", +# ), +# "_protobuf_library": attr.label( +# default = Label("@com_google_protobuf//:protobuf_python"), +# providers = [PyInfo], +# ), +# "imports": attr.string_list(), +# }, +# implementation = _generate_py_impl, +# ) +# def py_proto_library(*, deprecation = "Use py_proto_library from protobuf repository", **kwargs): +# _py_proto_library(deprecation = deprecation, **kwargs) +py_proto_library = protobuf_py_proto_library def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 3334aca80fbba..8f8b9829f593f 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -14,10 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +# load("@rules_proto//proto:defs.bzl", "proto_library") +# load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") + +load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") + load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", - "py_proto_library", + # "py_proto_library", ) load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_library", "py_test") @@ -27,97 +32,6 @@ package( default_testonly = 1, ) -# proto_library( -# name = "helloworld_proto", -# srcs = ["helloworld.proto"], -# deps = [ -# ":hello_dep_proto", -# "@com_google_protobuf//:duration_proto", -# "@com_google_protobuf//:timestamp_proto", -# ], -# ) - -# # Test that .proto files can be located in strict subdiretories of the package. -# proto_library( -# name = "hello_dep_proto", -# srcs = ["subdir/hello_dep.proto"], -# ) - -# py_proto_library( -# name = "helloworld_py_pb2", -# deps = [":helloworld_proto"], -# ) - -# py_grpc_library( -# name = "helloworld_py_pb2_grpc", -# srcs = [":helloworld_proto"], -# deps = [":helloworld_py_pb2"], -# ) - -# py_proto_library( -# name = "duration_py_pb2", -# deps = ["@com_google_protobuf//:duration_proto"], -# ) - -# py_proto_library( -# name = "timestamp_py_pb2", -# deps = ["@com_google_protobuf//:timestamp_proto"], -# ) - -# py_test( -# name = "import_test", -# srcs = ["helloworld.py"], -# main = "helloworld.py", -# python_version = "PY3", -# deps = [ -# ":duration_py_pb2", -# ":helloworld_py_pb2", -# ":helloworld_py_pb2_grpc", -# ":timestamp_py_pb2", -# ], -# ) - -# # Test compatibility of py_proto_library and py_grpc_library rules with -# # proto_library targets as deps when the latter use import_prefix and/or -# # strip_import_prefix arguments -# # -# # See namespaced/upper/example for more encompassing tests. -# proto_library( -# name = "helloworld_moved_proto", -# srcs = ["helloworld.proto"], -# import_prefix = "google/cloud", -# strip_import_prefix = "", -# deps = [ -# ":hello_dep_proto", -# "@com_google_protobuf//:duration_proto", -# "@com_google_protobuf//:timestamp_proto", -# ], -# ) - -# py_proto_library( -# name = "helloworld_moved_py_pb2", -# deps = [":helloworld_moved_proto"], -# ) - -# py_grpc_library( -# name = "helloworld_moved_py_pb2_grpc", -# srcs = [":helloworld_moved_proto"], -# deps = [":helloworld_moved_py_pb2"], -# ) - -# py_test( -# name = "import_moved_test", -# srcs = ["helloworld_moved.py"], -# main = "helloworld_moved.py", -# python_version = "PY3", -# deps = [ -# ":duration_py_pb2", -# ":helloworld_moved_py_pb2", -# ":helloworld_moved_py_pb2_grpc", -# ":timestamp_py_pb2", -# ], -# ) - # Test that a py_proto_library wrapping a proto_library in another package can # be imported from the package that contains the py_proto_library *AND* from # the package that contains the proto_library. @@ -135,64 +49,3 @@ py_test( ":subpackage_py_pb2", ], ) - -# py_test( -# name = "import_from_proto_library_package_test", -# srcs = ["import_from_proto_library_package.py"], -# main = "import_from_proto_library_package.py", -# python_version = "PY3", -# deps = [ -# ":subpackage_py_pb2", -# ], -# ) - -# py_test( -# name = "import_from_grpcio_reflection_test", -# srcs = ["import_from_grpcio_reflection.py"], -# main = "import_from_grpcio_reflection.py", -# python_version = "PY3", -# deps = [ -# "@com_github_grpc_grpc//src/python/grpcio_reflection/grpc_reflection/v1alpha:grpc_reflection", -# ], -# ) - -# # Test that a py_proto_library can be successfully imported without requiring -# # explicit dependencies on unused dependencies of the generated code. -# py_test( -# name = "transitive_proto_dep_test", -# srcs = ["transitive_proto_dep.py"], -# main = "transitive_proto_dep.py", -# python_version = "PY3", -# deps = [ -# ":helloworld_py_pb2", -# ], -# ) - -# python_rules_test_suite( -# name = "python_rules_test", -# ) - -# # Test that grpc_library attribute replaces grpcio dependency on -# # py_grpc_library targets - -# py_library( -# name = "grpc_library_replacement", -# srcs = ["grpc_library_replacement.py"], -# ) - -# py_grpc_library( -# name = "helloworld_py_pb2_grpc_library_changed", -# srcs = [":helloworld_proto"], -# grpc_library = ":grpc_library_replacement", -# deps = [":helloworld_py_pb2"], -# ) - -# py_test( -# name = "grpc_library_replacement_test", -# srcs = ["grpc_library_replacement_test.py"], -# main = "grpc_library_replacement_test.py", -# python_version = "PY3", -# deps = [ -# ":helloworld_py_pb2_grpc_library_changed", -# ], -# ) diff --git a/test/distrib/bazel/python/in_subpackage/BUILD b/test/distrib/bazel/python/in_subpackage/BUILD index 2b008c8b5d301..c21a220f736bf 100644 --- a/test/distrib/bazel/python/in_subpackage/BUILD +++ b/test/distrib/bazel/python/in_subpackage/BUILD @@ -14,7 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@rules_proto//proto:defs.bzl", "proto_library") +# load("@rules_proto//proto:defs.bzl", "proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") package( default_testonly = 1, From 1e65d481d01d72ab413e5488fa6d75d08812936d Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 8 Oct 2024 17:26:53 +0000 Subject: [PATCH 03/26] test bazel 6.5.0 --- bazel/python_rules.bzl | 46 ++++++++++++++++----------------- test/distrib/bazel/python/BUILD | 4 +-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index e9f38d103436f..d7d63ffffc4ec 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -160,31 +160,31 @@ def _generate_py_impl(context): out_pyinfo, ] -# py_proto_library = rule( -# attrs = { -# "deps": attr.label_list( -# mandatory = True, -# allow_empty = False, -# providers = [ProtoInfo], -# aspects = [_gen_py_aspect], -# ), -# "_protoc": attr.label( -# default = Label("@com_google_protobuf//:protoc"), -# providers = ["files_to_run"], -# executable = True, -# cfg = "exec", -# ), -# "_protobuf_library": attr.label( -# default = Label("@com_google_protobuf//:protobuf_python"), -# providers = [PyInfo], -# ), -# "imports": attr.string_list(), -# }, -# implementation = _generate_py_impl, -# ) +py_proto_library = rule( + attrs = { + "deps": attr.label_list( + mandatory = True, + allow_empty = False, + providers = [ProtoInfo], + aspects = [_gen_py_aspect], + ), + "_protoc": attr.label( + default = Label("@com_google_protobuf//:protoc"), + providers = ["files_to_run"], + executable = True, + cfg = "exec", + ), + "_protobuf_library": attr.label( + default = Label("@com_google_protobuf//:protobuf_python"), + providers = [PyInfo], + ), + "imports": attr.string_list(), + }, + implementation = _generate_py_impl, +) # def py_proto_library(*, deprecation = "Use py_proto_library from protobuf repository", **kwargs): # _py_proto_library(deprecation = deprecation, **kwargs) -py_proto_library = protobuf_py_proto_library +# py_proto_library = protobuf_py_proto_library def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 8f8b9829f593f..262d68c9a283f 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -17,12 +17,12 @@ # load("@rules_proto//proto:defs.bzl", "proto_library") # load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") -load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") +# load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", - # "py_proto_library", + "py_proto_library", ) load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_library", "py_test") From b11bb25b8b3593bd4d493bf48a6da6e2467741cc Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 8 Oct 2024 17:30:01 +0000 Subject: [PATCH 04/26] Use protobuf py_proto_library --- test/distrib/bazel/python/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 262d68c9a283f..8f8b9829f593f 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -17,12 +17,12 @@ # load("@rules_proto//proto:defs.bzl", "proto_library") # load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") -# load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") +load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", - "py_proto_library", + # "py_proto_library", ) load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_library", "py_test") From afb211ecb61f9ce07427b7ba36642159b51d268e Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Fri, 18 Oct 2024 19:38:40 +0000 Subject: [PATCH 05/26] Test fixes --- test/distrib/bazel/python/BUILD | 159 +++++++++++++++++- .../python/grpc_library_replacement_test.py | 2 +- test/distrib/bazel/python/helloworld_moved.py | 4 + .../bazel/python/import_from_this_package.py | 3 +- 4 files changed, 163 insertions(+), 5 deletions(-) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 8f8b9829f593f..9739e4e37cb2f 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -14,10 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# load("@rules_proto//proto:defs.bzl", "proto_library") -# load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") - load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", @@ -32,6 +30,100 @@ package( default_testonly = 1, ) + +proto_library( + name = "helloworld_proto", + srcs = ["helloworld.proto"], + deps = [ + ":hello_dep_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:timestamp_proto", + ], +) + +# Test that .proto files can be located in strict subdiretories of the package. +proto_library( + name = "hello_dep_proto", + srcs = ["subdir/hello_dep.proto"], +) + +py_proto_library( + name = "helloworld_py_pb2", + deps = [":helloworld_proto"], +) + +py_grpc_library( + name = "helloworld_py_pb2_grpc", + srcs = [":helloworld_proto"], + deps = [":helloworld_py_pb2"], +) + +py_proto_library( + name = "duration_py_pb2", + deps = ["@com_google_protobuf//:duration_proto"], +) + +py_proto_library( + name = "timestamp_py_pb2", + deps = ["@com_google_protobuf//:timestamp_proto"], +) + +py_test( + name = "import_test", + srcs = ["helloworld.py"], + main = "helloworld.py", + python_version = "PY3", + deps = [ + ":duration_py_pb2", + ":helloworld_py_pb2", + ":helloworld_py_pb2_grpc", + ":timestamp_py_pb2", + ], +) + +# Test compatibility of py_proto_library and py_grpc_library rules with +# proto_library targets as deps when the latter use import_prefix and/or +# strip_import_prefix arguments +# +# See namespaced/upper/example for more encompassing tests. +proto_library( + name = "helloworld_moved_proto", + srcs = ["helloworld.proto"], + import_prefix = "google/cloud", + strip_import_prefix = "", + deps = [ + ":hello_dep_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:timestamp_proto", + ], +) + +py_proto_library( + name = "helloworld_moved_py_pb2", + deps = [":helloworld_moved_proto"], +) + +py_grpc_library( + name = "helloworld_moved_py_pb2_grpc", + srcs = [":helloworld_moved_proto"], + deps = [":helloworld_moved_py_pb2"], +) + +py_test( + name = "import_moved_test", + srcs = ["helloworld_moved.py"], + main = "helloworld_moved.py", + python_version = "PY3", + deps = [ + ":duration_py_pb2", + # ":helloworld_py_pb2", + # ":helloworld_py_pb2_grpc", + ":helloworld_moved_py_pb2", + ":helloworld_moved_py_pb2_grpc", + ":timestamp_py_pb2", + ], +) + # Test that a py_proto_library wrapping a proto_library in another package can # be imported from the package that contains the py_proto_library *AND* from # the package that contains the proto_library. @@ -49,3 +141,64 @@ py_test( ":subpackage_py_pb2", ], ) + +py_test( + name = "import_from_proto_library_package_test", + srcs = ["import_from_proto_library_package.py"], + main = "import_from_proto_library_package.py", + python_version = "PY3", + deps = [ + ":subpackage_py_pb2", + ], +) + +py_test( + name = "import_from_grpcio_reflection_test", + srcs = ["import_from_grpcio_reflection.py"], + main = "import_from_grpcio_reflection.py", + python_version = "PY3", + deps = [ + "@com_github_grpc_grpc//src/python/grpcio_reflection/grpc_reflection/v1alpha:grpc_reflection", + ], +) + +# Test that a py_proto_library can be successfully imported without requiring +# explicit dependencies on unused dependencies of the generated code. +py_test( + name = "transitive_proto_dep_test", + srcs = ["transitive_proto_dep.py"], + main = "transitive_proto_dep.py", + python_version = "PY3", + deps = [ + ":helloworld_py_pb2", + ], +) + +python_rules_test_suite( + name = "python_rules_test", +) + +# Test that grpc_library attribute replaces grpcio dependency on +# py_grpc_library targets + +py_library( + name = "grpc_library_replacement", + srcs = ["grpc_library_replacement.py"], +) + +py_grpc_library( + name = "helloworld_py_pb2_grpc_library_changed", + srcs = [":helloworld_proto"], + grpc_library = ":grpc_library_replacement", + deps = [":helloworld_py_pb2"], +) + +py_test( + name = "grpc_library_replacement_test", + srcs = ["grpc_library_replacement_test.py"], + main = "grpc_library_replacement_test.py", + python_version = "PY3", + deps = [ + ":helloworld_py_pb2_grpc_library_changed", + ], +) diff --git a/test/distrib/bazel/python/grpc_library_replacement_test.py b/test/distrib/bazel/python/grpc_library_replacement_test.py index fb3e449c07f78..a21ce8f9258c1 100644 --- a/test/distrib/bazel/python/grpc_library_replacement_test.py +++ b/test/distrib/bazel/python/grpc_library_replacement_test.py @@ -15,7 +15,7 @@ import sys try: - import grpc + from grpc import aio except ImportError: pass else: diff --git a/test/distrib/bazel/python/helloworld_moved.py b/test/distrib/bazel/python/helloworld_moved.py index 7a459ddf4a208..a5376208bbfb9 100644 --- a/test/distrib/bazel/python/helloworld_moved.py +++ b/test/distrib/bazel/python/helloworld_moved.py @@ -24,6 +24,10 @@ import grpc from google.protobuf import duration_pb2 from google.protobuf import timestamp_pb2 +import sys +for path in sys.path: + print(f"[xuan_testing] sys.path: {path}\n") +# import sys; sys.stderr.write(f"[xuan_testing] sys.path: {sys.path}\n"); sys.stderr.flush() from google.cloud import helloworld_pb2 from google.cloud import helloworld_pb2_grpc diff --git a/test/distrib/bazel/python/import_from_this_package.py b/test/distrib/bazel/python/import_from_this_package.py index 1191ff2e5699c..d41bee418422d 100644 --- a/test/distrib/bazel/python/import_from_this_package.py +++ b/test/distrib/bazel/python/import_from_this_package.py @@ -15,4 +15,5 @@ proto_library and py_proto_library are in different Bazel packages. """ -import subpackage_pb2 +# import subpackage_pb2 +import in_subpackage.subpackage_pb2 From 8bc9d0bf2ee6a4cad0e1e1be850f07c5c8463f47 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Fri, 18 Oct 2024 21:26:10 +0000 Subject: [PATCH 06/26] Fix more issues --- test/distrib/bazel/python/BUILD | 5 +---- test/distrib/bazel/python/helloworld_moved.py | 8 ++------ test/distrib/bazel/python/python_rules_test.bzl | 12 ++++++------ tools/bazelify_tests/test/bazel_distribtests.bzl | 2 ++ 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 9739e4e37cb2f..50177a56fbdf3 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -20,7 +20,6 @@ load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", - # "py_proto_library", ) load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_library", "py_test") @@ -89,7 +88,7 @@ py_test( proto_library( name = "helloworld_moved_proto", srcs = ["helloworld.proto"], - import_prefix = "google/cloud", + import_prefix = "foo/bar", strip_import_prefix = "", deps = [ ":hello_dep_proto", @@ -116,8 +115,6 @@ py_test( python_version = "PY3", deps = [ ":duration_py_pb2", - # ":helloworld_py_pb2", - # ":helloworld_py_pb2_grpc", ":helloworld_moved_py_pb2", ":helloworld_moved_py_pb2_grpc", ":timestamp_py_pb2", diff --git a/test/distrib/bazel/python/helloworld_moved.py b/test/distrib/bazel/python/helloworld_moved.py index a5376208bbfb9..47c90603809d7 100644 --- a/test/distrib/bazel/python/helloworld_moved.py +++ b/test/distrib/bazel/python/helloworld_moved.py @@ -24,12 +24,8 @@ import grpc from google.protobuf import duration_pb2 from google.protobuf import timestamp_pb2 -import sys -for path in sys.path: - print(f"[xuan_testing] sys.path: {path}\n") -# import sys; sys.stderr.write(f"[xuan_testing] sys.path: {sys.path}\n"); sys.stderr.flush() -from google.cloud import helloworld_pb2 -from google.cloud import helloworld_pb2_grpc +from foo.bar import helloworld_pb2 +from foo.bar import helloworld_pb2_grpc # isort: on diff --git a/test/distrib/bazel/python/python_rules_test.bzl b/test/distrib/bazel/python/python_rules_test.bzl index a0e85afc0f87d..9f59cd5a529e4 100644 --- a/test/distrib/bazel/python/python_rules_test.bzl +++ b/test/distrib/bazel/python/python_rules_test.bzl @@ -39,19 +39,19 @@ def _py_proto_library_provider_contents_test_impl(ctx): ] _assert_in(env, "helloworld_pb2.py", files) - _assert_in(env, "helloworld_pb2.pyi", files) + # _assert_in(env, "helloworld_pb2.pyi", files) _assert_in(env, "subdir/hello_dep_pb2.py", files) - _assert_in(env, "subdir/hello_dep_pb2.pyi", files) + # _assert_in(env, "subdir/hello_dep_pb2.pyi", files) _assert_in(env, "helloworld_pb2.py", runfiles) - _assert_in(env, "helloworld_pb2.pyi", runfiles) + # _assert_in(env, "helloworld_pb2.pyi", runfiles) _assert_in(env, "subdir/hello_dep_pb2.py", runfiles) - _assert_in(env, "subdir/hello_dep_pb2.pyi", runfiles) + # _assert_in(env, "subdir/hello_dep_pb2.pyi", runfiles) _assert_in(env, "helloworld_pb2.py", py_info_transitive_sources) - _assert_in(env, "helloworld_pb2.pyi", py_info_transitive_sources) + # _assert_in(env, "helloworld_pb2.pyi", py_info_transitive_sources) _assert_in(env, "subdir/hello_dep_pb2.py", py_info_transitive_sources) - _assert_in(env, "subdir/hello_dep_pb2.pyi", py_info_transitive_sources) + # _assert_in(env, "subdir/hello_dep_pb2.pyi", py_info_transitive_sources) return analysistest.end(env) diff --git a/tools/bazelify_tests/test/bazel_distribtests.bzl b/tools/bazelify_tests/test/bazel_distribtests.bzl index 70c750041d4cf..7e0e550b348ea 100644 --- a/tools/bazelify_tests/test/bazel_distribtests.bzl +++ b/tools/bazelify_tests/test/bazel_distribtests.bzl @@ -38,6 +38,8 @@ def generate_bazel_distribtests(name): # TODO(https://github.com/grpc/grpc/issues/35391): Fix bazel 7 + distribtest_python test # if bazel_version.startswith("7") and shard_name == "distribtest_python": # continue + if shard_name != "distribtest_python": + continue test_name = "bazel_distribtest_%s_%s" % (bazel_version, shard_name) grpc_run_bazel_distribtest_test( name = test_name, From 5378960bcbd00e362de2910522a6c9c78ee6fd5b Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Mon, 28 Oct 2024 23:57:17 +0000 Subject: [PATCH 07/26] Replace our rule to Protobufs --- bazel/python_rules.bzl | 49 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index d7d63ffffc4ec..7e1c923eeab2c 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -160,31 +160,30 @@ def _generate_py_impl(context): out_pyinfo, ] -py_proto_library = rule( - attrs = { - "deps": attr.label_list( - mandatory = True, - allow_empty = False, - providers = [ProtoInfo], - aspects = [_gen_py_aspect], - ), - "_protoc": attr.label( - default = Label("@com_google_protobuf//:protoc"), - providers = ["files_to_run"], - executable = True, - cfg = "exec", - ), - "_protobuf_library": attr.label( - default = Label("@com_google_protobuf//:protobuf_python"), - providers = [PyInfo], - ), - "imports": attr.string_list(), - }, - implementation = _generate_py_impl, -) -# def py_proto_library(*, deprecation = "Use py_proto_library from protobuf repository", **kwargs): -# _py_proto_library(deprecation = deprecation, **kwargs) -# py_proto_library = protobuf_py_proto_library +# py_proto_library = rule( +# attrs = { +# "deps": attr.label_list( +# mandatory = True, +# allow_empty = False, +# providers = [ProtoInfo], +# aspects = [_gen_py_aspect], +# ), +# "_protoc": attr.label( +# default = Label("@com_google_protobuf//:protoc"), +# providers = ["files_to_run"], +# executable = True, +# cfg = "exec", +# ), +# "_protobuf_library": attr.label( +# default = Label("@com_google_protobuf//:protobuf_python"), +# providers = [PyInfo], +# ), +# "imports": attr.string_list(), +# }, +# implementation = _generate_py_impl, +# ) + +py_proto_library = protobuf_py_proto_library def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) From dafae49ae47221e7d4d61ae7c0a58037176edc6e Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Mon, 28 Oct 2024 23:58:31 +0000 Subject: [PATCH 08/26] Enable all tests --- tools/bazelify_tests/test/bazel_distribtests.bzl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/bazelify_tests/test/bazel_distribtests.bzl b/tools/bazelify_tests/test/bazel_distribtests.bzl index 7e0e550b348ea..8f1b6b6473076 100644 --- a/tools/bazelify_tests/test/bazel_distribtests.bzl +++ b/tools/bazelify_tests/test/bazel_distribtests.bzl @@ -35,11 +35,6 @@ def generate_bazel_distribtests(name): for bazel_version in SUPPORTED_BAZEL_VERSIONS: for shard_name in _TEST_SHARDS: - # TODO(https://github.com/grpc/grpc/issues/35391): Fix bazel 7 + distribtest_python test - # if bazel_version.startswith("7") and shard_name == "distribtest_python": - # continue - if shard_name != "distribtest_python": - continue test_name = "bazel_distribtest_%s_%s" % (bazel_version, shard_name) grpc_run_bazel_distribtest_test( name = test_name, From 45eedaa83ed0d6fe82fb1dbeda50da912df0e721 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 29 Oct 2024 18:21:58 +0000 Subject: [PATCH 09/26] Rey remove imports from py_proto_library --- src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index 49f9e8beec62c..f6b23b7922dfd 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -18,7 +18,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "channelz_py_pb2", - imports = ["../../"], + # imports = ["../../"], deps = ["//src/proto/grpc/channelz:channelz_proto_only"], ) From 4ab9929be69dae07a7e10016aaecc43e9789e0da Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 30 Oct 2024 19:07:39 +0000 Subject: [PATCH 10/26] Try add py_proto_library.patch --- bazel/grpc_deps.bzl | 1 + third_party/BUILD | 1 + third_party/py_proto_library.patch | 32 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 third_party/py_proto_library.patch diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 442a9e1f8ba13..3af3863fe1ddd 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -67,6 +67,7 @@ def grpc_deps(): ], patches = [ "@com_github_grpc_grpc//third_party:protobuf.patch", + "@com_github_grpc_grpc//third_party:py_proto_library.patch", ], patch_args = ["-p1"], ) diff --git a/third_party/BUILD b/third_party/BUILD index 9d0c08258746a..3918243ac3ef9 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -11,6 +11,7 @@ exports_files([ "enum34.BUILD", "futures.BUILD", "protobuf.patch", + "py_proto_library.patch", "protoc-gen-validate.patch", ]) diff --git a/third_party/py_proto_library.patch b/third_party/py_proto_library.patch new file mode 100644 index 0000000000000..9e0a2f6e4094f --- /dev/null +++ b/third_party/py_proto_library.patch @@ -0,0 +1,32 @@ +diff --git a/bazel/py_proto_library.bzl b/bazel/py_proto_library.bzl +index 86af99950..8396661ae 100644 +--- a/bazel/py_proto_library.bzl ++++ b/bazel/py_proto_library.bzl +@@ -147,6 +147,9 @@ def _py_proto_library_rule(ctx): + transitive = [info.transitive_sources for info in pyproto_infos], + ) + ++ # Gather imports from the 'imports' attribute ++ imports = depset(direct = [ctx.label.package + "/" + i for i in ctx.attr.imports]) ++ + return [ + DefaultInfo( + files = default_outputs, +@@ -161,7 +164,8 @@ def _py_proto_library_rule(ctx): + ), + PyInfo( + transitive_sources = default_outputs, +- imports = depset(transitive = [info.imports for info in pyproto_infos]), ++ # Include imports from the 'imports' attribute and from dependencies ++ imports = depset(transitive = [info.imports for info in pyproto_infos] + [imports]), + # Proto always produces 2- and 3- compatible source files + has_py2_only_sources = False, + has_py3_only_sources = False, +@@ -206,6 +210,7 @@ proto_library( + providers = [ProtoInfo], + aspects = [_py_proto_aspect], + ), ++ "imports": attr.string_list(), + }, + provides = [PyInfo], + ) From 4ec2c8bc72240c9a467a7a31a7a69d77e4cd8b33 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 12 Nov 2024 18:05:07 +0000 Subject: [PATCH 11/26] add logs --- bazel/grpc_deps.bzl | 2 +- bazel/python_rules.bzl | 4 ++ .../grpc_channelz/v1/_servicer.py | 5 +++ .../tests/channelz/_channelz_servicer_test.py | 40 ++++++++++--------- .../linux/grpc_python_bazel_test_in_docker.sh | 14 +++---- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 3af3863fe1ddd..15df851c3833c 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -67,7 +67,7 @@ def grpc_deps(): ], patches = [ "@com_github_grpc_grpc//third_party:protobuf.patch", - "@com_github_grpc_grpc//third_party:py_proto_library.patch", + # "@com_github_grpc_grpc//third_party:py_proto_library.patch", ], patch_args = ["-p1"], ) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 7e1c923eeab2c..3f98afb0a83b1 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -148,10 +148,14 @@ def _generate_py_impl(context): # Collect output PyInfo provider. imports = [context.label.package + "/" + i for i in context.attr.imports] + print("[xuan_testing] py_sources:") + print(py_sources) py_info = PyInfo(transitive_sources = depset(direct = py_sources), imports = depset(direct = imports)) out_pyinfo = _merge_pyinfos([py_info, context.attr.deps[0][PyProtoInfo].py_info]) runfiles = context.runfiles(files = out_pyinfo.transitive_sources.to_list()).merge(context.attr._protobuf_library[DefaultInfo].data_runfiles) + print("[xuan_testing] out_pyinfo:") + print(out_pyinfo) return [ DefaultInfo( files = out_pyinfo.transitive_sources, diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index b167bef044745..78b5dd765a0ed 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,7 +16,12 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc +import sys +print(f"[xuan_testing] Import paths:") +for path in sys.path: + print(path) import grpc_channelz.v1.channelz_pb2 as _channelz_pb2 +print(f"[xuan_testing] grpc_channelz.v1.channelz_pb2.__file__: {_channelz_pb2.__file__}") import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index 2379ab59a3cc4..ab19a4d6dd04f 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -18,6 +18,8 @@ import unittest import grpc +import grpc_channelz +print(f"[xuan_testing] grpc_channelz.__file__: {grpc_channelz.__file__}") from grpc_channelz.v1 import channelz from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc @@ -172,7 +174,7 @@ def test_get_top_channels_basic(self): self.assertEqual(len(resp.channel), 1) self.assertEqual(resp.end, True) - def test_get_top_channels_high_start_id(self): + def a_test_get_top_channels_high_start_id(self): self._pairs = _generate_channel_server_pairs(1) resp = self._channelz_stub.GetTopChannels( channelz_pb2.GetTopChannelsRequest(start_channel_id=10000) @@ -180,7 +182,7 @@ def test_get_top_channels_high_start_id(self): self.assertEqual(len(resp.channel), 0) self.assertEqual(resp.end, True) - def test_successful_request(self): + def a_test_successful_request(self): self._pairs = _generate_channel_server_pairs(1) self._send_successful_unary_unary(0) resp = self._channelz_stub.GetChannel( @@ -190,7 +192,7 @@ def test_successful_request(self): self.assertEqual(resp.channel.data.calls_succeeded, 1) self.assertEqual(resp.channel.data.calls_failed, 0) - def test_failed_request(self): + def a_test_failed_request(self): self._pairs = _generate_channel_server_pairs(1) self._send_failed_unary_unary(0) resp = self._channelz_stub.GetChannel( @@ -200,7 +202,7 @@ def test_failed_request(self): self.assertEqual(resp.channel.data.calls_succeeded, 0) self.assertEqual(resp.channel.data.calls_failed, 1) - def test_many_requests(self): + def a_test_many_requests(self): self._pairs = _generate_channel_server_pairs(1) k_success = 7 k_failed = 9 @@ -215,7 +217,7 @@ def test_many_requests(self): self.assertEqual(resp.channel.data.calls_succeeded, k_success) self.assertEqual(resp.channel.data.calls_failed, k_failed) - def test_many_channel(self): + def a_test_many_channel(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) resp = self._channelz_stub.GetTopChannels( @@ -223,7 +225,7 @@ def test_many_channel(self): ) self.assertEqual(len(resp.channel), k_channels) - def test_many_requests_many_channel(self): + def a_test_many_requests_many_channel(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 11 @@ -267,7 +269,7 @@ def test_many_requests_many_channel(self): self.assertEqual(resp.channel.data.calls_succeeded, 0) self.assertEqual(resp.channel.data.calls_failed, 0) - def test_many_subchannels(self): + def a_test_many_subchannels(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 17 @@ -311,14 +313,14 @@ def test_many_subchannels(self): gsc_resp.subchannel.data.calls_failed, ) - def test_server_basic(self): + def a_test_server_basic(self): self._pairs = _generate_channel_server_pairs(1) resp = self._channelz_stub.GetServers( channelz_pb2.GetServersRequest(start_server_id=0) ) self.assertEqual(len(resp.server), 1) - def test_get_one_server(self): + def a_test_get_one_server(self): self._pairs = _generate_channel_server_pairs(1) gss_resp = self._channelz_stub.GetServers( channelz_pb2.GetServersRequest(start_server_id=0) @@ -333,7 +335,7 @@ def test_get_one_server(self): gss_resp.server[0].ref.server_id, gs_resp.server.ref.server_id ) - def test_server_call(self): + def a_test_server_call(self): self._pairs = _generate_channel_server_pairs(1) k_success = 23 k_failed = 29 @@ -352,7 +354,7 @@ def test_server_call(self): self.assertEqual(resp.server[0].data.calls_succeeded, k_success) self.assertEqual(resp.server[0].data.calls_failed, k_failed) - def test_many_subchannels_and_sockets(self): + def a_test_many_subchannels_and_sockets(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 3 @@ -420,7 +422,7 @@ def test_many_subchannels_and_sockets(self): len(address) == 4 or len(address) == 16, address ) - def test_streaming_rpc(self): + def a_test_streaming_rpc(self): self._pairs = _generate_channel_server_pairs(1) # In C++, the argument for _send_successful_stream_stream is message length. # Here the argument is still channel idx, to be consistent with the other two. @@ -477,7 +479,7 @@ def test_streaming_rpc(self): gs_resp.socket.data.messages_received, test_constants.STREAM_LENGTH ) - def test_server_sockets(self): + def a_test_server_sockets(self): self._pairs = _generate_channel_server_pairs(1) self._send_successful_unary_unary(0) self._send_failed_unary_unary(0) @@ -498,7 +500,7 @@ def test_server_sockets(self): # If the RPC call failed, it will raise a grpc.RpcError # So, if there is no exception raised, considered pass - def test_server_listen_sockets(self): + def a_test_server_listen_sockets(self): self._pairs = _generate_channel_server_pairs(1) gss_resp = self._channelz_stub.GetServers( @@ -516,7 +518,7 @@ def test_server_listen_sockets(self): # If the RPC call failed, it will raise a grpc.RpcError # So, if there is no exception raised, considered pass - def test_invalid_query_get_server(self): + def a_test_invalid_query_get_server(self): try: self._channelz_stub.GetServer( channelz_pb2.GetServerRequest(server_id=10000) @@ -526,7 +528,7 @@ def test_invalid_query_get_server(self): else: self.fail("Invalid query not detected") - def test_invalid_query_get_channel(self): + def a_test_invalid_query_get_channel(self): try: self._channelz_stub.GetChannel( channelz_pb2.GetChannelRequest(channel_id=10000) @@ -536,7 +538,7 @@ def test_invalid_query_get_channel(self): else: self.fail("Invalid query not detected") - def test_invalid_query_get_subchannel(self): + def a_test_invalid_query_get_subchannel(self): try: self._channelz_stub.GetSubchannel( channelz_pb2.GetSubchannelRequest(subchannel_id=10000) @@ -546,7 +548,7 @@ def test_invalid_query_get_subchannel(self): else: self.fail("Invalid query not detected") - def test_invalid_query_get_socket(self): + def a_test_invalid_query_get_socket(self): try: self._channelz_stub.GetSocket( channelz_pb2.GetSocketRequest(socket_id=10000) @@ -556,7 +558,7 @@ def test_invalid_query_get_socket(self): else: self.fail("Invalid query not detected") - def test_invalid_query_get_server_sockets(self): + def a_test_invalid_query_get_server_sockets(self): try: self._channelz_stub.GetServerSockets( channelz_pb2.GetServerSocketsRequest( diff --git a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh index da6b5bc2f5b9c..c8a17a22b8626 100755 --- a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh @@ -16,20 +16,20 @@ set -ex RESULTSTORE_RESULTS_FLAG="--bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc" -TEST_TARGETS="//src/python/... //tools/distrib/python/grpcio_tools/... //examples/python/..." +TEST_TARGETS="//src/python/grpcio_tests/tests/channelz:channelz_servicer_test" BAZEL_FLAGS="--test_output=errors" python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests python_bazel_tests/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test ${BAZEL_FLAGS} ${TEST_TARGETS} -python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_single_threaded_unary_streams -python_bazel_tests_single_threaded_unary_streams/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_single_threaded_unary_stream ${BAZEL_FLAGS} ${TEST_TARGETS} +# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_single_threaded_unary_streams +# python_bazel_tests_single_threaded_unary_streams/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_single_threaded_unary_stream ${BAZEL_FLAGS} ${TEST_TARGETS} -python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_poller_engine -python_bazel_tests_poller_engine/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_poller_engine ${BAZEL_FLAGS} ${TEST_TARGETS} +# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_poller_engine +# python_bazel_tests_poller_engine/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_poller_engine ${BAZEL_FLAGS} ${TEST_TARGETS} -python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_fork_support +# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_fork_support # TODO(https://github.com/grpc/grpc/issues/32207): Remove from this job once # the fork job is in the master dashboard. -python_bazel_tests_fork_support/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=fork_support --runs_per_test=16 ${BAZEL_FLAGS} //src/python/grpcio_tests/tests/fork:fork_test +# python_bazel_tests_fork_support/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=fork_support --runs_per_test=16 ${BAZEL_FLAGS} //src/python/grpcio_tests/tests/fork:fork_test From 5a74bd7a719fc03ddbe84aef0015eb2eb67b79db Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 10 Dec 2024 17:19:02 +0000 Subject: [PATCH 12/26] Working draft to use strip_import_prefix --- bazel/grpc_deps.bzl | 1 - bazel/protobuf.bzl | 23 +++- bazel/python_rules.bzl | 122 +++++++++++++++++- examples/python/debug/asyncio_get_stats.py | 4 +- examples/python/debug/get_stats.py | 4 +- .../python/health_checking/greeter_client.py | 4 +- .../python/health_checking/greeter_server.py | 4 +- examples/python/xds/server.py | 4 +- src/proto/grpc/channelz/BUILD | 14 +- src/proto/grpc/health/v1/BUILD | 6 + src/proto/grpc/reflection/v1/BUILD | 9 +- src/proto/grpc/reflection/v1alpha/BUILD | 8 +- .../grpc_channelz/v1/BUILD.bazel | 4 +- .../grpc_channelz/v1/_async.py | 4 +- .../grpc_channelz/v1/_servicer.py | 17 ++- .../grpc_channelz/v1/channelz.py | 2 +- .../grpc_health/v1/BUILD.bazel | 4 +- .../grpc_health/v1/_async.py | 4 +- .../grpc_health/v1/health.py | 4 +- .../grpc_reflection/v1alpha/BUILD.bazel | 4 +- .../grpc_reflection/v1alpha/_async.py | 2 +- .../grpc_reflection/v1alpha/_base.py | 4 +- .../proto_reflection_descriptor_database.py | 16 +-- .../grpc_reflection/v1alpha/reflection.py | 4 +- .../grpcio_tests/tests/admin/admin_test.py | 4 +- .../tests/channelz/_channelz_servicer_test.py | 6 +- .../health_check/_health_servicer_test.py | 4 +- .../reflection/_reflection_servicer_test.py | 4 +- .../channelz/channelz_servicer_test.py | 4 +- .../health_check/health_servicer_test.py | 4 +- .../reflection/reflection_servicer_test.py | 4 +- .../interop/xds_interop_server.py | 6 +- third_party/py_proto_library.patch | 32 ----- 33 files changed, 238 insertions(+), 102 deletions(-) delete mode 100644 third_party/py_proto_library.patch diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 15df851c3833c..442a9e1f8ba13 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -67,7 +67,6 @@ def grpc_deps(): ], patches = [ "@com_github_grpc_grpc//third_party:protobuf.patch", - # "@com_github_grpc_grpc//third_party:py_proto_library.patch", ], patch_args = ["-p1"], ) diff --git a/bazel/protobuf.bzl b/bazel/protobuf.bzl index 971af9e19a81f..a8576ba525363 100644 --- a/bazel/protobuf.bzl +++ b/bazel/protobuf.bzl @@ -200,6 +200,9 @@ def get_staged_proto_file(label, context, source_file): # probably even in different repositories) prefix = _make_prefix(source_file.owner) copied_proto = context.actions.declare_file(source_file.path[len(prefix):]) + # print(">>[xuan_testing] copy proto from: " + str(source_file.path) + " to :" + str(copied_proto.path)) + # copy proto from: src/proto/grpc/channelz/channelz.proto + # to :bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto context.actions.run_shell( inputs = [source_file], outputs = [copied_proto], @@ -220,6 +223,7 @@ def protos_from_context(context): protos = [] for src in context.attr.deps: for file in src[ProtoInfo].direct_sources: + # print(">>[xuan_testing] Checking file " + str(file)) protos.append(get_staged_proto_file(context.label, context, file)) return protos @@ -270,6 +274,7 @@ def declare_out_files(protos, context, generated_file_format): """ out_file_paths = [] + # print("[xuan_testing] gen_path: " + str(context.genfiles_dir.path)) for proto in protos: if not is_in_virtual_imports(proto): prefix = _make_prefix(proto.owner) @@ -279,8 +284,17 @@ def declare_out_files(protos, context, generated_file_format): elif proto.path.startswith(prefix): out_file_paths.append(proto.path[len(prefix):]) else: + # print("[xuan_testing] declare_out_files proto.path: " + str(proto.path)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto out_file_paths.append(proto.path[proto.path.index(_VIRTUAL_IMPORTS) + 1:]) - + # print("[xuan_testing] out_file_path: " + str(out_file_paths[-1])) + # _virtual_imports/channelz_proto_descriptors/channelz.proto + # path = proto_path_to_generated_filename( + # out_file_paths[-1], + # generated_file_format, + # ) + # print("[xuan_testing] path: " + str(path)) + # _virtual_imports/channelz_proto_descriptors/channelz_pb2_grpc.py return [ context.actions.declare_file( proto_path_to_generated_filename( @@ -310,9 +324,14 @@ def get_out_dir(protos, context): fail("Proto sources must be either all virtual imports or all real") if at_least_one_virtual: out_dir = get_include_directory(protos[0]) + # print(" [xuan_testing] include_directory: " + str(out_dir)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors ws_root = protos[0].owner.workspace_root + # print(" [xuan_testing] ws_root: " + str(ws_root)) + # ws_root: prefix = "/" + _make_prefix(protos[0].owner) + _VIRTUAL_IMPORTS[1:] - + # print(" [xuan_testing] prefix: " + str(prefix)) + # /src/proto/grpc/channelz/_virtual_imports/ return struct( path = out_dir, import_path = out_dir[out_dir.find(prefix) + 1:], diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 3f98afb0a83b1..42b9c51732275 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -27,9 +27,12 @@ load( "get_staged_proto_file", "includes_from_deps", "is_well_known", + "is_in_virtual_imports", "protos_from_context", + "proto_path_to_generated_filename", ) +_VIRTUAL_IMPORTS = "/_virtual_imports/" _GENERATED_PROTO_FORMAT = "{}_pb2.py" _GENERATED_PROTO_STUB_FORMAT = "{}_pb2.pyi" _GENERATED_GRPC_PROTO_FORMAT = "{}_pb2_grpc.py" @@ -70,7 +73,8 @@ def _gen_py_aspect_impl(target, context): tools = [context.executable._protoc] out_dir = get_out_dir(protos, context) - + print("[xuan_testing] python_out out_dir.path:") + print(out_dir) arguments = ([ "--python_out={}".format(out_dir.path), "--pyi_out={}".format(out_dir.path), @@ -97,6 +101,10 @@ def _gen_py_aspect_impl(target, context): imports.append("{}/{}".format(context.workspace_name, out_dir.import_path)) py_info = PyInfo(transitive_sources = depset(direct = out_files), imports = depset(direct = imports)) + print("[xuan_testing] py_info in deps:") + print(py_info) + print("[xuan_testing] generated_py_srcs in deps:") + print(generated_py_srcs) return PyProtoInfo( py_info = _merge_pyinfos( [ @@ -142,8 +150,10 @@ def _generate_py_impl(context): if context.label.package != context.attr.deps[0].label.package: for py_src in context.attr.deps[0][PyProtoInfo].generated_py_srcs: reimport_py_file = context.actions.declare_file(py_src.basename) + print("[xuan_testing] reimport_py_file: " + str(reimport_py_file)) py_sources.append(reimport_py_file) import_line = "from %s import *" % py_src.short_path.replace("..", "external").replace("/", ".")[:-len(".py")] + print("[xuan_testing] import_line: " + import_line) context.actions.write(reimport_py_file, import_line) # Collect output PyInfo provider. @@ -191,33 +201,114 @@ py_proto_library = protobuf_py_proto_library def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) + is_virtual = False + for proto in protos: + print(">>[xuan_testing] pb2_grpc protos: " + str(proto)) + # + # + print(">>[xuan_testing] pb2_grpc protos.path: " + str(proto.path)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz.proto + print(">>[xuan_testing] pb2_grpc protos.dirname: " + str(proto.dirname)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 + if is_in_virtual_imports(proto): + is_virtual = True includes = includes_from_deps(context.attr.deps) + out_files = declare_out_files(protos, context, _GENERATED_GRPC_PROTO_FORMAT) + print(">>>>>>[xuan_testing] pb2_grpc out_files: " + str(out_files)) + # [] + # [] + # [] + + print(">>>>>>[xuan_testing] pb2_grpc out_files.dirname: " + str(out_files[0].dirname)) + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1 + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 + if is_virtual: + root, relative = out_files[0].path.split(_VIRTUAL_IMPORTS, 2) + # root: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1 + # relative: channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py + result = root + _VIRTUAL_IMPORTS + relative.split("/", 1)[0] + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors + print(">>>>>>[xuan_testing] result: " + str(result)) + out_path = result plugin_flags = ["grpc_2_0"] + context.attr.strip_prefixes arguments = [] tools = [context.executable._protoc, context.executable._grpc_plugin] out_dir = get_out_dir(protos, context) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + print("[xuan_testing] pb2_grpc out_dir: " + str(out_dir)) + # struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors", + # path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors") + # struct(import_path = None, path = "bazel-out/k8-fastbuild/bin") + # struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors", + # path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors") + print("[xuan_testing] pb2_grpc out_dir.path: " + str(out_dir.path)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + # bazel-out/k8-fastbuild/bin + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + print("[xuan_testing] pb2_grpc context.genfiles_dir.path: " + str(context.genfiles_dir.path)) + # bazel-out/k8-fastbuild/bin if out_dir.import_path: # is virtual imports out_path = out_dir.path else: out_path = context.genfiles_dir.path + print(">>>>>>[xuan_testing] pb2_grpc out_path: " + str(out_path)) + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + # bazel-out/k8-fastbuild/bin + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + # Fix 1: + # out_path = out_files[0].dirname + if is_virtual: + out_path = result + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors + # Fix 2: + # out_path = result arguments += get_plugin_args( context.executable._grpc_plugin, plugin_flags, out_path, False, ) + # --PLUGIN_out=grpc_2_0,src.python.grpcio_channelz.: + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors (==out_path) + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors (Fixed) + # bazel-out/k8-fastbuild/bin + # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 arguments += [ "--proto_path={}".format(get_include_directory(i)) for i in includes ] + # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors arguments.append("--proto_path={}".format(context.genfiles_dir.path)) + print("[xuan_testing] pb2_grpc proto_path: " + str(context.genfiles_dir.path)) + # bazel-out/k8-fastbuild/bin arguments += get_proto_arguments(protos, context.genfiles_dir.path) - + print("[xuan_testing] pb2_grpc get_proto_arguments: " + str(arguments)) + # --plugin=protoc-gen-PLUGIN=bazel-out/k8-opt-exec-ST-a828a81199fe/bin/src/compiler/grpc_python_plugin + # --PLUGIN_out=XXX + # --proto_path=bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors (Old & Fixed) + # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/any_proto + # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/duration_proto + # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/timestamp_proto + # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/wrappers_proto + # --proto_path=bazel-out/k8-fastbuild/bin + # channelz.proto + + # --proto_path=. + # src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto + + # --proto_path=bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors + # grpc_channelz/v1/channelz.proto + + # for dep in context.attr.py_deps: + # print("~~~~~[xuan_testing] dep: " + str(dep[PyInfo].transitive_sources.to_list())) context.actions.run( inputs = protos + includes, tools = tools, @@ -226,8 +317,33 @@ def _generate_pb2_grpc_src_impl(context): arguments = arguments, mnemonic = "ProtocInvocation", ) + # Fix: + # Out file: [] + # Plugin out: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors + # Proto path: channelz.proto + # Actual out: .runfiles/com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/channelz_pb2_grpc.py + + # Out file: [] + # Plugin out: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 + # Proto path: grpc_channelz/v1/channelz.proto + # Actual out: ? + # Expected: src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py - p = PyInfo(transitive_sources = depset(direct = out_files)) + imports = [] + # Fix 1: + if is_virtual: + import_path = out_path + # Handles virtual import cases + if out_path.startswith(context.genfiles_dir.path): + import_path = import_path[len(context.genfiles_dir.path) + 1:] + + import_path = "{}/{}".format(context.workspace_name, import_path) + imports.append(import_path) + print(">>>>[xuan_testing] pb2_grpc added imports: " + str(imports)) + # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors (Fixed) + # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors + + p = PyInfo(transitive_sources = depset(direct = out_files), imports = depset(direct = imports)) py_info = _merge_pyinfos( [ p, diff --git a/examples/python/debug/asyncio_get_stats.py b/examples/python/debug/asyncio_get_stats.py index 467d3dc75d5ff..ca24266b8bc64 100644 --- a/examples/python/debug/asyncio_get_stats.py +++ b/examples/python/debug/asyncio_get_stats.py @@ -18,8 +18,8 @@ import logging import grpc -from grpc_channelz.v1 import channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc +import channelz_pb2 +import channelz_pb2_grpc async def run(addr: str) -> None: diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index ce2ac7db110ca..b77cde9b32146 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -21,8 +21,8 @@ import logging import grpc -from grpc_channelz.v1 import channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc +import channelz_pb2 +import channelz_pb2_grpc def run(addr): diff --git a/examples/python/health_checking/greeter_client.py b/examples/python/health_checking/greeter_client.py index 6e11369d3ea3b..eb213b6d434ce 100644 --- a/examples/python/health_checking/greeter_client.py +++ b/examples/python/health_checking/greeter_client.py @@ -17,8 +17,8 @@ from time import sleep import grpc -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc diff --git a/examples/python/health_checking/greeter_server.py b/examples/python/health_checking/greeter_server.py index ed5efd522d7f3..18e0204e94468 100644 --- a/examples/python/health_checking/greeter_server.py +++ b/examples/python/health_checking/greeter_server.py @@ -20,8 +20,8 @@ import grpc from grpc_health.v1 import health -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc diff --git a/examples/python/xds/server.py b/examples/python/xds/server.py index bea103876bfe0..dc5cb0ff672d0 100644 --- a/examples/python/xds/server.py +++ b/examples/python/xds/server.py @@ -20,8 +20,8 @@ import grpc from grpc_health.v1 import health -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc from grpc_reflection.v1alpha import reflection import helloworld_pb2 import helloworld_pb2_grpc diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD index 555c46f74d245..b82384effb883 100644 --- a/src/proto/grpc/channelz/BUILD +++ b/src/proto/grpc/channelz/BUILD @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") licenses(["notice"]) @@ -31,6 +31,18 @@ grpc_proto_library( well_known_protos = True, ) +grpc_internal_proto_library( + name = "channelz_proto_descriptors", + srcs = ["channelz.proto"], + deps = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:timestamp_proto", + "@com_google_protobuf//:wrappers_proto", + ], + strip_import_prefix = "/src/proto/grpc/channelz", +) + filegroup( name = "channelz_proto_file", srcs = [ diff --git a/src/proto/grpc/health/v1/BUILD b/src/proto/grpc/health/v1/BUILD index f6165e039284c..5e5167fa5e2d0 100644 --- a/src/proto/grpc/health/v1/BUILD +++ b/src/proto/grpc/health/v1/BUILD @@ -38,6 +38,12 @@ grpc_cc_grpc_library( deps = ["health_cc_proto"], ) +grpc_internal_proto_library( + name = "health_proto_descriptor", + srcs = ["health.proto"], + strip_import_prefix = "/src/proto/grpc/health/v1", +) + filegroup( name = "health_proto_file", srcs = [ diff --git a/src/proto/grpc/reflection/v1/BUILD b/src/proto/grpc/reflection/v1/BUILD index 7319477dfe9cc..5d18f0204f899 100644 --- a/src/proto/grpc/reflection/v1/BUILD +++ b/src/proto/grpc/reflection/v1/BUILD @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") licenses(["notice"]) @@ -29,6 +29,13 @@ grpc_proto_library( srcs = ["reflection.proto"], ) +grpc_internal_proto_library( + name = "reflection_proto_descriptor", + srcs = ["reflection.proto"], + strip_import_prefix = "/src/proto/grpc/reflection/v1", +) + + filegroup( name = "reflection_proto_file", srcs = [ diff --git a/src/proto/grpc/reflection/v1alpha/BUILD b/src/proto/grpc/reflection/v1alpha/BUILD index 054b7f8805893..0f228a759ef07 100644 --- a/src/proto/grpc/reflection/v1alpha/BUILD +++ b/src/proto/grpc/reflection/v1alpha/BUILD @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") licenses(["notice"]) @@ -29,6 +29,12 @@ grpc_proto_library( srcs = ["reflection.proto"], ) +grpc_internal_proto_library( + name = "reflection_proto_descriptor", + srcs = ["reflection.proto"], + strip_import_prefix = "/src/proto/grpc/reflection/v1alpha", +) + filegroup( name = "reflection_proto_file", srcs = [ diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index f6b23b7922dfd..8ceb511e8dc5b 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -19,12 +19,12 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "channelz_py_pb2", # imports = ["../../"], - deps = ["//src/proto/grpc/channelz:channelz_proto_only"], + deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], ) py_grpc_library( name = "channelz_py_pb2_grpc", - srcs = ["//src/proto/grpc/channelz:channelz_proto_only"], + srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], strip_prefixes = ["src.python.grpcio_channelz."], deps = [":channelz_py_pb2"], ) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index 47f3d6963f4a3..df9d5455ebb47 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -15,8 +15,8 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer -import grpc_channelz.v1.channelz_pb2 as _channelz_pb2 -import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc +import channelz_pb2 as _channelz_pb2 +import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index 78b5dd765a0ed..671663e15bdaa 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,14 +16,19 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc +import channelz_pb2 as _channelz_pb2 +import channelz_pb2_grpc as _channelz_pb2_grpc + import sys -print(f"[xuan_testing] Import paths:") +print(f"=============================================") +print(f"[xuan_testing] Import paths in _servicer:") for path in sys.path: - print(path) -import grpc_channelz.v1.channelz_pb2 as _channelz_pb2 -print(f"[xuan_testing] grpc_channelz.v1.channelz_pb2.__file__: {_channelz_pb2.__file__}") -import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc - + if "com_google_protobuf" not in path: + print(path) +print(f"---------------------------------------------") +print(f"[xuan_testing] channelz_pb2.__file__: {_channelz_pb2.__file__}") +print(f"[xuan_testing] _channelz_pb2_grpc.__file__: {_channelz_pb2_grpc.__file__}") +print(f"---------------------------------------------") class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index bfd5851096973..a7a27cdbdf639 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -17,7 +17,7 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer -import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc +import channelz_pb2_grpc as _channelz_pb2_grpc _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index 22e45b3584c4d..35f6f85f45a25 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -19,12 +19,12 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "health_py_pb2", imports = ["../../"], - deps = ["//src/proto/grpc/health/v1:health_proto"], + deps = ["//src/proto/grpc/health/v1:health_proto_descriptor"], ) py_grpc_library( name = "health_py_pb2_grpc", - srcs = ["//src/proto/grpc/health/v1:health_proto"], + srcs = ["//src/proto/grpc/health/v1:health_proto_descriptor"], strip_prefixes = ["src.python.grpcio_health_checking."], deps = [":health_py_pb2"], ) diff --git a/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/src/python/grpcio_health_checking/grpc_health/v1/_async.py index 3788050f21b32..44e4a1dce88da 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -18,8 +18,8 @@ from typing import MutableMapping import grpc -from grpc_health.v1 import health_pb2 as _health_pb2 -from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc +import health_pb2 as _health_pb2 +import health_pb2_grpc as _health_pb2_grpc class HealthServicer(_health_pb2_grpc.HealthServicer): diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index db8756fa78a67..721d4cbe669af 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -18,8 +18,8 @@ import threading import grpc -from grpc_health.v1 import health_pb2 as _health_pb2 -from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc +import health_pb2 as _health_pb2 +import health_pb2_grpc as _health_pb2_grpc if sys.version_info[0] >= 3 and sys.version_info[1] >= 6: # Exposes AsyncHealthServicer as public API. diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index 9fc0b99506433..07c5f48f970dd 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -19,12 +19,12 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "reflection_py_pb2", imports = ["../../"], - deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_only"], + deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], ) py_grpc_library( name = "reflection_py_pb2_grpc", - srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_only"], + srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], strip_prefixes = ["src.python.grpcio_reflection."], deps = ["reflection_py_pb2"], ) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index 88762b7d51928..633b1d9149295 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -16,7 +16,7 @@ from typing import AsyncIterable import grpc -from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 +import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha._base import BaseReflectionServicer diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index 50d671a92d73f..f5e5205ff1cfa 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -16,8 +16,8 @@ from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool import grpc -from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 -from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc +import reflection_pb2 as _reflection_pb2 +import reflection_pb2_grpc as _reflection_pb2_grpc _POOL = descriptor_pool.Default() diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py index 876461b2a1748..0e4491ae37a2b 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py @@ -23,14 +23,14 @@ from google.protobuf.descriptor_database import DescriptorDatabase from google.protobuf.descriptor_pb2 import FileDescriptorProto import grpc -from grpc_reflection.v1alpha.reflection_pb2 import ExtensionNumberResponse -from grpc_reflection.v1alpha.reflection_pb2 import ExtensionRequest -from grpc_reflection.v1alpha.reflection_pb2 import FileDescriptorResponse -from grpc_reflection.v1alpha.reflection_pb2 import ListServiceResponse -from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionRequest -from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionResponse -from grpc_reflection.v1alpha.reflection_pb2 import ServiceResponse -from grpc_reflection.v1alpha.reflection_pb2_grpc import ServerReflectionStub +from reflection_pb2 import ExtensionNumberResponse +from reflection_pb2 import ExtensionRequest +from reflection_pb2 import FileDescriptorResponse +from reflection_pb2 import ListServiceResponse +from reflection_pb2 import ServerReflectionRequest +from reflection_pb2 import ServerReflectionResponse +from reflection_pb2 import ServiceResponse +from reflection_pb2_grpc import ServerReflectionStub class ProtoReflectionDescriptorDatabase(DescriptorDatabase): diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index 4315ac9fcbffe..9b7383adfef64 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -16,8 +16,8 @@ import sys import grpc -from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 -from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc +import reflection_pb2 as _reflection_pb2 +import reflection_pb2_grpc as _reflection_pb2_grpc from grpc_reflection.v1alpha._base import BaseReflectionServicer SERVICE_NAME = _reflection_pb2.DESCRIPTOR.services_by_name[ diff --git a/src/python/grpcio_tests/tests/admin/admin_test.py b/src/python/grpcio_tests/tests/admin/admin_test.py index 9ca46dd8831fa..809cd19655aa2 100644 --- a/src/python/grpcio_tests/tests/admin/admin_test.py +++ b/src/python/grpcio_tests/tests/admin/admin_test.py @@ -20,8 +20,8 @@ import grpc import grpc_admin -from grpc_channelz.v1 import channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc +import channelz_pb2 +import channelz_pb2_grpc from grpc_csds import csds_pb2 from grpc_csds import csds_pb2_grpc diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index ab19a4d6dd04f..c0177e3835b82 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -18,11 +18,9 @@ import unittest import grpc -import grpc_channelz -print(f"[xuan_testing] grpc_channelz.__file__: {grpc_channelz.__file__}") from grpc_channelz.v1 import channelz -from grpc_channelz.v1 import channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc +import channelz_pb2 +import channelz_pb2_grpc from tests.unit import test_common from tests.unit.framework.common import test_constants diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 31580892e8163..70bd9463c043e 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,8 +22,8 @@ import grpc from grpc_health.v1 import health -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc from tests.unit import test_common from tests.unit import thread_pool diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 810b56f20fba1..f2db7ed1c02b6 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -20,8 +20,8 @@ from google.protobuf import descriptor_pool import grpc from grpc_reflection.v1alpha import reflection -from grpc_reflection.v1alpha import reflection_pb2 -from grpc_reflection.v1alpha import reflection_pb2_grpc +import reflection_pb2 +import reflection_pb2_grpc from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 diff --git a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py index 07cfe67427c09..6d0d688816da0 100644 --- a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py @@ -20,8 +20,8 @@ import grpc from grpc.experimental import aio from grpc_channelz.v1 import channelz -from grpc_channelz.v1 import channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc +import channelz_pb2 +import channelz_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py index 3bb0f6c31c4d4..0f5e89993528f 100644 --- a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py @@ -22,8 +22,8 @@ import grpc from grpc.experimental import aio from grpc_health.v1 import health -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py index d1cc2c7489173..458e59b7a5c05 100644 --- a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py @@ -20,8 +20,8 @@ import grpc from grpc.experimental import aio from grpc_reflection.v1alpha import reflection -from grpc_reflection.v1alpha import reflection_pb2 -from grpc_reflection.v1alpha import reflection_pb2_grpc +import reflection_pb2 +import reflection_pb2_grpc from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 diff --git a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py index f426bd001096d..273cdbd1f9126 100644 --- a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py +++ b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py @@ -25,11 +25,11 @@ import grpc from grpc_channelz.v1 import channelz -from grpc_channelz.v1 import channelz_pb2 +import channelz_pb2 from grpc_csm_observability import CsmOpenTelemetryPlugin from grpc_health.v1 import health as grpc_health -from grpc_health.v1 import health_pb2 -from grpc_health.v1 import health_pb2_grpc +import health_pb2 +import health_pb2_grpc from grpc_reflection.v1alpha import reflection from opentelemetry.exporter.prometheus import PrometheusMetricReader from opentelemetry.sdk.metrics import MeterProvider diff --git a/third_party/py_proto_library.patch b/third_party/py_proto_library.patch deleted file mode 100644 index 9e0a2f6e4094f..0000000000000 --- a/third_party/py_proto_library.patch +++ /dev/null @@ -1,32 +0,0 @@ -diff --git a/bazel/py_proto_library.bzl b/bazel/py_proto_library.bzl -index 86af99950..8396661ae 100644 ---- a/bazel/py_proto_library.bzl -+++ b/bazel/py_proto_library.bzl -@@ -147,6 +147,9 @@ def _py_proto_library_rule(ctx): - transitive = [info.transitive_sources for info in pyproto_infos], - ) - -+ # Gather imports from the 'imports' attribute -+ imports = depset(direct = [ctx.label.package + "/" + i for i in ctx.attr.imports]) -+ - return [ - DefaultInfo( - files = default_outputs, -@@ -161,7 +164,8 @@ def _py_proto_library_rule(ctx): - ), - PyInfo( - transitive_sources = default_outputs, -- imports = depset(transitive = [info.imports for info in pyproto_infos]), -+ # Include imports from the 'imports' attribute and from dependencies -+ imports = depset(transitive = [info.imports for info in pyproto_infos] + [imports]), - # Proto always produces 2- and 3- compatible source files - has_py2_only_sources = False, - has_py3_only_sources = False, -@@ -206,6 +210,7 @@ proto_library( - providers = [ProtoInfo], - aspects = [_py_proto_aspect], - ), -+ "imports": attr.string_list(), - }, - provides = [PyInfo], - ) From 9cde44602e98b049e04e3c369167cd90bf0fd6c0 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 10 Dec 2024 18:33:20 +0000 Subject: [PATCH 13/26] Use proto_library from Protobuf repo --- src/proto/grpc/channelz/BUILD | 5 +++-- src/proto/grpc/health/v1/BUILD | 3 ++- src/proto/grpc/reflection/v1/BUILD | 5 +++-- src/proto/grpc/reflection/v1alpha/BUILD | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD index b82384effb883..3a12776ad616a 100644 --- a/src/proto/grpc/channelz/BUILD +++ b/src/proto/grpc/channelz/BUILD @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -31,7 +32,7 @@ grpc_proto_library( well_known_protos = True, ) -grpc_internal_proto_library( +proto_library( name = "channelz_proto_descriptors", srcs = ["channelz.proto"], deps = [ diff --git a/src/proto/grpc/health/v1/BUILD b/src/proto/grpc/health/v1/BUILD index 5e5167fa5e2d0..257b6e23baa1c 100644 --- a/src/proto/grpc/health/v1/BUILD +++ b/src/proto/grpc/health/v1/BUILD @@ -13,6 +13,7 @@ # limitations under the License. load("//bazel:grpc_build_system.bzl", "grpc_cc_grpc_library", "grpc_cc_proto_library", "grpc_internal_proto_library", "grpc_package") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -38,7 +39,7 @@ grpc_cc_grpc_library( deps = ["health_cc_proto"], ) -grpc_internal_proto_library( +proto_library( name = "health_proto_descriptor", srcs = ["health.proto"], strip_import_prefix = "/src/proto/grpc/health/v1", diff --git a/src/proto/grpc/reflection/v1/BUILD b/src/proto/grpc/reflection/v1/BUILD index 5d18f0204f899..a6fa346bb5f40 100644 --- a/src/proto/grpc/reflection/v1/BUILD +++ b/src/proto/grpc/reflection/v1/BUILD @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -29,7 +30,7 @@ grpc_proto_library( srcs = ["reflection.proto"], ) -grpc_internal_proto_library( +proto_library( name = "reflection_proto_descriptor", srcs = ["reflection.proto"], strip_import_prefix = "/src/proto/grpc/reflection/v1", diff --git a/src/proto/grpc/reflection/v1alpha/BUILD b/src/proto/grpc/reflection/v1alpha/BUILD index 0f228a759ef07..ac69ae0e39f0f 100644 --- a/src/proto/grpc/reflection/v1alpha/BUILD +++ b/src/proto/grpc/reflection/v1alpha/BUILD @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library", "grpc_internal_proto_library") +load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -29,7 +30,7 @@ grpc_proto_library( srcs = ["reflection.proto"], ) -grpc_internal_proto_library( +proto_library( name = "reflection_proto_descriptor", srcs = ["reflection.proto"], strip_import_prefix = "/src/proto/grpc/reflection/v1alpha", From e31a20ec0d18975b244674e0d1d43c96fef1a090 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 10 Dec 2024 20:38:56 +0000 Subject: [PATCH 14/26] Add test_env BUILD_SYSTEM --- examples/python/debug/asyncio_get_stats.py | 9 +++- examples/python/debug/get_stats.py | 9 +++- .../python/health_checking/greeter_client.py | 9 +++- .../python/health_checking/greeter_server.py | 9 +++- examples/python/xds/server.py | 9 +++- .../grpc_channelz/v1/_async.py | 9 +++- .../grpc_channelz/v1/_servicer.py | 9 +++- .../grpc_health/v1/_async.py | 9 +++- .../grpc_health/v1/health.py | 9 +++- .../grpc_reflection/v1alpha/_async.py | 6 ++- .../grpc_reflection/v1alpha/_base.py | 13 ++++- .../proto_reflection_descriptor_database.py | 28 +++++++---- .../grpc_reflection/v1alpha/reflection.py | 9 +++- .../grpcio_tests/tests/admin/admin_test.py | 9 +++- .../tests/channelz/_channelz_servicer_test.py | 47 ++++++++++--------- .../health_check/_health_servicer_test.py | 9 +++- .../channelz/channelz_servicer_test.py | 9 +++- .../health_check/health_servicer_test.py | 9 +++- .../interop/xds_interop_server.py | 12 +++-- .../linux/grpc_python_bazel_test_in_docker.sh | 16 +++---- 20 files changed, 177 insertions(+), 71 deletions(-) diff --git a/examples/python/debug/asyncio_get_stats.py b/examples/python/debug/asyncio_get_stats.py index ca24266b8bc64..81bd5cfe8866f 100644 --- a/examples/python/debug/asyncio_get_stats.py +++ b/examples/python/debug/asyncio_get_stats.py @@ -18,8 +18,13 @@ import logging import grpc -import channelz_pb2 -import channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 + import channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc async def run(addr: str) -> None: diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index b77cde9b32146..a39abdd73037e 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -21,8 +21,13 @@ import logging import grpc -import channelz_pb2 -import channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 + import channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc def run(addr): diff --git a/examples/python/health_checking/greeter_client.py b/examples/python/health_checking/greeter_client.py index eb213b6d434ce..dbd7a09b4ce2b 100644 --- a/examples/python/health_checking/greeter_client.py +++ b/examples/python/health_checking/greeter_client.py @@ -17,8 +17,13 @@ from time import sleep import grpc -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc diff --git a/examples/python/health_checking/greeter_server.py b/examples/python/health_checking/greeter_server.py index 18e0204e94468..f365fb0bf2786 100644 --- a/examples/python/health_checking/greeter_server.py +++ b/examples/python/health_checking/greeter_server.py @@ -20,8 +20,13 @@ import grpc from grpc_health.v1 import health -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc diff --git a/examples/python/xds/server.py b/examples/python/xds/server.py index dc5cb0ff672d0..96c0b72022d82 100644 --- a/examples/python/xds/server.py +++ b/examples/python/xds/server.py @@ -20,8 +20,13 @@ import grpc from grpc_health.v1 import health -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc from grpc_reflection.v1alpha import reflection import helloworld_pb2 import helloworld_pb2_grpc diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index df9d5455ebb47..48c61cf3e102a 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -15,8 +15,13 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer -import channelz_pb2 as _channelz_pb2 -import channelz_pb2_grpc as _channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 as _channelz_pb2 + import channelz_pb2_grpc as _channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index 671663e15bdaa..a8c3e93cf87ce 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,8 +16,13 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc -import channelz_pb2 as _channelz_pb2 -import channelz_pb2_grpc as _channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 as _channelz_pb2 + import channelz_pb2_grpc as _channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc import sys print(f"=============================================") diff --git a/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/src/python/grpcio_health_checking/grpc_health/v1/_async.py index 44e4a1dce88da..7a5e1869043f7 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -18,8 +18,13 @@ from typing import MutableMapping import grpc -import health_pb2 as _health_pb2 -import health_pb2_grpc as _health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 as _health_pb2 + import health_pb2_grpc as _health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 as _health_pb2 + from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc class HealthServicer(_health_pb2_grpc.HealthServicer): diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 721d4cbe669af..83f56dcbbbc72 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -18,8 +18,13 @@ import threading import grpc -import health_pb2 as _health_pb2 -import health_pb2_grpc as _health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 as _health_pb2 + import health_pb2_grpc as _health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 as _health_pb2 + from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc if sys.version_info[0] >= 3 and sys.version_info[1] >= 6: # Exposes AsyncHealthServicer as public API. diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index 633b1d9149295..0d9815bc27f82 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -16,7 +16,11 @@ from typing import AsyncIterable import grpc -import reflection_pb2 as _reflection_pb2 +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 as _reflection_pb2 +else: + from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha._base import BaseReflectionServicer diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index f5e5205ff1cfa..8335335cbdd68 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -16,8 +16,17 @@ from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool import grpc -import reflection_pb2 as _reflection_pb2 -import reflection_pb2_grpc as _reflection_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 as _reflection_pb2 +else: + from grpc_reflection.v1alpha import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 as _reflection_pb2 + import reflection_pb2_grpc as _reflection_pb2_grpc +else: + from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 + from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc _POOL = descriptor_pool.Default() diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py index 0e4491ae37a2b..b5e465bcd16db 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py @@ -23,14 +23,26 @@ from google.protobuf.descriptor_database import DescriptorDatabase from google.protobuf.descriptor_pb2 import FileDescriptorProto import grpc -from reflection_pb2 import ExtensionNumberResponse -from reflection_pb2 import ExtensionRequest -from reflection_pb2 import FileDescriptorResponse -from reflection_pb2 import ListServiceResponse -from reflection_pb2 import ServerReflectionRequest -from reflection_pb2 import ServerReflectionResponse -from reflection_pb2 import ServiceResponse -from reflection_pb2_grpc import ServerReflectionStub +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + from reflection_pb2 import ExtensionNumberResponse + from reflection_pb2 import ExtensionRequest + from reflection_pb2 import FileDescriptorResponse + from reflection_pb2 import ListServiceResponse + from reflection_pb2 import ServerReflectionRequest + from reflection_pb2 import ServerReflectionResponse + from reflection_pb2 import ServiceResponse + from reflection_pb2_grpc import ServerReflectionStub +else: + from grpc_reflection.v1alpha.reflection_pb2 import ExtensionNumberResponse + from grpc_reflection.v1alpha.reflection_pb2 import ExtensionRequest + from grpc_reflection.v1alpha.reflection_pb2 import FileDescriptorResponse + from grpc_reflection.v1alpha.reflection_pb2 import ListServiceResponse + from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionRequest + from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionResponse + from grpc_reflection.v1alpha.reflection_pb2 import ServiceResponse + from grpc_reflection.v1alpha.reflection_pb2_grpc import ServerReflectionStub + class ProtoReflectionDescriptorDatabase(DescriptorDatabase): diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index 9b7383adfef64..15d525a57ce1d 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -16,8 +16,13 @@ import sys import grpc -import reflection_pb2 as _reflection_pb2 -import reflection_pb2_grpc as _reflection_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 as _reflection_pb2 + import reflection_pb2_grpc as _reflection_pb2_grpc +else: + from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 + from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc from grpc_reflection.v1alpha._base import BaseReflectionServicer SERVICE_NAME = _reflection_pb2.DESCRIPTOR.services_by_name[ diff --git a/src/python/grpcio_tests/tests/admin/admin_test.py b/src/python/grpcio_tests/tests/admin/admin_test.py index 809cd19655aa2..1e1f6cd724a79 100644 --- a/src/python/grpcio_tests/tests/admin/admin_test.py +++ b/src/python/grpcio_tests/tests/admin/admin_test.py @@ -20,8 +20,13 @@ import grpc import grpc_admin -import channelz_pb2 -import channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 + import channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc from grpc_csds import csds_pb2 from grpc_csds import csds_pb2_grpc diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index c0177e3835b82..e002bc54daab8 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -19,8 +19,13 @@ import grpc from grpc_channelz.v1 import channelz -import channelz_pb2 -import channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 + import channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc from tests.unit import test_common from tests.unit.framework.common import test_constants @@ -172,7 +177,7 @@ def test_get_top_channels_basic(self): self.assertEqual(len(resp.channel), 1) self.assertEqual(resp.end, True) - def a_test_get_top_channels_high_start_id(self): + def test_get_top_channels_high_start_id(self): self._pairs = _generate_channel_server_pairs(1) resp = self._channelz_stub.GetTopChannels( channelz_pb2.GetTopChannelsRequest(start_channel_id=10000) @@ -180,7 +185,7 @@ def a_test_get_top_channels_high_start_id(self): self.assertEqual(len(resp.channel), 0) self.assertEqual(resp.end, True) - def a_test_successful_request(self): + def test_successful_request(self): self._pairs = _generate_channel_server_pairs(1) self._send_successful_unary_unary(0) resp = self._channelz_stub.GetChannel( @@ -190,7 +195,7 @@ def a_test_successful_request(self): self.assertEqual(resp.channel.data.calls_succeeded, 1) self.assertEqual(resp.channel.data.calls_failed, 0) - def a_test_failed_request(self): + def test_failed_request(self): self._pairs = _generate_channel_server_pairs(1) self._send_failed_unary_unary(0) resp = self._channelz_stub.GetChannel( @@ -200,7 +205,7 @@ def a_test_failed_request(self): self.assertEqual(resp.channel.data.calls_succeeded, 0) self.assertEqual(resp.channel.data.calls_failed, 1) - def a_test_many_requests(self): + def test_many_requests(self): self._pairs = _generate_channel_server_pairs(1) k_success = 7 k_failed = 9 @@ -215,7 +220,7 @@ def a_test_many_requests(self): self.assertEqual(resp.channel.data.calls_succeeded, k_success) self.assertEqual(resp.channel.data.calls_failed, k_failed) - def a_test_many_channel(self): + def test_many_channel(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) resp = self._channelz_stub.GetTopChannels( @@ -223,7 +228,7 @@ def a_test_many_channel(self): ) self.assertEqual(len(resp.channel), k_channels) - def a_test_many_requests_many_channel(self): + def test_many_requests_many_channel(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 11 @@ -267,7 +272,7 @@ def a_test_many_requests_many_channel(self): self.assertEqual(resp.channel.data.calls_succeeded, 0) self.assertEqual(resp.channel.data.calls_failed, 0) - def a_test_many_subchannels(self): + def test_many_subchannels(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 17 @@ -311,14 +316,14 @@ def a_test_many_subchannels(self): gsc_resp.subchannel.data.calls_failed, ) - def a_test_server_basic(self): + def test_server_basic(self): self._pairs = _generate_channel_server_pairs(1) resp = self._channelz_stub.GetServers( channelz_pb2.GetServersRequest(start_server_id=0) ) self.assertEqual(len(resp.server), 1) - def a_test_get_one_server(self): + def test_get_one_server(self): self._pairs = _generate_channel_server_pairs(1) gss_resp = self._channelz_stub.GetServers( channelz_pb2.GetServersRequest(start_server_id=0) @@ -333,7 +338,7 @@ def a_test_get_one_server(self): gss_resp.server[0].ref.server_id, gs_resp.server.ref.server_id ) - def a_test_server_call(self): + def test_server_call(self): self._pairs = _generate_channel_server_pairs(1) k_success = 23 k_failed = 29 @@ -352,7 +357,7 @@ def a_test_server_call(self): self.assertEqual(resp.server[0].data.calls_succeeded, k_success) self.assertEqual(resp.server[0].data.calls_failed, k_failed) - def a_test_many_subchannels_and_sockets(self): + def test_many_subchannels_and_sockets(self): k_channels = 4 self._pairs = _generate_channel_server_pairs(k_channels) k_success = 3 @@ -420,7 +425,7 @@ def a_test_many_subchannels_and_sockets(self): len(address) == 4 or len(address) == 16, address ) - def a_test_streaming_rpc(self): + def test_streaming_rpc(self): self._pairs = _generate_channel_server_pairs(1) # In C++, the argument for _send_successful_stream_stream is message length. # Here the argument is still channel idx, to be consistent with the other two. @@ -477,7 +482,7 @@ def a_test_streaming_rpc(self): gs_resp.socket.data.messages_received, test_constants.STREAM_LENGTH ) - def a_test_server_sockets(self): + def test_server_sockets(self): self._pairs = _generate_channel_server_pairs(1) self._send_successful_unary_unary(0) self._send_failed_unary_unary(0) @@ -498,7 +503,7 @@ def a_test_server_sockets(self): # If the RPC call failed, it will raise a grpc.RpcError # So, if there is no exception raised, considered pass - def a_test_server_listen_sockets(self): + def test_server_listen_sockets(self): self._pairs = _generate_channel_server_pairs(1) gss_resp = self._channelz_stub.GetServers( @@ -516,7 +521,7 @@ def a_test_server_listen_sockets(self): # If the RPC call failed, it will raise a grpc.RpcError # So, if there is no exception raised, considered pass - def a_test_invalid_query_get_server(self): + def test_invalid_query_get_server(self): try: self._channelz_stub.GetServer( channelz_pb2.GetServerRequest(server_id=10000) @@ -526,7 +531,7 @@ def a_test_invalid_query_get_server(self): else: self.fail("Invalid query not detected") - def a_test_invalid_query_get_channel(self): + def test_invalid_query_get_channel(self): try: self._channelz_stub.GetChannel( channelz_pb2.GetChannelRequest(channel_id=10000) @@ -536,7 +541,7 @@ def a_test_invalid_query_get_channel(self): else: self.fail("Invalid query not detected") - def a_test_invalid_query_get_subchannel(self): + def test_invalid_query_get_subchannel(self): try: self._channelz_stub.GetSubchannel( channelz_pb2.GetSubchannelRequest(subchannel_id=10000) @@ -546,7 +551,7 @@ def a_test_invalid_query_get_subchannel(self): else: self.fail("Invalid query not detected") - def a_test_invalid_query_get_socket(self): + def test_invalid_query_get_socket(self): try: self._channelz_stub.GetSocket( channelz_pb2.GetSocketRequest(socket_id=10000) @@ -556,7 +561,7 @@ def a_test_invalid_query_get_socket(self): else: self.fail("Invalid query not detected") - def a_test_invalid_query_get_server_sockets(self): + def test_invalid_query_get_server_sockets(self): try: self._channelz_stub.GetServerSockets( channelz_pb2.GetServerSocketsRequest( diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 70bd9463c043e..4f52011d3a047 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,8 +22,13 @@ import grpc from grpc_health.v1 import health -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc from tests.unit import test_common from tests.unit import thread_pool diff --git a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py index 6d0d688816da0..c21e044894e20 100644 --- a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py @@ -20,8 +20,13 @@ import grpc from grpc.experimental import aio from grpc_channelz.v1 import channelz -import channelz_pb2 -import channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2 + import channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2 + from grpc_channelz.v1 import channelz_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py index 0f5e89993528f..62238efad0b68 100644 --- a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py @@ -22,8 +22,13 @@ import grpc from grpc.experimental import aio from grpc_health.v1 import health -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py index 273cdbd1f9126..f4852123375d3 100644 --- a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py +++ b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py @@ -25,11 +25,17 @@ import grpc from grpc_channelz.v1 import channelz -import channelz_pb2 from grpc_csm_observability import CsmOpenTelemetryPlugin from grpc_health.v1 import health as grpc_health -import health_pb2 -import health_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import health_pb2 + import health_pb2_grpc + import channelz_pb2 +else: + from grpc_health.v1 import health_pb2 + from grpc_health.v1 import health_pb2_grpc + from grpc_channelz.v1 import channelz_pb2 from grpc_reflection.v1alpha import reflection from opentelemetry.exporter.prometheus import PrometheusMetricReader from opentelemetry.sdk.metrics import MeterProvider diff --git a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh index c8a17a22b8626..a5d54285c851e 100755 --- a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh @@ -16,20 +16,20 @@ set -ex RESULTSTORE_RESULTS_FLAG="--bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc" -TEST_TARGETS="//src/python/grpcio_tests/tests/channelz:channelz_servicer_test" -BAZEL_FLAGS="--test_output=errors" +TEST_TARGETS="//src/python/... //tools/distrib/python/grpcio_tools/... //examples/python/..." +BAZEL_FLAGS="--test_output=errors --test_env=BUILD_SYSTEM=Bazel" python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests python_bazel_tests/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test ${BAZEL_FLAGS} ${TEST_TARGETS} -# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_single_threaded_unary_streams -# python_bazel_tests_single_threaded_unary_streams/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_single_threaded_unary_stream ${BAZEL_FLAGS} ${TEST_TARGETS} +python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_single_threaded_unary_streams +python_bazel_tests_single_threaded_unary_streams/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_single_threaded_unary_stream ${BAZEL_FLAGS} ${TEST_TARGETS} -# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_poller_engine -# python_bazel_tests_poller_engine/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_poller_engine ${BAZEL_FLAGS} ${TEST_TARGETS} +python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_poller_engine +python_bazel_tests_poller_engine/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=python_poller_engine ${BAZEL_FLAGS} ${TEST_TARGETS} -# python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_fork_support +python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests_fork_support # TODO(https://github.com/grpc/grpc/issues/32207): Remove from this job once # the fork job is in the master dashboard. -# python_bazel_tests_fork_support/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=fork_support --runs_per_test=16 ${BAZEL_FLAGS} //src/python/grpcio_tests/tests/fork:fork_test +python_bazel_tests_fork_support/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test --config=fork_support --runs_per_test=16 ${BAZEL_FLAGS} //src/python/grpcio_tests/tests/fork:fork_test From ff023e823595bdaa241fee9e7bc2b318a07aef3e Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 10 Dec 2024 20:52:36 +0000 Subject: [PATCH 15/26] Remove imports from all py_proto_library --- src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel | 2 +- .../grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index 35f6f85f45a25..3e2002808b85a 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -18,7 +18,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "health_py_pb2", - imports = ["../../"], + # imports = ["../../"], deps = ["//src/proto/grpc/health/v1:health_proto_descriptor"], ) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index 07c5f48f970dd..d879097bebd72 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -18,7 +18,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "reflection_py_pb2", - imports = ["../../"], + # imports = ["../../"], deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], ) From c763cbdd7fdd26d300f77087c328a8edc1293afc Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Thu, 12 Dec 2024 18:30:55 +0000 Subject: [PATCH 16/26] Fix bug --- .../grpcio_reflection/grpc_reflection/v1alpha/_base.py | 4 ---- .../tests_aio/reflection/reflection_servicer_test.py | 10 ++++++++-- third_party/BUILD | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index 8335335cbdd68..eb9a275f1c5aa 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -17,10 +17,6 @@ from google.protobuf import descriptor_pool import grpc import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': - import reflection_pb2 as _reflection_pb2 -else: - from grpc_reflection.v1alpha import os if os.environ.get('BUILD_SYSTEM') == 'Bazel': import reflection_pb2 as _reflection_pb2 import reflection_pb2_grpc as _reflection_pb2_grpc diff --git a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py index 458e59b7a5c05..7cb5c57c5767e 100644 --- a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py @@ -20,8 +20,14 @@ import grpc from grpc.experimental import aio from grpc_reflection.v1alpha import reflection -import reflection_pb2 -import reflection_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 + import reflection_pb2_grpc +else: + from grpc_reflection.v1alpha import reflection_pb2 + from grpc_reflection.v1alpha import reflection_pb2_grpc + from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 diff --git a/third_party/BUILD b/third_party/BUILD index 3918243ac3ef9..9d0c08258746a 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -11,7 +11,6 @@ exports_files([ "enum34.BUILD", "futures.BUILD", "protobuf.patch", - "py_proto_library.patch", "protoc-gen-validate.patch", ]) From bff48e0dbf41edfd6ba94fe699e403d81b5f6c42 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 17 Dec 2024 18:26:43 +0000 Subject: [PATCH 17/26] Fix missed path --- .../grpcio_channelz/grpc_channelz/v1/_servicer.py | 11 ----------- .../grpcio_channelz/grpc_channelz/v1/channelz.py | 6 +++++- .../tests/reflection/_reflection_servicer_test.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index a8c3e93cf87ce..26e7b059b8ba4 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -24,17 +24,6 @@ from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc -import sys -print(f"=============================================") -print(f"[xuan_testing] Import paths in _servicer:") -for path in sys.path: - if "com_google_protobuf" not in path: - print(path) -print(f"---------------------------------------------") -print(f"[xuan_testing] channelz_pb2.__file__: {_channelz_pb2.__file__}") -print(f"[xuan_testing] _channelz_pb2_grpc.__file__: {_channelz_pb2_grpc.__file__}") -print(f"---------------------------------------------") - class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index a7a27cdbdf639..81d5299edf2ad 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -17,7 +17,11 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer -import channelz_pb2_grpc as _channelz_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import channelz_pb2_grpc as _channelz_pb2_grpc +else: + from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index f2db7ed1c02b6..31dda58d7b173 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -20,8 +20,14 @@ from google.protobuf import descriptor_pool import grpc from grpc_reflection.v1alpha import reflection -import reflection_pb2 -import reflection_pb2_grpc +import os +if os.environ.get('BUILD_SYSTEM') == 'Bazel': + import reflection_pb2 + import reflection_pb2_grpc +else: + from grpc_reflection.v1alpha import reflection_pb2 + from grpc_reflection.v1alpha import reflection_pb2_grpc + from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 From e5c3b3694c62d8e228732620a68eec5388207526 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Tue, 17 Dec 2024 18:30:50 +0000 Subject: [PATCH 18/26] Add BUILD_SYSTEM flag to bazel distrib test --- test/distrib/bazel/test_single_bazel_version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/distrib/bazel/test_single_bazel_version.sh b/test/distrib/bazel/test_single_bazel_version.sh index fc72b57bac068..25884fe3b02ad 100755 --- a/test/distrib/bazel/test_single_bazel_version.sh +++ b/test/distrib/bazel/test_single_bazel_version.sh @@ -88,7 +88,7 @@ do pushd "test/distrib/bazel/${TEST_DIRECTORY}/" if [ "${TEST_SHARD}" == "distribtest_${TEST_DIRECTORY}" ] ; then tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; } - tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} " + tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all --test_env=BUILD_SYSTEM=Bazel //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} " SHARD_RAN="true" fi popd From 6a77b158a11a4f96ddbf6b12b1fab5df0ad03a0e Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 18 Dec 2024 17:47:09 +0000 Subject: [PATCH 19/26] Refactor --- bazel/python_rules.bzl | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 42b9c51732275..93a5708e2e023 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -29,7 +29,6 @@ load( "is_well_known", "is_in_virtual_imports", "protos_from_context", - "proto_path_to_generated_filename", ) _VIRTUAL_IMPORTS = "/_virtual_imports/" @@ -73,8 +72,6 @@ def _gen_py_aspect_impl(target, context): tools = [context.executable._protoc] out_dir = get_out_dir(protos, context) - print("[xuan_testing] python_out out_dir.path:") - print(out_dir) arguments = ([ "--python_out={}".format(out_dir.path), "--pyi_out={}".format(out_dir.path), @@ -101,10 +98,6 @@ def _gen_py_aspect_impl(target, context): imports.append("{}/{}".format(context.workspace_name, out_dir.import_path)) py_info = PyInfo(transitive_sources = depset(direct = out_files), imports = depset(direct = imports)) - print("[xuan_testing] py_info in deps:") - print(py_info) - print("[xuan_testing] generated_py_srcs in deps:") - print(generated_py_srcs) return PyProtoInfo( py_info = _merge_pyinfos( [ @@ -150,22 +143,16 @@ def _generate_py_impl(context): if context.label.package != context.attr.deps[0].label.package: for py_src in context.attr.deps[0][PyProtoInfo].generated_py_srcs: reimport_py_file = context.actions.declare_file(py_src.basename) - print("[xuan_testing] reimport_py_file: " + str(reimport_py_file)) py_sources.append(reimport_py_file) import_line = "from %s import *" % py_src.short_path.replace("..", "external").replace("/", ".")[:-len(".py")] - print("[xuan_testing] import_line: " + import_line) context.actions.write(reimport_py_file, import_line) # Collect output PyInfo provider. imports = [context.label.package + "/" + i for i in context.attr.imports] - print("[xuan_testing] py_sources:") - print(py_sources) py_info = PyInfo(transitive_sources = depset(direct = py_sources), imports = depset(direct = imports)) out_pyinfo = _merge_pyinfos([py_info, context.attr.deps[0][PyProtoInfo].py_info]) runfiles = context.runfiles(files = out_pyinfo.transitive_sources.to_list()).merge(context.attr._protobuf_library[DefaultInfo].data_runfiles) - print("[xuan_testing] out_pyinfo:") - print(out_pyinfo) return [ DefaultInfo( files = out_pyinfo.transitive_sources, @@ -203,15 +190,6 @@ def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) is_virtual = False for proto in protos: - print(">>[xuan_testing] pb2_grpc protos: " + str(proto)) - # - # - print(">>[xuan_testing] pb2_grpc protos.path: " + str(proto.path)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz.proto - print(">>[xuan_testing] pb2_grpc protos.dirname: " + str(proto.dirname)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 if is_in_virtual_imports(proto): is_virtual = True includes = includes_from_deps(context.attr.deps) @@ -255,7 +233,8 @@ def _generate_pb2_grpc_src_impl(context): # bazel-out/k8-fastbuild/bin if out_dir.import_path: # is virtual imports - out_path = out_dir.path + # out_path = out_dir.path + out_path = get_include_directory(out_files[0]) else: out_path = context.genfiles_dir.path print(">>>>>>[xuan_testing] pb2_grpc out_path: " + str(out_path)) @@ -264,8 +243,8 @@ def _generate_pb2_grpc_src_impl(context): # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors # Fix 1: # out_path = out_files[0].dirname - if is_virtual: - out_path = result + # if is_virtual: + # out_path = result # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors # Fix 2: # out_path = result @@ -331,7 +310,11 @@ def _generate_pb2_grpc_src_impl(context): imports = [] # Fix 1: - if is_virtual: + # Adding to PYTHONPATH so the generated modules can be imported. + # This is necessary when there is strip_import_prefix, the Python modules are generated under _virtual_imports. + # But it's undesirable otherwise, because it will put the repo root at the top of the PYTHONPATH, ahead of + # directories added through `imports` attributes. + if _VIRTUAL_IMPORTS in out_path: import_path = out_path # Handles virtual import cases if out_path.startswith(context.genfiles_dir.path): @@ -339,7 +322,7 @@ def _generate_pb2_grpc_src_impl(context): import_path = "{}/{}".format(context.workspace_name, import_path) imports.append(import_path) - print(">>>>[xuan_testing] pb2_grpc added imports: " + str(imports)) + print(">>>>[xuan_testing] pb2_grpc added imports: " + str(import_path)) # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors (Fixed) # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors From 11299a8a43a9a96721992800750ba0a3a4d1e17e Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 18 Dec 2024 20:31:15 +0000 Subject: [PATCH 20/26] Remove logs --- bazel/protobuf.bzl | 23 +---- bazel/python_rules.bzl | 91 +------------------ examples/python/debug/asyncio_get_stats.py | 6 +- examples/python/debug/get_stats.py | 6 +- .../python/health_checking/greeter_client.py | 6 +- .../python/health_checking/greeter_server.py | 6 +- examples/python/xds/server.py | 6 +- .../grpc_channelz/v1/BUILD.bazel | 1 - .../grpc_channelz/v1/_async.py | 6 +- .../grpc_channelz/v1/_servicer.py | 6 +- .../grpc_channelz/v1/channelz.py | 6 +- .../grpc_health/v1/BUILD.bazel | 1 - .../grpc_health/v1/_async.py | 6 +- .../grpc_health/v1/health.py | 6 +- .../grpc_reflection/v1alpha/BUILD.bazel | 1 - .../grpc_reflection/v1alpha/_async.py | 6 +- .../grpc_reflection/v1alpha/_base.py | 6 +- .../proto_reflection_descriptor_database.py | 6 +- .../grpc_reflection/v1alpha/reflection.py | 6 +- .../grpcio_tests/tests/admin/admin_test.py | 6 +- .../tests/channelz/_channelz_servicer_test.py | 6 +- .../health_check/_health_servicer_test.py | 6 +- .../reflection/_reflection_servicer_test.py | 6 +- .../channelz/channelz_servicer_test.py | 6 +- .../health_check/health_servicer_test.py | 6 +- .../reflection/reflection_servicer_test.py | 6 +- .../interop/xds_interop_server.py | 6 +- .../bazel/python/import_from_this_package.py | 1 - test/distrib/bazel/python/in_subpackage/BUILD | 3 +- .../bazel/python/python_rules_test.bzl | 12 ++- .../bazel/test_single_bazel_version.sh | 2 +- .../linux/grpc_python_bazel_test_in_docker.sh | 2 +- 32 files changed, 79 insertions(+), 190 deletions(-) diff --git a/bazel/protobuf.bzl b/bazel/protobuf.bzl index a8576ba525363..971af9e19a81f 100644 --- a/bazel/protobuf.bzl +++ b/bazel/protobuf.bzl @@ -200,9 +200,6 @@ def get_staged_proto_file(label, context, source_file): # probably even in different repositories) prefix = _make_prefix(source_file.owner) copied_proto = context.actions.declare_file(source_file.path[len(prefix):]) - # print(">>[xuan_testing] copy proto from: " + str(source_file.path) + " to :" + str(copied_proto.path)) - # copy proto from: src/proto/grpc/channelz/channelz.proto - # to :bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto context.actions.run_shell( inputs = [source_file], outputs = [copied_proto], @@ -223,7 +220,6 @@ def protos_from_context(context): protos = [] for src in context.attr.deps: for file in src[ProtoInfo].direct_sources: - # print(">>[xuan_testing] Checking file " + str(file)) protos.append(get_staged_proto_file(context.label, context, file)) return protos @@ -274,7 +270,6 @@ def declare_out_files(protos, context, generated_file_format): """ out_file_paths = [] - # print("[xuan_testing] gen_path: " + str(context.genfiles_dir.path)) for proto in protos: if not is_in_virtual_imports(proto): prefix = _make_prefix(proto.owner) @@ -284,17 +279,8 @@ def declare_out_files(protos, context, generated_file_format): elif proto.path.startswith(prefix): out_file_paths.append(proto.path[len(prefix):]) else: - # print("[xuan_testing] declare_out_files proto.path: " + str(proto.path)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors/channelz.proto out_file_paths.append(proto.path[proto.path.index(_VIRTUAL_IMPORTS) + 1:]) - # print("[xuan_testing] out_file_path: " + str(out_file_paths[-1])) - # _virtual_imports/channelz_proto_descriptors/channelz.proto - # path = proto_path_to_generated_filename( - # out_file_paths[-1], - # generated_file_format, - # ) - # print("[xuan_testing] path: " + str(path)) - # _virtual_imports/channelz_proto_descriptors/channelz_pb2_grpc.py + return [ context.actions.declare_file( proto_path_to_generated_filename( @@ -324,14 +310,9 @@ def get_out_dir(protos, context): fail("Proto sources must be either all virtual imports or all real") if at_least_one_virtual: out_dir = get_include_directory(protos[0]) - # print(" [xuan_testing] include_directory: " + str(out_dir)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors ws_root = protos[0].owner.workspace_root - # print(" [xuan_testing] ws_root: " + str(ws_root)) - # ws_root: prefix = "/" + _make_prefix(protos[0].owner) + _VIRTUAL_IMPORTS[1:] - # print(" [xuan_testing] prefix: " + str(prefix)) - # /src/proto/grpc/channelz/_virtual_imports/ + return struct( path = out_dir, import_path = out_dir[out_dir.find(prefix) + 1:], diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 93a5708e2e023..c8ffa639c5afc 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -27,7 +27,6 @@ load( "get_staged_proto_file", "includes_from_deps", "is_well_known", - "is_in_virtual_imports", "protos_from_context", ) @@ -72,6 +71,7 @@ def _gen_py_aspect_impl(target, context): tools = [context.executable._protoc] out_dir = get_out_dir(protos, context) + arguments = ([ "--python_out={}".format(out_dir.path), "--pyi_out={}".format(out_dir.path), @@ -188,106 +188,32 @@ py_proto_library = protobuf_py_proto_library def _generate_pb2_grpc_src_impl(context): protos = protos_from_context(context) - is_virtual = False - for proto in protos: - if is_in_virtual_imports(proto): - is_virtual = True includes = includes_from_deps(context.attr.deps) out_files = declare_out_files(protos, context, _GENERATED_GRPC_PROTO_FORMAT) - print(">>>>>>[xuan_testing] pb2_grpc out_files: " + str(out_files)) - # [] - # [] - # [] - - print(">>>>>>[xuan_testing] pb2_grpc out_files.dirname: " + str(out_files[0].dirname)) - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1 - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 - if is_virtual: - root, relative = out_files[0].path.split(_VIRTUAL_IMPORTS, 2) - # root: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1 - # relative: channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py - result = root + _VIRTUAL_IMPORTS + relative.split("/", 1)[0] - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors - print(">>>>>>[xuan_testing] result: " + str(result)) - out_path = result - plugin_flags = ["grpc_2_0"] + context.attr.strip_prefixes arguments = [] tools = [context.executable._protoc, context.executable._grpc_plugin] out_dir = get_out_dir(protos, context) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - print("[xuan_testing] pb2_grpc out_dir: " + str(out_dir)) - # struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors", - # path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors") - # struct(import_path = None, path = "bazel-out/k8-fastbuild/bin") - # struct(import_path = "src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors", - # path = "bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors") - print("[xuan_testing] pb2_grpc out_dir.path: " + str(out_dir.path)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - # bazel-out/k8-fastbuild/bin - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - print("[xuan_testing] pb2_grpc context.genfiles_dir.path: " + str(context.genfiles_dir.path)) - # bazel-out/k8-fastbuild/bin if out_dir.import_path: # is virtual imports - # out_path = out_dir.path out_path = get_include_directory(out_files[0]) else: out_path = context.genfiles_dir.path - print(">>>>>>[xuan_testing] pb2_grpc out_path: " + str(out_path)) - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - # bazel-out/k8-fastbuild/bin - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - # Fix 1: - # out_path = out_files[0].dirname - # if is_virtual: - # out_path = result - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors - # Fix 2: - # out_path = result arguments += get_plugin_args( context.executable._grpc_plugin, plugin_flags, out_path, False, ) - # --PLUGIN_out=grpc_2_0,src.python.grpcio_channelz.: - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors (==out_path) - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors (Fixed) - # bazel-out/k8-fastbuild/bin - # bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 arguments += [ "--proto_path={}".format(get_include_directory(i)) for i in includes ] - # bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors arguments.append("--proto_path={}".format(context.genfiles_dir.path)) - print("[xuan_testing] pb2_grpc proto_path: " + str(context.genfiles_dir.path)) - # bazel-out/k8-fastbuild/bin arguments += get_proto_arguments(protos, context.genfiles_dir.path) - print("[xuan_testing] pb2_grpc get_proto_arguments: " + str(arguments)) - # --plugin=protoc-gen-PLUGIN=bazel-out/k8-opt-exec-ST-a828a81199fe/bin/src/compiler/grpc_python_plugin - # --PLUGIN_out=XXX - # --proto_path=bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors (Old & Fixed) - # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/any_proto - # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/duration_proto - # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/timestamp_proto - # --proto_path=bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/wrappers_proto - # --proto_path=bazel-out/k8-fastbuild/bin - # channelz.proto - - # --proto_path=. - # src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto - - # --proto_path=bazel-out/k8-fastbuild/bin/src/proto/grpc/channelz/_virtual_imports/channelz_proto_descriptors - # grpc_channelz/v1/channelz.proto - - # for dep in context.attr.py_deps: - # print("~~~~~[xuan_testing] dep: " + str(dep[PyInfo].transitive_sources.to_list())) context.actions.run( inputs = protos + includes, tools = tools, @@ -296,20 +222,8 @@ def _generate_pb2_grpc_src_impl(context): arguments = arguments, mnemonic = "ProtocInvocation", ) - # Fix: - # Out file: [] - # Plugin out: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors - # Proto path: channelz.proto - # Actual out: .runfiles/com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/channelz_pb2_grpc.py - - # Out file: [] - # Plugin out: bazel-out/k8-fastbuild/bin/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1 - # Proto path: grpc_channelz/v1/channelz.proto - # Actual out: ? - # Expected: src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors/grpc_channelz/v1/channelz_pb2_grpc.py imports = [] - # Fix 1: # Adding to PYTHONPATH so the generated modules can be imported. # This is necessary when there is strip_import_prefix, the Python modules are generated under _virtual_imports. # But it's undesirable otherwise, because it will put the repo root at the top of the PYTHONPATH, ahead of @@ -322,9 +236,6 @@ def _generate_pb2_grpc_src_impl(context): import_path = "{}/{}".format(context.workspace_name, import_path) imports.append(import_path) - print(">>>>[xuan_testing] pb2_grpc added imports: " + str(import_path)) - # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors (Fixed) - # com_github_grpc_grpc/src/python/grpcio_channelz/grpc_channelz/v1/_virtual_imports/channelz_proto_descriptors p = PyInfo(transitive_sources = depset(direct = out_files), imports = depset(direct = imports)) py_info = _merge_pyinfos( diff --git a/examples/python/debug/asyncio_get_stats.py b/examples/python/debug/asyncio_get_stats.py index 81bd5cfe8866f..3a022dea70b8a 100644 --- a/examples/python/debug/asyncio_get_stats.py +++ b/examples/python/debug/asyncio_get_stats.py @@ -18,11 +18,11 @@ import logging import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 import channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index a39abdd73037e..2e738299b5acb 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -21,11 +21,11 @@ import logging import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 import channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc diff --git a/examples/python/health_checking/greeter_client.py b/examples/python/health_checking/greeter_client.py index dbd7a09b4ce2b..e2ebee0f99f88 100644 --- a/examples/python/health_checking/greeter_client.py +++ b/examples/python/health_checking/greeter_client.py @@ -17,11 +17,11 @@ from time import sleep import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 diff --git a/examples/python/health_checking/greeter_server.py b/examples/python/health_checking/greeter_server.py index f365fb0bf2786..bb9e9f0aa0f71 100644 --- a/examples/python/health_checking/greeter_server.py +++ b/examples/python/health_checking/greeter_server.py @@ -20,11 +20,11 @@ import grpc from grpc_health.v1 import health -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 diff --git a/examples/python/xds/server.py b/examples/python/xds/server.py index 96c0b72022d82..696bcb2446d29 100644 --- a/examples/python/xds/server.py +++ b/examples/python/xds/server.py @@ -20,11 +20,11 @@ import grpc from grpc_health.v1 import health -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from grpc_reflection.v1alpha import reflection diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index 8ceb511e8dc5b..dc0a79f83260b 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -18,7 +18,6 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "channelz_py_pb2", - # imports = ["../../"], deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], ) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index 48c61cf3e102a..5640776ff9c2d 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -15,11 +15,11 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 as _channelz_pb2 import channelz_pb2_grpc as _channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index 26e7b059b8ba4..9e22379a5141d 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,11 +16,11 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 as _channelz_pb2 import channelz_pb2_grpc as _channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index 81d5299edf2ad..72616370e0d74 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -17,10 +17,10 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2_grpc as _channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index 3e2002808b85a..90efb149f3ff1 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -18,7 +18,6 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "health_py_pb2", - # imports = ["../../"], deps = ["//src/proto/grpc/health/v1:health_proto_descriptor"], ) diff --git a/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/src/python/grpcio_health_checking/grpc_health/v1/_async.py index 7a5e1869043f7..051da9d61cd61 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -18,11 +18,11 @@ from typing import MutableMapping import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 as _health_pb2 import health_pb2_grpc as _health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 as _health_pb2 from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 83f56dcbbbc72..1bea0c5732d82 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -18,11 +18,11 @@ import threading import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 as _health_pb2 import health_pb2_grpc as _health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 as _health_pb2 from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index d879097bebd72..e13e72efa73a1 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -18,7 +18,6 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "reflection_py_pb2", - # imports = ["../../"], deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], ) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index 0d9815bc27f82..a0b342b56fea3 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -16,10 +16,10 @@ from typing import AsyncIterable import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import reflection_pb2 as _reflection_pb2 -else: +except ImportError: from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha._base import BaseReflectionServicer diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index eb9a275f1c5aa..9fd9851d8d424 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -16,11 +16,11 @@ from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import reflection_pb2 as _reflection_pb2 import reflection_pb2_grpc as _reflection_pb2_grpc -else: +except ImportError: from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py index b5e465bcd16db..a08d3cf941311 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py @@ -23,8 +23,8 @@ from google.protobuf.descriptor_database import DescriptorDatabase from google.protobuf.descriptor_pb2 import FileDescriptorProto import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: from reflection_pb2 import ExtensionNumberResponse from reflection_pb2 import ExtensionRequest from reflection_pb2 import FileDescriptorResponse @@ -33,7 +33,7 @@ from reflection_pb2 import ServerReflectionResponse from reflection_pb2 import ServiceResponse from reflection_pb2_grpc import ServerReflectionStub -else: +except ImportError: from grpc_reflection.v1alpha.reflection_pb2 import ExtensionNumberResponse from grpc_reflection.v1alpha.reflection_pb2 import ExtensionRequest from grpc_reflection.v1alpha.reflection_pb2 import FileDescriptorResponse diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index 15d525a57ce1d..af9d4b950b473 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -16,11 +16,11 @@ import sys import grpc -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import reflection_pb2 as _reflection_pb2 import reflection_pb2_grpc as _reflection_pb2_grpc -else: +except ImportError: from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc from grpc_reflection.v1alpha._base import BaseReflectionServicer diff --git a/src/python/grpcio_tests/tests/admin/admin_test.py b/src/python/grpcio_tests/tests/admin/admin_test.py index 1e1f6cd724a79..2242a9f056438 100644 --- a/src/python/grpcio_tests/tests/admin/admin_test.py +++ b/src/python/grpcio_tests/tests/admin/admin_test.py @@ -20,11 +20,11 @@ import grpc import grpc_admin -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 import channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc from grpc_csds import csds_pb2 diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index e002bc54daab8..839f7e3fa7af9 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -19,11 +19,11 @@ import grpc from grpc_channelz.v1 import channelz -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 import channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 4f52011d3a047..8b904f5275390 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,11 +22,11 @@ import grpc from grpc_health.v1 import health -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 31dda58d7b173..623ae57475163 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -20,11 +20,11 @@ from google.protobuf import descriptor_pool import grpc from grpc_reflection.v1alpha import reflection -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import reflection_pb2 import reflection_pb2_grpc -else: +except ImportError: from grpc_reflection.v1alpha import reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc diff --git a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py index c21e044894e20..56260a55e68e4 100644 --- a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py @@ -20,11 +20,11 @@ import grpc from grpc.experimental import aio from grpc_channelz.v1 import channelz -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import channelz_pb2 import channelz_pb2_grpc -else: +except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc diff --git a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py index 62238efad0b68..46bd73ce5c6af 100644 --- a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py @@ -22,11 +22,11 @@ import grpc from grpc.experimental import aio from grpc_health.v1 import health -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc diff --git a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py index 7cb5c57c5767e..7d493ce443cef 100644 --- a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py @@ -20,11 +20,11 @@ import grpc from grpc.experimental import aio from grpc_reflection.v1alpha import reflection -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import reflection_pb2 import reflection_pb2_grpc -else: +except ImportError: from grpc_reflection.v1alpha import reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc diff --git a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py index f4852123375d3..742db34dc8655 100644 --- a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py +++ b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py @@ -27,12 +27,12 @@ from grpc_channelz.v1 import channelz from grpc_csm_observability import CsmOpenTelemetryPlugin from grpc_health.v1 import health as grpc_health -import os -if os.environ.get('BUILD_SYSTEM') == 'Bazel': +# Bazel build uses another path. +try: import health_pb2 import health_pb2_grpc import channelz_pb2 -else: +except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from grpc_channelz.v1 import channelz_pb2 diff --git a/test/distrib/bazel/python/import_from_this_package.py b/test/distrib/bazel/python/import_from_this_package.py index d41bee418422d..9a7e085c45767 100644 --- a/test/distrib/bazel/python/import_from_this_package.py +++ b/test/distrib/bazel/python/import_from_this_package.py @@ -15,5 +15,4 @@ proto_library and py_proto_library are in different Bazel packages. """ -# import subpackage_pb2 import in_subpackage.subpackage_pb2 diff --git a/test/distrib/bazel/python/in_subpackage/BUILD b/test/distrib/bazel/python/in_subpackage/BUILD index c21a220f736bf..2b008c8b5d301 100644 --- a/test/distrib/bazel/python/in_subpackage/BUILD +++ b/test/distrib/bazel/python/in_subpackage/BUILD @@ -14,8 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# load("@rules_proto//proto:defs.bzl", "proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") package( default_testonly = 1, diff --git a/test/distrib/bazel/python/python_rules_test.bzl b/test/distrib/bazel/python/python_rules_test.bzl index 9f59cd5a529e4..b1545b8021a56 100644 --- a/test/distrib/bazel/python/python_rules_test.bzl +++ b/test/distrib/bazel/python/python_rules_test.bzl @@ -39,18 +39,20 @@ def _py_proto_library_provider_contents_test_impl(ctx): ] _assert_in(env, "helloworld_pb2.py", files) - # _assert_in(env, "helloworld_pb2.pyi", files) _assert_in(env, "subdir/hello_dep_pb2.py", files) - # _assert_in(env, "subdir/hello_dep_pb2.pyi", files) _assert_in(env, "helloworld_pb2.py", runfiles) - # _assert_in(env, "helloworld_pb2.pyi", runfiles) _assert_in(env, "subdir/hello_dep_pb2.py", runfiles) - # _assert_in(env, "subdir/hello_dep_pb2.pyi", runfiles) _assert_in(env, "helloworld_pb2.py", py_info_transitive_sources) - # _assert_in(env, "helloworld_pb2.pyi", py_info_transitive_sources) _assert_in(env, "subdir/hello_dep_pb2.py", py_info_transitive_sources) + + # TODO: Enable after py_proto_library supports outputting .pyi files. + # _assert_in(env, "helloworld_pb2.pyi", files) + # _assert_in(env, "subdir/hello_dep_pb2.pyi", files) + # _assert_in(env, "helloworld_pb2.pyi", runfiles) + # _assert_in(env, "subdir/hello_dep_pb2.pyi", runfiles) + # _assert_in(env, "helloworld_pb2.pyi", py_info_transitive_sources) # _assert_in(env, "subdir/hello_dep_pb2.pyi", py_info_transitive_sources) return analysistest.end(env) diff --git a/test/distrib/bazel/test_single_bazel_version.sh b/test/distrib/bazel/test_single_bazel_version.sh index 25884fe3b02ad..fc72b57bac068 100755 --- a/test/distrib/bazel/test_single_bazel_version.sh +++ b/test/distrib/bazel/test_single_bazel_version.sh @@ -88,7 +88,7 @@ do pushd "test/distrib/bazel/${TEST_DIRECTORY}/" if [ "${TEST_SHARD}" == "distribtest_${TEST_DIRECTORY}" ] ; then tools/bazel version | grep "$VERSION" || { echo "Detected bazel version did not match expected value of $VERSION" >/dev/stderr; exit 1; } - tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all --test_env=BUILD_SYSTEM=Bazel //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} " + tools/bazel test "${ACTION_ENV_FLAG}" --test_output=all //:all || FAILED_TESTS="${FAILED_TESTS}distribtest_${TEST_DIRECTORY} " SHARD_RAN="true" fi popd diff --git a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh index a5d54285c851e..da6b5bc2f5b9c 100755 --- a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh @@ -17,7 +17,7 @@ set -ex RESULTSTORE_RESULTS_FLAG="--bazelrc=tools/remote_build/include/test_locally_with_resultstore_results.bazelrc" TEST_TARGETS="//src/python/... //tools/distrib/python/grpcio_tools/... //examples/python/..." -BAZEL_FLAGS="--test_output=errors --test_env=BUILD_SYSTEM=Bazel" +BAZEL_FLAGS="--test_output=errors" python3 tools/run_tests/python_utils/bazel_report_helper.py --report_path python_bazel_tests python_bazel_tests/bazel_wrapper ${RESULTSTORE_RESULTS_FLAG} test ${BAZEL_FLAGS} ${TEST_TARGETS} From 6b9631b5eb9cbde89ecb85eaf18e97738103c6be Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 18 Dec 2024 20:41:27 +0000 Subject: [PATCH 21/26] Fix sanity --- bazel/python_rules.bzl | 3 ++- examples/python/debug/asyncio_get_stats.py | 1 + examples/python/debug/get_stats.py | 1 + examples/python/health_checking/greeter_client.py | 5 +++-- examples/python/health_checking/greeter_server.py | 7 +++++-- examples/python/xds/server.py | 10 +++++++--- src/proto/grpc/channelz/BUILD | 2 +- src/proto/grpc/reflection/v1/BUILD | 1 - src/python/grpcio_channelz/grpc_channelz/v1/_async.py | 3 +++ .../grpcio_channelz/grpc_channelz/v1/_servicer.py | 2 ++ .../grpcio_channelz/grpc_channelz/v1/channelz.py | 3 +++ .../grpcio_health_checking/grpc_health/v1/_async.py | 1 + .../grpcio_health_checking/grpc_health/v1/health.py | 1 + .../grpc_reflection/v1alpha/_async.py | 3 ++- .../grpcio_reflection/grpc_reflection/v1alpha/_base.py | 5 ++++- .../v1alpha/proto_reflection_descriptor_database.py | 2 +- .../grpc_reflection/v1alpha/reflection.py | 9 +++++++-- src/python/grpcio_tests/tests/admin/admin_test.py | 2 ++ .../tests/channelz/_channelz_servicer_test.py | 1 + .../tests/health_check/_health_servicer_test.py | 1 + .../tests/reflection/_reflection_servicer_test.py | 2 +- .../tests_aio/channelz/channelz_servicer_test.py | 1 + .../tests_aio/health_check/health_servicer_test.py | 1 + .../tests_aio/reflection/reflection_servicer_test.py | 2 +- .../tests_py3_only/interop/xds_interop_server.py | 4 +++- test/distrib/bazel/python/BUILD | 2 -- 26 files changed, 55 insertions(+), 20 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index c8ffa639c5afc..7ce50b8393ff9 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -16,7 +16,6 @@ load("@rules_proto//proto:defs.bzl", "ProtoInfo") load("@rules_python//python:py_info.bzl", "PyInfo") load("@com_google_protobuf//bazel:py_proto_library.bzl", protobuf_py_proto_library = "py_proto_library") - load( "//bazel:protobuf.bzl", "declare_out_files", @@ -224,12 +223,14 @@ def _generate_pb2_grpc_src_impl(context): ) imports = [] + # Adding to PYTHONPATH so the generated modules can be imported. # This is necessary when there is strip_import_prefix, the Python modules are generated under _virtual_imports. # But it's undesirable otherwise, because it will put the repo root at the top of the PYTHONPATH, ahead of # directories added through `imports` attributes. if _VIRTUAL_IMPORTS in out_path: import_path = out_path + # Handles virtual import cases if out_path.startswith(context.genfiles_dir.path): import_path = import_path[len(context.genfiles_dir.path) + 1:] diff --git a/examples/python/debug/asyncio_get_stats.py b/examples/python/debug/asyncio_get_stats.py index 3a022dea70b8a..9600e1bc51959 100644 --- a/examples/python/debug/asyncio_get_stats.py +++ b/examples/python/debug/asyncio_get_stats.py @@ -18,6 +18,7 @@ import logging import grpc + # Bazel build uses another path. try: import channelz_pb2 diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index 2e738299b5acb..290ebb4730bcd 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -21,6 +21,7 @@ import logging import grpc + # Bazel build uses another path. try: import channelz_pb2 diff --git a/examples/python/health_checking/greeter_client.py b/examples/python/health_checking/greeter_client.py index e2ebee0f99f88..cb3bf785628d0 100644 --- a/examples/python/health_checking/greeter_client.py +++ b/examples/python/health_checking/greeter_client.py @@ -17,6 +17,9 @@ from time import sleep import grpc +import helloworld_pb2 +import helloworld_pb2_grpc + # Bazel build uses another path. try: import health_pb2 @@ -24,8 +27,6 @@ except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc -import helloworld_pb2 -import helloworld_pb2_grpc def unary_call(stub: helloworld_pb2_grpc.GreeterStub, message: str): diff --git a/examples/python/health_checking/greeter_server.py b/examples/python/health_checking/greeter_server.py index bb9e9f0aa0f71..d4185b7fc709e 100644 --- a/examples/python/health_checking/greeter_server.py +++ b/examples/python/health_checking/greeter_server.py @@ -20,15 +20,18 @@ import grpc from grpc_health.v1 import health +import helloworld_pb2 +import helloworld_pb2_grpc + # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import health_pb2 import health_pb2_grpc except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc -import helloworld_pb2 -import helloworld_pb2_grpc +# pylint: enable=ungrouped-imports class Greeter(helloworld_pb2_grpc.GreeterServicer): diff --git a/examples/python/xds/server.py b/examples/python/xds/server.py index 696bcb2446d29..61f5550810c16 100644 --- a/examples/python/xds/server.py +++ b/examples/python/xds/server.py @@ -20,16 +20,20 @@ import grpc from grpc_health.v1 import health +from grpc_reflection.v1alpha import reflection +import helloworld_pb2 +import helloworld_pb2_grpc + # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import health_pb2 import health_pb2_grpc except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc -from grpc_reflection.v1alpha import reflection -import helloworld_pb2 -import helloworld_pb2_grpc +# pylint: enable=ungrouped-imports + _DESCRIPTION = "A general purpose phony server." diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD index 3a12776ad616a..f1ae411f1e6ce 100644 --- a/src/proto/grpc/channelz/BUILD +++ b/src/proto/grpc/channelz/BUILD @@ -35,13 +35,13 @@ grpc_proto_library( proto_library( name = "channelz_proto_descriptors", srcs = ["channelz.proto"], + strip_import_prefix = "/src/proto/grpc/channelz", deps = [ "@com_google_protobuf//:any_proto", "@com_google_protobuf//:duration_proto", "@com_google_protobuf//:timestamp_proto", "@com_google_protobuf//:wrappers_proto", ], - strip_import_prefix = "/src/proto/grpc/channelz", ) filegroup( diff --git a/src/proto/grpc/reflection/v1/BUILD b/src/proto/grpc/reflection/v1/BUILD index a6fa346bb5f40..35db08e9044ab 100644 --- a/src/proto/grpc/reflection/v1/BUILD +++ b/src/proto/grpc/reflection/v1/BUILD @@ -36,7 +36,6 @@ proto_library( strip_import_prefix = "/src/proto/grpc/reflection/v1", ) - filegroup( name = "reflection_proto_file", srcs = [ diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index 5640776ff9c2d..d612df8d076d4 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -15,13 +15,16 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer + # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import channelz_pb2 as _channelz_pb2 import channelz_pb2_grpc as _channelz_pb2_grpc except ImportError: from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc +# pylint: enable=ungrouped-imports class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index 9e22379a5141d..fab3f24b6829c 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,6 +16,7 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc + # Bazel build uses another path. try: import channelz_pb2 as _channelz_pb2 @@ -24,6 +25,7 @@ from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc + class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index 72616370e0d74..263b05431e837 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -17,11 +17,14 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer + # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import channelz_pb2_grpc as _channelz_pb2_grpc except ImportError: from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc +# pylint: enable=ungrouped-imports _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/src/python/grpcio_health_checking/grpc_health/v1/_async.py index 051da9d61cd61..b3752170bfbde 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -18,6 +18,7 @@ from typing import MutableMapping import grpc + # Bazel build uses another path. try: import health_pb2 as _health_pb2 diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 1bea0c5732d82..4ab52d49befa3 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -18,6 +18,7 @@ import threading import grpc + # Bazel build uses another path. try: import health_pb2 as _health_pb2 diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index a0b342b56fea3..4e8a55d804397 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -16,12 +16,13 @@ from typing import AsyncIterable import grpc +from grpc_reflection.v1alpha._base import BaseReflectionServicer + # Bazel build uses another path. try: import reflection_pb2 as _reflection_pb2 except ImportError: from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 -from grpc_reflection.v1alpha._base import BaseReflectionServicer class ReflectionServicer(BaseReflectionServicer): diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index 9fd9851d8d424..f1ab35f0a3ef0 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -16,13 +16,16 @@ from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool import grpc + # Bazel build uses another path. try: import reflection_pb2 as _reflection_pb2 import reflection_pb2_grpc as _reflection_pb2_grpc except ImportError: + from grpc_reflection.v1alpha import ( + reflection_pb2_grpc as _reflection_pb2_grpc, + ) from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 - from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc _POOL = descriptor_pool.Default() diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py index a08d3cf941311..655eaa9d48260 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py @@ -23,6 +23,7 @@ from google.protobuf.descriptor_database import DescriptorDatabase from google.protobuf.descriptor_pb2 import FileDescriptorProto import grpc + # Bazel build uses another path. try: from reflection_pb2 import ExtensionNumberResponse @@ -44,7 +45,6 @@ from grpc_reflection.v1alpha.reflection_pb2_grpc import ServerReflectionStub - class ProtoReflectionDescriptorDatabase(DescriptorDatabase): """ A container and interface for receiving descriptors from a server's diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index af9d4b950b473..f506cba7f6d67 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -16,14 +16,19 @@ import sys import grpc +from grpc_reflection.v1alpha._base import BaseReflectionServicer + # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import reflection_pb2 as _reflection_pb2 import reflection_pb2_grpc as _reflection_pb2_grpc except ImportError: + from grpc_reflection.v1alpha import ( + reflection_pb2_grpc as _reflection_pb2_grpc, + ) from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 - from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc -from grpc_reflection.v1alpha._base import BaseReflectionServicer +# pylint: enable=ungrouped-imports SERVICE_NAME = _reflection_pb2.DESCRIPTOR.services_by_name[ "ServerReflection" diff --git a/src/python/grpcio_tests/tests/admin/admin_test.py b/src/python/grpcio_tests/tests/admin/admin_test.py index 2242a9f056438..2f4bb1e1e6b5c 100644 --- a/src/python/grpcio_tests/tests/admin/admin_test.py +++ b/src/python/grpcio_tests/tests/admin/admin_test.py @@ -20,6 +20,7 @@ import grpc import grpc_admin + # Bazel build uses another path. try: import channelz_pb2 @@ -27,6 +28,7 @@ except ImportError: from grpc_channelz.v1 import channelz_pb2 from grpc_channelz.v1 import channelz_pb2_grpc + from grpc_csds import csds_pb2 from grpc_csds import csds_pb2_grpc diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index 839f7e3fa7af9..bb6331d598335 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -19,6 +19,7 @@ import grpc from grpc_channelz.v1 import channelz + # Bazel build uses another path. try: import channelz_pb2 diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 8b904f5275390..192201976ce5d 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,6 +22,7 @@ import grpc from grpc_health.v1 import health + # Bazel build uses another path. try: import health_pb2 diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 623ae57475163..8ffe2ed0a7b4e 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -20,6 +20,7 @@ from google.protobuf import descriptor_pool import grpc from grpc_reflection.v1alpha import reflection + # Bazel build uses another path. try: import reflection_pb2 @@ -28,7 +29,6 @@ from grpc_reflection.v1alpha import reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc - from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 from src.proto.grpc.testing.proto2 import empty2_pb2 diff --git a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py index 56260a55e68e4..7435c081fc3c7 100644 --- a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py @@ -20,6 +20,7 @@ import grpc from grpc.experimental import aio from grpc_channelz.v1 import channelz + # Bazel build uses another path. try: import channelz_pb2 diff --git a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py index 46bd73ce5c6af..5a860f2e83a4b 100644 --- a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py @@ -22,6 +22,7 @@ import grpc from grpc.experimental import aio from grpc_health.v1 import health + # Bazel build uses another path. try: import health_pb2 diff --git a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py index 7d493ce443cef..6dc96fb81218d 100644 --- a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py @@ -20,6 +20,7 @@ import grpc from grpc.experimental import aio from grpc_reflection.v1alpha import reflection + # Bazel build uses another path. try: import reflection_pb2 @@ -28,7 +29,6 @@ from grpc_reflection.v1alpha import reflection_pb2 from grpc_reflection.v1alpha import reflection_pb2_grpc - from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 from src.proto.grpc.testing.proto2 import empty2_pb2 diff --git a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py index 742db34dc8655..098020f0d0948 100644 --- a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py +++ b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py @@ -27,15 +27,17 @@ from grpc_channelz.v1 import channelz from grpc_csm_observability import CsmOpenTelemetryPlugin from grpc_health.v1 import health as grpc_health + # Bazel build uses another path. try: + import channelz_pb2 import health_pb2 import health_pb2_grpc - import channelz_pb2 except ImportError: from grpc_health.v1 import health_pb2 from grpc_health.v1 import health_pb2_grpc from grpc_channelz.v1 import channelz_pb2 + from grpc_reflection.v1alpha import reflection from opentelemetry.exporter.prometheus import PrometheusMetricReader from opentelemetry.sdk.metrics import MeterProvider diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 50177a56fbdf3..d8c2bd25c4ff0 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -16,7 +16,6 @@ load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") - load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", @@ -29,7 +28,6 @@ package( default_testonly = 1, ) - proto_library( name = "helloworld_proto", srcs = ["helloworld.proto"], From 8ec286a62a1f46f04394fa09ef67e1ac28aa82a6 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 18 Dec 2024 21:37:26 +0000 Subject: [PATCH 22/26] Fix sanity --- src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py | 3 ++- test/distrib/bazel/python/BUILD | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index 4e8a55d804397..cd1f0ce9b98bb 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -19,11 +19,12 @@ from grpc_reflection.v1alpha._base import BaseReflectionServicer # Bazel build uses another path. +# pylint: disable=ungrouped-imports try: import reflection_pb2 as _reflection_pb2 except ImportError: from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 - +# pylint: enable=ungrouped-imports class ReflectionServicer(BaseReflectionServicer): """Servicer handling RPCs for service statuses.""" diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index d8c2bd25c4ff0..9604eac9221cf 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -15,7 +15,6 @@ # limitations under the License. load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", From a8a21bcef473b3f36ae678f318f5cd9544d0e64a Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Wed, 18 Dec 2024 23:51:00 +0000 Subject: [PATCH 23/26] Run balck_code --- src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index cd1f0ce9b98bb..d3980f50b1d83 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -26,6 +26,7 @@ from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 # pylint: enable=ungrouped-imports + class ReflectionServicer(BaseReflectionServicer): """Servicer handling RPCs for service statuses.""" From 9f15588b648093ec5a9e8ed8aac30a2cbf03e2c2 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Thu, 20 Feb 2025 20:46:12 +0000 Subject: [PATCH 24/26] Test move proto file --- src/proto/grpc/channelz/BUILD | 22 +- src/python/grpcio_channelz/.gitignore | 1 - .../grpc_channelz/v1/BUILD.bazel | 18 +- .../grpc_channelz/v1/_async.py | 12 +- .../grpc_channelz/v1/_servicer.py | 10 +- .../grpc_channelz/v1/channelz.proto | 564 ++++++++++++++++++ .../grpc_channelz/v1/channelz.py | 8 +- .../tests/channelz/_channelz_servicer_test.py | 10 +- 8 files changed, 598 insertions(+), 47 deletions(-) create mode 100644 src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD index f1ae411f1e6ce..ca69ebc8eb87b 100644 --- a/src/proto/grpc/channelz/BUILD +++ b/src/proto/grpc/channelz/BUILD @@ -32,17 +32,17 @@ grpc_proto_library( well_known_protos = True, ) -proto_library( - name = "channelz_proto_descriptors", - srcs = ["channelz.proto"], - strip_import_prefix = "/src/proto/grpc/channelz", - deps = [ - "@com_google_protobuf//:any_proto", - "@com_google_protobuf//:duration_proto", - "@com_google_protobuf//:timestamp_proto", - "@com_google_protobuf//:wrappers_proto", - ], -) +# proto_library( +# name = "channelz_proto_descriptors", +# srcs = ["channelz.proto"], +# # strip_import_prefix = "/src/proto/grpc/channelz", +# deps = [ +# "@com_google_protobuf//:any_proto", +# "@com_google_protobuf//:duration_proto", +# "@com_google_protobuf//:timestamp_proto", +# "@com_google_protobuf//:wrappers_proto", +# ], +# ) filegroup( name = "channelz_proto_file", diff --git a/src/python/grpcio_channelz/.gitignore b/src/python/grpcio_channelz/.gitignore index 0c5da6b5af1d4..129e3d2b6238d 100644 --- a/src/python/grpcio_channelz/.gitignore +++ b/src/python/grpcio_channelz/.gitignore @@ -1,4 +1,3 @@ -*.proto *_pb2.py *_pb2_grpc.py build/ diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index dc0a79f83260b..f0a284086fe24 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -12,18 +12,32 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) +proto_library( + name = "channelz_proto_descriptors", + srcs = ["channelz.proto"], + deps = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:timestamp_proto", + "@com_google_protobuf//:wrappers_proto", + ], +) + py_proto_library( name = "channelz_py_pb2", - deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], + # deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], + deps = [":channelz_proto_descriptors"], ) py_grpc_library( name = "channelz_py_pb2_grpc", - srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], + # srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], + srcs = [":channelz_proto_descriptors"], strip_prefixes = ["src.python.grpcio_channelz."], deps = [":channelz_py_pb2"], ) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index d612df8d076d4..875e0a5904efa 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -16,16 +16,8 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import channelz_pb2 as _channelz_pb2 - import channelz_pb2_grpc as _channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc -# pylint: enable=ungrouped-imports - +from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """AsyncIO servicer for handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index fab3f24b6829c..8c8631880c323 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -17,14 +17,8 @@ import grpc from grpc._cython import cygrpc -# Bazel build uses another path. -try: - import channelz_pb2 as _channelz_pb2 - import channelz_pb2_grpc as _channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc - +from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto new file mode 100644 index 0000000000000..d0781094ea8be --- /dev/null +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.proto @@ -0,0 +1,564 @@ +// Copyright 2018 The gRPC 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 +// +// http://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. + +// This file defines an interface for exporting monitoring information +// out of gRPC servers. See the full design at +// https://github.com/grpc/proposal/blob/master/A14-channelz.md +// +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/channelz/v1/channelz.proto + +syntax = "proto3"; + +package grpc.channelz.v1; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option go_package = "google.golang.org/grpc/channelz/grpc_channelz_v1"; +option java_multiple_files = true; +option java_package = "io.grpc.channelz.v1"; +option java_outer_classname = "ChannelzProto"; + +// Channel is a logical grouping of channels, subchannels, and sockets. +message Channel { + // The identifier for this channel. This should be set. + ChannelRef ref = 1; + // Data specific to this channel. + ChannelData data = 2; + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + + // There are no ordering guarantees on the order of channel refs. + // There may not be cycles in the ref graph. + // A channel ref may be present in more than one channel or subchannel. + repeated ChannelRef channel_ref = 3; + + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + // There are no ordering guarantees on the order of subchannel refs. + // There may not be cycles in the ref graph. + // A sub channel ref may be present in more than one channel or subchannel. + repeated SubchannelRef subchannel_ref = 4; + + // There are no ordering guarantees on the order of sockets. + repeated SocketRef socket_ref = 5; +} + +// Subchannel is a logical grouping of channels, subchannels, and sockets. +// A subchannel is load balanced over by it's ancestor +message Subchannel { + // The identifier for this channel. + SubchannelRef ref = 1; + // Data specific to this channel. + ChannelData data = 2; + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + + // There are no ordering guarantees on the order of channel refs. + // There may not be cycles in the ref graph. + // A channel ref may be present in more than one channel or subchannel. + repeated ChannelRef channel_ref = 3; + + // At most one of 'channel_ref+subchannel_ref' and 'socket' is set. + // There are no ordering guarantees on the order of subchannel refs. + // There may not be cycles in the ref graph. + // A sub channel ref may be present in more than one channel or subchannel. + repeated SubchannelRef subchannel_ref = 4; + + // There are no ordering guarantees on the order of sockets. + repeated SocketRef socket_ref = 5; +} + +// These come from the specified states in this document: +// https://github.com/grpc/grpc/blob/master/doc/connectivity-semantics-and-api.md +message ChannelConnectivityState { + enum State { + UNKNOWN = 0; + IDLE = 1; + CONNECTING = 2; + READY = 3; + TRANSIENT_FAILURE = 4; + SHUTDOWN = 5; + } + State state = 1; +} + +// Channel data is data related to a specific Channel or Subchannel. +message ChannelData { + // The connectivity state of the channel or subchannel. Implementations + // should always set this. + ChannelConnectivityState state = 1; + + // The target this channel originally tried to connect to. May be absent + string target = 2; + + // A trace of recent events on the channel. May be absent. + ChannelTrace trace = 3; + + // The number of calls started on the channel + int64 calls_started = 4; + // The number of calls that have completed with an OK status + int64 calls_succeeded = 5; + // The number of calls that have completed with a non-OK status + int64 calls_failed = 6; + + // The last time a call was started on the channel. + google.protobuf.Timestamp last_call_started_timestamp = 7; +} + +// A trace event is an interesting thing that happened to a channel or +// subchannel, such as creation, address resolution, subchannel creation, etc. +message ChannelTraceEvent { + // High level description of the event. + string description = 1; + // The supported severity levels of trace events. + enum Severity { + CT_UNKNOWN = 0; + CT_INFO = 1; + CT_WARNING = 2; + CT_ERROR = 3; + } + // the severity of the trace event + Severity severity = 2; + // When this event occurred. + google.protobuf.Timestamp timestamp = 3; + // ref of referenced channel or subchannel. + // Optional, only present if this event refers to a child object. For example, + // this field would be filled if this trace event was for a subchannel being + // created. + oneof child_ref { + ChannelRef channel_ref = 4; + SubchannelRef subchannel_ref = 5; + } +} + +// ChannelTrace represents the recent events that have occurred on the channel. +message ChannelTrace { + // Number of events ever logged in this tracing object. This can differ from + // events.size() because events can be overwritten or garbage collected by + // implementations. + int64 num_events_logged = 1; + // Time that this channel was created. + google.protobuf.Timestamp creation_timestamp = 2; + // List of events that have occurred on this channel. + repeated ChannelTraceEvent events = 3; +} + +// ChannelRef is a reference to a Channel. +message ChannelRef { + // The globally unique id for this channel. Must be a positive number. + int64 channel_id = 1; + // An optional name associated with the channel. + string name = 2; + // Intentionally don't use field numbers from other refs. + reserved 3, 4, 5, 6, 7, 8; +} + +// SubchannelRef is a reference to a Subchannel. +message SubchannelRef { + // The globally unique id for this subchannel. Must be a positive number. + int64 subchannel_id = 7; + // An optional name associated with the subchannel. + string name = 8; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 3, 4, 5, 6; +} + +// SocketRef is a reference to a Socket. +message SocketRef { + // The globally unique id for this socket. Must be a positive number. + int64 socket_id = 3; + // An optional name associated with the socket. + string name = 4; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 5, 6, 7, 8; +} + +// ServerRef is a reference to a Server. +message ServerRef { + // A globally unique identifier for this server. Must be a positive number. + int64 server_id = 5; + // An optional name associated with the server. + string name = 6; + // Intentionally don't use field numbers from other refs. + reserved 1, 2, 3, 4, 7, 8; +} + +// Server represents a single server. There may be multiple servers in a single +// program. +message Server { + // The identifier for a Server. This should be set. + ServerRef ref = 1; + // The associated data of the Server. + ServerData data = 2; + + // The sockets that the server is listening on. There are no ordering + // guarantees. This may be absent. + repeated SocketRef listen_socket = 3; +} + +// ServerData is data for a specific Server. +message ServerData { + // A trace of recent events on the server. May be absent. + ChannelTrace trace = 1; + + // The number of incoming calls started on the server + int64 calls_started = 2; + // The number of incoming calls that have completed with an OK status + int64 calls_succeeded = 3; + // The number of incoming calls that have a completed with a non-OK status + int64 calls_failed = 4; + + // The last time a call was started on the server. + google.protobuf.Timestamp last_call_started_timestamp = 5; +} + +// Information about an actual connection. Pronounced "sock-ay". +message Socket { + // The identifier for the Socket. + SocketRef ref = 1; + + // Data specific to this Socket. + SocketData data = 2; + // The locally bound address. + Address local = 3; + // The remote bound address. May be absent. + Address remote = 4; + // Security details for this socket. May be absent if not available, or + // there is no security on the socket. + Security security = 5; + + // Optional, represents the name of the remote endpoint, if different than + // the original target name. + string remote_name = 6; +} + +// SocketData is data associated for a specific Socket. The fields present +// are specific to the implementation, so there may be minor differences in +// the semantics. (e.g. flow control windows) +message SocketData { + // The number of streams that have been started. + int64 streams_started = 1; + // The number of streams that have ended successfully: + // On client side, received frame with eos bit set; + // On server side, sent frame with eos bit set. + int64 streams_succeeded = 2; + // The number of streams that have ended unsuccessfully: + // On client side, ended without receiving frame with eos bit set; + // On server side, ended without sending frame with eos bit set. + int64 streams_failed = 3; + // The number of grpc messages successfully sent on this socket. + int64 messages_sent = 4; + // The number of grpc messages received on this socket. + int64 messages_received = 5; + + // The number of keep alives sent. This is typically implemented with HTTP/2 + // ping messages. + int64 keep_alives_sent = 6; + + // The last time a stream was created by this endpoint. Usually unset for + // servers. + google.protobuf.Timestamp last_local_stream_created_timestamp = 7; + // The last time a stream was created by the remote endpoint. Usually unset + // for clients. + google.protobuf.Timestamp last_remote_stream_created_timestamp = 8; + + // The last time a message was sent by this endpoint. + google.protobuf.Timestamp last_message_sent_timestamp = 9; + // The last time a message was received by this endpoint. + google.protobuf.Timestamp last_message_received_timestamp = 10; + + // The amount of window, granted to the local endpoint by the remote endpoint. + // This may be slightly out of date due to network latency. This does NOT + // include stream level or TCP level flow control info. + google.protobuf.Int64Value local_flow_control_window = 11; + + // The amount of window, granted to the remote endpoint by the local endpoint. + // This may be slightly out of date due to network latency. This does NOT + // include stream level or TCP level flow control info. + google.protobuf.Int64Value remote_flow_control_window = 12; + + // Socket options set on this socket. May be absent if 'summary' is set + // on GetSocketRequest. + repeated SocketOption option = 13; +} + +// Address represents the address used to create the socket. +message Address { + message TcpIpAddress { + // Either the IPv4 or IPv6 address in bytes. Will be either 4 bytes or 16 + // bytes in length. + bytes ip_address = 1; + // 0-64k, or -1 if not appropriate. + int32 port = 2; + } + // A Unix Domain Socket address. + message UdsAddress { + string filename = 1; + } + // An address type not included above. + message OtherAddress { + // The human readable version of the value. This value should be set. + string name = 1; + // The actual address message. + google.protobuf.Any value = 2; + } + + oneof address { + TcpIpAddress tcpip_address = 1; + UdsAddress uds_address = 2; + OtherAddress other_address = 3; + } +} + +// Security represents details about how secure the socket is. +message Security { + message Tls { + oneof cipher_suite { + // The cipher suite name in the RFC 4346 format: + // https://tools.ietf.org/html/rfc4346#appendix-C + string standard_name = 1; + // Some other way to describe the cipher suite if + // the RFC 4346 name is not available. + string other_name = 2; + } + // the certificate used by this endpoint. + bytes local_certificate = 3; + // the certificate used by the remote endpoint. + bytes remote_certificate = 4; + } + message OtherSecurity { + // The human readable version of the value. + string name = 1; + // The actual security details message. + google.protobuf.Any value = 2; + } + oneof model { + Tls tls = 1; + OtherSecurity other = 2; + } +} + +// SocketOption represents socket options for a socket. Specifically, these +// are the options returned by getsockopt(). +message SocketOption { + // The full name of the socket option. Typically this will be the upper case + // name, such as "SO_REUSEPORT". + string name = 1; + // The human readable value of this socket option. At least one of value or + // additional will be set. + string value = 2; + // Additional data associated with the socket option. At least one of value + // or additional will be set. + google.protobuf.Any additional = 3; +} + +// For use with SocketOption's additional field. This is primarily used for +// SO_RCVTIMEO and SO_SNDTIMEO +message SocketOptionTimeout { + google.protobuf.Duration duration = 1; +} + +// For use with SocketOption's additional field. This is primarily used for +// SO_LINGER. +message SocketOptionLinger { + // active maps to `struct linger.l_onoff` + bool active = 1; + // duration maps to `struct linger.l_linger` + google.protobuf.Duration duration = 2; +} + +// For use with SocketOption's additional field. Tcp info for +// SOL_TCP and TCP_INFO. +message SocketOptionTcpInfo { + uint32 tcpi_state = 1; + + uint32 tcpi_ca_state = 2; + uint32 tcpi_retransmits = 3; + uint32 tcpi_probes = 4; + uint32 tcpi_backoff = 5; + uint32 tcpi_options = 6; + uint32 tcpi_snd_wscale = 7; + uint32 tcpi_rcv_wscale = 8; + + uint32 tcpi_rto = 9; + uint32 tcpi_ato = 10; + uint32 tcpi_snd_mss = 11; + uint32 tcpi_rcv_mss = 12; + + uint32 tcpi_unacked = 13; + uint32 tcpi_sacked = 14; + uint32 tcpi_lost = 15; + uint32 tcpi_retrans = 16; + uint32 tcpi_fackets = 17; + + uint32 tcpi_last_data_sent = 18; + uint32 tcpi_last_ack_sent = 19; + uint32 tcpi_last_data_recv = 20; + uint32 tcpi_last_ack_recv = 21; + + uint32 tcpi_pmtu = 22; + uint32 tcpi_rcv_ssthresh = 23; + uint32 tcpi_rtt = 24; + uint32 tcpi_rttvar = 25; + uint32 tcpi_snd_ssthresh = 26; + uint32 tcpi_snd_cwnd = 27; + uint32 tcpi_advmss = 28; + uint32 tcpi_reordering = 29; +} + +// Channelz is a service exposed by gRPC servers that provides detailed debug +// information. +service Channelz { + // Gets all root channels (i.e. channels the application has directly + // created). This does not include subchannels nor non-top level channels. + rpc GetTopChannels(GetTopChannelsRequest) returns (GetTopChannelsResponse); + // Gets all servers that exist in the process. + rpc GetServers(GetServersRequest) returns (GetServersResponse); + // Returns a single Server, or else a NOT_FOUND code. + rpc GetServer(GetServerRequest) returns (GetServerResponse); + // Gets all server sockets that exist in the process. + rpc GetServerSockets(GetServerSocketsRequest) returns (GetServerSocketsResponse); + // Returns a single Channel, or else a NOT_FOUND code. + rpc GetChannel(GetChannelRequest) returns (GetChannelResponse); + // Returns a single Subchannel, or else a NOT_FOUND code. + rpc GetSubchannel(GetSubchannelRequest) returns (GetSubchannelResponse); + // Returns a single Socket or else a NOT_FOUND code. + rpc GetSocket(GetSocketRequest) returns (GetSocketResponse); +} + +message GetTopChannelsRequest { + // start_channel_id indicates that only channels at or above this id should be + // included in the results. + // To request the first page, this should be set to 0. To request + // subsequent pages, the client generates this value by adding 1 to + // the highest seen result ID. + int64 start_channel_id = 1; + + // If non-zero, the server will return a page of results containing + // at most this many items. If zero, the server will choose a + // reasonable page size. Must never be negative. + int64 max_results = 2; +} + +message GetTopChannelsResponse { + // list of channels that the connection detail service knows about. Sorted in + // ascending channel_id order. + // Must contain at least 1 result, otherwise 'end' must be true. + repeated Channel channel = 1; + // If set, indicates that the list of channels is the final list. Requesting + // more channels can only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetServersRequest { + // start_server_id indicates that only servers at or above this id should be + // included in the results. + // To request the first page, this must be set to 0. To request + // subsequent pages, the client generates this value by adding 1 to + // the highest seen result ID. + int64 start_server_id = 1; + + // If non-zero, the server will return a page of results containing + // at most this many items. If zero, the server will choose a + // reasonable page size. Must never be negative. + int64 max_results = 2; +} + +message GetServersResponse { + // list of servers that the connection detail service knows about. Sorted in + // ascending server_id order. + // Must contain at least 1 result, otherwise 'end' must be true. + repeated Server server = 1; + // If set, indicates that the list of servers is the final list. Requesting + // more servers will only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetServerRequest { + // server_id is the identifier of the specific server to get. + int64 server_id = 1; +} + +message GetServerResponse { + // The Server that corresponds to the requested server_id. This field + // should be set. + Server server = 1; +} + +message GetServerSocketsRequest { + int64 server_id = 1; + // start_socket_id indicates that only sockets at or above this id should be + // included in the results. + // To request the first page, this must be set to 0. To request + // subsequent pages, the client generates this value by adding 1 to + // the highest seen result ID. + int64 start_socket_id = 2; + + // If non-zero, the server will return a page of results containing + // at most this many items. If zero, the server will choose a + // reasonable page size. Must never be negative. + int64 max_results = 3; +} + +message GetServerSocketsResponse { + // list of socket refs that the connection detail service knows about. Sorted in + // ascending socket_id order. + // Must contain at least 1 result, otherwise 'end' must be true. + repeated SocketRef socket_ref = 1; + // If set, indicates that the list of sockets is the final list. Requesting + // more sockets will only return more if they are created after this RPC + // completes. + bool end = 2; +} + +message GetChannelRequest { + // channel_id is the identifier of the specific channel to get. + int64 channel_id = 1; +} + +message GetChannelResponse { + // The Channel that corresponds to the requested channel_id. This field + // should be set. + Channel channel = 1; +} + +message GetSubchannelRequest { + // subchannel_id is the identifier of the specific subchannel to get. + int64 subchannel_id = 1; +} + +message GetSubchannelResponse { + // The Subchannel that corresponds to the requested subchannel_id. This + // field should be set. + Subchannel subchannel = 1; +} + +message GetSocketRequest { + // socket_id is the identifier of the specific socket to get. + int64 socket_id = 1; + + // If true, the response will contain only high level information + // that is inexpensive to obtain. Fields thay may be omitted are + // documented. + bool summary = 2; +} + +message GetSocketResponse { + // The Socket that corresponds to the requested socket_id. This field + // should be set. + Socket socket = 1; +} diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index 263b05431e837..b31b5cfbeef29 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -18,13 +18,7 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import channelz_pb2_grpc as _channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc -# pylint: enable=ungrouped-imports +from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py index bb6331d598335..2379ab59a3cc4 100644 --- a/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py @@ -19,14 +19,8 @@ import grpc from grpc_channelz.v1 import channelz - -# Bazel build uses another path. -try: - import channelz_pb2 - import channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc +from grpc_channelz.v1 import channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc from tests.unit import test_common from tests.unit.framework.common import test_constants From e0fbf28f74b8bc0d67012a9f7af9bdd3becb8120 Mon Sep 17 00:00:00 2001 From: Xuan Wang Date: Thu, 20 Feb 2025 23:15:04 +0000 Subject: [PATCH 25/26] Add health and reflection proto --- examples/python/debug/asyncio_get_stats.py | 10 +- examples/python/debug/get_stats.py | 10 +- .../python/health_checking/greeter_client.py | 10 +- .../python/health_checking/greeter_server.py | 12 +- examples/python/xds/server.py | 13 +- src/proto/grpc/health/v1/BUILD | 7 - src/proto/grpc/reflection/v1/BUILD | 7 - src/proto/grpc/reflection/v1alpha/BUILD | 7 - .../grpc_channelz/v1/_async.py | 4 +- .../grpc_channelz/v1/_servicer.py | 4 +- .../grpc_channelz/v1/channelz.py | 3 +- src/python/grpcio_health_checking/.gitignore | 1 - .../grpc_health/v1/BUILD.bazel | 10 +- .../grpc_health/v1/_async.py | 10 +- .../grpc_health/v1/health.proto | 63 ++++++++ .../grpc_health/v1/health.py | 10 +- src/python/grpcio_reflection/.gitignore | 1 - .../grpc_reflection/v1alpha/BUILD.bazel | 10 +- .../grpc_reflection/v1alpha/_async.py | 9 +- .../grpc_reflection/v1alpha/_base.py | 12 +- .../proto_reflection_descriptor_database.py | 28 ++-- .../grpc_reflection/v1alpha/reflection.proto | 136 ++++++++++++++++++ .../grpc_reflection/v1alpha/reflection.py | 14 +- .../grpcio_tests/tests/admin/admin_test.py | 11 +- .../health_check/_health_servicer_test.py | 10 +- .../reflection/_reflection_servicer_test.py | 10 +- .../channelz/channelz_servicer_test.py | 10 +- .../health_check/health_servicer_test.py | 10 +- .../reflection/reflection_servicer_test.py | 10 +- .../interop/xds_interop_server.py | 14 +- 30 files changed, 262 insertions(+), 204 deletions(-) create mode 100644 src/python/grpcio_health_checking/grpc_health/v1/health.proto create mode 100644 src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.proto diff --git a/examples/python/debug/asyncio_get_stats.py b/examples/python/debug/asyncio_get_stats.py index 9600e1bc51959..467d3dc75d5ff 100644 --- a/examples/python/debug/asyncio_get_stats.py +++ b/examples/python/debug/asyncio_get_stats.py @@ -18,14 +18,8 @@ import logging import grpc - -# Bazel build uses another path. -try: - import channelz_pb2 - import channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc +from grpc_channelz.v1 import channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc async def run(addr: str) -> None: diff --git a/examples/python/debug/get_stats.py b/examples/python/debug/get_stats.py index 290ebb4730bcd..ce2ac7db110ca 100644 --- a/examples/python/debug/get_stats.py +++ b/examples/python/debug/get_stats.py @@ -21,14 +21,8 @@ import logging import grpc - -# Bazel build uses another path. -try: - import channelz_pb2 - import channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc +from grpc_channelz.v1 import channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc def run(addr): diff --git a/examples/python/health_checking/greeter_client.py b/examples/python/health_checking/greeter_client.py index cb3bf785628d0..6e11369d3ea3b 100644 --- a/examples/python/health_checking/greeter_client.py +++ b/examples/python/health_checking/greeter_client.py @@ -17,17 +17,11 @@ from time import sleep import grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc -# Bazel build uses another path. -try: - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc - def unary_call(stub: helloworld_pb2_grpc.GreeterStub, message: str): response = stub.SayHello( diff --git a/examples/python/health_checking/greeter_server.py b/examples/python/health_checking/greeter_server.py index d4185b7fc709e..ed5efd522d7f3 100644 --- a/examples/python/health_checking/greeter_server.py +++ b/examples/python/health_checking/greeter_server.py @@ -20,19 +20,11 @@ import grpc from grpc_health.v1 import health +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc import helloworld_pb2 import helloworld_pb2_grpc -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc -# pylint: enable=ungrouped-imports - class Greeter(helloworld_pb2_grpc.GreeterServicer): def SayHello(self, request, context): diff --git a/examples/python/xds/server.py b/examples/python/xds/server.py index 61f5550810c16..bea103876bfe0 100644 --- a/examples/python/xds/server.py +++ b/examples/python/xds/server.py @@ -20,21 +20,12 @@ import grpc from grpc_health.v1 import health +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc from grpc_reflection.v1alpha import reflection import helloworld_pb2 import helloworld_pb2_grpc -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc -# pylint: enable=ungrouped-imports - - _DESCRIPTION = "A general purpose phony server." _LISTEN_HOST = "0.0.0.0" diff --git a/src/proto/grpc/health/v1/BUILD b/src/proto/grpc/health/v1/BUILD index 257b6e23baa1c..f6165e039284c 100644 --- a/src/proto/grpc/health/v1/BUILD +++ b/src/proto/grpc/health/v1/BUILD @@ -13,7 +13,6 @@ # limitations under the License. load("//bazel:grpc_build_system.bzl", "grpc_cc_grpc_library", "grpc_cc_proto_library", "grpc_internal_proto_library", "grpc_package") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -39,12 +38,6 @@ grpc_cc_grpc_library( deps = ["health_cc_proto"], ) -proto_library( - name = "health_proto_descriptor", - srcs = ["health.proto"], - strip_import_prefix = "/src/proto/grpc/health/v1", -) - filegroup( name = "health_proto_file", srcs = [ diff --git a/src/proto/grpc/reflection/v1/BUILD b/src/proto/grpc/reflection/v1/BUILD index 35db08e9044ab..7319477dfe9cc 100644 --- a/src/proto/grpc/reflection/v1/BUILD +++ b/src/proto/grpc/reflection/v1/BUILD @@ -13,7 +13,6 @@ # limitations under the License. load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -30,12 +29,6 @@ grpc_proto_library( srcs = ["reflection.proto"], ) -proto_library( - name = "reflection_proto_descriptor", - srcs = ["reflection.proto"], - strip_import_prefix = "/src/proto/grpc/reflection/v1", -) - filegroup( name = "reflection_proto_file", srcs = [ diff --git a/src/proto/grpc/reflection/v1alpha/BUILD b/src/proto/grpc/reflection/v1alpha/BUILD index ac69ae0e39f0f..054b7f8805893 100644 --- a/src/proto/grpc/reflection/v1alpha/BUILD +++ b/src/proto/grpc/reflection/v1alpha/BUILD @@ -13,7 +13,6 @@ # limitations under the License. load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) @@ -30,12 +29,6 @@ grpc_proto_library( srcs = ["reflection.proto"], ) -proto_library( - name = "reflection_proto_descriptor", - srcs = ["reflection.proto"], - strip_import_prefix = "/src/proto/grpc/reflection/v1alpha", -) - filegroup( name = "reflection_proto_file", srcs = [ diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py index 875e0a5904efa..47f3d6963f4a3 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_async.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_async.py @@ -15,9 +15,9 @@ from grpc.experimental import aio from grpc_channelz.v1._servicer import ChannelzServicer as _SyncChannelzServicer +import grpc_channelz.v1.channelz_pb2 as _channelz_pb2 +import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc -from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """AsyncIO servicer for handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py index 8c8631880c323..b167bef044745 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/_servicer.py @@ -16,9 +16,9 @@ from google.protobuf import json_format import grpc from grpc._cython import cygrpc +import grpc_channelz.v1.channelz_pb2 as _channelz_pb2 +import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc -from grpc_channelz.v1 import channelz_pb2 as _channelz_pb2 -from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc class ChannelzServicer(_channelz_pb2_grpc.ChannelzServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py index b31b5cfbeef29..bfd5851096973 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py +++ b/src/python/grpcio_channelz/grpc_channelz/v1/channelz.py @@ -17,8 +17,7 @@ import grpc from grpc_channelz.v1._servicer import ChannelzServicer - -from grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc +import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc _add_channelz_servicer_doc = """Add Channelz servicer to a server. diff --git a/src/python/grpcio_health_checking/.gitignore b/src/python/grpcio_health_checking/.gitignore index 432c3194f040d..6d77a3d049053 100644 --- a/src/python/grpcio_health_checking/.gitignore +++ b/src/python/grpcio_health_checking/.gitignore @@ -1,4 +1,3 @@ -*.proto *_pb2.py *_pb2_grpc.py build/ diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index 90efb149f3ff1..ade34c34d7056 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -12,18 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) +proto_library( + name = "health_proto_descriptor", + srcs = ["health.proto"], +) + py_proto_library( name = "health_py_pb2", - deps = ["//src/proto/grpc/health/v1:health_proto_descriptor"], + deps = [":health_proto_descriptor"], ) py_grpc_library( name = "health_py_pb2_grpc", - srcs = ["//src/proto/grpc/health/v1:health_proto_descriptor"], + srcs = [":health_proto_descriptor"], strip_prefixes = ["src.python.grpcio_health_checking."], deps = [":health_py_pb2"], ) diff --git a/src/python/grpcio_health_checking/grpc_health/v1/_async.py b/src/python/grpcio_health_checking/grpc_health/v1/_async.py index b3752170bfbde..3788050f21b32 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/_async.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/_async.py @@ -18,14 +18,8 @@ from typing import MutableMapping import grpc - -# Bazel build uses another path. -try: - import health_pb2 as _health_pb2 - import health_pb2_grpc as _health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 as _health_pb2 - from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc +from grpc_health.v1 import health_pb2 as _health_pb2 +from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc class HealthServicer(_health_pb2_grpc.HealthServicer): diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.proto b/src/python/grpcio_health_checking/grpc_health/v1/health.proto new file mode 100644 index 0000000000000..38843ff1e73ac --- /dev/null +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.proto @@ -0,0 +1,63 @@ +// Copyright 2015 The gRPC 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 +// +// http://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. + +// The canonical version of this proto can be found at +// https://github.com/grpc/grpc-proto/blob/master/grpc/health/v1/health.proto + +syntax = "proto3"; + +package grpc.health.v1; + +option csharp_namespace = "Grpc.Health.V1"; +option go_package = "google.golang.org/grpc/health/grpc_health_v1"; +option java_multiple_files = true; +option java_outer_classname = "HealthProto"; +option java_package = "io.grpc.health.v1"; + +message HealthCheckRequest { + string service = 1; +} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + SERVICE_UNKNOWN = 3; // Used only by the Watch method. + } + ServingStatus status = 1; +} + +service Health { + // If the requested service is unknown, the call will fail with status + // NOT_FOUND. + rpc Check(HealthCheckRequest) returns (HealthCheckResponse); + + // Performs a watch for the serving status of the requested service. + // The server will immediately send back a message indicating the current + // serving status. It will then subsequently send a new message whenever + // the service's serving status changes. + // + // If the requested service is unknown when the call is received, the + // server will send a message setting the serving status to + // SERVICE_UNKNOWN but will *not* terminate the call. If at some + // future point, the serving status of the service becomes known, the + // server will send a new message with the service's serving status. + // + // If the call terminates with status UNIMPLEMENTED, then clients + // should assume this method is not supported and should not retry the + // call. If the call terminates with any other status (including OK), + // clients should retry the call with appropriate exponential backoff. + rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); +} diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 4ab52d49befa3..db8756fa78a67 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -18,14 +18,8 @@ import threading import grpc - -# Bazel build uses another path. -try: - import health_pb2 as _health_pb2 - import health_pb2_grpc as _health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 as _health_pb2 - from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc +from grpc_health.v1 import health_pb2 as _health_pb2 +from grpc_health.v1 import health_pb2_grpc as _health_pb2_grpc if sys.version_info[0] >= 3 and sys.version_info[1] >= 6: # Exposes AsyncHealthServicer as public API. diff --git a/src/python/grpcio_reflection/.gitignore b/src/python/grpcio_reflection/.gitignore index c0befdc8eadf0..1dc3f446ff036 100644 --- a/src/python/grpcio_reflection/.gitignore +++ b/src/python/grpcio_reflection/.gitignore @@ -1,4 +1,3 @@ -*.proto *_pb2.py build/ grpcio_reflection.egg-info/ diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index e13e72efa73a1..35d86da0ec4a7 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -12,18 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) +proto_library( + name = "reflection_proto_descriptor", + srcs = ["reflection.proto"], +) + py_proto_library( name = "reflection_py_pb2", - deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], + deps = [":reflection_proto_descriptor"], ) py_grpc_library( name = "reflection_py_pb2_grpc", - srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor"], + srcs = [":reflection_proto_descriptor"], strip_prefixes = ["src.python.grpcio_reflection."], deps = ["reflection_py_pb2"], ) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py index d3980f50b1d83..88762b7d51928 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_async.py @@ -16,16 +16,9 @@ from typing import AsyncIterable import grpc +from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 from grpc_reflection.v1alpha._base import BaseReflectionServicer -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import reflection_pb2 as _reflection_pb2 -except ImportError: - from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 -# pylint: enable=ungrouped-imports - class ReflectionServicer(BaseReflectionServicer): """Servicer handling RPCs for service statuses.""" diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py index f1ab35f0a3ef0..50d671a92d73f 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/_base.py @@ -16,16 +16,8 @@ from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool import grpc - -# Bazel build uses another path. -try: - import reflection_pb2 as _reflection_pb2 - import reflection_pb2_grpc as _reflection_pb2_grpc -except ImportError: - from grpc_reflection.v1alpha import ( - reflection_pb2_grpc as _reflection_pb2_grpc, - ) - from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 +from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 +from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc _POOL = descriptor_pool.Default() diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py index 655eaa9d48260..876461b2a1748 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/proto_reflection_descriptor_database.py @@ -23,26 +23,14 @@ from google.protobuf.descriptor_database import DescriptorDatabase from google.protobuf.descriptor_pb2 import FileDescriptorProto import grpc - -# Bazel build uses another path. -try: - from reflection_pb2 import ExtensionNumberResponse - from reflection_pb2 import ExtensionRequest - from reflection_pb2 import FileDescriptorResponse - from reflection_pb2 import ListServiceResponse - from reflection_pb2 import ServerReflectionRequest - from reflection_pb2 import ServerReflectionResponse - from reflection_pb2 import ServiceResponse - from reflection_pb2_grpc import ServerReflectionStub -except ImportError: - from grpc_reflection.v1alpha.reflection_pb2 import ExtensionNumberResponse - from grpc_reflection.v1alpha.reflection_pb2 import ExtensionRequest - from grpc_reflection.v1alpha.reflection_pb2 import FileDescriptorResponse - from grpc_reflection.v1alpha.reflection_pb2 import ListServiceResponse - from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionRequest - from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionResponse - from grpc_reflection.v1alpha.reflection_pb2 import ServiceResponse - from grpc_reflection.v1alpha.reflection_pb2_grpc import ServerReflectionStub +from grpc_reflection.v1alpha.reflection_pb2 import ExtensionNumberResponse +from grpc_reflection.v1alpha.reflection_pb2 import ExtensionRequest +from grpc_reflection.v1alpha.reflection_pb2 import FileDescriptorResponse +from grpc_reflection.v1alpha.reflection_pb2 import ListServiceResponse +from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionRequest +from grpc_reflection.v1alpha.reflection_pb2 import ServerReflectionResponse +from grpc_reflection.v1alpha.reflection_pb2 import ServiceResponse +from grpc_reflection.v1alpha.reflection_pb2_grpc import ServerReflectionStub class ProtoReflectionDescriptorDatabase(DescriptorDatabase): diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.proto b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.proto new file mode 100644 index 0000000000000..816852f825345 --- /dev/null +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.proto @@ -0,0 +1,136 @@ +// Copyright 2016 gRPC 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 +// +// http://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. + +// Service exported by server reflection + +syntax = "proto3"; + +package grpc.reflection.v1alpha; + +service ServerReflection { + // The reflection service is structured as a bidirectional stream, ensuring + // all related requests go to a single server. + rpc ServerReflectionInfo(stream ServerReflectionRequest) + returns (stream ServerReflectionResponse); +} + +// The message sent by the client when calling ServerReflectionInfo method. +message ServerReflectionRequest { + string host = 1; + // To use reflection service, the client should set one of the following + // fields in message_request. The server distinguishes requests by their + // defined field and then handles them using corresponding methods. + oneof message_request { + // Find a proto file by the file name. + string file_by_filename = 3; + + // Find the proto file that declares the given fully-qualified symbol name. + // This field should be a fully-qualified symbol name + // (e.g. .[.] or .). + string file_containing_symbol = 4; + + // Find the proto file which defines an extension extending the given + // message type with the given field number. + ExtensionRequest file_containing_extension = 5; + + // Finds the tag numbers used by all known extensions of the given message + // type, and appends them to ExtensionNumberResponse in an undefined order. + // Its corresponding method is best-effort: it's not guaranteed that the + // reflection service will implement this method, and it's not guaranteed + // that this method will provide all extensions. Returns + // StatusCode::UNIMPLEMENTED if it's not implemented. + // This field should be a fully-qualified type name. The format is + // . + string all_extension_numbers_of_type = 6; + + // List the full names of registered services. The content will not be + // checked. + string list_services = 7; + } +} + +// The type name and extension number sent by the client when requesting +// file_containing_extension. +message ExtensionRequest { + // Fully-qualified type name. The format should be . + string containing_type = 1; + int32 extension_number = 2; +} + +// The message sent by the server to answer ServerReflectionInfo method. +message ServerReflectionResponse { + string valid_host = 1; + ServerReflectionRequest original_request = 2; + // The server set one of the following fields accroding to the message_request + // in the request. + oneof message_response { + // This message is used to answer file_by_filename, file_containing_symbol, + // file_containing_extension requests with transitive dependencies. As + // the repeated label is not allowed in oneof fields, we use a + // FileDescriptorResponse message to encapsulate the repeated fields. + // The reflection service is allowed to avoid sending FileDescriptorProtos + // that were previously sent in response to earlier requests in the stream. + FileDescriptorResponse file_descriptor_response = 4; + + // This message is used to answer all_extension_numbers_of_type requst. + ExtensionNumberResponse all_extension_numbers_response = 5; + + // This message is used to answer list_services request. + ListServiceResponse list_services_response = 6; + + // This message is used when an error occurs. + ErrorResponse error_response = 7; + } +} + +// Serialized FileDescriptorProto messages sent by the server answering +// a file_by_filename, file_containing_symbol, or file_containing_extension +// request. +message FileDescriptorResponse { + // Serialized FileDescriptorProto messages. We avoid taking a dependency on + // descriptor.proto, which uses proto2 only features, by making them opaque + // bytes instead. + repeated bytes file_descriptor_proto = 1; +} + +// A list of extension numbers sent by the server answering +// all_extension_numbers_of_type request. +message ExtensionNumberResponse { + // Full name of the base type, including the package name. The format + // is . + string base_type_name = 1; + repeated int32 extension_number = 2; +} + +// A list of ServiceResponse sent by the server answering list_services request. +message ListServiceResponse { + // The information of each service may be expanded in the future, so we use + // ServiceResponse message to encapsulate it. + repeated ServiceResponse service = 1; +} + +// The information of a single service used by ListServiceResponse to answer +// list_services request. +message ServiceResponse { + // Full name of a registered service, including its package name. The format + // is . + string name = 1; +} + +// The error code and error message sent by the server when an error occurs. +message ErrorResponse { + // This field uses the error codes defined in grpc::StatusCode. + int32 error_code = 1; + string error_message = 2; +} diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index f506cba7f6d67..4315ac9fcbffe 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -16,20 +16,10 @@ import sys import grpc +from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 +from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc from grpc_reflection.v1alpha._base import BaseReflectionServicer -# Bazel build uses another path. -# pylint: disable=ungrouped-imports -try: - import reflection_pb2 as _reflection_pb2 - import reflection_pb2_grpc as _reflection_pb2_grpc -except ImportError: - from grpc_reflection.v1alpha import ( - reflection_pb2_grpc as _reflection_pb2_grpc, - ) - from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 -# pylint: enable=ungrouped-imports - SERVICE_NAME = _reflection_pb2.DESCRIPTOR.services_by_name[ "ServerReflection" ].full_name diff --git a/src/python/grpcio_tests/tests/admin/admin_test.py b/src/python/grpcio_tests/tests/admin/admin_test.py index 2f4bb1e1e6b5c..9ca46dd8831fa 100644 --- a/src/python/grpcio_tests/tests/admin/admin_test.py +++ b/src/python/grpcio_tests/tests/admin/admin_test.py @@ -20,15 +20,8 @@ import grpc import grpc_admin - -# Bazel build uses another path. -try: - import channelz_pb2 - import channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc - +from grpc_channelz.v1 import channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc from grpc_csds import csds_pb2 from grpc_csds import csds_pb2_grpc diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 192201976ce5d..31580892e8163 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -22,14 +22,8 @@ import grpc from grpc_health.v1 import health - -# Bazel build uses another path. -try: - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc from tests.unit import test_common from tests.unit import thread_pool diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 8ffe2ed0a7b4e..810b56f20fba1 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -20,14 +20,8 @@ from google.protobuf import descriptor_pool import grpc from grpc_reflection.v1alpha import reflection - -# Bazel build uses another path. -try: - import reflection_pb2 - import reflection_pb2_grpc -except ImportError: - from grpc_reflection.v1alpha import reflection_pb2 - from grpc_reflection.v1alpha import reflection_pb2_grpc +from grpc_reflection.v1alpha import reflection_pb2 +from grpc_reflection.v1alpha import reflection_pb2_grpc from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 diff --git a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py index 7435c081fc3c7..07cfe67427c09 100644 --- a/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/channelz/channelz_servicer_test.py @@ -20,14 +20,8 @@ import grpc from grpc.experimental import aio from grpc_channelz.v1 import channelz - -# Bazel build uses another path. -try: - import channelz_pb2 - import channelz_pb2_grpc -except ImportError: - from grpc_channelz.v1 import channelz_pb2 - from grpc_channelz.v1 import channelz_pb2_grpc +from grpc_channelz.v1 import channelz_pb2 +from grpc_channelz.v1 import channelz_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py index 5a860f2e83a4b..3bb0f6c31c4d4 100644 --- a/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/health_check/health_servicer_test.py @@ -22,14 +22,8 @@ import grpc from grpc.experimental import aio from grpc_health.v1 import health - -# Bazel build uses another path. -try: - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc from tests.unit.framework.common import test_constants from tests_aio.unit._test_base import AioTestBase diff --git a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py index 6dc96fb81218d..d1cc2c7489173 100644 --- a/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests_aio/reflection/reflection_servicer_test.py @@ -20,14 +20,8 @@ import grpc from grpc.experimental import aio from grpc_reflection.v1alpha import reflection - -# Bazel build uses another path. -try: - import reflection_pb2 - import reflection_pb2_grpc -except ImportError: - from grpc_reflection.v1alpha import reflection_pb2 - from grpc_reflection.v1alpha import reflection_pb2_grpc +from grpc_reflection.v1alpha import reflection_pb2 +from grpc_reflection.v1alpha import reflection_pb2_grpc from src.proto.grpc.testing import empty_pb2 from src.proto.grpc.testing.proto2 import empty2_extensions_pb2 diff --git a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py index 098020f0d0948..f426bd001096d 100644 --- a/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py +++ b/src/python/grpcio_tests/tests_py3_only/interop/xds_interop_server.py @@ -25,19 +25,11 @@ import grpc from grpc_channelz.v1 import channelz +from grpc_channelz.v1 import channelz_pb2 from grpc_csm_observability import CsmOpenTelemetryPlugin from grpc_health.v1 import health as grpc_health - -# Bazel build uses another path. -try: - import channelz_pb2 - import health_pb2 - import health_pb2_grpc -except ImportError: - from grpc_health.v1 import health_pb2 - from grpc_health.v1 import health_pb2_grpc - from grpc_channelz.v1 import channelz_pb2 - +from grpc_health.v1 import health_pb2 +from grpc_health.v1 import health_pb2_grpc from grpc_reflection.v1alpha import reflection from opentelemetry.exporter.prometheus import PrometheusMetricReader from opentelemetry.sdk.metrics import MeterProvider From aad636f702aa32a7d311e53fc5fb30fc854057e1 Mon Sep 17 00:00:00 2001 From: XuanWang-Amos <24593237+XuanWang-Amos@users.noreply.github.com> Date: Thu, 20 Feb 2025 23:35:08 +0000 Subject: [PATCH 26/26] Automated change: Fix sanity tests --- bazel/python_rules.bzl | 2 +- src/proto/grpc/channelz/BUILD | 1 - src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel | 3 ++- src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel | 3 ++- .../grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel | 3 ++- test/distrib/bazel/python/BUILD | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 7ce50b8393ff9..bbc71363153eb 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -13,9 +13,9 @@ # limitations under the License. """Generates and compiles Python gRPC stubs from proto_library rules.""" +load("@com_google_protobuf//bazel:py_proto_library.bzl", protobuf_py_proto_library = "py_proto_library") load("@rules_proto//proto:defs.bzl", "ProtoInfo") load("@rules_python//python:py_info.bzl", "PyInfo") -load("@com_google_protobuf//bazel:py_proto_library.bzl", protobuf_py_proto_library = "py_proto_library") load( "//bazel:protobuf.bzl", "declare_out_files", diff --git a/src/proto/grpc/channelz/BUILD b/src/proto/grpc/channelz/BUILD index ca69ebc8eb87b..b19dda6125bea 100644 --- a/src/proto/grpc/channelz/BUILD +++ b/src/proto/grpc/channelz/BUILD @@ -13,7 +13,6 @@ # limitations under the License. load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") licenses(["notice"]) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index f0a284086fe24..5f07879f6672c 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -1,3 +1,5 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") + # Copyright 2021 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index ade34c34d7056..92e67c3b29e3a 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -1,3 +1,5 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") + # Copyright 2021 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index 35d86da0ec4a7..e40740b17b705 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -1,3 +1,5 @@ +load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") + # Copyright 2021 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_python//python:defs.bzl", "py_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library") package(default_visibility = ["//visibility:public"]) diff --git a/test/distrib/bazel/python/BUILD b/test/distrib/bazel/python/BUILD index 9604eac9221cf..e7bf21041ea8d 100644 --- a/test/distrib/bazel/python/BUILD +++ b/test/distrib/bazel/python/BUILD @@ -14,11 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", "py_grpc_library", ) +load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_library", "py_test") load("//:python_rules_test.bzl", "python_rules_test_suite")