Separate py_grpc_library and py_proto_library.

By popular demand, we'll now be offering separate py_grpc_library and
py_proto_library targets sharing the same interface as within google3.
This change necessitated some modifications to how we pull in our own
Python-level dependencies and how we make those available to those
pulling in our project via Bazel.

There is now a grpc_python_deps() Bazel workspace rule that pulls in the
appropriate dependencies, which should be called from the client
project's WORKSPACE file. A test has been added to the bazel/test/
directory to verify that this behavior works as intended.

It's worth noting that the protobuf repository's usage of Starlark
bind() caused a great deal of trouble in ensuring that we could also
pull in six.

This change also required a change in the way generated proto code is
imported in the channelz and health-check modules, as well as in their
associated tests. We were importing them two different ways, each
relative. This resulted in two different module objects being imported
into the process, which were incompatible. I am not sure exactly what
caused this behavior to begin, as this should have been possible before
this PR. As a workaround, I am simply trying two different absolute
imports and using the one that works. This should function both inside
and outside of Bazel environments.
pull/19822/head
Richard Belleville 5 years ago
parent 74b981a6a3
commit 7b2c8c27b0
  1. 43
      WORKSPACE
  2. 69
      bazel/grpc_python_deps.bzl
  3. 192
      bazel/python_rules.bzl
  4. 2
      bazel/test/python_test_repo/.gitignore
  5. 46
      bazel/test/python_test_repo/BUILD
  6. 10
      bazel/test/python_test_repo/WORKSPACE
  7. 43
      bazel/test/python_test_repo/helloworld.proto
  8. 73
      bazel/test/python_test_repo/helloworld.py
  9. 1
      bazel/test/python_test_repo/tools/bazel
  10. 16
      examples/BUILD
  11. 18
      examples/python/multiprocessing/BUILD
  12. 3
      examples/python/wait_for_ready/BUILD.bazel
  13. 10
      src/proto/grpc/channelz/BUILD
  14. 31
      src/proto/grpc/testing/BUILD
  15. 8
      src/proto/grpc/testing/proto2/BUILD.bazel
  16. 6
      src/python/grpcio/grpc/BUILD.bazel
  17. 1
      src/python/grpcio/grpc/experimental/BUILD.bazel
  18. 5
      src/python/grpcio/grpc/framework/common/BUILD.bazel
  19. 11
      src/python/grpcio/grpc/framework/foundation/BUILD.bazel
  20. 7
      src/python/grpcio/grpc/framework/interfaces/base/BUILD.bazel
  21. 5
      src/python/grpcio/grpc/framework/interfaces/face/BUILD.bazel
  22. 16
      src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel
  23. 4
      src/python/grpcio_channelz/grpc_channelz/v1/channelz.py
  24. 15
      src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel
  25. 5
      src/python/grpcio_health_checking/grpc_health/v1/health.py
  26. 17
      src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel
  27. 4
      src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py
  28. 2
      src/python/grpcio_status/grpc_status/BUILD.bazel
  29. 5
      src/python/grpcio_tests/tests/channelz/_channelz_servicer_test.py
  30. 9
      src/python/grpcio_tests/tests/health_check/_health_servicer_test.py
  31. 7
      src/python/grpcio_tests/tests/interop/BUILD.bazel
  32. 2
      src/python/grpcio_tests/tests/reflection/BUILD.bazel
  33. 5
      src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py
  34. 4
      src/python/grpcio_tests/tests/unit/BUILD.bazel
  35. 3
      third_party/BUILD
  36. 6
      third_party/enum34.BUILD
  37. 6
      third_party/futures.BUILD
  38. 6
      third_party/six.BUILD
  39. 3
      tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh

@ -18,33 +18,6 @@ register_toolchains(
"//third_party/toolchains/bazel_0.23.2_rbe_windows:cc-toolchain-x64_windows",
)
git_repository(
name = "io_bazel_rules_python",
commit = "fdbb17a4118a1728d19e638a5291b4c4266ea5b8",
remote = "https://github.com/bazelbuild/rules_python.git",
)
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
pip_import(
name = "grpc_python_dependencies",
requirements = "//:requirements.bazel.txt",
)
http_archive(
name = "cython",
build_file = "//third_party:cython.BUILD",
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
urls = [
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
)
load("//bazel:grpc_python_deps.bzl", "grpc_python_deps")
grpc_python_deps()
load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
# Create toolchain configuration for remote execution.
@ -65,3 +38,19 @@ rbe_autoconfig(
},
),
)
load("@com_github_grpc_grpc//bazel:grpc_python_deps.bzl", "grpc_python_deps")
grpc_python_deps()
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
pip_import(
name = "grpc_python_dependencies",
requirements = "@com_github_grpc_grpc//:requirements.bazel.txt",
)
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
pip_repositories()
pip_install()

@ -1,8 +1,67 @@
load("//third_party/py:python_configure.bzl", "python_configure")
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")
load("@grpc_python_dependencies//:requirements.bzl", "pip_install")
"""Load dependencies needed to compile and test the grpc python library as a 3rd-party consumer."""
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@com_github_grpc_grpc//third_party/py:python_configure.bzl", "python_configure")
def grpc_python_deps():
native.bind(
name = "six",
actual = "@six_archive//:six",
)
# protobuf binds to the name "six", so we can't use it here.
# See https://github.com/bazelbuild/bazel/issues/1952 for why bind is
# horrible.
if "six_archive" not in native.existing_rules():
http_archive(
name = "six_archive",
strip_prefix = "six-1.12.0",
build_file = "@com_github_grpc_grpc//third_party:six.BUILD",
sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
urls = ["https://files.pythonhosted.org/packages/dd/bf/4138e7bfb757de47d1f4b6994648ec67a51efe58fa907c1e11e350cddfca/six-1.12.0.tar.gz"],
)
if "enum34" not in native.existing_rules():
http_archive(
name = "enum34",
build_file = "@com_github_grpc_grpc//third_party:enum34.BUILD",
strip_prefix = "enum34-1.1.6",
sha256 = "8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1",
urls = ["https://files.pythonhosted.org/packages/bf/3e/31d502c25302814a7c2f1d3959d2a3b3f78e509002ba91aea64993936876/enum34-1.1.6.tar.gz"],
)
if "futures" not in native.existing_rules():
http_archive(
name = "futures",
build_file = "@com_github_grpc_grpc//third_party:futures.BUILD",
strip_prefix = "futures-3.3.0",
sha256 = "7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794",
urls = ["https://files.pythonhosted.org/packages/47/04/5fc6c74ad114032cd2c544c575bffc17582295e9cd6a851d6026ab4b2c00/futures-3.3.0.tar.gz"],
)
if "io_bazel_rules_python" not in native.existing_rules():
git_repository(
name = "io_bazel_rules_python",
commit = "fdbb17a4118a1728d19e638a5291b4c4266ea5b8",
remote = "https://github.com/bazelbuild/rules_python.git",
)
python_configure(name = "local_config_python")
pip_repositories()
pip_install()
native.bind(
name = "python_headers",
actual = "@local_config_python//:python_headers",
)
if "cython" not in native.existing_rules():
http_archive(
name = "cython",
build_file = "@com_github_grpc_grpc//third_party:cython.BUILD",
sha256 = "d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27",
strip_prefix = "cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c",
urls = [
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
)

@ -1,6 +1,5 @@
"""Generates and compiles Python gRPC stubs from proto_library rules."""
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load(
"//bazel:protobuf.bzl",
"get_include_protoc_args",
@ -36,35 +35,116 @@ def _generate_py_impl(context):
for file in src[ProtoInfo].transitive_imports.to_list()
]
proto_root = get_proto_root(context.label.workspace_root)
format_str = (_GENERATED_GRPC_PROTO_FORMAT if context.executable.plugin else _GENERATED_PROTO_FORMAT)
out_files = [
context.actions.declare_file(
proto_path_to_generated_filename(
proto.basename,
format_str,
_GENERATED_PROTO_FORMAT,
),
)
for proto in protos
]
arguments = []
tools = [context.executable._protoc]
if context.executable.plugin:
arguments += get_plugin_args(
context.executable.plugin,
context.attr.flags,
arguments = ([
"--python_out={}".format(
context.genfiles_dir.path,
False,
),
] + get_include_protoc_args(includes) + [
"--proto_path={}".format(context.genfiles_dir.path)
for proto in protos
])
for proto in protos:
massaged_path = proto.path
if massaged_path.startswith(context.genfiles_dir.path):
massaged_path = proto.path[len(context.genfiles_dir.path) + 1:]
arguments.append(massaged_path)
context.actions.run(
inputs = protos + includes,
tools = tools,
outputs = out_files,
executable = context.executable._protoc,
arguments = arguments,
mnemonic = "ProtocInvocation",
)
tools += [context.executable.plugin]
else:
arguments += [
"--python_out={}:{}".format(
",".join(context.attr.flags),
context.genfiles_dir.path,
return struct(files = depset(out_files))
_generate_pb2_src = rule(
attrs = {
"deps": attr.label_list(
mandatory = True,
allow_empty = False,
providers = [ProtoInfo],
),
"_protoc": attr.label(
default = Label("//external:protocol_compiler"),
providers = ["files_to_run"],
executable = True,
cfg = "host",
),
},
implementation = _generate_py_impl,
)
def py_proto_library(
name,
srcs,
**kwargs):
"""Generate python code for a protobuf.
Args:
name: The name of the target.
srcs: A list of proto_library dependencies. Must contain a single element.
"""
codegen_target = "_{}_codegen".format(name)
if len(srcs) > 1:
fail("Can only compile a single proto at a time.")
_generate_pb2_src(
name = codegen_target,
deps = srcs,
**kwargs
)
native.py_library(
name = name,
srcs = [":{}".format(codegen_target)],
deps = ["@com_google_protobuf//:protobuf_python"],
**kwargs
)
def _generate_pb2_grpc_src_impl(context):
protos = []
for src in context.attr.deps:
for file in src[ProtoInfo].direct_sources:
protos.append(_get_staged_proto_file(context, file))
includes = [
file
for src in context.attr.deps
for file in src[ProtoInfo].transitive_imports.to_list()
]
proto_root = get_proto_root(context.label.workspace_root)
out_files = [
context.actions.declare_file(
proto_path_to_generated_filename(
proto.basename,
_GENERATED_GRPC_PROTO_FORMAT,
),
)
for proto in protos
]
arguments = []
tools = [context.executable._protoc, context.executable._plugin]
arguments += get_plugin_args(
context.executable._plugin,
[],
context.genfiles_dir.path,
False,
)
arguments += get_include_protoc_args(includes)
arguments += [
"--proto_path={}".format(context.genfiles_dir.path)
@ -76,16 +156,8 @@ def _generate_py_impl(context):
massaged_path = proto.path[len(context.genfiles_dir.path) + 1:]
arguments.append(massaged_path)
well_known_proto_files = []
if context.attr.well_known_protos:
well_known_proto_directory = context.attr.well_known_protos.files.to_list(
)[0].dirname
arguments += ["-I{}".format(well_known_proto_directory + "/../..")]
well_known_proto_files = context.attr.well_known_protos.files.to_list()
context.actions.run(
inputs = protos + includes + well_known_proto_files,
inputs = protos + includes,
tools = tools,
outputs = out_files,
executable = context.executable._protoc,
@ -94,77 +166,51 @@ def _generate_py_impl(context):
)
return struct(files = depset(out_files))
__generate_py = rule(
_generate_pb2_grpc_src = rule(
attrs = {
"deps": attr.label_list(
mandatory = True,
allow_empty = False,
providers = [ProtoInfo],
),
"plugin": attr.label(
"_plugin": attr.label(
executable = True,
providers = ["files_to_run"],
cfg = "host",
default = Label("//src/compiler:grpc_python_plugin"),
),
"flags": attr.string_list(
mandatory = False,
allow_empty = True,
),
"well_known_protos": attr.label(mandatory = False),
"_protoc": attr.label(
default = Label("//external:protocol_compiler"),
executable = True,
providers = ["files_to_run"],
cfg = "host",
default = Label("//external:protocol_compiler"),
),
},
output_to_genfiles = True,
implementation = _generate_py_impl,
)
def _generate_py(well_known_protos, **kwargs):
if well_known_protos:
__generate_py(
well_known_protos = "@com_google_protobuf//:well_known_protos",
**kwargs
implementation = _generate_pb2_grpc_src_impl,
)
else:
__generate_py(**kwargs)
def py_proto_library(
def py_grpc_library(
name,
srcs,
deps,
well_known_protos = True,
proto_only = False,
**kwargs):
"""Generate python code for a protobuf.
"""Generate python code for gRPC services defined in a protobuf.
Args:
name: The name of the target.
deps: A list of dependencies. Must contain a single element.
well_known_protos: A bool indicating whether or not to include well-known
protos.
proto_only: A bool indicating whether to generate vanilla protobuf code
or to also generate gRPC code.
srcs: (List of `labels`) a single proto_library target containing the
schema of the service.
deps: (List of `labels`) a single py_proto_library target for the
proto_library in `srcs`.
"""
if len(deps) > 1:
fail("The supported length of 'deps' is 1.")
codegen_target = "_{}_codegen".format(name)
codegen_grpc_target = "_{}_grpc_codegen".format(name)
if len(srcs) > 1:
fail("Can only compile a single proto at a time.")
_generate_py(
name = codegen_target,
deps = deps,
well_known_protos = well_known_protos,
**kwargs
)
if not proto_only:
_generate_py(
_generate_pb2_grpc_src(
name = codegen_grpc_target,
deps = deps,
plugin = "//src/compiler:grpc_python_plugin",
well_known_protos = well_known_protos,
deps = srcs,
**kwargs
)
@ -172,15 +218,7 @@ def py_proto_library(
name = name,
srcs = [
":{}".format(codegen_grpc_target),
":{}".format(codegen_target),
],
deps = [requirement("protobuf")],
**kwargs
)
else:
native.py_library(
name = name,
srcs = [":{}".format(codegen_target), ":{}".format(codegen_target)],
deps = [requirement("protobuf")],
deps = [Label("//src/python/grpcio/grpc:grpcio")] + deps,
**kwargs
)

@ -0,0 +1,2 @@
bazel-*
tools/bazel-*

@ -0,0 +1,46 @@
load("@com_github_grpc_grpc//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
package(default_testonly = 1)
proto_library(
name = "helloworld_proto",
srcs = ["helloworld.proto"],
deps = [
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
py_proto_library(
name = "helloworld_py_pb2",
srcs = [":helloworld_proto"],
)
py_grpc_library(
name = "helloworld_py_pb2_grpc",
srcs = [":helloworld_proto"],
deps = [":helloworld_py_pb2"],
)
py_proto_library(
name = "duration_py_pb2",
srcs = ["@com_google_protobuf//:duration_proto"],
)
py_proto_library(
name = "timestamp_py_pb2",
srcs = ["@com_google_protobuf//:timestamp_proto"],
)
py_test(
name = "import_test",
main = "helloworld.py",
srcs = ["helloworld.py"],
deps = [
":helloworld_py_pb2",
":helloworld_py_pb2_grpc",
":duration_py_pb2",
":timestamp_py_pb2",
],
python_version = "PY3",
)

@ -0,0 +1,10 @@
local_repository(
name = "com_github_grpc_grpc",
path = "../../..",
)
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_python_deps.bzl", "grpc_python_deps")
grpc_python_deps()

@ -0,0 +1,43 @@
// Copyright 2019 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.
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
google.protobuf.Timestamp request_initiation = 2;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
google.protobuf.Duration request_duration = 2;
}

@ -0,0 +1,73 @@
# Copyright 2019 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 Python implementation of the GRPC helloworld.Greeter client."""
import contextlib
import datetime
import logging
import unittest
import grpc
import duration_pb2
import helloworld_pb2
import helloworld_pb2_grpc
_HOST = 'localhost'
_SERVER_ADDRESS = '{}:0'.format(_HOST)
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
request_in_flight = datetime.now() - request.request_initation.ToDatetime()
request_duration = duration_pb2.Duration()
request_duration.FromTimedelta(request_in_flight)
return helloworld_pb2.HelloReply(
message='Hello, %s!' % request.name,
request_duration=request_duration,
)
@contextlib.contextmanager
def _listening_server():
server = grpc.server(futures.ThreadPoolExecutor())
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
port = server.add_insecure_port(_SERVER_ADDRESS)
server.start()
try:
yield port
finally:
server.stop(0)
class ImportTest(unittest.TestCase):
def run():
with _listening_server() as port:
with grpc.insecure_channel('{}:{}'.format(_HOST, port)) as channel:
stub = helloworld_pb2_grpc.GreeterStub(channel)
request_timestamp = timestamp_pb2.Timestamp()
request_timestamp.GetCurrentTime()
response = stub.SayHello(helloworld_pb2.HelloRequest(
name='you',
request_initiation=request_timestamp,
),
wait_for_ready=True)
self.assertEqual(response.message, "Hello, you!")
self.assertGreater(response.request_duration.microseconds, 0)
if __name__ == '__main__':
logging.basicConfig()
unittest.main()

@ -0,0 +1 @@
../../../../tools/bazel

@ -18,7 +18,8 @@ package(default_visibility = ["//visibility:public"])
load("//bazel:grpc_build_system.bzl", "grpc_proto_library")
load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
grpc_proto_library(
name = "auth_sample",
@ -60,13 +61,20 @@ grpc_proto_library(
)
proto_library(
name = "helloworld_proto_descriptor",
name = "protos/helloworld_proto",
srcs = ["protos/helloworld.proto"],
)
py_proto_library(
name = "py_helloworld",
deps = [":helloworld_proto_descriptor"],
name = "helloworld_py_pb2",
srcs = [":protos/helloworld_proto"],
deps = [requirement('protobuf')],
)
py_grpc_library(
name = "helloworld_py_pb2_grpc",
srcs = [":protos/helloworld_proto"],
deps = [":helloworld_py_pb2"],
)
cc_binary(

@ -14,8 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
proto_library(
name = "prime_proto",
@ -24,8 +23,13 @@ proto_library(
py_proto_library(
name = "prime_proto_pb2",
deps = [":prime_proto"],
well_known_protos = False,
srcs = [":prime_proto"],
)
py_grpc_library(
name = "prime_proto_pb2_grpc",
srcs = [":prime_proto"],
deps = [":prime_proto_pb2"],
)
py_binary(
@ -35,6 +39,7 @@ py_binary(
deps = [
"//src/python/grpcio/grpc:grpcio",
":prime_proto_pb2",
":prime_proto_pb2_grpc",
],
srcs_version = "PY3",
)
@ -45,9 +50,10 @@ py_binary(
srcs = ["server.py"],
deps = [
"//src/python/grpcio/grpc:grpcio",
":prime_proto_pb2"
":prime_proto_pb2",
":prime_proto_pb2_grpc",
] + select({
"//conditions:default": [requirement("futures")],
"//conditions:default": ["@futures//:futures"],
"//:python3": [],
}),
srcs_version = "PY3",

@ -20,7 +20,8 @@ py_library(
srcs = ["wait_for_ready_example.py"],
deps = [
"//src/python/grpcio/grpc:grpcio",
"//examples:py_helloworld",
"//examples:helloworld_py_pb2",
"//examples:helloworld_py_pb2_grpc",
],
)

@ -27,7 +27,15 @@ grpc_proto_library(
proto_library(
name = "channelz_proto_descriptors",
srcs = ["channelz.proto"],
srcs = [
"channelz.proto",
],
deps = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:wrappers_proto",
],
)
filegroup(

@ -16,7 +16,7 @@ licenses(["notice"]) # Apache v2
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
grpc_package(
name = "testing",
@ -75,8 +75,14 @@ proto_library(
)
py_proto_library(
name = "py_empty_proto",
deps = [":empty_proto_descriptor"],
name = "empty_py_pb2",
srcs = [":empty_proto_descriptor"],
)
py_grpc_library(
name = "empty_py_pb2_grpc",
srcs = [":empty_proto_descriptor"],
deps = [":empty_py_pb2"],
)
grpc_proto_library(
@ -92,7 +98,13 @@ proto_library(
py_proto_library(
name = "py_messages_proto",
deps = [":messages_proto_descriptor"],
srcs = [":messages_proto_descriptor"],
)
py_grpc_library(
name = "messages_py_pb2_grpc",
srcs = [":messages_proto_descriptor"],
deps = [":py_messages_proto"],
)
grpc_proto_library(
@ -196,7 +208,12 @@ proto_library(
py_proto_library(
name = "py_test_proto",
deps = [
":test_proto_descriptor",
],
srcs = [":test_proto_descriptor"],
)
py_grpc_library(
name = "test_py_pb2_grpc",
srcs = [":test_proto_descriptor"],
deps = [":py_test_proto"],
)

@ -10,9 +10,7 @@ proto_library(
py_proto_library(
name = "empty2_proto",
deps = [
":empty2_proto_descriptor",
],
srcs = [":empty2_proto_descriptor"],
)
proto_library(
@ -25,8 +23,6 @@ proto_library(
py_proto_library(
name = "empty2_extensions_proto",
deps = [
":empty2_extensions_proto_descriptor",
],
srcs = [":empty2_extensions_proto_descriptor"],
)

@ -1,5 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(
@ -16,9 +14,9 @@ py_library(
"//src/python/grpcio/grpc/_cython:cygrpc",
"//src/python/grpcio/grpc/experimental",
"//src/python/grpcio/grpc/framework",
requirement('six'),
"@six_archive//:six",
] + select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
data = [

@ -1,4 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(

@ -1,4 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(
@ -14,7 +13,7 @@ py_library(
name = "cardinality",
srcs = ["cardinality.py"],
deps = select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)
@ -23,7 +22,7 @@ py_library(
name = "style",
srcs = ["style.py"],
deps = select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)

@ -1,4 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(
@ -23,9 +22,9 @@ py_library(
name = "callable_util",
srcs = ["callable_util.py"],
deps = [
requirement("six"),
"//external:six",
] + select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)
@ -34,7 +33,7 @@ py_library(
name = "future",
srcs = ["future.py"],
deps = [
requirement("six"),
"//external:six",
],
)
@ -42,7 +41,7 @@ py_library(
name = "logging_pool",
srcs = ["logging_pool.py"],
deps = select({
"//conditions:default": [requirement('futures'),],
"//conditions:default": ["@futures//:futures",],
"//:python3": [],
}),
)
@ -59,6 +58,6 @@ py_library(
name = "stream",
srcs = ["stream.py"],
deps = [
requirement("six"),
"//external:six",
],
)

@ -1,4 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(
@ -15,9 +14,9 @@ py_library(
srcs = ["base.py"],
deps = [
"//src/python/grpcio/grpc/framework/foundation:abandonment",
requirement("six"),
"//external:six",
] + select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)
@ -26,7 +25,7 @@ py_library(
name = "utilities",
srcs = ["utilities.py"],
deps = select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)

@ -1,4 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_library(
@ -16,9 +15,9 @@ py_library(
deps = [
"//src/python/grpcio/grpc/framework/foundation",
"//src/python/grpcio/grpc/framework/common",
requirement("six"),
"//external:six",
] + select({
"//conditions:default": [requirement('enum34'),],
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
}),
)

@ -1,17 +1,23 @@
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
package(default_visibility = ["//visibility:public"])
py_proto_library(
name = "py_channelz_proto",
well_known_protos = True,
deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"],
name = "channelz_py_pb2",
srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"],
)
py_grpc_library(
name = "channelz_py_pb2_grpc",
srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"],
deps = [":channelz_py_pb2"],
)
py_library(
name = "grpc_channelz",
srcs = ["channelz.py",],
deps = [
":py_channelz_proto",
":channelz_py_pb2",
":channelz_py_pb2_grpc",
"//src/python/grpcio/grpc:grpcio",
],
imports=["../../",],

@ -16,6 +16,10 @@
import grpc
from grpc._cython import cygrpc
try:
from src.python.grpcio_channelz.grpc_channelz.v1 import channelz_pb2 as _channelz_pb2
from src.python.grpcio_channelz.grpc_channelz.v1 import channelz_pb2_grpc as _channelz_pb2_grpc
except ImportError:
import grpc_channelz.v1.channelz_pb2 as _channelz_pb2
import grpc_channelz.v1.channelz_pb2_grpc as _channelz_pb2_grpc

@ -1,16 +1,23 @@
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
package(default_visibility = ["//visibility:public"])
py_proto_library(
name = "py_health_proto",
deps = ["//src/proto/grpc/health/v1:health_proto_descriptor",],
name = "health_py_pb2",
srcs = ["//src/proto/grpc/health/v1:health_proto_descriptor",],
)
py_grpc_library(
name = "health_py_pb2_grpc",
srcs = ["//src/proto/grpc/health/v1:health_proto_descriptor",],
deps = [":health_py_pb2"],
)
py_library(
name = "grpc_health",
srcs = ["health.py",],
deps = [
":py_health_proto",
":health_py_pb2",
":health_py_pb2_grpc",
"//src/python/grpcio/grpc:grpcio",
],
imports=["../../",],

@ -18,6 +18,11 @@ import threading
import grpc
# Import using an absolute path to ensure no duplicate loaded modules.
try:
from src.python.grpcio_health_checking.grpc_health.v1 import health_pb2 as _health_pb2
from src.python.grpcio_health_checking.grpc_health.v1 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

@ -1,20 +1,27 @@
load("//bazel:python_rules.bzl", "py_proto_library")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
py_proto_library(
name = "py_reflection_proto",
deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor",],
name = "reflection_py_pb2",
srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor",],
)
py_grpc_library(
name = "reflection_py_pb2_grpc",
srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor",],
deps = ["reflection_py_pb2"],
)
py_library(
name = "grpc_reflection",
srcs = ["reflection.py",],
deps = [
":py_reflection_proto",
":reflection_py_pb2",
":reflection_py_pb2_grpc",
"//src/python/grpcio/grpc:grpcio",
requirement('protobuf'),
"@com_google_protobuf//:protobuf_python",
],
imports=["../../",],
)

@ -17,6 +17,10 @@ import grpc
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor_pool
try:
from src.python.grpcio_reflection.grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2
from src.python.grpcio_reflection.grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc
except ImportError:
from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2
from grpc_reflection.v1alpha import reflection_pb2_grpc as _reflection_pb2_grpc

@ -7,7 +7,7 @@ py_library(
srcs = ["rpc_status.py",],
deps = [
"//src/python/grpcio/grpc:grpcio",
requirement('protobuf'),
"@com_google_protobuf//:protobuf_python",
requirement('googleapis-common-protos'),
],
imports=["../",],

@ -18,6 +18,11 @@ import unittest
from concurrent import futures
import grpc
try:
from src.python.grpcio_channelz.grpc_channelz.v1 import channelz
from src.python.grpcio_channelz.grpc_channelz.v1 import channelz_pb2
from src.python.grpcio_channelz.grpc_channelz.v1 import channelz_pb2_grpc
except ImportError:
from grpc_channelz.v1 import channelz
from grpc_channelz.v1 import channelz_pb2
from grpc_channelz.v1 import channelz_pb2_grpc

@ -13,11 +13,19 @@
# limitations under the License.
"""Tests of grpc_health.v1.health."""
import logging
import threading
import time
import unittest
import grpc
# Import using an absolute path to ensure no duplicate loaded modules.
try:
from src.python.grpcio_health_checking.grpc_health.v1 import health
from src.python.grpcio_health_checking.grpc_health.v1 import health_pb2
from src.python.grpcio_health_checking.grpc_health.v1 import health_pb2_grpc
except ImportError:
from grpc_health.v1 import health
from grpc_health.v1 import health_pb2
from grpc_health.v1 import health_pb2_grpc
@ -276,4 +284,5 @@ class HealthServicerBackwardsCompatibleWatchTest(BaseWatchTests.WatchTests):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -31,9 +31,12 @@ py_library(
deps = [
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_tests/tests:bazel_namespace_package_hack",
"//src/proto/grpc/testing:py_empty_proto",
"//src/proto/grpc/testing:empty_py_pb2",
"//src/proto/grpc/testing:empty_py_pb2_grpc",
"//src/proto/grpc/testing:py_messages_proto",
"//src/proto/grpc/testing:messages_py_pb2_grpc",
"//src/proto/grpc/testing:py_test_proto",
"//src/proto/grpc/testing:test_py_pb2_grpc",
requirement("google-auth"),
requirement("requests"),
requirement("urllib3"),
@ -59,7 +62,7 @@ py_library(
srcs = ["service.py"],
imports = ["../../"],
deps = [
"//src/proto/grpc/testing:py_empty_proto",
"//src/proto/grpc/testing:empty_py_pb2",
"//src/proto/grpc/testing:py_messages_proto",
"//src/proto/grpc/testing:py_test_proto",
"//src/python/grpcio/grpc:grpcio",

@ -12,7 +12,7 @@ py_test(
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_reflection/grpc_reflection/v1alpha:grpc_reflection",
"//src/python/grpcio_tests/tests/unit:test_common",
"//src/proto/grpc/testing:py_empty_proto",
"//src/proto/grpc/testing:empty_py_pb2",
"//src/proto/grpc/testing/proto2:empty2_extensions_proto",
"//src/proto/grpc/testing/proto2:empty2_proto",
requirement('protobuf'),

@ -16,6 +16,11 @@
import unittest
import grpc
try:
from src.python.grpcio_reflection.grpc_reflection.v1alpha import reflection
from src.python.grpcio_reflection.grpc_reflection.v1alpha import reflection_pb2
from src.python.grpcio_reflection.grpc_reflection.v1alpha import reflection_pb2_grpc
except ImportError:
from grpc_reflection.v1alpha import reflection
from grpc_reflection.v1alpha import reflection_pb2
from grpc_reflection.v1alpha import reflection_pb2_grpc

@ -1,5 +1,3 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
package(default_visibility = ["//visibility:public"])
GRPCIO_TESTS_UNIT = [
@ -89,7 +87,7 @@ py_library(
":_tcp_proxy",
"//src/python/grpcio_tests/tests/unit/framework/common",
"//src/python/grpcio_tests/tests/testing",
requirement('six'),
"//external:six"
],
imports=["../../",],
data=[

3
third_party/BUILD vendored

@ -8,4 +8,7 @@ exports_files([
"zope_interface.BUILD",
"constantly.BUILD",
"cython.BUILD",
"six.BUILD",
"enum34.BUILD",
"futures.BUILD",
])

@ -0,0 +1,6 @@
py_library(
name = "enum34",
srcs = ["enum/__init__.py"],
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
)

@ -0,0 +1,6 @@
py_library(
name = "futures",
srcs = glob(["concurrent/**/*.py"]),
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
)

@ -0,0 +1,6 @@
py_library(
name = "six",
srcs = ["six.py"],
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
)

@ -29,3 +29,6 @@ bazel test --spawn_strategy=standalone --genrule_strategy=standalone --test_outp
bazel clean --expunge
bazel test --config=python3 --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //src/python/...
bazel test --config=python3 --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //examples/python/...
(cd bazel/test/python_test_repo;
bazel test --test_output=errors //...
)

Loading…
Cancel
Save